From e3bb2c5d7a7bb9f6ebabf9a2719a759007f7f63d Mon Sep 17 00:00:00 2001 From: SebastianEbert <sebastian.ebert@tu-dresden.de> Date: Fri, 13 May 2022 11:15:31 +0200 Subject: [PATCH] update build --- .gitlab-ci.yml | 14 +- build.gradle | 222 ++++++--- gradle.properties | 6 +- .../st/pnml/base/constants/PnmlConstants.java | 0 .../base/data/ClauseValuesDefinition.java | 0 .../base/data/CommunicatorInformation.java | 2 - src/main/jastadd/{ => base}/Constraints.jrag | 0 src/main/jastadd/{ => base}/Graphviz.jrag | 0 src/main/jastadd/{ => base}/Navigation.jrag | 0 src/main/jastadd/{ => base}/References.jrag | 2 +- src/main/jastadd/{ => base}/Util.jadd | 7 +- .../jastadd/base/checking/TinaAccessor.jadd | 126 ++++++ .../clauses/ExpressionParser.beaver} | 0 .../{ => base}/clauses/expressions.flex | 2 +- .../{ => base}/clauses/expressions.jadd | 0 .../{ => base}/clauses/expressions.relast | 0 src/main/jastadd/base/data/Tuples.jadd | 43 ++ .../base/distribution/DistributedPN.jadd | 52 +++ .../{ => base}/distribution/Filtering.jadd | 0 .../base/export/ComplexElementsConverter.jadd | 116 +++++ .../jastadd/base/export/PnmlExporter.jadd | 365 +++++++++++++++ .../export/PrimitiveElementsConverter.jadd | 207 +++++++++ src/main/jastadd/{ => base}/io/IoPN.jadd | 6 +- src/main/jastadd/{ => base}/io/IoPN.relast | 0 .../jastadd/{ => base}/marking/Execution.jadd | 0 .../jastadd/{ => base}/marking/Marking.jrag | 0 .../jastadd/{ => base}/marking/Marking.relast | 0 .../jastadd/{ => base}/marking/Printing.jrag | 0 .../base/parsing/PnmlParseException.jadd | 18 + src/main/jastadd/base/parsing/PnmlParser.jadd | 69 +++ .../base/parsing/PnmlParserInternal.jadd | 422 ++++++++++++++++++ .../base/parsing/PnmlSignalParser.jadd | 222 +++++++++ .../base/parsing/ToolSpecificsParser.jadd | 375 ++++++++++++++++ .../resolving/PnmlRefTransitionResolver.jadd | 54 +++ .../transforming/PnmlReferenceFlatter.jadd | 140 ++++++ .../jastadd/base/transforming/PnmlSlicer.jadd | 96 ++++ .../jastadd/distribution/DistributedPN.jadd | 52 --- .../pnml/base/parsing/PnmlParseException.java | 17 - .../inf/st/pnml/base/parsing/PnmlParser.java | 71 --- .../pnml/base/parsing/PnmlParserInternal.java | 422 ------------------ .../parsing/PnmlRefTransitionResolver.java | 53 --- .../pnml/base/parsing/PnmlSignalParser.java | 304 ------------- .../base/parsing/ToolSpecificsParser.java | 382 ---------------- .../inf/st/pnml/base/tina/TinaAccessor.java | 129 ------ .../transforming/PnmlReferenceFlatter.java | 138 ------ .../st/pnml/base/transforming/PnmlSlicer.java | 94 ---- .../resources/PnmlRelAstVersion.properties | 2 + 47 files changed, 2492 insertions(+), 1738 deletions(-) rename src/{main => data}/java/de/tudresden/inf/st/pnml/base/constants/PnmlConstants.java (100%) rename src/{main => data}/java/de/tudresden/inf/st/pnml/base/data/ClauseValuesDefinition.java (100%) rename src/{main => data}/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java (96%) rename src/main/jastadd/{ => base}/Constraints.jrag (100%) rename src/main/jastadd/{ => base}/Graphviz.jrag (100%) rename src/main/jastadd/{ => base}/Navigation.jrag (100%) rename src/main/jastadd/{ => base}/References.jrag (94%) rename src/main/jastadd/{ => base}/Util.jadd (72%) create mode 100644 src/main/jastadd/base/checking/TinaAccessor.jadd rename src/main/jastadd/{clauses/Parser.beaver => base/clauses/ExpressionParser.beaver} (100%) rename src/main/jastadd/{ => base}/clauses/expressions.flex (90%) rename src/main/jastadd/{ => base}/clauses/expressions.jadd (100%) rename src/main/jastadd/{ => base}/clauses/expressions.relast (100%) create mode 100644 src/main/jastadd/base/data/Tuples.jadd create mode 100644 src/main/jastadd/base/distribution/DistributedPN.jadd rename src/main/jastadd/{ => base}/distribution/Filtering.jadd (100%) create mode 100644 src/main/jastadd/base/export/ComplexElementsConverter.jadd create mode 100644 src/main/jastadd/base/export/PnmlExporter.jadd create mode 100644 src/main/jastadd/base/export/PrimitiveElementsConverter.jadd rename src/main/jastadd/{ => base}/io/IoPN.jadd (84%) rename src/main/jastadd/{ => base}/io/IoPN.relast (100%) rename src/main/jastadd/{ => base}/marking/Execution.jadd (100%) rename src/main/jastadd/{ => base}/marking/Marking.jrag (100%) rename src/main/jastadd/{ => base}/marking/Marking.relast (100%) rename src/main/jastadd/{ => base}/marking/Printing.jrag (100%) create mode 100644 src/main/jastadd/base/parsing/PnmlParseException.jadd create mode 100644 src/main/jastadd/base/parsing/PnmlParser.jadd create mode 100644 src/main/jastadd/base/parsing/PnmlParserInternal.jadd create mode 100644 src/main/jastadd/base/parsing/PnmlSignalParser.jadd create mode 100644 src/main/jastadd/base/parsing/ToolSpecificsParser.jadd create mode 100644 src/main/jastadd/base/resolving/PnmlRefTransitionResolver.jadd create mode 100644 src/main/jastadd/base/transforming/PnmlReferenceFlatter.jadd create mode 100644 src/main/jastadd/base/transforming/PnmlSlicer.jadd delete mode 100644 src/main/jastadd/distribution/DistributedPN.jadd delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParseException.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParser.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParserInternal.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlRefTransitionResolver.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlSignalParser.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/parsing/ToolSpecificsParser.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/tina/TinaAccessor.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlReferenceFlatter.java delete mode 100644 src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlSlicer.java create mode 100644 src/main/resources/PnmlRelAstVersion.properties diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e4c1122..df50bd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ variables: stages: - build - - deploy + # - deploy before_script: - export GRADLE_USER_HOME=`pwd`/.gradle @@ -22,9 +22,9 @@ build: paths: - build/libs/*.jar -publish_dev: - image: openjdk:11 - stage: deploy - script: - - "./gradlew setDevVersionForCI" - - "./gradlew publish" +#publish_dev: + # image: openjdk:11 + # stage: deploy + # script: + # - "./gradlew setDevVersionForCI" + # - "./gradlew publish" diff --git a/build.gradle b/build.gradle index 2818ff8..d4b0993 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,23 @@ -// General configuration (plugins, settings, dependencies) +plugins { + id 'java-library' + id 'org.jastadd' version "${jastaddgradle_version}" + id 'idea' + id 'maven-publish' +} + group 'de.tudresden.inf.st' version '0.1' -apply plugin: 'java' -apply plugin: 'jastadd' -apply plugin: 'application' -apply plugin: "idea" -apply plugin: 'java-library' +//sourceCompatibility = 1.8 +//targetCompatibility = 1.8 -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java.toolchain.languageVersion = JavaLanguageVersion.of(11) -repositories.mavenCentral() - -buildscript { - repositories.mavenCentral() - dependencies { - classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.3' +repositories { + mavenCentral() + maven { + name 'gitlab-maven' + url 'https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven' } } @@ -26,17 +27,116 @@ sourceSets.main.java.srcDir "src/gen/java" jar.manifest.attributes('Main-Class': 'de.tudresden.inf.st.pnml.base.Main') configurations { + model + data + ecore relast myBeaver } +def jastaddSources = objects.sourceDirectorySet("resources", "Resources1") +jastaddSources.srcDir 'src/main' +jastaddSources.include 'jastadd/**' + +def jastaddGenSources = objects.sourceDirectorySet("resources", "Resources2") +jastaddGenSources.srcDir 'src/gen' +jastaddGenSources.include 'jastadd/pnml/*.relast', 'jastadd/pnml/*.ecore.jadd' + +sourceSets { + + data { + java { + srcDir 'src/data/java' + } + } + + model { + compileClasspath += sourceSets.data.output + java { + srcDir 'src/gen/java' + } + } + + main { + compileClasspath += sourceSets.model.output + compileClasspath += sourceSets.data.output + resources { + source(jastaddSources) + source(jastaddGenSources) + } + } + test { + compileClasspath += sourceSets.model.output + runtimeClasspath += sourceSets.model.output + } +} + +jar { + includeEmptyDirs false +} + +File genSrc = file('src/gen/java') +idea.module.generatedSourceDirs += genSrc + +def versionFile = 'src/main/resources/PnmlRelAstVersion.properties' +def oldProps = new Properties() + +try { + file(versionFile).withInputStream { stream -> oldProps.load(stream) } + version = oldProps['version'] +} catch (ignored) { + // this happens, if either the properties file is not present, or cannot be read from + throw new GradleException("File ${versionFile} not found or unreadable. Aborting.") +} + +// set using `gradle newVersion -Pvalue=<VERSION>` +task newVersion() { + doFirst { + def props = new Properties() + props['version'] = value + props.store(file(versionFile).newWriter(), null) + } +} + +task printVersion() { + doLast { + println(version) + } +} + +task setDevVersionForCI() { + doFirst { + def props = new Properties() + props['version'] = version + "-$System.env.CI_PIPELINE_IID" + props.store(file(versionFile).newWriter(), null) + } +} + dependencies { implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jackson_version}" - implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' + + runtimeOnly group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' + compileOnly group: 'net.sf.beaver', name: 'beaver-ant', version: '0.9.11' + modelRuntimeOnly group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' + modelCompileOnly group: 'net.sf.beaver', name: 'beaver-ant', version: '0.9.11' + + // logging + modelImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' + modelImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.13.2' implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.13.2' // pnml lib + modelImplementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore', version: '2.12.0' + modelImplementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.12.0' + modelImplementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.12.0' + modelImplementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.mwe.core', version: '1.3.13' + modelImplementation group: 'fr.lip6.pnml', name: 'fr.lip6.pnml.framework.ptnet', version: '2.2.12' + modelImplementation group: 'fr.lip6.pnml', name: 'fr.lip6.pnml.framework.utils', version: '2.2.12' + modelImplementation group: 'org.apache.ws.commons.axiom', name: 'axiom-api', version: '1.2.22' + modelImplementation group: 'org.apache.ws.commons.axiom', name: 'axiom-impl', version: '1.2.22' + modelImplementation group: 'com.thaiopensource', name: 'jing', version: '20091111' + implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore', version: '2.12.0' implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.12.0' implementation group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.12.0' @@ -47,74 +147,80 @@ dependencies { implementation group: 'org.apache.ws.commons.axiom', name: 'axiom-impl', version: '1.2.22' implementation group: 'com.thaiopensource', name: 'jing', version: '20091111' - // https://mvnrepository.com/artifact/xalan/xalan + // apache utils implementation group: 'xalan', name: 'xalan', version: '2.7.2' - // https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 - implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4' - + dataImplementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4' compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0' + // from configs myBeaver group: 'net.sf.beaver', name: 'beaver-ant', version: '0.9.11' - + myBeaver "org.jastadd:jastadd:2.3.5" relast group: 'org.jastadd', name: 'relast', version: "${relast_version}" - - jastadd2 "org.jastadd:jastadd:2.3.4" -} - -// Default run configuration -run { - mainClassName = 'de.tudresden.inf.st.pnml.base.Main' - standardInput = System.in + ecore files("libs/ecore2relast-0.1.jar") + jastadd2 "org.jastadd:jastadd:2.3.5" } // Generated files -def ecoreFile = "./src/main/resources/placeTransition.ecore" -def relastAspect = "./src/gen/jastadd/placeTransition.ecore.jadd" -def relastFile = "./src/gen/jastadd/placeTransition.relast" +def ecoreFile = './src/main/resources/placeTransition.ecore' +def ecoreRelastAspect = './src/gen/jastadd/pnml/placeTransition.ecore.jadd' +def ecoreRelastGrammar = './src/gen/jastadd/pnml/placeTransition.relast' + +def ecoreInputFiles = [ecoreFile] +def ecoreOutputFiles = [ecoreRelastAspect, + ecoreRelastGrammar] + +def relastInputFiles = [ecoreRelastGrammar, './src/main/jastadd/base/marking/Marking.relast', './src/main/jastadd/base/io/IoPN.relast', './src/main/jastadd/base/clauses/expressions.relast'] +def relastOutputFiles = ['src/gen/jastadd/pnml/placeTransition.ast', 'src/gen/jastadd/pnml/placeTransition.jadd'] + // Input relast files -def relastInputFiles = ['./src/main/jastadd/marking/Marking.relast', './src/main/jastadd/io/IoPN.relast', './src/main/jastadd/clauses/expressions.relast'] +//def relastInputFiles = ['./src/main/jastadd/marking/Marking.relast', './src/main/jastadd/io/IoPN.relast', './src/main/jastadd/clauses/expressions.relast'] // First phase: Ecore -> RelAst task ecoreToRelast(type: JavaExec) { group = 'Build' - main = "-jar" - + classpath = configurations.ecore + mainClass = 'de.tudresden.inf.st.e2j.Main' doFirst { - delete "src/gen/jastadd" - mkdir "src/gen/jastadd" + delete ecoreOutputFiles + mkdir 'src/gen/jastadd' } - args "libs/ecore2relast-0.1.jar", ecoreFile, relastFile + args ecoreFile, ecoreRelastGrammar - inputs.files file(ecoreFile) - outputs.files file(relastFile), file(relastAspect) + inputs.files ecoreInputFiles + outputs.files ecoreOutputFiles } // Second phase: RelAst -> JastAdd task relastToJastAdd(type: JavaExec) { group = 'Build' - main = "-jar" + classpath = configurations.relast + mainClass = 'org.jastadd.relast.compiler.Compiler' - args "libs/relast.jar", - "--grammarName=./src/gen/jastadd/placeTransition", - "--useJastAddNames", - "--listClass=ArrayList", + doFirst { + delete relastOutputFiles + mkdir "src/gen/jastadd" + } + + args "--useJastAddNames", + "--grammarName=src/gen/jastadd/pnml/placeTransition", + "--listClass=java.util.ArrayList", "--jastAddList=JastAddList", "--resolverHelper", - "--file", - relastFile + '--file' args relastInputFiles inputs.files relastInputFiles - outputs.files file("./src/gen/jastadd/placeTransition.ast"), file("./src/gen/jastadd/placeTransition.jadd") + outputs.files relastOutputFiles } + task generateBeaver(type: JavaExec) { inputs.files { - project.file("src/main/jastadd/clauses/Parser.beaver") + project.file("src/main/jastadd/clauses/ExpressionParser.beaver") } outputs.dir { // This closure is needed to delay reading the genDir setting. @@ -129,8 +235,8 @@ task generateBeaver(type: JavaExec) { if (!outdir.isDirectory()) { outdir.mkdirs() } - def inputFile = project.file("src/main/jastadd/clauses/Parser.beaver") - args ([ '-d', outdir.path, '-t', '-c', '-w', inputFile.path ]) + def inputFile = project.file("src/main/jastadd/base/clauses/ExpressionParser.beaver") + args(['-d', outdir.path, '-t', '-c', '-w', inputFile.path]) } } @@ -148,16 +254,16 @@ jastadd { jastadd { basedir "src/" - include "main/jastadd/**/*.ast" - include "main/jastadd/**/*.jadd" - include "main/jastadd/**/*.jrag" + include "main/jastadd/base/**/*.ast" + include "main/jastadd/base/**/*.jadd" + include "main/jastadd/base/**/*.jrag" include "gen/jastadd/**/*.ast" include "gen/jastadd/**/*.jadd" include "gen/jastadd/**/*.jrag" } scanner { - include "src/main/jastadd/clauses/expressions.flex" + include "src/main/jastadd/base/clauses/expressions.flex" } parser { @@ -167,8 +273,8 @@ jastadd { } cleanGen.doFirst { - delete "src/gen/java/de" - delete "src/gen-res/BuildInfo.properties" + delete "src/gen" + delete "src/gen-res" } module = "pnml-relast-base" @@ -187,7 +293,7 @@ jastadd { } // publish gitlab project -publishing { +/*publishing { publications { maven(MavenPublication) { from components.java @@ -206,7 +312,7 @@ publishing { } } -} +}*/ // Workflow configuration for phases relastToJastAdd.dependsOn ecoreToRelast diff --git a/gradle.properties b/gradle.properties index 20d0d23..ecdf250 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,7 @@ jackson_version = 2.9.8 apache_httpcomponents_version = 4.5.8 -relast_version = 0.3.0-137 \ No newline at end of file +relast_version = 0.3.0-137 +relast2uml_version = 0.3.7-59 +jupyter_version = 5.8.2 +assertj_version = 3.22.0 +jastaddgradle_version = 1.14.5 \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/constants/PnmlConstants.java b/src/data/java/de/tudresden/inf/st/pnml/base/constants/PnmlConstants.java similarity index 100% rename from src/main/java/de/tudresden/inf/st/pnml/base/constants/PnmlConstants.java rename to src/data/java/de/tudresden/inf/st/pnml/base/constants/PnmlConstants.java diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/data/ClauseValuesDefinition.java b/src/data/java/de/tudresden/inf/st/pnml/base/data/ClauseValuesDefinition.java similarity index 100% rename from src/main/java/de/tudresden/inf/st/pnml/base/data/ClauseValuesDefinition.java rename to src/data/java/de/tudresden/inf/st/pnml/base/data/ClauseValuesDefinition.java diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java b/src/data/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java similarity index 96% rename from src/main/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java rename to src/data/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java index b8ecbe4..06aa890 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java +++ b/src/data/java/de/tudresden/inf/st/pnml/base/data/CommunicatorInformation.java @@ -3,8 +3,6 @@ package de.tudresden.inf.st.pnml.base.data; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; -import java.util.HashMap; - public class CommunicatorInformation { // private HashMap<String, String> communicatorMapping; diff --git a/src/main/jastadd/Constraints.jrag b/src/main/jastadd/base/Constraints.jrag similarity index 100% rename from src/main/jastadd/Constraints.jrag rename to src/main/jastadd/base/Constraints.jrag diff --git a/src/main/jastadd/Graphviz.jrag b/src/main/jastadd/base/Graphviz.jrag similarity index 100% rename from src/main/jastadd/Graphviz.jrag rename to src/main/jastadd/base/Graphviz.jrag diff --git a/src/main/jastadd/Navigation.jrag b/src/main/jastadd/base/Navigation.jrag similarity index 100% rename from src/main/jastadd/Navigation.jrag rename to src/main/jastadd/base/Navigation.jrag diff --git a/src/main/jastadd/References.jrag b/src/main/jastadd/base/References.jrag similarity index 94% rename from src/main/jastadd/References.jrag rename to src/main/jastadd/base/References.jrag index 9fd4348..3c3abdd 100644 --- a/src/main/jastadd/References.jrag +++ b/src/main/jastadd/base/References.jrag @@ -6,7 +6,7 @@ aspect References { return object; } } - throw new RuntimeException(new de.tudresden.inf.st.pnml.base.parsing.PnmlParseException("Unable to resolve id " + id)); + throw new RuntimeException(new PnmlParseException("Unable to resolve id " + id)); } eq PnObject.globallyResolveArcByToken(String id) = (Arc) petriNet().resolve(id); diff --git a/src/main/jastadd/Util.jadd b/src/main/jastadd/base/Util.jadd similarity index 72% rename from src/main/jastadd/Util.jadd rename to src/main/jastadd/base/Util.jadd index fb2cf4b..47cd741 100644 --- a/src/main/jastadd/Util.jadd +++ b/src/main/jastadd/base/Util.jadd @@ -1,10 +1,11 @@ -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +//import org.apache.logging.log4j.LogManager; +// import org.apache.logging.log4j.Logger; import java.util.*; import java.util.stream.Collectors; aspect Logging { - static Logger ASTNode.logger = LogManager.getLogger(ASTNode.class); + static org.apache.logging.log4j.Logger ASTNode.logger = org.apache.logging.log4j.LogManager.getLogger(ASTNode.class); + // static org.slf4j.Logger ASTNode.logger = org.slf4j.LoggerFactory.getLogger(ASTNode.class); } aspect JastAddAPIExtension { diff --git a/src/main/jastadd/base/checking/TinaAccessor.jadd b/src/main/jastadd/base/checking/TinaAccessor.jadd new file mode 100644 index 0000000..7b54be3 --- /dev/null +++ b/src/main/jastadd/base/checking/TinaAccessor.jadd @@ -0,0 +1,126 @@ +import java.io.*; +import java.util.UUID; + +aspect TinaAccessor { + + public class TinaAccessor { + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TinaAccessor.class); + + /** + * @param inputPath + * @return path with file containing results + */ + public static String analyzePetriNet(String inputPath) throws IOException, InterruptedException { + + boolean isWindows = System.getProperty("os.name") + .toLowerCase().startsWith("windows"); + + String homeDirectory = System.getProperty("user.dir"); + ProcessBuilder tinaProcessBuilder = new ProcessBuilder(); + String fileName = "temp/tina/tina-result-" + UUID.randomUUID().toString() + ".txt"; + + File file = new File(fileName); + if (!file.exists()) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); + + FileWriter fileWriter = new FileWriter(fileName); + + // -- Linux -- + // tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", + // homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/zero-reset-correct-2.pnml"); + + if (!isWindows) { + + // testing adds subproject as path-part + if (homeDirectory.contains("pnml-relast-checker")) { + tinaProcessBuilder.command(homeDirectory + "/libs/tina-3.7.0/bin/tina", + "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", "-bcg", inputPath); + } else { + tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", + "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", "-bcg", inputPath); + } + } else { + logger.error("Windows is currently not supported. Exiting ..."); + return null; + } + + try { + + Process process = tinaProcessBuilder.start(); + //StringBuilder output = new StringBuilder(); + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + + String line; + while ((line = reader.readLine()) != null) { + fileWriter.write(line + "\n"); + } + + fileWriter.close(); + + int exitVal = process.waitFor(); + if (exitVal == 0) { + System.exit(0); + } + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + return fileName; + } + + public static boolean isPetriNetBounded(String inputPath) throws IOException { + + boolean isWindows = System.getProperty("os.name") + .toLowerCase().startsWith("windows"); + + String homeDirectory = System.getProperty("user.dir"); + ProcessBuilder tinaProcessBuilder = new ProcessBuilder(); + + if (!isWindows) { + if (homeDirectory.contains("pnml-relast-checker")) { + tinaProcessBuilder.command(homeDirectory + "/libs/tina-3.7.0/bin/tina", "-PNML", inputPath); + } else { + tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", "-PNML", inputPath); + } + } else { + logger.error("Windows is currently not supported. Exiting ..."); + return false; + } + + try { + + Process process = tinaProcessBuilder.start(); + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + + String line; + boolean isInAnalysisSection = false; + + while ((line = reader.readLine()) != null) { + if (line.startsWith("bounded") && isInAnalysisSection) { + return true; + } + if (line.startsWith("REACHABILITY ANALYSIS")) { + isInAnalysisSection = true; + } + } + + + int exitVal = process.waitFor(); + if (exitVal == 0) { + System.exit(0); + } + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/clauses/Parser.beaver b/src/main/jastadd/base/clauses/ExpressionParser.beaver similarity index 100% rename from src/main/jastadd/clauses/Parser.beaver rename to src/main/jastadd/base/clauses/ExpressionParser.beaver diff --git a/src/main/jastadd/clauses/expressions.flex b/src/main/jastadd/base/clauses/expressions.flex similarity index 90% rename from src/main/jastadd/clauses/expressions.flex rename to src/main/jastadd/base/clauses/expressions.flex index eb1089f..e370a9e 100644 --- a/src/main/jastadd/clauses/expressions.flex +++ b/src/main/jastadd/base/clauses/expressions.flex @@ -1,6 +1,6 @@ package de.tudresden.inf.st.pnml.jastadd.scanner; -import de.tudresden.inf.st.pnml.jastadd.parser.Parser.Terminals; +import de.tudresden.inf.st.pnml.jastadd.parser.ExpressionParser.Terminals; %% diff --git a/src/main/jastadd/clauses/expressions.jadd b/src/main/jastadd/base/clauses/expressions.jadd similarity index 100% rename from src/main/jastadd/clauses/expressions.jadd rename to src/main/jastadd/base/clauses/expressions.jadd diff --git a/src/main/jastadd/clauses/expressions.relast b/src/main/jastadd/base/clauses/expressions.relast similarity index 100% rename from src/main/jastadd/clauses/expressions.relast rename to src/main/jastadd/base/clauses/expressions.relast diff --git a/src/main/jastadd/base/data/Tuples.jadd b/src/main/jastadd/base/data/Tuples.jadd new file mode 100644 index 0000000..9d4e3f0 --- /dev/null +++ b/src/main/jastadd/base/data/Tuples.jadd @@ -0,0 +1,43 @@ +public class Tuple2<K, V> { + + private K _1; + private V _2; + + public Tuple2(K _1, V _2){ + this._1 = _1; + this._2 = _2; + } + + public K get_1() { + return _1; + } + + public V get_2() { + return _2; + } +} + +public class Tuple3<K, V, L> { + + private K _1; + private V _2; + private L _3; + + public Tuple3(K _1, V _2, L _3){ + this._1 = _1; + this._2 = _2; + this._3 = _3; + } + + public K get_1() { + return _1; + } + + public V get_2() { + return _2; + } + + public L get_3() { + return _3; + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/distribution/DistributedPN.jadd b/src/main/jastadd/base/distribution/DistributedPN.jadd new file mode 100644 index 0000000..bf9bb85 --- /dev/null +++ b/src/main/jastadd/base/distribution/DistributedPN.jadd @@ -0,0 +1,52 @@ +import de.tudresden.inf.st.pnml.base.data.CommunicatorInformation; + +aspect PnDistribution { + + syn TransitionInformation InputSignalTransition.getStaticTransitionInformation() { + + if(this.getMutualTransitionInformation() == null){ + TransitionInformation tInfo = ToolSpecificsParser.getTransitionInformation(this.getToolspecificList()); + return tInfo; + } + + return this.getMutualTransitionInformation(); + } + + syn PlaceInformation OutputSignalPlace.getStaticPlaceInformation() { + + if(this.getMutualPlaceInformation() == null){ + PlaceInformation tInfo = ToolSpecificsParser.getPlaceInformationInformation(this.getToolspecificList()); + return tInfo; + } + + return this.getMutualPlaceInformation(); + } + + syn lazy String RefTransition.getLocation() { + return ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefTransition.getSubNet() { + return ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefPlace.getLocation() { + return ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefPlace.getSubNet() { + return ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy Root InputSignalTransition.getInputSignalClause(){ + return ToolSpecificsParser.getClauseFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy CommunicatorInformation PetriNet.getCommunicatorInformation(){ + return ToolSpecificsParser.getCommunicatorInformationFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String Arc.getType() { + return ToolSpecificsParser.getArcTypeFromToolSpecifics(this.getToolspecificList()); + } +} \ No newline at end of file diff --git a/src/main/jastadd/distribution/Filtering.jadd b/src/main/jastadd/base/distribution/Filtering.jadd similarity index 100% rename from src/main/jastadd/distribution/Filtering.jadd rename to src/main/jastadd/base/distribution/Filtering.jadd diff --git a/src/main/jastadd/base/export/ComplexElementsConverter.jadd b/src/main/jastadd/base/export/ComplexElementsConverter.jadd new file mode 100644 index 0000000..168001c --- /dev/null +++ b/src/main/jastadd/base/export/ComplexElementsConverter.jadd @@ -0,0 +1,116 @@ +import de.tudresden.inf.st.pnml.jastadd.model.Page; +import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; +import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; +import fr.lip6.move.pnml.framework.utils.exception.VoidRepositoryException; +import fr.lip6.move.pnml.ptnet.hlapi.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +aspect ComplexElementsConverter{ + + public class ComplexElementsConverter { + + private static final Logger logger = LoggerFactory.getLogger(ComplexElementsConverter.class); + + private static StringBuffer clipToolSpecificsFormattedXmlBuffer(String toolName, String toolVersion, StringBuffer formattedXmlBuffer) { + + if (formattedXmlBuffer != null) { + + int endCharsLength = 15; + int toolNameLenth = (toolName == null) ? 0 : toolName.length(); + int toolVersionLength = (toolVersion == null) ? 0 : toolVersion.length(); + int indexGt = 0; + + if (formattedXmlBuffer.indexOf("?xml") > -1) { + indexGt = formattedXmlBuffer.indexOf(">", formattedXmlBuffer.indexOf(">") + 1); + } else { + indexGt = formattedXmlBuffer.indexOf(">"); + } + + if (toolNameLenth > 0 || toolVersionLength > 0) { + formattedXmlBuffer.delete(0, indexGt + 1); + formattedXmlBuffer.delete(formattedXmlBuffer.length() - endCharsLength, formattedXmlBuffer.length()); + } + } + return formattedXmlBuffer; + } + + public static PetriNetHLAPI convertPetriNetContainerToPnmlObject(PetriNet petriNet, PetriNetDocHLAPI doc) { + + try { + PetriNetHLAPI pn = new PetriNetHLAPI(petriNet.getId(), PNTypeHLAPI.COREMODEL, null, doc); + + if (petriNet.getName() != null && petriNet.getName() != null) { + pn.setNameHLAPI(new NameHLAPI(petriNet.getName().getText())); + } + + if (petriNet.getType().getValue() == fr.lip6.move.pnml.ptnet.PNType.PTNET_VALUE) { + pn.setTypeHLAPI(fr.lip6.move.pnml.ptnet.PNType.PTNET); + } + + for (int i = 0; i < petriNet.getNumToolspecific(); i++) { + if (petriNet.getToolspecific(i).getFormattedXMLBuffer().indexOf("</toolspecific>") > -1) { + + pn.addToolspecificsHLAPI(new ToolInfoHLAPI(petriNet.getToolspecific(i).getTool(), petriNet.getToolspecific(i).getVersion(), + clipToolSpecificsFormattedXmlBuffer(petriNet.getToolspecific(i).getTool(), petriNet.getToolspecific(i).getVersion(), + petriNet.getToolspecific(i).getFormattedXMLBuffer()), petriNet.getToolspecific(i).getToolInfoGrammarURI(), null)); + } else { + pn.addToolspecificsHLAPI(new ToolInfoHLAPI(petriNet.getToolspecific(i).getTool(), petriNet.getToolspecific(i).getVersion(), petriNet.getToolspecific(i).getFormattedXMLBuffer() + , petriNet.getToolspecific(i).getToolInfoGrammarURI(), null)); + } + } + + return pn; + + } catch (InvalidIDException | VoidRepositoryException e) { + logger.error("Could not handle: " + e.getMessage()); + e.printStackTrace(); + return null; + } + } + + public static PageHLAPI convertTopLevelPageContainerToPnmlObject(Page page, PetriNetHLAPI containerNet) { + return convertPageContainerToPnmlObject(page, null, containerNet); + } + + public static PageHLAPI convertNonTopLevelPageContainerToPnmlObject(Page page, PageHLAPI containerPage) { + return convertPageContainerToPnmlObject(page, containerPage, null); + } + + private static PageHLAPI convertPageContainerToPnmlObject(Page page, PageHLAPI containerPage, PetriNetHLAPI containerNet) { + + try { + PageHLAPI p = new PageHLAPI(page.getId()); + + if (page.getName() != null && page.getName() != null) { + p.setNameHLAPI(new NameHLAPI(page.getName().getText())); + } + + page.getToolspecificList().forEach(toolInfo -> + p.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + if (page.getNodeGraphics() != null && page.getNodeGraphics().getLine() != null && page.getNodeGraphics().getDimension() != null) { + + p.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + page.getNodeGraphics().getPosition().getX(), page.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(page.getNodeGraphics().getDimension().getX(), page.getNodeGraphics().getDimension().getY()), + null, null)); + } + + if (containerPage != null) { + p.setContainerPageHLAPI(containerPage); + } else { + p.setContainerPetriNetHLAPI(containerNet); + } + return p; + + } catch (InvalidIDException | VoidRepositoryException e) { + logger.error("Could not handle: " + e.getMessage()); + e.printStackTrace(); + return null; + } + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/export/PnmlExporter.jadd b/src/main/jastadd/base/export/PnmlExporter.jadd new file mode 100644 index 0000000..e5f6747 --- /dev/null +++ b/src/main/jastadd/base/export/PnmlExporter.jadd @@ -0,0 +1,365 @@ +import de.tudresden.inf.st.pnml.jastadd.model.*; +import fr.lip6.move.pnml.framework.general.PnmlExport; +import fr.lip6.move.pnml.framework.utils.ModelRepository; +import fr.lip6.move.pnml.framework.utils.exception.*; +import fr.lip6.move.pnml.ptnet.hlapi.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +aspect PnmlExporter{ + + public class PnmlExporter { + + private static final Logger logger = LoggerFactory.getLogger(PnmlExporter.class); + + public static String serializeToPnmlFile(PetriNet petriNet, String fileNameSuffix) throws InvalidIDException { + + ModelRepository mr = ModelRepository.getInstance(); + mr.createDocumentWorkspace("pnml-export-workspace"); + mr.setPrettyPrintStatus(true); + + // build basic document and net + PetriNetDocHLAPI doc = new PetriNetDocHLAPI(); + PetriNetHLAPI net = ComplexElementsConverter.convertPetriNetContainerToPnmlObject(petriNet, doc); + + // setup the page trees + Set<PageHLAPI> convertedPages = buildPageTrees(petriNet, net); + + // convert and include places + Set<PlaceHLAPI> convertedPlaces = convertAndIncludePlaces(petriNet, convertedPages); + + // convert and include transitions + Set<TransitionHLAPI> convertedTransitions = convertAndIncludeTransitions(petriNet, convertedPages); + + // convert and include reference transitions + Set<RefTransitionHLAPI> convertedRefTransitions = convertAndIncludeRefTransitions(petriNet, convertedPages, convertedTransitions); + + // convert and include reference places + Set<RefPlaceHLAPI> convertedRefPlaces = convertAndIncludeRefPlaces(petriNet, convertedPages, convertedPlaces); + + // convert and include arcs + Set<ArcHLAPI> convertedArcs = convertAndIncludeArcs(petriNet, convertedPages, convertedPlaces, convertedTransitions, convertedRefTransitions, convertedRefPlaces); + + // export the created objects to pnml + String homeDirectory = System.getProperty("user.dir"); + String targetPath = homeDirectory + "/temp/pnml/" + UUID.randomUUID().toString() + fileNameSuffix + ".pnml"; + boolean hasFailed = false; + + + try { + File myObj = new File(targetPath); + + if (!myObj.exists()) { + myObj.getParentFile().mkdirs(); + } + + if (myObj.createNewFile()) { + // logger.info("File created: " + myObj.getName()); + } else { + logger.info("File already exists."); + } + } catch (IOException e) { + logger.error("An error occurred."); + e.printStackTrace(); + } + + try { + PnmlExport pex = new PnmlExport(); + pex.exportObject(doc, targetPath, true); + } catch (UnhandledNetType | OCLValidationFailed unhandledNetType) { + logger.error("EXCEPTION: " + Arrays.toString(unhandledNetType.getStackTrace())); + hasFailed = true; + } catch (IOException | ValidationFailedException | BadFileFormatException | OtherException e) { + logger.error("EXCEPTION: " + Arrays.toString(e.getStackTrace())); + e.printStackTrace(); + hasFailed = true; + } + + // ctor of the workspace + try { + ModelRepository.getInstance().destroyCurrentWorkspace(); + } catch (VoidRepositoryException e) { + logger.error("EXCEPTION: " + Arrays.toString(e.getStackTrace())); + hasFailed = true; + } + + return hasFailed ? null : targetPath; + } + + private static Set<RefTransitionHLAPI> convertAndIncludeRefTransitions(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<TransitionHLAPI> convertedTransitions) { + + Set<RefTransitionHLAPI> convertedRefTransitions = new HashSet<>(); + TransitionHLAPI rootTransition = null; + + // get the root transition to construct reference tree + for (RefTransition r : petriNet.allRefTransitions()) { + if (r.getRef().isTransition()) { + for (TransitionHLAPI th : convertedTransitions) { + if (th.getId().equals(r.getRef().asTransition().getId())) { + rootTransition = th; + break; + } + } + break; + } + } + + // construct the first reference level + for (RefTransition r : petriNet.allRefTransitions()) { + assert rootTransition != null; + if (r.getRef().getId().equals(rootTransition.getId())) { + RefTransitionHLAPI rth = PrimitiveElementsConverter.convertRefTransitionToPnmlObject(r, rootTransition, null); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(r.ContainingPage().getId())) { + assert rth != null; + rth.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefTransitions.add(rth); + } + } + + // construct the remaining levels + for (RefTransition r : petriNet.allRefTransitions()) { + for (RefTransitionHLAPI convRef : convertedRefTransitions) { + if (convRef.getId().equals(r.getRef().getId())) { + RefTransitionHLAPI convertedTransition = PrimitiveElementsConverter.convertRefTransitionToPnmlObject(r, null, convRef); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(r.ContainingPage().getId())) { + assert convertedTransition != null; + convertedTransition.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefTransitions.add(convertedTransition); + } + } + } + return convertedRefTransitions; + } + + private static Set<RefPlaceHLAPI> convertAndIncludeRefPlaces(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<PlaceHLAPI> convertedPlaces) { + + Set<RefPlaceHLAPI> convertedRefPlaces = new HashSet<>(); + PlaceHLAPI rootPlace = null; + + // get the root transition to construct reference tree + for (RefPlace p : petriNet.allRefPlaces()) { + if (p.getRef().isPlace()) { + for (PlaceHLAPI ph : convertedPlaces) { + if (ph.getId().equals(p.getRef().getId())) { + rootPlace = ph; + + // construct the first reference level + for (RefPlace p_one : petriNet.allRefPlaces()) { + assert rootPlace != null; + if (p_one.getRef().getId().equals(rootPlace.getId())) { + RefPlaceHLAPI rph = PrimitiveElementsConverter.convertRefPlaceToPnmlObject(p_one, rootPlace, null); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(p_one.ContainingPage().getId())) { + assert rph != null; + rph.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefPlaces.add(rph); + } + } + + // construct the remaining levels + for (RefPlace p_tree : petriNet.allRefPlaces()) { + for (RefPlaceHLAPI convRef : convertedRefPlaces) { + if (convRef.getId().equals(p_tree.getRef().getId())) { + RefPlaceHLAPI rph = PrimitiveElementsConverter.convertRefPlaceToPnmlObject(p_tree, null, convRef); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(p_tree.ContainingPage().getId())) { + assert rph != null; + rph.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefPlaces.add(rph); + } + } + } + } + } + } + } + return convertedRefPlaces; + } + + private static Set<PlaceHLAPI> convertAndIncludePlaces(PetriNet petriNet, Set<PageHLAPI> convertedPages) { + + Set<PlaceHLAPI> convertedPlaces = new HashSet<>(); + + for (Place p : petriNet.allPlaces()) { + PlaceHLAPI convertedPlace = PrimitiveElementsConverter.convertPlaceToPnmlObject(p.asOutputSignalPlace()); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(p.ContainingPage().getId())) { + assert convertedPlace != null; + convertedPlace.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedPlaces.add(convertedPlace); + } + return convertedPlaces; + } + + private static Set<TransitionHLAPI> convertAndIncludeTransitions(PetriNet petriNet, Set<PageHLAPI> convertedPages) { + + Set<TransitionHLAPI> convertedTransitions = new HashSet<>(); + + for (Transition t : petriNet.allTransitions()) { + TransitionHLAPI convertedTransition = PrimitiveElementsConverter.convertTransitionToPnmlObject(t.asInputSignalTransition()); + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(t.ContainingPage().getId())) { + assert convertedTransition != null; + convertedTransition.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedTransitions.add(convertedTransition); + } + return convertedTransitions; + } + + private static Set<ArcHLAPI> convertAndIncludeArcs(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<PlaceHLAPI> convertedPlaces, + Set<TransitionHLAPI> convertedTransitions, Set<RefTransitionHLAPI> convertedRefTransitions, Set<RefPlaceHLAPI> convertedRefPlaces) { + + Set<ArcHLAPI> convertedArcs = new HashSet<>(); + for (Arc a : petriNet.allArcs()) { + + NodeHLAPI source = null; + NodeHLAPI target = null; + + for (TransitionHLAPI th : convertedTransitions) { + if (th.getId().equals(a.getSource().getId())) { + source = th; + break; + } + if (th.getId().equals(a.getTarget().getId())) { + target = th; + break; + } + } + + for (PlaceHLAPI ph : convertedPlaces) { + if (ph.getId().equals(a.getSource().getId())) { + source = ph; + break; + } + if (ph.getId().equals(a.getTarget().getId())) { + target = ph; + break; + } + } + + // also include arcs to/from refs + if (source == null || target == null) { + for (RefTransitionHLAPI rth : convertedRefTransitions) { + if (rth.getId().equals(a.getSource().getId())) { + source = rth; + break; + } + if (rth.getId().equals(a.getTarget().getId())) { + target = rth; + break; + } + } + + for (RefPlaceHLAPI rph : convertedRefPlaces) { + if (rph.getId().equals(a.getSource().getId())) { + source = rph; + break; + } + if (rph.getId().equals(a.getTarget().getId())) { + target = rph; + break; + } + } + } + + ArcHLAPI convertedArc = PrimitiveElementsConverter.convertArcToPnmlObject(a, source, target); + + Page containingPage = a.ContainingPage(); + + for (PageHLAPI pageHLAPI : convertedPages) { + if (pageHLAPI.getId().equals(containingPage.getId())) { + assert convertedArc != null; + convertedArc.setContainerPageHLAPI(pageHLAPI); + break; + } + } + + convertedArcs.add(convertedArc); + } + + return convertedArcs; + } + + private static Set<PageHLAPI> buildPageTrees(PetriNet petriNet, PetriNetHLAPI net) { + + Set<PageHLAPI> convertedPages = new HashSet<>(); + // Set<String> processedPageIds = new HashSet<>(); + + List<Page> topLevelPages = getTopLevelPages(petriNet); + List<Page> nonTopLevelPages = getNonTopLevelPages(petriNet); + + for (Page page : topLevelPages) { + convertedPages.add(ComplexElementsConverter.convertTopLevelPageContainerToPnmlObject(page, net)); + // processedPageIds.add(page.getId()); + } + + for (Page nonTopLevelPage : nonTopLevelPages) { + Page parent = nonTopLevelPage.ContainingPage(); + + for (PageHLAPI convertedPage : convertedPages) { + if (parent.getId().equals(convertedPage.getId())) {//&& !processedPageIds.contains(convertedPage.getId())) { + // processedPageIds.add(convertedPage.getId()); + convertedPages.add(ComplexElementsConverter.convertNonTopLevelPageContainerToPnmlObject(nonTopLevelPage, convertedPage)); + break; + } + } + + // if ((processedPageIds.size() != nonTopLevelPages.size()) && (i == (nonTopLevelPages.size() - 1))) { + // i = -1; + // } + } + + return convertedPages; + } + + private static List<Page> getTopLevelPages(PetriNet petriNet) { + + List<Page> topLevelPages = new ArrayList<>(); + + for (Page page : petriNet.allPages()) { + if (page.ContainingPage() == null) { + topLevelPages.add(page); + } + } + + return topLevelPages; + } + + private static List<Page> getNonTopLevelPages(PetriNet petriNet) { + + List<Page> nonTopLevelPages = new ArrayList<>(); + + for (Page page : petriNet.allPages()) { + if (page.ContainingPage() != null) { + nonTopLevelPages.add(page); + } + } + + return nonTopLevelPages; + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/export/PrimitiveElementsConverter.jadd b/src/main/jastadd/base/export/PrimitiveElementsConverter.jadd new file mode 100644 index 0000000..46d8d89 --- /dev/null +++ b/src/main/jastadd/base/export/PrimitiveElementsConverter.jadd @@ -0,0 +1,207 @@ +import de.tudresden.inf.st.pnml.jastadd.model.*; +import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; +import fr.lip6.move.pnml.framework.utils.exception.VoidRepositoryException; +import fr.lip6.move.pnml.ptnet.hlapi.*; + +aspect PrimitiveElementsConverter{ + + public class PrimitiveElementsConverter { + + private static StringBuffer clipToolSpecificsFormattedXmlBuffer(String toolName, String toolVersion, StringBuffer formattedXmlBuffer) { + + StringBuffer bufferCopy = new StringBuffer(formattedXmlBuffer); + + if (bufferCopy != null && bufferCopy.indexOf("</toolspecific>") > -1) { + + int endCharsLength = 15; + int toolNameLenth = (toolName == null) ? 0 : toolName.length(); + int toolVersionLength = (toolVersion == null) ? 0 : toolVersion.length(); + int indexGt = 0; + + if (bufferCopy.indexOf("?xml") > -1) { + indexGt = bufferCopy.indexOf(">", bufferCopy.indexOf(">") + 1); + } else { + indexGt = bufferCopy.indexOf(">"); + } + + if (toolNameLenth > 0 || toolVersionLength > 0) { + bufferCopy.delete(0, indexGt + 1); + bufferCopy.delete(bufferCopy.length() - endCharsLength, bufferCopy.length()); + } + } + return bufferCopy; + } + + public static RefTransitionHLAPI convertRefTransitionToPnmlObject(RefTransition refTransition, TransitionHLAPI referencedTransition, RefTransitionHLAPI referencedRefTransition) { + + try { + RefTransitionHLAPI r; + + if (referencedTransition != null) { + r = new RefTransitionHLAPI(refTransition.getId(), referencedTransition); + } else { + r = new RefTransitionHLAPI(refTransition.getId(), referencedRefTransition); + } + + if (refTransition.getName() != null) { + r.setNameHLAPI(new NameHLAPI(refTransition.getName().getText())); + } + + if (refTransition.getNodeGraphics() != null && refTransition.getNodeGraphics().getLine() != null + && refTransition.getNodeGraphics().getDimension() != null) { + r.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + refTransition.getNodeGraphics().getPosition().getX(), refTransition.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(refTransition.getNodeGraphics().getDimension().getX(), refTransition.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + refTransition.getToolspecificList().forEach(toolInfo -> + r.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + return r; + } catch (InvalidIDException e) { + e.printStackTrace(); + } catch (VoidRepositoryException e) { + e.printStackTrace(); + } + + return null; + } + + public static RefPlaceHLAPI convertRefPlaceToPnmlObject(RefPlace refPlace, PlaceHLAPI referencedPlace, RefPlaceHLAPI referencedRefPlace) { + + try { + + RefPlaceHLAPI r; + + if (referencedPlace != null) { + r = new RefPlaceHLAPI(refPlace.getId(), referencedPlace); + } else { + r = new RefPlaceHLAPI(refPlace.getId(), referencedRefPlace); + } + + r.setNameHLAPI(new NameHLAPI(refPlace.getName().getText())); + + if (refPlace.getNodeGraphics() != null && refPlace.getNodeGraphics().getLine() != null + && refPlace.getNodeGraphics().getDimension() != null) { + r.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + refPlace.getNodeGraphics().getPosition().getX(), refPlace.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(refPlace.getNodeGraphics().getDimension().getX(), refPlace.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + refPlace.getToolspecificList().forEach(toolInfo -> + r.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + return r; + } catch (InvalidIDException e) { + e.printStackTrace(); + } catch (VoidRepositoryException e) { + e.printStackTrace(); + } + + return null; + } + + public static TransitionHLAPI convertTransitionToPnmlObject(InputSignalTransition inputSignalTransition) { + + try { + TransitionHLAPI t = new TransitionHLAPI(inputSignalTransition.getId()); + + t.setNameHLAPI(new NameHLAPI(inputSignalTransition.getName().getText())); + + if (inputSignalTransition.getNodeGraphics() != null && inputSignalTransition.getNodeGraphics().getLine() != null + && inputSignalTransition.getNodeGraphics().getDimension() != null) { + t.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + inputSignalTransition.getNodeGraphics().getPosition().getX(), inputSignalTransition.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(inputSignalTransition.getNodeGraphics().getDimension().getX(), inputSignalTransition.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + inputSignalTransition.getToolspecificList().forEach(toolInfo -> + t.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + return t; + } catch (InvalidIDException | VoidRepositoryException e) { + e.printStackTrace(); + } + return null; + } + + public static PlaceHLAPI convertPlaceToPnmlObject(OutputSignalPlace outputSignalPlace) { + + try { + PlaceHLAPI p = new PlaceHLAPI(outputSignalPlace.getId()); + p.setNameHLAPI(new NameHLAPI(outputSignalPlace.getName().getText())); + + if (outputSignalPlace.getNodeGraphics() != null && outputSignalPlace.getNodeGraphics().getLine() != null && outputSignalPlace.getNodeGraphics().getDimension() != null) { + p.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + outputSignalPlace.getNodeGraphics().getPosition().getX(), outputSignalPlace.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(outputSignalPlace.getNodeGraphics().getDimension().getX(), outputSignalPlace.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + outputSignalPlace.getToolspecificList().forEach(toolInfo -> + p.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + // TODO tranfer graphics + if (outputSignalPlace.getInitialMarking() != null) { + p.setInitialMarkingHLAPI(new PTMarkingHLAPI(Long.valueOf(outputSignalPlace.getInitialMarking().getText()))); + } else { + p.setInitialMarkingHLAPI(new PTMarkingHLAPI(0L)); + } + return p; + } catch (InvalidIDException | VoidRepositoryException e) { + e.printStackTrace(); + } + return null; + } + + public static ArcHLAPI convertArcToPnmlObject(Arc arc, NodeHLAPI source, NodeHLAPI target) { + + try { + ArcHLAPI a = new ArcHLAPI(arc.getId(), source, target); + + if (arc.getNumToolspecific() > 0) { + arc.getToolspecificList().forEach(toolInfo -> + a.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + } + + if (arc.getName() != null) { + a.setNameHLAPI(new NameHLAPI(arc.getName().getText())); + } + + if (arc.getArcGraphics() != null && arc.getArcGraphics().getLine() != null) { + a.setArcgraphicsHLAPI(new ArcGraphicsHLAPI(new LineHLAPI(CSS2ColorHLAPI.get(arc.getArcGraphics().getLine().getColor().getValue()), + LineShapeHLAPI.get(arc.getArcGraphics().getLine().getShape().getValue()), arc.getArcGraphics().getLine().getWidth(), + LineStyleHLAPI.get(arc.getArcGraphics().getLine().getStyle().getValue())))); + } + + return a; + } catch (InvalidIDException | VoidRepositoryException e) { + e.printStackTrace(); + } + return null; + } + } + + syn fr.lip6.move.pnml.ptnet.hlapi.TransitionHLAPI InputSignalTransition.convertToPnmlObject(){ + return PrimitiveElementsConverter.convertTransitionToPnmlObject(this); + } + + syn fr.lip6.move.pnml.ptnet.hlapi.PlaceHLAPI OutputSignalPlace.convertToPnmlObject(){ + return PrimitiveElementsConverter.convertPlaceToPnmlObject(this); + } +} \ No newline at end of file diff --git a/src/main/jastadd/io/IoPN.jadd b/src/main/jastadd/base/io/IoPN.jadd similarity index 84% rename from src/main/jastadd/io/IoPN.jadd rename to src/main/jastadd/base/io/IoPN.jadd index 29b37c2..e6d9f22 100644 --- a/src/main/jastadd/io/IoPN.jadd +++ b/src/main/jastadd/base/io/IoPN.jadd @@ -15,7 +15,7 @@ aspect IoPnExtension{ syn lazy JastAddList<InputSignalBinding> InputSignalTransition.getStaticInputSignalBindingList() { if(this.getMutualInputSignalBindingList() == null || this.getMutualInputSignalBindingList().getNumChild() == 0){ - JastAddList<InputSignalBinding> isBindings = de.tudresden.inf.st.pnml.base.parsing.PnmlSignalParser.parseInputSignalBindingDefinitions(this.getToolspecificList()); + JastAddList<InputSignalBinding> isBindings = PnmlSignalParser.parseInputSignalBindingDefinitions(this.getToolspecificList()); return isBindings; } @@ -24,13 +24,13 @@ aspect IoPnExtension{ syn lazy JastAddList<OutputSignalBinding> OutputSignalPlace.getOutputSignalBindingList() { - JastAddList<OutputSignalBinding> osBindings = de.tudresden.inf.st.pnml.base.parsing.PnmlSignalParser.parseOutputSignalBindingDefinitions(this.getToolspecificList()); + JastAddList<OutputSignalBinding> osBindings = PnmlSignalParser.parseOutputSignalBindingDefinitions(this.getToolspecificList()); return osBindings; } syn String OutputSignalPlace.getInitialOutputSignalValue(String id){ - return de.tudresden.inf.st.pnml.base.parsing.PnmlSignalParser.getInitialOutputSignalValueBySignalID(this.getToolspecificList(), id); + return PnmlSignalParser.getInitialOutputSignalValueBySignalID(this.getToolspecificList(), id); } // updates automatically based on dependencies to the corresponding place diff --git a/src/main/jastadd/io/IoPN.relast b/src/main/jastadd/base/io/IoPN.relast similarity index 100% rename from src/main/jastadd/io/IoPN.relast rename to src/main/jastadd/base/io/IoPN.relast diff --git a/src/main/jastadd/marking/Execution.jadd b/src/main/jastadd/base/marking/Execution.jadd similarity index 100% rename from src/main/jastadd/marking/Execution.jadd rename to src/main/jastadd/base/marking/Execution.jadd diff --git a/src/main/jastadd/marking/Marking.jrag b/src/main/jastadd/base/marking/Marking.jrag similarity index 100% rename from src/main/jastadd/marking/Marking.jrag rename to src/main/jastadd/base/marking/Marking.jrag diff --git a/src/main/jastadd/marking/Marking.relast b/src/main/jastadd/base/marking/Marking.relast similarity index 100% rename from src/main/jastadd/marking/Marking.relast rename to src/main/jastadd/base/marking/Marking.relast diff --git a/src/main/jastadd/marking/Printing.jrag b/src/main/jastadd/base/marking/Printing.jrag similarity index 100% rename from src/main/jastadd/marking/Printing.jrag rename to src/main/jastadd/base/marking/Printing.jrag diff --git a/src/main/jastadd/base/parsing/PnmlParseException.jadd b/src/main/jastadd/base/parsing/PnmlParseException.jadd new file mode 100644 index 0000000..f110e29 --- /dev/null +++ b/src/main/jastadd/base/parsing/PnmlParseException.jadd @@ -0,0 +1,18 @@ +aspect PnmlParseException{ + + public class PnmlParseException extends Exception { + + public PnmlParseException(String message) { + super(message); + } + + public PnmlParseException(String message, Throwable cause) { + super(message, cause); + } + + public PnmlParseException(Throwable cause) { + super(cause); + } + + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/parsing/PnmlParser.jadd b/src/main/jastadd/base/parsing/PnmlParser.jadd new file mode 100644 index 0000000..ca1b900 --- /dev/null +++ b/src/main/jastadd/base/parsing/PnmlParser.jadd @@ -0,0 +1,69 @@ +import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; +import fr.lip6.move.pnml.framework.hlapi.HLAPIRootClass; +import fr.lip6.move.pnml.framework.utils.ModelRepository; +import fr.lip6.move.pnml.framework.utils.PNMLUtils; +import fr.lip6.move.pnml.framework.utils.exception.ImportException; +import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; +import fr.lip6.move.pnml.ptnet.hlapi.PetriNetDocHLAPI; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +aspect PnmlParser { + + public class PnmlParser { + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PnmlParser.class); + + public static List<PetriNet> parsePnml(String fileName) { + + Path file = Paths.get(fileName); + + HLAPIRootClass document = null; + + try { + document = PNMLUtils.importPnmlDocument(file.toFile(), false); + + //logger.info(document.toPNML()); + } catch (ImportException | InvalidIDException e) { + logger.error("Unable to import PNML document from file '{}'", fileName); + logger.error("Exception was thrown!", e); + System.exit(-1); + } + + //logger.info("Imported document workspace ID: {}", ModelRepository.getInstance().getCurrentDocWSId()); + + List<PetriNet> petriNets = new ArrayList<>(); + + fr.lip6.move.pnml.framework.general.PNType type = PNMLUtils.determinePNType(document); + switch (type) { + case PTNET: + PetriNetDocHLAPI ptDoc = + (PetriNetDocHLAPI) document; + + + for (fr.lip6.move.pnml.ptnet.PetriNet pmnlNet : ptDoc.getNets()) { + PnmlParserInternal parser; + try { + parser = new PnmlParserInternal(pmnlNet); + petriNets.add(parser.getPetriNet()); + } catch (PnmlParseException e) { + logger.error("Parsing the Petri net using the PNML framework failed.", e); + } + } + + break; + case COREMODEL: + case SYMNET: + case HLPN: + case PTHLPN: + default: + logger.error("Petri net is of unsupported type {}.", type.getLiteral()); + System.exit(-1); + } + return petriNets; + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/parsing/PnmlParserInternal.jadd b/src/main/jastadd/base/parsing/PnmlParserInternal.jadd new file mode 100644 index 0000000..64d6266 --- /dev/null +++ b/src/main/jastadd/base/parsing/PnmlParserInternal.jadd @@ -0,0 +1,422 @@ +import de.tudresden.inf.st.pnml.jastadd.model.*; + +aspect PnmlParserInternal{ + + public class PnmlParserInternal { + + private final PetriNet petriNet; + + public PnmlParserInternal(fr.lip6.move.pnml.ptnet.PetriNet source) throws PnmlParseException { + this.petriNet = getPetriNet(source); + petriNet.treeResolveAll(); + } + + public PetriNet getPetriNet() { + return petriNet; + } + + // the get methods + + private PetriNet getPetriNet(fr.lip6.move.pnml.ptnet.PetriNet source) throws PnmlParseException { + PetriNet result = new PetriNet(); + fillPetriNet(source, result); + return result; + } + + private Page getPage(fr.lip6.move.pnml.ptnet.Page source) throws PnmlParseException { + Page result = new Page(); + fillPage(source, result); + return result; + } + + private NodeGraphics getNodeGraphics(fr.lip6.move.pnml.ptnet.NodeGraphics source) { + NodeGraphics result = new NodeGraphics(); + fillNodeGraphics(source, result); + return result; + } + + private Line getLine(fr.lip6.move.pnml.ptnet.Line source) { + Line result = new Line(); + fillLine(source, result); + return result; + } + + private Fill getFill(fr.lip6.move.pnml.ptnet.Fill source) { + Fill result = new Fill(); + fillFill(source, result); + return result; + } + + private Dimension getDimension(fr.lip6.move.pnml.ptnet.Dimension source) { + Dimension result = new Dimension(); + fillDimension(source, result); + return result; + } + + private Offset getOffset(fr.lip6.move.pnml.ptnet.Offset source) { + Offset result = new Offset(); + fillOffset(source, result); + return result; + } + + private Position getPosition(fr.lip6.move.pnml.ptnet.Position source) { + Position result = new Position(); + fillPosition(source, result); + return result; + } + + private Name getName(fr.lip6.move.pnml.ptnet.Name source) { + Name result = new Name(); + fillName(source, result); + return result; + } + + private AnnotationGraphics getAnnotationGraphics(fr.lip6.move.pnml.ptnet.AnnotationGraphics source) { + AnnotationGraphics result = new AnnotationGraphics(); + fillAnnotationGraphics(source, result); + return result; + } + + private Font getFont(fr.lip6.move.pnml.ptnet.Font source) { + Font result = new Font(); + fillFont(source, result); + return result; + } + + private ToolInfo getToolInfo(fr.lip6.move.pnml.ptnet.ToolInfo source) { + ToolInfo result = new ToolInfo(); + fillToolInfo(source, result); + return result; + } + + private Node getNode(fr.lip6.move.pnml.ptnet.Node source) throws PnmlParseException { + if (source instanceof fr.lip6.move.pnml.ptnet.PlaceNode) { + return getPlaceNode((fr.lip6.move.pnml.ptnet.PlaceNode) source); + } else if (source instanceof fr.lip6.move.pnml.ptnet.TransitionNode) { + return getTransitionNode((fr.lip6.move.pnml.ptnet.TransitionNode) source); + } else { + throw new PnmlParseException("Encountered illegal unknown subtype of Node " + source.getClass().getCanonicalName()); + } + } + + private PlaceNode getPlaceNode(fr.lip6.move.pnml.ptnet.PlaceNode source) throws PnmlParseException { + if (source instanceof fr.lip6.move.pnml.ptnet.Place) { + return getPlace((fr.lip6.move.pnml.ptnet.Place) source); + } else if (source instanceof fr.lip6.move.pnml.ptnet.RefPlace) { + return getRefPlace((fr.lip6.move.pnml.ptnet.RefPlace) source); + } else { + throw new PnmlParseException("Encountered illegal unknown subtype of PlaceNode " + source.getClass().getCanonicalName()); + } + } + + private Place getPlace(fr.lip6.move.pnml.ptnet.Place source) { + Place result = new OutputSignalPlace(); + fillPlace(source, result); + return result; + } + + private PTMarking getPTMarking(fr.lip6.move.pnml.ptnet.PTMarking source) { + PTMarking result = new PTMarking(); + fillPTMarking(source, result); + return result; + } + + private RefPlace getRefPlace(fr.lip6.move.pnml.ptnet.RefPlace source) { + RefPlace result = new RefPlace(); + fillRefPlace(source, result); + return result; + } + + private TransitionNode getTransitionNode(fr.lip6.move.pnml.ptnet.TransitionNode source) throws PnmlParseException { + if (source instanceof fr.lip6.move.pnml.ptnet.Transition) { + return getTransition((fr.lip6.move.pnml.ptnet.Transition) source); + } else if (source instanceof fr.lip6.move.pnml.ptnet.RefTransition) { + return getRefTransition((fr.lip6.move.pnml.ptnet.RefTransition) source); + } else { + throw new PnmlParseException("Encountered illegal unknown subtype of TransitionNode " + source.getClass().getCanonicalName()); + } + } + + private RefTransition getRefTransition(fr.lip6.move.pnml.ptnet.RefTransition source) { + RefTransition result = new RefTransition(); + fillRefTransition(source, result); + return result; + } + + private Transition getTransition(fr.lip6.move.pnml.ptnet.Transition source) { + Transition result = new InputSignalTransition(); + fillTransition(source, result); + return result; + } + + private Arc getArc(fr.lip6.move.pnml.ptnet.Arc source) { + Arc result = new Arc(); + fillArc(source, result); + return result; + } + + private PTArcAnnotation getPTArcannotation(fr.lip6.move.pnml.ptnet.PTArcAnnotation source) { + PTArcAnnotation result = new PTArcAnnotation(); + fillPTAnnotation(source, result); + return result; + } + + private ArcGraphics getArcGraphics(fr.lip6.move.pnml.ptnet.ArcGraphics source) { + ArcGraphics result = new ArcGraphics(); + fillArcGraphics(source, result); + return result; + } + + private PnObject getPnObject(fr.lip6.move.pnml.ptnet.PnObject source) throws PnmlParseException { + if (source instanceof fr.lip6.move.pnml.ptnet.Page) { + return getPage((fr.lip6.move.pnml.ptnet.Page) source); + } else if (source instanceof Node) { + return getNode((fr.lip6.move.pnml.ptnet.Node) source); + } else if (source instanceof fr.lip6.move.pnml.ptnet.Arc) { + return getArc((fr.lip6.move.pnml.ptnet.Arc) source); + } else if (source instanceof fr.lip6.move.pnml.ptnet.Node) { + return getNode((fr.lip6.move.pnml.ptnet.Node) source); + } else { + throw new PnmlParseException("Encountered illegal unknown subtype of PnObject " + source.getClass().getCanonicalName()); + } + } + + // the fill methods + + private void fillPetriNet(fr.lip6.move.pnml.ptnet.PetriNet source, PetriNet result) throws PnmlParseException { + for (fr.lip6.move.pnml.ptnet.Page page : source.getPages()) { + result.addPage(getPage(page)); + } + if (source.getName() != null) { + result.setName(getName(source.getName())); + } + for (fr.lip6.move.pnml.ptnet.ToolInfo toolInfo : source.getToolspecifics()) { + result.addToolspecific(getToolInfo(toolInfo)); + } + + // if(source.getToolspecifics().size() > 0) { + // System.out.println("-->" + source.getToolspecifics()); + // } + + result.setId(source.getId()); + if (source.getType() == fr.lip6.move.pnml.ptnet.PNType.PTNET) { + result.setType(PNType.PTNET); + } else { + throw new PnmlParseException("Illegal Petri Net type '" + source.getType().getLiteral() + "' encountered."); + } + + } + + private void fillPage(fr.lip6.move.pnml.ptnet.Page source, Page result) throws PnmlParseException { + fillPnObject(source, result); + + for (fr.lip6.move.pnml.ptnet.PnObject object : source.getObjects()) { + result.addObject(getPnObject(object)); + } + if (source.getNodegraphics() != null) { + result.setNodeGraphics(getNodeGraphics(source.getNodegraphics())); + } + } + + private void fillPnObject(fr.lip6.move.pnml.ptnet.PnObject source, PnObject result) { + if (source.getName() != null) { + result.setName(getName(source.getName())); + } + for (fr.lip6.move.pnml.ptnet.ToolInfo toolInfo : source.getToolspecifics()) { + result.addToolspecific(getToolInfo(toolInfo)); + } + + result.setId(source.getId()); + } + + private void fillNodeGraphics(fr.lip6.move.pnml.ptnet.NodeGraphics source, NodeGraphics result) { + if (source.getPosition() != null) { + result.setPosition(getPosition(source.getPosition())); + } + if (source.getDimension() != null) { + result.setDimension(getDimension(source.getDimension())); + } + if (source.getFill() != null) { + result.setFill(getFill(source.getFill())); + } + if (source.getLine() != null) { + result.setLine(getLine(source.getLine())); + } + } + + private void fillLine(fr.lip6.move.pnml.ptnet.Line source, Line result) { + result.setColor(CSS2Color.valueOf(source.getColor().getName())); + result.setShape(LineShape.valueOf(source.getShape().getName())); + result.setWidth(source.getWidth()); + result.setStyle(LineStyle.valueOf(source.getStyle().getName())); + } + + private void fillFill(fr.lip6.move.pnml.ptnet.Fill source, Fill result) { + result.setColor(CSS2Color.valueOf(source.getColor().getName())); + result.setGradientcolor(CSS2Color.valueOf(source.getGradientcolor().getName())); + result.setGradientrotation(Gradient.valueOf(source.getGradientrotation().getName())); + result.setImage(source.getImage()); + } + + private void fillDimension(fr.lip6.move.pnml.ptnet.Dimension source, Dimension result) { + fillCoordinate(source, result); + } + + private void fillCoordinate(fr.lip6.move.pnml.ptnet.Coordinate source, Coordinate result) { + result.setX(source.getX()); + result.setY(source.getY()); + } + + private void fillOffset(fr.lip6.move.pnml.ptnet.Offset source, Offset result) { + fillCoordinate(source, result); + } + + private void fillPosition(fr.lip6.move.pnml.ptnet.Position source, Position result) { + fillCoordinate(source, result); + } + + private void fillName(fr.lip6.move.pnml.ptnet.Name source, Name result) { + fillAnnotation(source, result); + + result.setText(source.getText()); + } + + private void fillAnnotation(fr.lip6.move.pnml.ptnet.Annotation source, Annotation result) { + if (source.getAnnotationgraphics() != null) { + result.setAnnotationGraphics(getAnnotationGraphics(source.getAnnotationgraphics())); + } + fillLabel(source, result); + } + + private void fillLabel(fr.lip6.move.pnml.ptnet.Annotation source, Annotation result) { + for (fr.lip6.move.pnml.ptnet.ToolInfo info : source.getToolspecifics()) { + result.addToolspecific(getToolInfo(info)); + } + } + + private void fillAnnotationGraphics(fr.lip6.move.pnml.ptnet.AnnotationGraphics source, AnnotationGraphics result) { + if (source.getOffset() != null) { + result.setOffset(getOffset(source.getOffset())); + } + if (source.getFill() != null) { + result.setFill(getFill(source.getFill())); + } + if (source.getLine() != null) { + result.setLine(getLine(source.getLine())); + } + if (source.getFont() != null) { + result.setFont(getFont(source.getFont())); + } + } + + private void fillFont(fr.lip6.move.pnml.ptnet.Font source, Font result) { + result.setAlign(FontAlign.valueOf(source.getAlign().getName())); + result.setDecoration(FontDecoration.valueOf(source.getDecoration().getName())); + result.setFamily(CSS2FontFamily.valueOf(source.getFamily().getName())); + result.setRotation(source.getRotation()); + result.setSize(CSS2FontSize.valueOf(source.getSize().getName())); + result.setStyle(CSS2FontStyle.valueOf(source.getStyle().getName())); + result.setWeight(CSS2FontWeight.valueOf(source.getWeight().getName())); + } + + private void fillToolInfo(fr.lip6.move.pnml.ptnet.ToolInfo source, ToolInfo result) { + result.setTool(source.getTool()); + result.setVersion(source.getVersion()); + result.setFormattedXMLBuffer(source.getFormattedXMLBuffer()); + result.setToolInfoGrammarURI(source.getToolInfoGrammarURI()); + } + + private void fillPlace(fr.lip6.move.pnml.ptnet.Place source, Place result) { + fillPlaceNode(source, result); + + if (source.getInitialMarking() != null) { + result.setInitialMarking(getPTMarking(source.getInitialMarking())); + } + } + + private void fillPTMarking(fr.lip6.move.pnml.ptnet.PTMarking source, PTMarking result) { + fillAnnotation(source, result); + + // whatever this is supposed to be. they changed the Integer to Long + result.setText(Math.toIntExact(source.getText())); + } + + private void fillRefPlace(fr.lip6.move.pnml.ptnet.RefPlace source, RefPlace result) { + fillPlaceNode(source, result); + + result.setRef(PlaceNode.createRefDirection(source.getRef().getId())); + } + + private void fillPlaceNode(fr.lip6.move.pnml.ptnet.PlaceNode source, PlaceNode result) { + fillNode(source, result); + + for (fr.lip6.move.pnml.ptnet.RefPlace referencingPlace : source.getReferencingPlaces()) { + result.addReferencingPlace(RefPlace.createRefDirection(referencingPlace.getId())); + } + } + + private void fillRefTransition(fr.lip6.move.pnml.ptnet.RefTransition source, RefTransition result) { + fillTransitionNode(source, result); + + result.setRef(TransitionNode.createRefDirection(source.getRef().getId())); + } + + private void fillTransitionNode(fr.lip6.move.pnml.ptnet.TransitionNode source, TransitionNode result) { + fillNode(source, result); + + for (fr.lip6.move.pnml.ptnet.RefTransition refTransition : source.getReferencingTransitions()) { + result.addReferencingTransition(RefTransition.createRefDirection(refTransition.getId())); + } + } + + private void fillTransition(fr.lip6.move.pnml.ptnet.Transition source, Transition result) { + fillTransitionNode(source, result); + } + + private void fillNode(fr.lip6.move.pnml.ptnet.Node source, Node result) { + + fillPnObject(source, result); + + if (source.getNodegraphics() != null) { + result.setNodeGraphics(getNodeGraphics(source.getNodegraphics())); + } + + for (fr.lip6.move.pnml.ptnet.Arc outArc : source.getOutArcs()) { + result.addOutArc(Arc.createRefDirection(outArc.getId())); + } + for (fr.lip6.move.pnml.ptnet.Arc inArc : source.getInArcs()) { + result.addInArc(Arc.createRefDirection(inArc.getId())); + } + } + + private void fillArc(fr.lip6.move.pnml.ptnet.Arc source, Arc result) { + fillPnObject(source, result); + + if (source.getArcgraphics() != null) { + result.setArcGraphics(getArcGraphics(source.getArcgraphics())); + } + if (source.getInscription() != null) { + result.setInscription(getPTArcannotation(source.getInscription())); + } + + result.setSource(Node.createRefDirection(source.getSource().getId())); + result.setTarget(Node.createRefDirection(source.getTarget().getId())); + } + + private void fillPTAnnotation(fr.lip6.move.pnml.ptnet.PTArcAnnotation source, PTArcAnnotation result) { + fillAnnotation(source, result); + + // whatever this is supposed to be. they changed the Integer to Long + result.setText(Math.toIntExact(source.getText())); + } + + private void fillArcGraphics(fr.lip6.move.pnml.ptnet.ArcGraphics source, ArcGraphics result) { + for (fr.lip6.move.pnml.ptnet.Position position : source.getPositions()) { + result.addPosition(getPosition(position)); + } + if (source.getLine() != null) { + result.setLine(getLine(source.getLine())); + } + } + } +} diff --git a/src/main/jastadd/base/parsing/PnmlSignalParser.jadd b/src/main/jastadd/base/parsing/PnmlSignalParser.jadd new file mode 100644 index 0000000..31bd457 --- /dev/null +++ b/src/main/jastadd/base/parsing/PnmlSignalParser.jadd @@ -0,0 +1,222 @@ +import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; +import de.tudresden.inf.st.pnml.jastadd.model.*; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +aspect PnmlSignalParser{ + + public class PnmlSignalParser { + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PnmlSignalParser.class); + + public static JastAddList<InputSignalBinding> parseInputSignalBindingDefinitions(JastAddList<ToolInfo> toolInfos) { + + try { + Document doc = parseToolSpecifics(toolInfos); + return parseInputSignalBindingDefinitionsInternal(doc); + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + + return null; + } + + private static JastAddList<InputSignalBinding> parseInputSignalBindingDefinitionsInternal(Document doc) { + + if (doc == null) { + return null; + } + + org.w3c.dom.NodeList isBindingDefList = doc.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_BINDINGS_KEY); + JastAddList<InputSignalBinding> jastAddBindingList = new JastAddList<>(); + + if (isBindingDefList.getLength() > 0 && isBindingDefList.item(0) != null) { + + org.w3c.dom.Node isBindingsNode = isBindingDefList.item(0); + + + if (isBindingsNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { + + Element isBindingsElement = (Element) isBindingsNode; + + org.w3c.dom.NodeList isBindingNodes = isBindingsElement.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_BINDING_KEY); + + for (int i = 0; i < isBindingNodes.getLength(); i++) { + + org.w3c.dom.Node isBindingNode = isBindingNodes.item(i); + Element isBindingElement = (Element) isBindingNode; + + String tID = isBindingElement.getElementsByTagName(PnmlConstants.TRANSITION_ID_KEY).item(0).getTextContent(); + String isID = isBindingElement.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_ID_KEY).item(0).getTextContent(); + int cVal = Integer.valueOf(isBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); + + // now detected by pnml-relast-validator + /* + if(cVal != 1 && cVal != 0){ + logger.error("[PARSER] Initial value of input signal " + isID + " is not value. Falling back to 0."); + cVal = 0; + } + */ + + InputSignalBinding isb = new InputSignalBinding(); + isb.setInputSignalValue(cVal); + isb.setInputSignalID(isID); + isb.setTransitionID(tID); + + jastAddBindingList.add(isb); + } + } + } + return jastAddBindingList; + } + + public static JastAddList<OutputSignalBinding> parseOutputSignalBindingDefinitions(JastAddList<ToolInfo> toolInfos) { + + try { + Document doc = parseToolSpecifics(toolInfos); + return parseOutputSignalBindingDefinitionsInternal(doc); + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + + return null; + } + + public static String getInitialOutputSignalValueBySignalID(JastAddList<ToolInfo> toolInfos, String id) { + + try { + Document doc = parseToolSpecifics(toolInfos); + + org.w3c.dom.NodeList osBindingDefList = doc.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDINGS_KEY); + + if (osBindingDefList.getLength() > 0 && osBindingDefList.item(0) != null) { + + org.w3c.dom.Node osBindingsNode = osBindingDefList.item(0); + + if (osBindingsNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { + + Element osBindingsElement = (Element) osBindingsNode; + + org.w3c.dom.NodeList osBindingNodes = osBindingsElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDING_KEY); + + for (int i = 0; i < osBindingNodes.getLength(); i++) { + + org.w3c.dom.Node osBindingNode = osBindingNodes.item(i); + Element osBindingElement = (Element) osBindingNode; + + String osID = osBindingElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_ID_KEY).item(0).getTextContent(); + + if (osID.equals(id)) { + return String.valueOf(osBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); + } + } + } + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + + return null; + } + + private static JastAddList<OutputSignalBinding> parseOutputSignalBindingDefinitionsInternal(Document doc) { + + org.w3c.dom.NodeList osBindingDefList = doc.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDINGS_KEY); + JastAddList<OutputSignalBinding> jastAddBindingList = new JastAddList<>(); + + if (osBindingDefList.getLength() > 0 && osBindingDefList.item(0) != null) { + + org.w3c.dom.Node osBindingsNode = osBindingDefList.item(0); + + if (osBindingsNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { + + Element osBindingsElement = (Element) osBindingsNode; + + org.w3c.dom.NodeList osBindingNodes = osBindingsElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDING_KEY); + + for (int i = 0; i < osBindingNodes.getLength(); i++) { + + org.w3c.dom.Node osBindingNode = osBindingNodes.item(i); + Element osBindingElement = (Element) osBindingNode; + + String pID = osBindingElement.getElementsByTagName(PnmlConstants.PLACE_ID_KEY).item(0).getTextContent(); + String osID = osBindingElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_ID_KEY).item(0).getTextContent(); + String cVal = String.valueOf(osBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); + + OutputSignalBinding osb = new OutputSignalBinding(); + parseOutputMappings(osBindingElement, pID, osID, cVal, osb); + jastAddBindingList.add(osb); + } + } + } + + return jastAddBindingList; + } + + private static void parseOutputMappings(Element osBindingElement, String pID, String osID, String cVal, OutputSignalBinding osb) { + //osb.setCurrentValue(cVal); + osb.setOutputSignalID(osID); + osb.setPlaceID(pID); + + org.w3c.dom.NodeList eqMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.EQUAL_OS_KEY); + org.w3c.dom.NodeList thresholdMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.THRESHOLD_KEY); + org.w3c.dom.NodeList rangeMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.RANGE_OS_KEY); + + for (int j = 0; j < eqMappingNodeList.getLength(); j++) { + Element eqElement = (Element) eqMappingNodeList.item(j); + EqualityOutputMapping eom = new EqualityOutputMapping(); + eom.setValue(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.VALUE_KEY).item(0).getTextContent())); + eom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); + osb.addEqualityOM(eom); + } + + for (int k = 0; k < thresholdMappingNodeList.getLength(); k++) { + Element eqElement = (Element) thresholdMappingNodeList.item(k); + ThresholdOutputMapping tom = new ThresholdOutputMapping(); + tom.setValue(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.VALUE_KEY).item(0).getTextContent())); + tom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); + osb.addThresholdOM(tom); + } + + for (int l = 0; l < rangeMappingNodeList.getLength(); l++) { + Element eqElement = (Element) rangeMappingNodeList.item(l); + RangeOutputMapping rom = new RangeOutputMapping(); + rom.setLowerBound(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.LOWER_BOUND_KEY).item(0).getTextContent())); + rom.setUpperBound(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.UPPER_BOUND_KEY).item(0).getTextContent())); + rom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); + osb.addRangeOM(rom); + } + } + + private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException { + + if (toolInfos == null || toolInfos.getNumChild() == 0) { + return null; + } + + StringBuffer toolInfoStringBuffer = toolInfos.getChild(0).getFormattedXMLBuffer(); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + + Document doc = dBuilder.parse(fromStringBuffer(toolInfoStringBuffer)); + doc.getDocumentElement().normalize(); + return doc; + } + + private static InputStream fromStringBuffer(StringBuffer buf) { + return new ByteArrayInputStream(buf.toString().getBytes()); + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd new file mode 100644 index 0000000..e6936bc --- /dev/null +++ b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd @@ -0,0 +1,375 @@ +import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; +import de.tudresden.inf.st.pnml.base.data.CommunicatorInformation; +import de.tudresden.inf.st.pnml.jastadd.parser.ExpressionParser; +import de.tudresden.inf.st.pnml.jastadd.scanner.ExpressionScanner; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; + +aspect ToolSpecificsParser{ + + public class ToolSpecificsParser { + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ToolSpecificsParser.class); + + public static Root getClauseFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList locationList = doc.getElementsByTagName(PnmlConstants.CLAUSE_KEY); + + if (locationList.getLength() > 0 && locationList.item(0) != null) { + String content = locationList.item(0).getTextContent(); + StringReader reader = new StringReader(content); + ExpressionScanner scanner = new ExpressionScanner(reader); + ExpressionParser parser = new ExpressionParser(); + return ((Root) parser.parse(scanner)); + } + + } catch (ParserConfigurationException | SAXException | IOException | beaver.Parser.Exception e) { + logger.error(e.getMessage()); + } + } + + return new Root(); + } + + public static CommunicatorInformation getCommunicatorInformationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + CommunicatorInformation ci = new CommunicatorInformation(); + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList communicatorList = doc.getElementsByTagName(PnmlConstants.COMMUNICATOR); + + for (int i = 0; i < communicatorList.getLength(); i++) { + + String ct = null; + String cs = null; + + for (int j = 0; j < communicatorList.item(i).getChildNodes().getLength(); j++) { + org.w3c.dom.Node n = communicatorList.item(i).getChildNodes().item(j); + + String newline = System.getProperty("line.separator"); + if (n.getTextContent().length() > 1 && !n.getTextContent().contains(newline)) { + + if (n.getNodeName().equals(PnmlConstants.COMMUNICATOR_TYPE)) { + ct = n.getTextContent(); + } + + if (n.getNodeName().equals(PnmlConstants.COMMUNICATOR_SUBNET)) { + cs = n.getTextContent(); + } + + if (ct != null && cs != null) { + ci.addMapping(cs, ct); + ct = null; + cs = null; + } + } + } + } + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return ci; + } + + public static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList locationList = doc.getElementsByTagName(PnmlConstants.LOCATION_KEY); + + if (locationList.getLength() > 0 && locationList.item(0) != null) { + return locationList.item(0).getTextContent(); + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + + return ""; + } + + public static String getArcTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList locationList = doc.getElementsByTagName(PnmlConstants.ARC_TYPE_KEY); + + if (locationList.getLength() > 0 && locationList.item(0) != null) { + String content = locationList.item(0).getTextContent(); + + if (content.equals(PnmlConstants.DEFAULT_ARC) || content.equals(PnmlConstants.INHIBITOR_ARC)) { + return content; + } + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + + return ""; + } + + public static String getTransitionTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); + + if (typeList.getLength() > 0 && typeList.item(0) != null) { + String type = typeList.item(0).getTextContent(); + if (!type.equals(PnmlConstants.TRANSITION_TYPE_CONTINUOUS) || type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE) + || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC) || !type.equals(PnmlConstants.TRANSITION_TYPE_SERVICE_REQUEST) + || !type.equals(PnmlConstants.TRANSITION_TYPE_SERVICE_RESPONSE)) { + return type; + } else { + logger.error("Error: Invalid transition type configured: " + type + "."); + } + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + + return null; + } + + public static String getTransitionTopicFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); + + if (typeList.getLength() > 0 && typeList.item(0) != null) { + String type = typeList.item(0).getTextContent(); + if (type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_LIMITED_IN) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_LIMITED_OUT) + || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_UNLIMITED_IN) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_UNLIMITED_OUT) + || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC)) { + + org.w3c.dom.NodeList topicList = doc.getElementsByTagName(PnmlConstants.TOPIC_KEY); + + if (topicList.getLength() > 0 && topicList.item(0) != null) { + return topicList.item(0).getTextContent(); + } + } + } + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return null; + } + + public static String getTransitionServiceNameFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList typeList = doc.getElementsByTagName(PnmlConstants.SERVICE_NAME); + + if (typeList.getLength() > 0 && typeList.item(0) != null) { + + String type = typeList.item(0).getTextContent(); + if (!type.equals("") && type != null) { + return type; + } + } + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return null; + } + + private static String getPlaceTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + org.w3c.dom.NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); + + if (typeList.getLength() > 0 && typeList.item(0) != null) { + String type = typeList.item(0).getTextContent(); + if (type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS)) { + return type; + } + } + + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return null; + } + + public static String getSubnetFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + return getSubnetInfoInternal(toolInfos); + } + + private static String getSubnetInfoInternal(JastAddList<ToolInfo> toolInfos) { + + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + // String typeTrans = getTransitionTypeFromToolSpecifics(toolInfos); + // String typePlace = getPlaceTypeFromToolSpecifics(toolInfos); + + // String type = typePlace == null ? typeTrans : typePlace; + + // if (type != null && (type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE) + // || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) + // || type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC))) { + + org.w3c.dom.NodeList snList = doc.getElementsByTagName(PnmlConstants.SUBNET_KEY); + + if (snList.getLength() > 0 && snList.item(0) != null) { + return snList.item(0).getTextContent(); + } + // } + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return null; + } + + private static String getTransitionSubnetInfo(JastAddList<ToolInfo> toolInfos) { + return getSubnetInfoInternal(toolInfos); + } + + private static String getPlaceSubnetInfo(JastAddList<ToolInfo> toolInfos) { + return getSubnetInfoInternal(toolInfos); + } + + private static int getTransitionLimitsInternal(JastAddList<ToolInfo> toolInfos, String limitType) { + if (toolInfos.getNumChild() > 0) { + try { + Document doc = parseToolSpecifics(toolInfos); + String transitionType = getTransitionTypeFromToolSpecifics(toolInfos); + + if (transitionType != null && (transitionType.equals(PnmlConstants.TRANSITION_TYPE_TOPIC))) { + + org.w3c.dom.NodeList limList = doc.getElementsByTagName(limitType); + + if (limList.getLength() > 0 && limList.item(0) != null) { + return Integer.valueOf(limList.item(0).getTextContent()); + } + } + } catch (ParserConfigurationException | SAXException | IOException e) { + logger.error(e.getMessage()); + } + } + return -1; + } + + private static int getTransitionOutputLimit(JastAddList<ToolInfo> toolInfos) { + return getTransitionLimitsInternal(toolInfos, PnmlConstants.OUTPUT_LIMIT_KEY); + } + + private static int getTransitionInputLimit(JastAddList<ToolInfo> toolInfos) { + return getTransitionLimitsInternal(toolInfos, PnmlConstants.INPUT_LIMIT_KEY); + } + + public static TransitionInformation getTransitionInformation(JastAddList<ToolInfo> toolInfos) { + + if (getTransitionTopicFromToolSpecifics(toolInfos) != null) { + TopicTransitionInformation topicTransition = new TopicTransitionInformation(); + topicTransition.setInputLimit(getTransitionInputLimit(toolInfos)); + topicTransition.setOutputLimit(getTransitionOutputLimit(toolInfos)); + topicTransition.setLocation(getLocationFromToolSpecifics(toolInfos)); + topicTransition.setType(getTransitionTypeFromToolSpecifics(toolInfos)); + topicTransition.setTopic(getTransitionTopicFromToolSpecifics(toolInfos)); + topicTransition.setSubNet(getTransitionSubnetInfo(toolInfos)); + return topicTransition; + } + + if (getTransitionServiceNameFromToolSpecifics(toolInfos) != null) { + ServiceTransitionInformation serviceTransition = new ServiceTransitionInformation(); + serviceTransition.setInputLimit(getTransitionInputLimit(toolInfos)); + serviceTransition.setOutputLimit(getTransitionOutputLimit(toolInfos)); + serviceTransition.setLocation(getLocationFromToolSpecifics(toolInfos)); + serviceTransition.setType(getTransitionTypeFromToolSpecifics(toolInfos)); + serviceTransition.setServiceName(getTransitionServiceNameFromToolSpecifics(toolInfos)); + serviceTransition.setSubNet(getTransitionSubnetInfo(toolInfos)); + return serviceTransition; + } + + DefaultTransitionInformation transitionInformation = new DefaultTransitionInformation(); + transitionInformation.setInputLimit(getTransitionInputLimit(toolInfos)); + transitionInformation.setOutputLimit(getTransitionOutputLimit(toolInfos)); + transitionInformation.setLocation(getLocationFromToolSpecifics(toolInfos)); + transitionInformation.setType(getTransitionTypeFromToolSpecifics(toolInfos)); + transitionInformation.setSubNet(getTransitionSubnetInfo(toolInfos)); + + return transitionInformation; + } + + public static PlaceInformation getPlaceInformationInformation(JastAddList<ToolInfo> toolInfos) { + + PlaceInformation placeInformation = new PlaceInformation(); + + placeInformation.setLocation(getLocationFromToolSpecifics(toolInfos)); + placeInformation.setType(getPlaceTypeFromToolSpecifics(toolInfos)); + String sn = getPlaceSubnetInfo(toolInfos); + placeInformation.setSubNet(sn); + + return placeInformation; + } + + public static PlaceInformation getPlaceInformation(JastAddList<ToolInfo> toolInfos) { + + PlaceInformation pi = new PlaceInformation(); + pi.setLocation(getLocationFromToolSpecifics(toolInfos)); + pi.setSubNet(getPlaceSubnetInfo(toolInfos)); + pi.setType(getPlaceTypeFromToolSpecifics(toolInfos)); + + return pi; + } + + private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException { + + ToolInfo ti = null; + + for (ToolInfo toolInfo : toolInfos) { + if (toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.SUBNET_KEY) > 0 || + toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.COMMUNICATOR) > 0) { + ti = toolInfo; + break; + } + } + + StringBuffer toolInfoStringBuffer = ti.getFormattedXMLBuffer(); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + + Document doc = dBuilder.parse(fromStringBuffer(toolInfoStringBuffer)); + doc.getDocumentElement().normalize(); + return doc; + } + + private static InputStream fromStringBuffer(StringBuffer buf) { + return new ByteArrayInputStream(buf.toString().getBytes()); + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/resolving/PnmlRefTransitionResolver.jadd b/src/main/jastadd/base/resolving/PnmlRefTransitionResolver.jadd new file mode 100644 index 0000000..090ed00 --- /dev/null +++ b/src/main/jastadd/base/resolving/PnmlRefTransitionResolver.jadd @@ -0,0 +1,54 @@ +import de.tudresden.inf.st.pnml.jastadd.model.Arc; +import de.tudresden.inf.st.pnml.jastadd.model.Place; +import de.tudresden.inf.st.pnml.jastadd.model.RefTransition; +import de.tudresden.inf.st.pnml.jastadd.model.TransitionNode; + +import java.util.Set; + +aspect PnmlRefTransitionResolver{ + + public class PnmlRefTransitionResolver { + + public static void resolveIncomingPlaces(TransitionNode transitionNode, Set<Place> incomingPlaces) { + + if (transitionNode.isTransition()) { + for (Arc incomingArc : transitionNode.getInArcList()) { + incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); + } + return; + } + + if (transitionNode.isRefTransition()) { + RefTransition rt = transitionNode.asRefTransition(); + TransitionNode subRt = rt.get_impl_ref(); + + for (Arc incomingArc : transitionNode.getInArcList()) { + incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); + } + + resolveIncomingPlaces(subRt, incomingPlaces); + } + } + + public static void resolveOutgoingPlaces(TransitionNode transitionNode, Set<Place> outgoingPlaces) { + + if (transitionNode.isTransition()) { + for (Arc outgoingArc : transitionNode.getOutArcList()) { + outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); + } + return; + } + + if (transitionNode.isRefTransition()) { + RefTransition rt = transitionNode.asRefTransition(); + TransitionNode subRt = rt.get_impl_ref(); + + for (Arc outgoingArc : transitionNode.getInArcList()) { + outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); + } + + resolveIncomingPlaces(subRt, outgoingPlaces); + } + } + } +} diff --git a/src/main/jastadd/base/transforming/PnmlReferenceFlatter.jadd b/src/main/jastadd/base/transforming/PnmlReferenceFlatter.jadd new file mode 100644 index 0000000..df003df --- /dev/null +++ b/src/main/jastadd/base/transforming/PnmlReferenceFlatter.jadd @@ -0,0 +1,140 @@ +import de.tudresden.inf.st.pnml.jastadd.model.*; + +import java.util.HashSet; +import java.util.Set; + +aspect PnmlReferenceFlatter{ + + public class PnmlReferenceFlatter { + + public static void findPlaceReferences(PlaceNode placeNode, Set<PlaceNode> nodes) { + + nodes.addAll(placeNode.getReferencingPlaces()); + + for (RefPlace rp : placeNode.getReferencingPlaces()) { + findPlaceReferences(rp, nodes); + } + } + + public static void findTransitionReferences(TransitionNode transitionNode, Set<TransitionNode> nodes) { + + nodes.addAll(transitionNode.getReferencingTransitions()); + + for (RefTransition rt : transitionNode.getReferencingTransitions()) { + findTransitionReferences(rt, nodes); + } + } + + public static void pnml2Tina(PetriNet petriNet) { + + excludeAllPages(petriNet); + resolvePlaceReferences(petriNet); + resolveTransitionReferences(petriNet); + petriNet.flushTreeCache(); + } + + public static void resolvePlaceReferences(PetriNet petriNet) { + + Set<PlaceNode> nodesToDelete = new HashSet<>(); + + for (Place p : petriNet.allReferencedPlaces()) { + + Set<PlaceNode> referencer = new HashSet<>(); + Set<Arc> connectedInArcs = new HashSet<>(); + Set<Arc> connectedOutArcs = new HashSet<>(); + + findPlaceReferences(p, referencer); + + // get all arcs + for (PlaceNode placeNode : referencer) { + connectedInArcs.addAll(placeNode.getInArcs()); + connectedOutArcs.addAll(placeNode.getOutArcs()); + nodesToDelete.add(placeNode); + } + + // relink in-arcs + for (Arc inArc : connectedInArcs) { + inArc.setTarget(p); + } + + // relink out-arcs + for (Arc outArc : connectedOutArcs) { + outArc.setSource(p); + } + } + + for (PlaceNode placeNode : nodesToDelete) { + placeNode.removeSelf(); + } + // petriNet.flushTreeCache(); + } + + public static void resolveTransitionReferences(PetriNet petriNet) { + + Set<TransitionNode> nodesToDelete = new HashSet<>(); + + for (Transition t : petriNet.allReferencedTransitions()) { + + Set<TransitionNode> referencer = new HashSet<>(); + Set<Arc> connectedInArcs = new HashSet<>(); + Set<Arc> connectedOutArcs = new HashSet<>(); + + findTransitionReferences(t, referencer); + + // get all arcs + for (TransitionNode transitionNode : referencer) { + connectedInArcs.addAll(transitionNode.getInArcs()); + connectedOutArcs.addAll(transitionNode.getOutArcs()); + nodesToDelete.add(transitionNode); + } + + // relink in-arcs + for (Arc inArc : connectedInArcs) { + inArc.setTarget(t); + } + + // relink out-arcs + for (Arc outArc : connectedOutArcs) { + outArc.setSource(t); + } + } + + for (TransitionNode transitionNode : nodesToDelete) { + transitionNode.removeSelf(); + } + // petriNet.flushTreeCache(); + } + + /** + * Excludes all but the top level page. + * + * @param petriNet + */ + public static void excludeAllPages(PetriNet petriNet) { + + Page topLevelPage = null; + + for (Page p : petriNet.allPages()) { + if (p.ContainingPage() == null) { + topLevelPage = p; + } + } + + for (PnObject pnObject : petriNet.allObjects()) { + assert topLevelPage != null; + if (pnObject.ContainingPage() != null && !pnObject.isPageNode()) { + // System.out.println("Moving: " + pnObject.getId()); + topLevelPage.addObject(pnObject); + } + } + + for (Page p : petriNet.allPages()) { + if (p.ContainingPage() != null) { + p.removeSelf(); + } + } + + // petriNet.flushTreeCache(); + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/base/transforming/PnmlSlicer.jadd b/src/main/jastadd/base/transforming/PnmlSlicer.jadd new file mode 100644 index 0000000..15408cb --- /dev/null +++ b/src/main/jastadd/base/transforming/PnmlSlicer.jadd @@ -0,0 +1,96 @@ +import de.tudresden.inf.st.pnml.jastadd.model.*; + +import java.util.HashSet; +import java.util.Set; + +aspect PnmlSlicer { + + public class PnmlSlicer { + + /** + * Cuts out a subnet ignoring pages. + * + * @param petriNet + * @param subnet + * @return + */ + public static PetriNet cutOutSubNet(PetriNet petriNet, String subnet) { + + Set<Arc> arcsToBeRemoved = collectNonSubnetArcs(petriNet, subnet); + + for (Arc a : arcsToBeRemoved) { + a.removeSelf(); + } + + for (Place p : petriNet.allPlaces()) { + if (!p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet().equals(subnet)) { + p.removeSelf(); + } + } + + for (RefPlace rp : petriNet.allRefPlaces()) { + if (!rp.getSubNet().equals(subnet)) { + rp.removeSelf(); + } + } + + for (Transition t : petriNet.allTransitions()) { + if (!t.asInputSignalTransition().getStaticTransitionInformation().getSubNet().equals(subnet)) { + t.removeSelf(); + } + } + + for (RefTransition rt : petriNet.allRefTransitions()) { + if (!rt.getSubNet().equals(subnet)) { + rt.removeSelf(); + } + } + + petriNet.flushTreeCache(); + return petriNet; + } + + private static Set<Arc> collectNonSubnetArcs(PetriNet petriNet, String subnet) { + + Set<Arc> arcs = new HashSet<>(); + + for (Arc a : petriNet.allArcs()) { + + if (a.getSource().isPlaceNode() && !isPlaceInSubnet(a.getSource().asPlaceNode(), petriNet, subnet)) { + arcs.add(a); + } + + if (a.getTarget().isPlaceNode() && !isPlaceInSubnet(a.getTarget().asPlaceNode(), petriNet, subnet)) { + arcs.add(a); + } + + if (a.getSource().isTransitionNode() && !isTransitionInSubnet(a.getSource().asTransitionNode(), petriNet, subnet)) { + arcs.add(a); + } + + if (a.getTarget().isTransitionNode() && !isTransitionInSubnet(a.getTarget().asTransitionNode(), petriNet, subnet)) { + arcs.add(a); + } + } + return arcs; + } + + private static boolean isPlaceInSubnet(PlaceNode p, PetriNet pn, String subnet) { + + if (p.isRefPlace()) { + return false; + } + + return pn.getPlaceFromPlaceNode(p).asOutputSignalPlace().getStaticPlaceInformation().getSubNet().equals(subnet); + } + + private static boolean isTransitionInSubnet(TransitionNode t, PetriNet pn, String subnet) { + + if (t.isRefTransition()) { + return false; + } + + return pn.getTransitionFromTransitionNode(t).asInputSignalTransition().getStaticTransitionInformation().getSubNet().equals(subnet); + } + } +} \ No newline at end of file diff --git a/src/main/jastadd/distribution/DistributedPN.jadd b/src/main/jastadd/distribution/DistributedPN.jadd deleted file mode 100644 index 448f917..0000000 --- a/src/main/jastadd/distribution/DistributedPN.jadd +++ /dev/null @@ -1,52 +0,0 @@ -import de.tudresden.inf.st.pnml.base.data.CommunicatorInformation; - -aspect PnDistribution { - - syn TransitionInformation InputSignalTransition.getStaticTransitionInformation() { - - if(this.getMutualTransitionInformation() == null){ - TransitionInformation tInfo = de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getTransitionInformation(this.getToolspecificList()); - return tInfo; - } - - return this.getMutualTransitionInformation(); - } - - syn PlaceInformation OutputSignalPlace.getStaticPlaceInformation() { - - if(this.getMutualPlaceInformation() == null){ - PlaceInformation tInfo = de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getPlaceInformationInformation(this.getToolspecificList()); - return tInfo; - } - - return this.getMutualPlaceInformation(); - } - - syn lazy String RefTransition.getLocation() { - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy String RefTransition.getSubNet() { - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy String RefPlace.getLocation() { - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy String RefPlace.getSubNet() { - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy Root InputSignalTransition.getInputSignalClause(){ - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getClauseFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy CommunicatorInformation PetriNet.getCommunicatorInformation(){ - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getCommunicatorInformationFromToolSpecifics(this.getToolspecificList()); - } - - syn lazy String Arc.getType() { - return de.tudresden.inf.st.pnml.base.parsing.ToolSpecificsParser.getArcTypeFromToolSpecifics(this.getToolspecificList()); - } -} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParseException.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParseException.java deleted file mode 100644 index 1faafee..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParseException.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -public class PnmlParseException extends Exception { - - public PnmlParseException(String message) { - super(message); - } - - public PnmlParseException(String message, Throwable cause) { - super(message, cause); - } - - public PnmlParseException(Throwable cause) { - super(cause); - } - -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParser.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParser.java deleted file mode 100644 index a201de6..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParser.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; -import fr.lip6.move.pnml.framework.general.PNType; -import fr.lip6.move.pnml.framework.hlapi.HLAPIRootClass; -import fr.lip6.move.pnml.framework.utils.ModelRepository; -import fr.lip6.move.pnml.framework.utils.PNMLUtils; -import fr.lip6.move.pnml.framework.utils.exception.ImportException; -import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; -import fr.lip6.move.pnml.ptnet.hlapi.PetriNetDocHLAPI; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -public class PnmlParser { - - private static final Logger logger = LoggerFactory.getLogger(PnmlParser.class); - - public static List<PetriNet> parsePnml(String fileName) { - - Path file = Paths.get(fileName); - - HLAPIRootClass document = null; - - try { - document = PNMLUtils.importPnmlDocument(file.toFile(), false); - - //logger.info(document.toPNML()); - } catch (ImportException | InvalidIDException e) { - logger.error("Unable to import PNML document from file '{}'", fileName); - logger.error("Exception was thrown!", e); - System.exit(-1); - } - - //logger.info("Imported document workspace ID: {}", ModelRepository.getInstance().getCurrentDocWSId()); - - List<PetriNet> petriNets = new ArrayList<>(); - - PNType type = PNMLUtils.determinePNType(document); - switch (type) { - case PTNET: - PetriNetDocHLAPI ptDoc = - (PetriNetDocHLAPI) document; - - - for (fr.lip6.move.pnml.ptnet.PetriNet pmnlNet : ptDoc.getNets()) { - PnmlParserInternal parser; - try { - parser = new PnmlParserInternal(pmnlNet); - petriNets.add(parser.getPetriNet()); - } catch (PnmlParseException e) { - logger.error("Parsing the Petri net using the PNML framework failed.", e); - } - } - - break; - case COREMODEL: - case SYMNET: - case HLPN: - case PTHLPN: - default: - logger.error("Petri net is of unsupported type {}.", type.getLiteral()); - System.exit(-1); - } - return petriNets; - } -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParserInternal.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParserInternal.java deleted file mode 100644 index 51ced46..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlParserInternal.java +++ /dev/null @@ -1,422 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -import de.tudresden.inf.st.pnml.jastadd.model.*; - -public class PnmlParserInternal { - - private final PetriNet petriNet; - - public PnmlParserInternal(fr.lip6.move.pnml.ptnet.PetriNet source) throws PnmlParseException { - this.petriNet = getPetriNet(source); - petriNet.treeResolveAll(); - } - - public PetriNet getPetriNet() { - return petriNet; - } - - // the get methods - - private PetriNet getPetriNet(fr.lip6.move.pnml.ptnet.PetriNet source) throws PnmlParseException { - PetriNet result = new PetriNet(); - fillPetriNet(source, result); - return result; - } - - private Page getPage(fr.lip6.move.pnml.ptnet.Page source) throws PnmlParseException { - Page result = new Page(); - fillPage(source, result); - return result; - } - - private NodeGraphics getNodeGraphics(fr.lip6.move.pnml.ptnet.NodeGraphics source) { - NodeGraphics result = new NodeGraphics(); - fillNodeGraphics(source, result); - return result; - } - - private Line getLine(fr.lip6.move.pnml.ptnet.Line source) { - Line result = new Line(); - fillLine(source, result); - return result; - } - - private Fill getFill(fr.lip6.move.pnml.ptnet.Fill source) { - Fill result = new Fill(); - fillFill(source, result); - return result; - } - - private Dimension getDimension(fr.lip6.move.pnml.ptnet.Dimension source) { - Dimension result = new Dimension(); - fillDimension(source, result); - return result; - } - - private Offset getOffset(fr.lip6.move.pnml.ptnet.Offset source) { - Offset result = new Offset(); - fillOffset(source, result); - return result; - } - - private Position getPosition(fr.lip6.move.pnml.ptnet.Position source) { - Position result = new Position(); - fillPosition(source, result); - return result; - } - - private Name getName(fr.lip6.move.pnml.ptnet.Name source) { - Name result = new Name(); - fillName(source, result); - return result; - } - - private AnnotationGraphics getAnnotationGraphics(fr.lip6.move.pnml.ptnet.AnnotationGraphics source) { - AnnotationGraphics result = new AnnotationGraphics(); - fillAnnotationGraphics(source, result); - return result; - } - - private Font getFont(fr.lip6.move.pnml.ptnet.Font source) { - Font result = new Font(); - fillFont(source, result); - return result; - } - - private ToolInfo getToolInfo(fr.lip6.move.pnml.ptnet.ToolInfo source) { - ToolInfo result = new ToolInfo(); - fillToolInfo(source, result); - return result; - } - - private Node getNode(fr.lip6.move.pnml.ptnet.Node source) throws PnmlParseException { - if (source instanceof fr.lip6.move.pnml.ptnet.PlaceNode) { - return getPlaceNode((fr.lip6.move.pnml.ptnet.PlaceNode) source); - } else if (source instanceof fr.lip6.move.pnml.ptnet.TransitionNode) { - return getTransitionNode((fr.lip6.move.pnml.ptnet.TransitionNode) source); - } else { - throw new PnmlParseException("Encountered illegal unknown subtype of Node " + source.getClass().getCanonicalName()); - } - } - - private PlaceNode getPlaceNode(fr.lip6.move.pnml.ptnet.PlaceNode source) throws PnmlParseException { - if (source instanceof fr.lip6.move.pnml.ptnet.Place) { - return getPlace((fr.lip6.move.pnml.ptnet.Place) source); - } else if (source instanceof fr.lip6.move.pnml.ptnet.RefPlace) { - return getRefPlace((fr.lip6.move.pnml.ptnet.RefPlace) source); - } else { - throw new PnmlParseException("Encountered illegal unknown subtype of PlaceNode " + source.getClass().getCanonicalName()); - } - } - - private Place getPlace(fr.lip6.move.pnml.ptnet.Place source) { - Place result = new OutputSignalPlace(); - fillPlace(source, result); - return result; - } - - private PTMarking getPTMarking(fr.lip6.move.pnml.ptnet.PTMarking source) { - PTMarking result = new PTMarking(); - fillPTMarking(source, result); - return result; - } - - private RefPlace getRefPlace(fr.lip6.move.pnml.ptnet.RefPlace source) { - RefPlace result = new RefPlace(); - fillRefPlace(source, result); - return result; - } - - private TransitionNode getTransitionNode(fr.lip6.move.pnml.ptnet.TransitionNode source) throws PnmlParseException { - if (source instanceof fr.lip6.move.pnml.ptnet.Transition) { - return getTransition((fr.lip6.move.pnml.ptnet.Transition) source); - } else if (source instanceof fr.lip6.move.pnml.ptnet.RefTransition) { - return getRefTransition((fr.lip6.move.pnml.ptnet.RefTransition) source); - } else { - throw new PnmlParseException("Encountered illegal unknown subtype of TransitionNode " + source.getClass().getCanonicalName()); - } - } - - private RefTransition getRefTransition(fr.lip6.move.pnml.ptnet.RefTransition source) { - RefTransition result = new RefTransition(); - fillRefTransition(source, result); - return result; - } - - private Transition getTransition(fr.lip6.move.pnml.ptnet.Transition source) { - Transition result = new InputSignalTransition(); - fillTransition(source, result); - return result; - } - - private Arc getArc(fr.lip6.move.pnml.ptnet.Arc source) { - Arc result = new Arc(); - fillArc(source, result); - return result; - } - - private PTArcAnnotation getPTArcannotation(fr.lip6.move.pnml.ptnet.PTArcAnnotation source) { - PTArcAnnotation result = new PTArcAnnotation(); - fillPTAnnotation(source, result); - return result; - } - - private ArcGraphics getArcGraphics(fr.lip6.move.pnml.ptnet.ArcGraphics source) { - ArcGraphics result = new ArcGraphics(); - fillArcGraphics(source, result); - return result; - } - - private PnObject getPnObject(fr.lip6.move.pnml.ptnet.PnObject source) throws PnmlParseException { - if (source instanceof fr.lip6.move.pnml.ptnet.Page) { - return getPage((fr.lip6.move.pnml.ptnet.Page) source); - } else if (source instanceof Node) { - return getNode((fr.lip6.move.pnml.ptnet.Node) source); - } else if (source instanceof fr.lip6.move.pnml.ptnet.Arc) { - return getArc((fr.lip6.move.pnml.ptnet.Arc) source); - } else if (source instanceof fr.lip6.move.pnml.ptnet.Node) { - return getNode((fr.lip6.move.pnml.ptnet.Node) source); - } else { - throw new PnmlParseException("Encountered illegal unknown subtype of PnObject " + source.getClass().getCanonicalName()); - } - } - - // the fill methods - - private void fillPetriNet(fr.lip6.move.pnml.ptnet.PetriNet source, PetriNet result) throws PnmlParseException { - for (fr.lip6.move.pnml.ptnet.Page page : source.getPages()) { - result.addPage(getPage(page)); - } - if (source.getName() != null) { - result.setName(getName(source.getName())); - } - for (fr.lip6.move.pnml.ptnet.ToolInfo toolInfo : source.getToolspecifics()) { - result.addToolspecific(getToolInfo(toolInfo)); - } - - // if(source.getToolspecifics().size() > 0) { - // System.out.println("-->" + source.getToolspecifics()); - // } - - result.setId(source.getId()); - if (source.getType() == fr.lip6.move.pnml.ptnet.PNType.PTNET) { - result.setType(PNType.PTNET); - } else { - throw new PnmlParseException("Illegal Petri Net type '" + source.getType().getLiteral() + "' encountered."); - } - - } - - private void fillPage(fr.lip6.move.pnml.ptnet.Page source, Page result) throws PnmlParseException { - fillPnObject(source, result); - - for (fr.lip6.move.pnml.ptnet.PnObject object : source.getObjects()) { - result.addObject(getPnObject(object)); - } - if (source.getNodegraphics() != null) { - result.setNodeGraphics(getNodeGraphics(source.getNodegraphics())); - } - } - - private void fillPnObject(fr.lip6.move.pnml.ptnet.PnObject source, PnObject result) { - if (source.getName() != null) { - result.setName(getName(source.getName())); - } - for (fr.lip6.move.pnml.ptnet.ToolInfo toolInfo : source.getToolspecifics()) { - result.addToolspecific(getToolInfo(toolInfo)); - } - - result.setId(source.getId()); - } - - private void fillNodeGraphics(fr.lip6.move.pnml.ptnet.NodeGraphics source, NodeGraphics result) { - if (source.getPosition() != null) { - result.setPosition(getPosition(source.getPosition())); - } - if (source.getDimension() != null) { - result.setDimension(getDimension(source.getDimension())); - } - if (source.getFill() != null) { - result.setFill(getFill(source.getFill())); - } - if (source.getLine() != null) { - result.setLine(getLine(source.getLine())); - } - } - - private void fillLine(fr.lip6.move.pnml.ptnet.Line source, Line result) { - result.setColor(CSS2Color.valueOf(source.getColor().getName())); - result.setShape(LineShape.valueOf(source.getShape().getName())); - result.setWidth(source.getWidth()); - result.setStyle(LineStyle.valueOf(source.getStyle().getName())); - } - - private void fillFill(fr.lip6.move.pnml.ptnet.Fill source, Fill result) { - result.setColor(CSS2Color.valueOf(source.getColor().getName())); - result.setGradientcolor(CSS2Color.valueOf(source.getGradientcolor().getName())); - result.setGradientrotation(Gradient.valueOf(source.getGradientrotation().getName())); - result.setImage(source.getImage()); - } - - private void fillDimension(fr.lip6.move.pnml.ptnet.Dimension source, Dimension result) { - fillCoordinate(source, result); - } - - private void fillCoordinate(fr.lip6.move.pnml.ptnet.Coordinate source, Coordinate result) { - result.setX(source.getX()); - result.setY(source.getY()); - } - - private void fillOffset(fr.lip6.move.pnml.ptnet.Offset source, Offset result) { - fillCoordinate(source, result); - } - - private void fillPosition(fr.lip6.move.pnml.ptnet.Position source, Position result) { - fillCoordinate(source, result); - } - - private void fillName(fr.lip6.move.pnml.ptnet.Name source, Name result) { - fillAnnotation(source, result); - - result.setText(source.getText()); - } - - private void fillAnnotation(fr.lip6.move.pnml.ptnet.Annotation source, Annotation result) { - if (source.getAnnotationgraphics() != null) { - result.setAnnotationGraphics(getAnnotationGraphics(source.getAnnotationgraphics())); - } - fillLabel(source, result); - } - - private void fillLabel(fr.lip6.move.pnml.ptnet.Annotation source, Annotation result) { - for (fr.lip6.move.pnml.ptnet.ToolInfo info : source.getToolspecifics()) { - result.addToolspecific(getToolInfo(info)); - } - } - - private void fillAnnotationGraphics(fr.lip6.move.pnml.ptnet.AnnotationGraphics source, AnnotationGraphics result) { - if (source.getOffset() != null) { - result.setOffset(getOffset(source.getOffset())); - } - if (source.getFill() != null) { - result.setFill(getFill(source.getFill())); - } - if (source.getLine() != null) { - result.setLine(getLine(source.getLine())); - } - if (source.getFont() != null) { - result.setFont(getFont(source.getFont())); - } - } - - private void fillFont(fr.lip6.move.pnml.ptnet.Font source, Font result) { - result.setAlign(FontAlign.valueOf(source.getAlign().getName())); - result.setDecoration(FontDecoration.valueOf(source.getDecoration().getName())); - result.setFamily(CSS2FontFamily.valueOf(source.getFamily().getName())); - result.setRotation(source.getRotation()); - result.setSize(CSS2FontSize.valueOf(source.getSize().getName())); - result.setStyle(CSS2FontStyle.valueOf(source.getStyle().getName())); - result.setWeight(CSS2FontWeight.valueOf(source.getWeight().getName())); - } - - private void fillToolInfo(fr.lip6.move.pnml.ptnet.ToolInfo source, ToolInfo result) { - result.setTool(source.getTool()); - result.setVersion(source.getVersion()); - result.setFormattedXMLBuffer(source.getFormattedXMLBuffer()); - result.setToolInfoGrammarURI(source.getToolInfoGrammarURI()); - } - - private void fillPlace(fr.lip6.move.pnml.ptnet.Place source, Place result) { - fillPlaceNode(source, result); - - if (source.getInitialMarking() != null) { - result.setInitialMarking(getPTMarking(source.getInitialMarking())); - } - } - - private void fillPTMarking(fr.lip6.move.pnml.ptnet.PTMarking source, PTMarking result) { - fillAnnotation(source, result); - - // whatever this is supposed to be. they changed the Integer to Long - result.setText(Math.toIntExact(source.getText())); - } - - private void fillRefPlace(fr.lip6.move.pnml.ptnet.RefPlace source, RefPlace result) { - fillPlaceNode(source, result); - - result.setRef(PlaceNode.createRefDirection(source.getRef().getId())); - } - - private void fillPlaceNode(fr.lip6.move.pnml.ptnet.PlaceNode source, PlaceNode result) { - fillNode(source, result); - - for (fr.lip6.move.pnml.ptnet.RefPlace referencingPlace : source.getReferencingPlaces()) { - result.addReferencingPlace(RefPlace.createRefDirection(referencingPlace.getId())); - } - } - - private void fillRefTransition(fr.lip6.move.pnml.ptnet.RefTransition source, RefTransition result) { - fillTransitionNode(source, result); - - result.setRef(TransitionNode.createRefDirection(source.getRef().getId())); - } - - private void fillTransitionNode(fr.lip6.move.pnml.ptnet.TransitionNode source, TransitionNode result) { - fillNode(source, result); - - for (fr.lip6.move.pnml.ptnet.RefTransition refTransition : source.getReferencingTransitions()) { - result.addReferencingTransition(RefTransition.createRefDirection(refTransition.getId())); - } - } - - private void fillTransition(fr.lip6.move.pnml.ptnet.Transition source, Transition result) { - fillTransitionNode(source, result); - } - - private void fillNode(fr.lip6.move.pnml.ptnet.Node source, Node result) { - - fillPnObject(source, result); - - if (source.getNodegraphics() != null) { - result.setNodeGraphics(getNodeGraphics(source.getNodegraphics())); - } - - for (fr.lip6.move.pnml.ptnet.Arc outArc : source.getOutArcs()) { - result.addOutArc(Arc.createRefDirection(outArc.getId())); - } - for (fr.lip6.move.pnml.ptnet.Arc inArc : source.getInArcs()) { - result.addInArc(Arc.createRefDirection(inArc.getId())); - } - } - - private void fillArc(fr.lip6.move.pnml.ptnet.Arc source, Arc result) { - fillPnObject(source, result); - - if (source.getArcgraphics() != null) { - result.setArcGraphics(getArcGraphics(source.getArcgraphics())); - } - if (source.getInscription() != null) { - result.setInscription(getPTArcannotation(source.getInscription())); - } - - result.setSource(Node.createRefDirection(source.getSource().getId())); - result.setTarget(Node.createRefDirection(source.getTarget().getId())); - } - - private void fillPTAnnotation(fr.lip6.move.pnml.ptnet.PTArcAnnotation source, PTArcAnnotation result) { - fillAnnotation(source, result); - - // whatever this is supposed to be. they changed the Integer to Long - result.setText(Math.toIntExact(source.getText())); - } - - private void fillArcGraphics(fr.lip6.move.pnml.ptnet.ArcGraphics source, ArcGraphics result) { - for (fr.lip6.move.pnml.ptnet.Position position : source.getPositions()) { - result.addPosition(getPosition(position)); - } - if (source.getLine() != null) { - result.setLine(getLine(source.getLine())); - } - } - -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlRefTransitionResolver.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlRefTransitionResolver.java deleted file mode 100644 index a3aca62..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlRefTransitionResolver.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -import de.tudresden.inf.st.pnml.jastadd.model.Arc; -import de.tudresden.inf.st.pnml.jastadd.model.Place; -import de.tudresden.inf.st.pnml.jastadd.model.RefTransition; -import de.tudresden.inf.st.pnml.jastadd.model.TransitionNode; - -import java.util.Set; - -public class PnmlRefTransitionResolver { - - public static void resolveIncomingPlaces(TransitionNode transitionNode, Set<Place> incomingPlaces){ - - if(transitionNode.isTransition()){ - for (Arc incomingArc : transitionNode.getInArcList()) { - incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); - } - return; - } - - if(transitionNode.isRefTransition()){ - RefTransition rt = transitionNode.asRefTransition(); - TransitionNode subRt = rt.get_impl_ref(); - - for (Arc incomingArc : transitionNode.getInArcList()) { - incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); - } - - resolveIncomingPlaces(subRt, incomingPlaces); - } - } - - public static void resolveOutgoingPlaces(TransitionNode transitionNode, Set<Place> outgoingPlaces){ - - if(transitionNode.isTransition()){ - for (Arc outgoingArc : transitionNode.getOutArcList()) { - outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); - } - return; - } - - if(transitionNode.isRefTransition()){ - RefTransition rt = transitionNode.asRefTransition(); - TransitionNode subRt = rt.get_impl_ref(); - - for (Arc outgoingArc : transitionNode.getInArcList()) { - outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); - } - - resolveIncomingPlaces(subRt, outgoingPlaces); - } - } -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlSignalParser.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlSignalParser.java deleted file mode 100644 index d3236a3..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/PnmlSignalParser.java +++ /dev/null @@ -1,304 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; -import de.tudresden.inf.st.pnml.jastadd.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - - -public class PnmlSignalParser { - - private static final Logger logger = LoggerFactory.getLogger(PnmlSignalParser.class); - - public static JastAddList<InputSignalBinding> parseInputSignalBindingDefinitions(JastAddList<ToolInfo> toolInfos){ - - try { - Document doc = parseToolSpecifics(toolInfos); - return parseInputSignalBindingDefinitionsInternal(doc); - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - - return null; - } - - private static JastAddList<InputSignalBinding> parseInputSignalBindingDefinitionsInternal(Document doc) { - - if(doc == null){ - return null; - } - - NodeList isBindingDefList = doc.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_BINDINGS_KEY); - JastAddList<InputSignalBinding> jastAddBindingList = new JastAddList<>(); - - if (isBindingDefList.getLength() > 0 && isBindingDefList.item(0) != null) { - - Node isBindingsNode = isBindingDefList.item(0); - - - if (isBindingsNode.getNodeType() == Node.ELEMENT_NODE) { - - Element isBindingsElement = (Element) isBindingsNode; - - NodeList isBindingNodes = isBindingsElement.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_BINDING_KEY); - - for (int i = 0; i < isBindingNodes.getLength(); i++) { - - Node isBindingNode = isBindingNodes.item(i); - Element isBindingElement = (Element) isBindingNode; - - String tID = isBindingElement.getElementsByTagName(PnmlConstants.TRANSITION_ID_KEY).item(0).getTextContent(); - String isID = isBindingElement.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_ID_KEY).item(0).getTextContent(); - int cVal = Integer.valueOf(isBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); - - // now detected by pnml-relast-validator - /* - if(cVal != 1 && cVal != 0){ - logger.error("[PARSER] Initial value of input signal " + isID + " is not value. Falling back to 0."); - cVal = 0; - } - */ - - InputSignalBinding isb = new InputSignalBinding(); - isb.setInputSignalValue(cVal); - isb.setInputSignalID(isID); - isb.setTransitionID(tID); - - jastAddBindingList.add(isb); - } - } - } - return jastAddBindingList; - } - - public static JastAddList<OutputSignalBinding> parseOutputSignalBindingDefinitions(JastAddList<ToolInfo> toolInfos){ - - try { - Document doc = parseToolSpecifics(toolInfos); - return parseOutputSignalBindingDefinitionsInternal(doc); - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - - return null; - } - - public static String getInitialOutputSignalValueBySignalID(JastAddList<ToolInfo> toolInfos, String id){ - - try { - Document doc = parseToolSpecifics(toolInfos); - - NodeList osBindingDefList = doc.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDINGS_KEY); - - if (osBindingDefList.getLength() > 0 && osBindingDefList.item(0) != null) { - - Node osBindingsNode = osBindingDefList.item(0); - - if (osBindingsNode.getNodeType() == Node.ELEMENT_NODE) { - - Element osBindingsElement = (Element) osBindingsNode; - - NodeList osBindingNodes = osBindingsElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDING_KEY); - - for (int i = 0; i < osBindingNodes.getLength(); i++) { - - Node osBindingNode = osBindingNodes.item(i); - Element osBindingElement = (Element) osBindingNode; - - String osID = osBindingElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_ID_KEY).item(0).getTextContent(); - - if(osID.equals(id)){ - return String.valueOf(osBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); - } - } - } - } - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - - return null; - } - - private static JastAddList<OutputSignalBinding> parseOutputSignalBindingDefinitionsInternal(Document doc) { - - NodeList osBindingDefList = doc.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDINGS_KEY); - JastAddList<OutputSignalBinding> jastAddBindingList = new JastAddList<>(); - - if (osBindingDefList.getLength() > 0 && osBindingDefList.item(0) != null) { - - Node osBindingsNode = osBindingDefList.item(0); - - if (osBindingsNode.getNodeType() == Node.ELEMENT_NODE) { - - Element osBindingsElement = (Element) osBindingsNode; - - NodeList osBindingNodes = osBindingsElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_BINDING_KEY); - - for (int i = 0; i < osBindingNodes.getLength(); i++) { - - Node osBindingNode = osBindingNodes.item(i); - Element osBindingElement = (Element) osBindingNode; - - String pID = osBindingElement.getElementsByTagName(PnmlConstants.PLACE_ID_KEY).item(0).getTextContent(); - String osID = osBindingElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_ID_KEY).item(0).getTextContent(); - String cVal = String.valueOf(osBindingElement.getElementsByTagName(PnmlConstants.CURRENT_VALUE_KEY).item(0).getTextContent()); - - OutputSignalBinding osb = new OutputSignalBinding(); - parseOutputMappings(osBindingElement, pID, osID, cVal, osb); - jastAddBindingList.add(osb); - } - } - } - - return jastAddBindingList; - } - - private static void parseOutputMappings(Element osBindingElement, String pID, String osID, String cVal, OutputSignalBinding osb) { - //osb.setCurrentValue(cVal); - osb.setOutputSignalID(osID); - osb.setPlaceID(pID); - - NodeList eqMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.EQUAL_OS_KEY); - NodeList thresholdMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.THRESHOLD_KEY); - NodeList rangeMappingNodeList = osBindingElement.getElementsByTagName(PnmlConstants.RANGE_OS_KEY); - - for (int j = 0; j < eqMappingNodeList.getLength(); j++) { - Element eqElement = (Element) eqMappingNodeList.item(j); - EqualityOutputMapping eom = new EqualityOutputMapping(); - eom.setValue(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.VALUE_KEY).item(0).getTextContent())); - eom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); - osb.addEqualityOM(eom); - } - - for (int k = 0; k < thresholdMappingNodeList.getLength(); k++) { - Element eqElement = (Element) thresholdMappingNodeList.item(k); - ThresholdOutputMapping tom = new ThresholdOutputMapping(); - tom.setValue(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.VALUE_KEY).item(0).getTextContent())); - tom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); - osb.addThresholdOM(tom); - } - - for (int l = 0; l < rangeMappingNodeList.getLength(); l++) { - Element eqElement = (Element) rangeMappingNodeList.item(l); - RangeOutputMapping rom = new RangeOutputMapping(); - rom.setLowerBound(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.LOWER_BOUND_KEY).item(0).getTextContent())); - rom.setUpperBound(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.UPPER_BOUND_KEY).item(0).getTextContent())); - rom.setResult(Integer.valueOf(eqElement.getElementsByTagName(PnmlConstants.RESULT_KEY).item(0).getTextContent())); - osb.addRangeOM(rom); - } - } - - private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException { - - if(toolInfos == null || toolInfos.getNumChild() == 0){ - return null; - } - - StringBuffer toolInfoStringBuffer = toolInfos.getChild(0).getFormattedXMLBuffer(); - - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - - Document doc = dBuilder.parse(fromStringBuffer(toolInfoStringBuffer)); - doc.getDocumentElement().normalize(); - return doc; - } - - private static InputStream fromStringBuffer(StringBuffer buf) { - return new ByteArrayInputStream(buf.toString().getBytes()); - } - - /*public IoPetriNet doPostProcessing(PetriNet petriNet) { - - System.out.println("doPostProcessing called"); - - try { - IoPetriNet ioPetriNet = new IoPetriNet(); - ioPetriNet.setPN(petriNet); - - if (petriNet.getToolspecificList() != null && petriNet.getToolspecificList().getNumChild() > 0) { - - Document doc = parseToolSpecifics(petriNet.getToolspecificList()); - this.parseSignalDefinitions(doc, ioPetriNet); - this.parseInputSignalBindingDefinitions(doc, ioPetriNet); - this.parseOutputSignalBindingDefinitions(doc, ioPetriNet); - } - - return ioPetriNet; - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - return null; - }/* - - - /*private void parseSignalDefinitions(Document doc, IoPetriNet ioPetriNet) { - - NodeList isDefList = doc.getElementsByTagName(PnmlConstants.INPUT_SIGNALS_KEY); - NodeList osDefList = doc.getElementsByTagName(PnmlConstants.OUTPUT_SIGNALS_KEY); - - ArrayList<String> inputSignalIds = new ArrayList<>(); - ArrayList<String> outputSignalIds = new ArrayList<>(); - - if (isDefList.getLength() > 0 && isDefList.item(0) != null) { - - Node nNode = isDefList.item(0); - - if (nNode.getNodeType() == Node.ELEMENT_NODE) { - - Element eElement = (Element) nNode; - - NodeList inputSignals = eElement.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_KEY); - - for (int i = 0; i < inputSignals.getLength(); i++) { - inputSignalIds.add(inputSignals.item(i).getTextContent()); - } - } - } - - if (osDefList.getLength() > 0 && osDefList.item(0) != null) { - - Node nNode = osDefList.item(0); - - if (nNode.getNodeType() == Node.ELEMENT_NODE) { - - Element eElement = (Element) nNode; - - NodeList outputSignals = eElement.getElementsByTagName(PnmlConstants.OUTPUT_SIGNAL_KEY); - - for (int i = 0; i < outputSignals.getLength(); i++) { - outputSignalIds.add(outputSignals.item(i).getTextContent()); - } - } - } - - for (String isId : inputSignalIds) { - InputSignal is = new InputSignal(); - is.setID(isId); - ioPetriNet.addIS(is); - } - - for (String osId : outputSignalIds) { - OutputSignal os = new OutputSignal(); - os.setID(osId); - ioPetriNet.addOS(os); - } - }*/ -} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/ToolSpecificsParser.java b/src/main/java/de/tudresden/inf/st/pnml/base/parsing/ToolSpecificsParser.java deleted file mode 100644 index 4972f8f..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/parsing/ToolSpecificsParser.java +++ /dev/null @@ -1,382 +0,0 @@ -package de.tudresden.inf.st.pnml.base.parsing; - -import beaver.Symbol; -import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; -import de.tudresden.inf.st.pnml.base.data.CommunicatorInformation; -import de.tudresden.inf.st.pnml.jastadd.model.*; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.ParserConfigurationException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; - -import de.tudresden.inf.st.pnml.jastadd.scanner.ExpressionScanner; -import de.tudresden.inf.st.pnml.jastadd.parser.Parser; - -public class ToolSpecificsParser { - - private static final Logger logger = LoggerFactory.getLogger(ToolSpecificsParser.class); - - public static Root getClauseFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList locationList = doc.getElementsByTagName(PnmlConstants.CLAUSE_KEY); - - if (locationList.getLength() > 0 && locationList.item(0) != null) { - String content = locationList.item(0).getTextContent(); - StringReader reader = new StringReader(content); - ExpressionScanner scanner = new ExpressionScanner(reader); - Parser parser = new Parser(); - return ((Root) parser.parse(scanner)); - } - - } catch (ParserConfigurationException | SAXException | IOException | beaver.Parser.Exception e) { - logger.error(e.getMessage()); - } - } - - return new Root(); - } - - public static CommunicatorInformation getCommunicatorInformationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - CommunicatorInformation ci = new CommunicatorInformation(); - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList communicatorList = doc.getElementsByTagName(PnmlConstants.COMMUNICATOR); - - for(int i = 0; i < communicatorList.getLength(); i++){ - - String ct = null; - String cs = null; - - for(int j = 0; j < communicatorList.item(i).getChildNodes().getLength(); j++){ - org.w3c.dom.Node n = communicatorList.item(i).getChildNodes().item(j); - - String newline = System.getProperty("line.separator"); - if(n.getTextContent().length() > 1 && !n.getTextContent().contains(newline)){ - - if(n.getNodeName().equals(PnmlConstants.COMMUNICATOR_TYPE)){ - ct = n.getTextContent(); - } - - if(n.getNodeName().equals(PnmlConstants.COMMUNICATOR_SUBNET)){ - cs = n.getTextContent(); - } - - if(ct != null && cs != null){ - ci.addMapping(cs, ct); - ct = null; - cs = null; - } - } - } - } - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return ci; - } - - public static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList locationList = doc.getElementsByTagName(PnmlConstants.LOCATION_KEY); - - if (locationList.getLength() > 0 && locationList.item(0) != null) { - return locationList.item(0).getTextContent(); - } - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - - return ""; - } - - public static String getArcTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList locationList = doc.getElementsByTagName(PnmlConstants.ARC_TYPE_KEY); - - if (locationList.getLength() > 0 && locationList.item(0) != null) { - String content = locationList.item(0).getTextContent(); - - if(content.equals(PnmlConstants.DEFAULT_ARC) || content.equals(PnmlConstants.INHIBITOR_ARC)){ - return content; - } - } - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - - return ""; - } - - public static String getTransitionTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); - - if (typeList.getLength() > 0 && typeList.item(0) != null) { - String type = typeList.item(0).getTextContent(); - if (!type.equals(PnmlConstants.TRANSITION_TYPE_CONTINUOUS) || type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE) - || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC) || !type.equals(PnmlConstants.TRANSITION_TYPE_SERVICE_REQUEST) - || !type.equals(PnmlConstants.TRANSITION_TYPE_SERVICE_RESPONSE)) { - return type; - } else { - logger.error("Error: Invalid transition type configured: " + type + "."); - } - } - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - - return null; - } - - public static String getTransitionTopicFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); - - if (typeList.getLength() > 0 && typeList.item(0) != null) { - String type = typeList.item(0).getTextContent(); - if (type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_LIMITED_IN) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_LIMITED_OUT) - || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_UNLIMITED_IN) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC_UNLIMITED_OUT) - || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC)) { - - NodeList topicList = doc.getElementsByTagName(PnmlConstants.TOPIC_KEY); - - if(topicList.getLength() > 0 && topicList.item(0) != null){ - return topicList.item(0).getTextContent(); - } - } - } - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } - - public static String getTransitionServiceNameFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList typeList = doc.getElementsByTagName(PnmlConstants.SERVICE_NAME); - - if (typeList.getLength() > 0 && typeList.item(0) != null) { - - String type = typeList.item(0).getTextContent(); - if (!type.equals("") && type != null){ - return type; - } - } - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } - - private static String getPlaceTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - NodeList typeList = doc.getElementsByTagName(PnmlConstants.TYPE_KEY); - - if (typeList.getLength() > 0 && typeList.item(0) != null) { - String type = typeList.item(0).getTextContent(); - if (type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS)) { - return type; - } - } - - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } - - public static String getSubnetFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { - return getSubnetInfoInternal(toolInfos); - } - - private static String getSubnetInfoInternal(JastAddList<ToolInfo> toolInfos) { - - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - // String typeTrans = getTransitionTypeFromToolSpecifics(toolInfos); - // String typePlace = getPlaceTypeFromToolSpecifics(toolInfos); - - // String type = typePlace == null ? typeTrans : typePlace; - - // if (type != null && (type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE) - // || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) - // || type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC))) { - - NodeList snList = doc.getElementsByTagName(PnmlConstants.SUBNET_KEY); - - if (snList.getLength() > 0 && snList.item(0) != null) { - return snList.item(0).getTextContent(); - } - // } - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } - - private static String getTransitionSubnetInfo(JastAddList<ToolInfo> toolInfos) { - return getSubnetInfoInternal(toolInfos); - } - - private static String getPlaceSubnetInfo(JastAddList<ToolInfo> toolInfos) { - return getSubnetInfoInternal(toolInfos); - } - - private static int getTransitionLimitsInternal(JastAddList<ToolInfo> toolInfos, String limitType) { - if (toolInfos.getNumChild() > 0) { - try { - Document doc = parseToolSpecifics(toolInfos); - String transitionType = getTransitionTypeFromToolSpecifics(toolInfos); - - if (transitionType != null && (transitionType.equals(PnmlConstants.TRANSITION_TYPE_TOPIC))) { - - NodeList limList = doc.getElementsByTagName(limitType); - - if (limList.getLength() > 0 && limList.item(0) != null) { - return Integer.valueOf(limList.item(0).getTextContent()); - } - } - } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error(e.getMessage()); - } - } - return -1; - } - - private static int getTransitionOutputLimit(JastAddList<ToolInfo> toolInfos) { - return getTransitionLimitsInternal(toolInfos, PnmlConstants.OUTPUT_LIMIT_KEY); - } - - private static int getTransitionInputLimit(JastAddList<ToolInfo> toolInfos) { - return getTransitionLimitsInternal(toolInfos, PnmlConstants.INPUT_LIMIT_KEY); - } - - public static TransitionInformation getTransitionInformation(JastAddList<ToolInfo> toolInfos) { - - if(getTransitionTopicFromToolSpecifics(toolInfos) != null){ - TopicTransitionInformation topicTransition = new TopicTransitionInformation(); - topicTransition.setInputLimit(getTransitionInputLimit(toolInfos)); - topicTransition.setOutputLimit(getTransitionOutputLimit(toolInfos)); - topicTransition.setLocation(getLocationFromToolSpecifics(toolInfos)); - topicTransition.setType(getTransitionTypeFromToolSpecifics(toolInfos)); - topicTransition.setTopic(getTransitionTopicFromToolSpecifics(toolInfos)); - topicTransition.setSubNet(getTransitionSubnetInfo(toolInfos)); - return topicTransition; - } - - if(getTransitionServiceNameFromToolSpecifics(toolInfos) != null){ - ServiceTransitionInformation serviceTransition = new ServiceTransitionInformation(); - serviceTransition.setInputLimit(getTransitionInputLimit(toolInfos)); - serviceTransition.setOutputLimit(getTransitionOutputLimit(toolInfos)); - serviceTransition.setLocation(getLocationFromToolSpecifics(toolInfos)); - serviceTransition.setType(getTransitionTypeFromToolSpecifics(toolInfos)); - serviceTransition.setServiceName(getTransitionServiceNameFromToolSpecifics(toolInfos)); - serviceTransition.setSubNet(getTransitionSubnetInfo(toolInfos)); - return serviceTransition; - } - - DefaultTransitionInformation transitionInformation = new DefaultTransitionInformation(); - transitionInformation.setInputLimit(getTransitionInputLimit(toolInfos)); - transitionInformation.setOutputLimit(getTransitionOutputLimit(toolInfos)); - transitionInformation.setLocation(getLocationFromToolSpecifics(toolInfos)); - transitionInformation.setType(getTransitionTypeFromToolSpecifics(toolInfos)); - transitionInformation.setSubNet(getTransitionSubnetInfo(toolInfos)); - - return transitionInformation; - } - - public static PlaceInformation getPlaceInformationInformation(JastAddList<ToolInfo> toolInfos){ - - PlaceInformation placeInformation = new PlaceInformation(); - - placeInformation.setLocation(getLocationFromToolSpecifics(toolInfos)); - placeInformation.setType(getPlaceTypeFromToolSpecifics(toolInfos)); - String sn = getPlaceSubnetInfo(toolInfos); - placeInformation.setSubNet(sn); - - return placeInformation; - } - - public static PlaceInformation getPlaceInformation(JastAddList<ToolInfo> toolInfos) { - - PlaceInformation pi = new PlaceInformation(); - pi.setLocation(getLocationFromToolSpecifics(toolInfos)); - pi.setSubNet(getPlaceSubnetInfo(toolInfos)); - pi.setType(getPlaceTypeFromToolSpecifics(toolInfos)); - - return pi; - } - - private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException { - - ToolInfo ti = null; - - for(ToolInfo toolInfo : toolInfos){ - if(toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.SUBNET_KEY) > 0 || - toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.COMMUNICATOR) > 0){ - ti = toolInfo; - break; - } - } - - StringBuffer toolInfoStringBuffer = ti.getFormattedXMLBuffer(); - - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - - Document doc = dBuilder.parse(fromStringBuffer(toolInfoStringBuffer)); - doc.getDocumentElement().normalize(); - return doc; - } - - private static InputStream fromStringBuffer(StringBuffer buf) { - return new ByteArrayInputStream(buf.toString().getBytes()); - } -} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/tina/TinaAccessor.java b/src/main/java/de/tudresden/inf/st/pnml/base/tina/TinaAccessor.java deleted file mode 100644 index 960b214..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/tina/TinaAccessor.java +++ /dev/null @@ -1,129 +0,0 @@ -package de.tudresden.inf.st.pnml.base.tina; - -import de.tudresden.inf.st.pnml.base.parsing.PnmlSignalParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.util.UUID; - -public class TinaAccessor { - - private static final Logger logger = LoggerFactory.getLogger(TinaAccessor.class); - - /** - * @param inputPath - * @return path with file containing results - */ - public static String analyzePetriNet(String inputPath) throws IOException, InterruptedException { - - boolean isWindows = System.getProperty("os.name") - .toLowerCase().startsWith("windows"); - - String homeDirectory = System.getProperty("user.dir"); - ProcessBuilder tinaProcessBuilder = new ProcessBuilder(); - String fileName = "temp/tina/tina-result-" + UUID.randomUUID().toString() + ".txt"; - - File file = new File(fileName); - if (!file.exists()){ - file.getParentFile().mkdirs(); - } - file.createNewFile(); - - FileWriter fileWriter = new FileWriter(fileName); - - // -- Linux -- - // tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", - // homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/zero-reset-correct-2.pnml"); - - if(!isWindows){ - - // testing adds subproject as path-part - if(homeDirectory.contains("pnml-relast-checker")){ - tinaProcessBuilder.command(homeDirectory + "/libs/tina-3.7.0/bin/tina", - "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", "-bcg",inputPath); - }else{ - tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", - "-R", "-s", "1", "-c", "0", "-t", "0", "-b", "0", "-m", "0", "-v", "-PNML", "-bcg",inputPath); - } - }else{ - logger.error("Windows is currently not supported. Exiting ..."); - return null; - } - - try { - - Process process = tinaProcessBuilder.start(); - //StringBuilder output = new StringBuilder(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream())); - - String line; - while ((line = reader.readLine()) != null) { - fileWriter.write(line + "\n"); - } - - fileWriter.close(); - - int exitVal = process.waitFor(); - if (exitVal == 0) { - System.exit(0); - } - - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - - return fileName; - } - - public static boolean isPetriNetBounded (String inputPath) throws IOException { - - boolean isWindows = System.getProperty("os.name") - .toLowerCase().startsWith("windows"); - - String homeDirectory = System.getProperty("user.dir"); - ProcessBuilder tinaProcessBuilder = new ProcessBuilder(); - - if(!isWindows){ - if(homeDirectory.contains("pnml-relast-checker")){ - tinaProcessBuilder.command(homeDirectory + "/libs/tina-3.7.0/bin/tina", "-PNML", inputPath); - }else{ - tinaProcessBuilder.command(homeDirectory + "/pnml-relast-checker/libs/tina-3.7.0/bin/tina", "-PNML", inputPath); - } - }else{ - logger.error("Windows is currently not supported. Exiting ..."); - return false; - } - - try { - - Process process = tinaProcessBuilder.start(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream())); - - String line; - boolean isInAnalysisSection = false; - - while ((line = reader.readLine()) != null) { - if(line.startsWith("bounded") && isInAnalysisSection){ - return true; - } - if(line.startsWith("REACHABILITY ANALYSIS")){ - isInAnalysisSection = true; - } - } - - - int exitVal = process.waitFor(); - if (exitVal == 0) { - System.exit(0); - } - - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - - return false; - } -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlReferenceFlatter.java b/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlReferenceFlatter.java deleted file mode 100644 index e09d437..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlReferenceFlatter.java +++ /dev/null @@ -1,138 +0,0 @@ -package de.tudresden.inf.st.pnml.base.transforming; - -import de.tudresden.inf.st.pnml.jastadd.model.*; - -import java.util.HashSet; -import java.util.Set; - -public class PnmlReferenceFlatter { - - public static void findPlaceReferences(PlaceNode placeNode, Set<PlaceNode> nodes){ - - nodes.addAll(placeNode.getReferencingPlaces()); - - for(RefPlace rp : placeNode.getReferencingPlaces()){ - findPlaceReferences(rp, nodes); - } - } - - public static void findTransitionReferences(TransitionNode transitionNode, Set<TransitionNode> nodes){ - - nodes.addAll(transitionNode.getReferencingTransitions()); - - for(RefTransition rt : transitionNode.getReferencingTransitions()){ - findTransitionReferences(rt, nodes); - } - } - - public static void pnml2Tina(PetriNet petriNet){ - - excludeAllPages(petriNet); - resolvePlaceReferences(petriNet); - resolveTransitionReferences(petriNet); - petriNet.flushTreeCache(); - } - - public static void resolvePlaceReferences(PetriNet petriNet){ - - Set<PlaceNode> nodesToDelete = new HashSet<>(); - - for(Place p : petriNet.allReferencedPlaces()){ - - Set<PlaceNode> referencer = new HashSet<>(); - Set<Arc> connectedInArcs = new HashSet<>(); - Set<Arc> connectedOutArcs = new HashSet<>(); - - findPlaceReferences(p, referencer); - - // get all arcs - for(PlaceNode placeNode : referencer){ - connectedInArcs.addAll(placeNode.getInArcs()); - connectedOutArcs.addAll(placeNode.getOutArcs()); - nodesToDelete.add(placeNode); - } - - // relink in-arcs - for(Arc inArc: connectedInArcs){ - inArc.setTarget(p); - } - - // relink out-arcs - for(Arc outArc: connectedOutArcs){ - outArc.setSource(p); - } - } - - for(PlaceNode placeNode : nodesToDelete){ - placeNode.removeSelf(); - } - // petriNet.flushTreeCache(); - } - - public static void resolveTransitionReferences(PetriNet petriNet){ - - Set<TransitionNode> nodesToDelete = new HashSet<>(); - - for(Transition t : petriNet.allReferencedTransitions()){ - - Set<TransitionNode> referencer = new HashSet<>(); - Set<Arc> connectedInArcs = new HashSet<>(); - Set<Arc> connectedOutArcs = new HashSet<>(); - - findTransitionReferences(t, referencer); - - // get all arcs - for(TransitionNode transitionNode : referencer){ - connectedInArcs.addAll(transitionNode.getInArcs()); - connectedOutArcs.addAll(transitionNode.getOutArcs()); - nodesToDelete.add(transitionNode); - } - - // relink in-arcs - for(Arc inArc: connectedInArcs){ - inArc.setTarget(t); - } - - // relink out-arcs - for(Arc outArc: connectedOutArcs){ - outArc.setSource(t); - } - } - - for(TransitionNode transitionNode : nodesToDelete){ - transitionNode.removeSelf(); - } - // petriNet.flushTreeCache(); - } - - /** - * Excludes all but the top level page. - * @param petriNet - */ - public static void excludeAllPages(PetriNet petriNet){ - - Page topLevelPage = null; - - for (Page p : petriNet.allPages()){ - if(p.ContainingPage() == null){ - topLevelPage = p; - } - } - - for (PnObject pnObject : petriNet.allObjects()){ - assert topLevelPage != null; - if(pnObject.ContainingPage() != null && !pnObject.isPageNode()){ - // System.out.println("Moving: " + pnObject.getId()); - topLevelPage.addObject(pnObject); - } - } - - for (Page p : petriNet.allPages()){ - if(p.ContainingPage() != null){ - p.removeSelf(); - } - } - - // petriNet.flushTreeCache(); - } -} diff --git a/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlSlicer.java b/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlSlicer.java deleted file mode 100644 index 2c08c2d..0000000 --- a/src/main/java/de/tudresden/inf/st/pnml/base/transforming/PnmlSlicer.java +++ /dev/null @@ -1,94 +0,0 @@ -package de.tudresden.inf.st.pnml.base.transforming; - -import de.tudresden.inf.st.pnml.jastadd.model.*; - -import java.util.HashSet; -import java.util.Set; - -public class PnmlSlicer { - - /** - * Cuts out a subnet ignoring pages. - * @param petriNet - * @param subnet - * @return - */ - public static PetriNet cutOutSubNet(PetriNet petriNet, String subnet){ - - Set<Arc> arcsToBeRemoved = collectNonSubnetArcs(petriNet, subnet); - - for(Arc a : arcsToBeRemoved){ - a.removeSelf(); - } - - for(Place p : petriNet.allPlaces()){ - if(!p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet().equals(subnet)){ - p.removeSelf(); - } - } - - for(RefPlace rp : petriNet.allRefPlaces()){ - if(!rp.getSubNet().equals(subnet)){ - rp.removeSelf(); - } - } - - for(Transition t : petriNet.allTransitions()){ - if(!t.asInputSignalTransition().getStaticTransitionInformation().getSubNet().equals(subnet)){ - t.removeSelf(); - } - } - - for(RefTransition rt : petriNet.allRefTransitions()){ - if(!rt.getSubNet().equals(subnet)){ - rt.removeSelf(); - } - } - - petriNet.flushTreeCache(); - return petriNet; - } - - private static Set<Arc> collectNonSubnetArcs(PetriNet petriNet, String subnet){ - - Set<Arc> arcs = new HashSet<>(); - - for(Arc a : petriNet.allArcs()){ - - if(a.getSource().isPlaceNode() && !isPlaceInSubnet(a.getSource().asPlaceNode(), petriNet, subnet)){ - arcs.add(a); - } - - if(a.getTarget().isPlaceNode() && !isPlaceInSubnet(a.getTarget().asPlaceNode(), petriNet, subnet)){ - arcs.add(a); - } - - if(a.getSource().isTransitionNode() && !isTransitionInSubnet(a.getSource().asTransitionNode(), petriNet, subnet)){ - arcs.add(a); - } - - if(a.getTarget().isTransitionNode() && !isTransitionInSubnet(a.getTarget().asTransitionNode(), petriNet, subnet)) { - arcs.add(a); - } - } - return arcs; - } - - private static boolean isPlaceInSubnet(PlaceNode p, PetriNet pn, String subnet){ - - if(p.isRefPlace()){ - return false; - } - - return pn.getPlaceFromPlaceNode(p).asOutputSignalPlace().getStaticPlaceInformation().getSubNet().equals(subnet); - } - - private static boolean isTransitionInSubnet(TransitionNode t, PetriNet pn, String subnet){ - - if(t.isRefTransition()){ - return false; - } - - return pn.getTransitionFromTransitionNode(t).asInputSignalTransition().getStaticTransitionInformation().getSubNet().equals(subnet); - } -} diff --git a/src/main/resources/PnmlRelAstVersion.properties b/src/main/resources/PnmlRelAstVersion.properties new file mode 100644 index 0000000..4b81a1b --- /dev/null +++ b/src/main/resources/PnmlRelAstVersion.properties @@ -0,0 +1,2 @@ +#Sun Apr 10 23:25:26 CEST 2022 +version=0.4.0 -- GitLab