Skip to content
Snippets Groups Projects
Commit 3b8f0d4a authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

changed to link structure

parent 69c9ea88
No related branches found
No related tags found
No related merge requests found
Showing
with 121 additions and 807 deletions
///////////////////////////////
////// B E A V E R ////////////
///////////////////////////////
configurations {
myBeaver2
jflex2
}
dependencies {
myBeaver2 group: 'net.sf.beaver', name: 'beaver-ant', version: '0.9.11'
jflex2 group: 'de.jflex', name: 'jflex', version: '1.6.1'
}
task generateExpressionBeaver(type: JavaExec) {
inputs.files {
project.file("src/main/jastadd/clauses/ExpressionParser.beaver")
}
outputs.dir {
// This closure is needed to delay reading the genDir setting.
project.file("src/gen/java/de/tudresden/inf/st/pnml/jastadd/parser")
}
classpath = configurations.myBeaver2
main = 'beaver.comp.run.Make'
doFirst {
def outdir = project.file("src/gen/java/de/tudresden/inf/st/pnml/jastadd/parser")
if (!outdir.isDirectory()) {
outdir.mkdirs()
}
def inputFile = project.file("src/main/jastadd/base/clauses/ExpressionParser.beaver")
args(['-d', outdir.path, '-t', '-c', '-w', inputFile.path])
}
}
\ No newline at end of file
// General configuration (plugins, settings, dependencies) // General configuration (plugins, settings, dependencies)
buildscript {
repositories.mavenCentral()
dependencies {
classpath 'org.jastadd:jastaddgradle:1.13.3'
}
}
group 'de.tudresden.inf.st' group 'de.tudresden.inf.st'
version '0.3' version '0.3'
...@@ -7,7 +14,8 @@ apply plugin: 'java-library' ...@@ -7,7 +14,8 @@ apply plugin: 'java-library'
apply plugin: 'jastadd' apply plugin: 'jastadd'
apply plugin: 'application' apply plugin: 'application'
apply plugin: "idea" apply plugin: "idea"
apply plugin: 'java-library'
apply from: 'beaver.gradle'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
...@@ -15,29 +23,13 @@ targetCompatibility = 1.8 ...@@ -15,29 +23,13 @@ targetCompatibility = 1.8
// maven central repo // maven central repo
repositories.mavenCentral() repositories.mavenCentral()
buildscript {
//repositories.mavenCentral()
repositories { repositories {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven {
name 'gitlab-maven'
url 'https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven'
} }
dependencies {
classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.3'
}
configurations {
classpath {
exclude group: 'org.slf4j', module: 'slf4j-api'//, version: '1.7.30'
}
}
/* configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'org.slf4j') {
details.useTarget 'org.slf4j:slf4j-api:1.7.+'
}
}
}*/
} }
idea.module.generatedSourceDirs += file('src/gen/java') idea.module.generatedSourceDirs += file('src/gen/java')
...@@ -47,12 +39,13 @@ jar.manifest.attributes('Main-Class': 'de.tudresden.inf.st.pnml.splitter.Main') ...@@ -47,12 +39,13 @@ jar.manifest.attributes('Main-Class': 'de.tudresden.inf.st.pnml.splitter.Main')
configurations { configurations {
myBeaver ecore
relast
} }
dependencies { dependencies {
implementation project(':pnml-relast-base') // implementation project(':pnml-relast-base')
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jackson_version}" implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jackson_version}"
implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' implementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
...@@ -75,10 +68,11 @@ dependencies { ...@@ -75,10 +68,11 @@ dependencies {
implementation group: 'xalan', name: 'xalan', version: '2.7.2' implementation group: 'xalan', name: 'xalan', version: '2.7.2'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0' compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
myBeaver group: 'net.sf.beaver', name: 'beaver-ant', version: '0.9.11'
jastadd2 "org.jastadd:jastadd:2.3.4" jastadd2 "org.jastadd:jastadd:2.3.4"
relast group: 'org.jastadd', name: 'relast', version: "${relast_version}"
ecore files("libs/ecore2relast-0.1.jar")
} }
// Default run configuration // Default run configuration
...@@ -88,9 +82,6 @@ run { ...@@ -88,9 +82,6 @@ run {
standardInput = System.in standardInput = System.in
} }
// Generated files
//def relastFile = "./src/gen/jastadd/pnml/placeTransition.relast"
jar { jar {
manifest { manifest {
attributes "Main-Class": "de.tudresden.inf.st.pnml.splitter.Main" attributes "Main-Class": "de.tudresden.inf.st.pnml.splitter.Main"
...@@ -108,32 +99,63 @@ jar { ...@@ -108,32 +99,63 @@ jar {
archiveBaseName = 'pnml-splitter' archiveBaseName = 'pnml-splitter'
} }
/*
// Generated files
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']
task ecoreToRelast(type: JavaExec) {
group = 'Build'
classpath = configurations.ecore
mainClass = 'de.tudresden.inf.st.e2j.Main'
doFirst {
delete ecoreOutputFiles
mkdir 'src/gen/jastadd'
}
args ecoreFile, ecoreRelastGrammar
inputs.files ecoreInputFiles
outputs.files ecoreOutputFiles
}
task relastToJastAdd(type: JavaExec) { task relastToJastAdd(type: JavaExec) {
group = 'Build' group = 'Build'
main = "-jar" classpath = configurations.relast
mainClass = 'org.jastadd.relast.compiler.Compiler'
args "libs/relast.jar", doFirst {
"--grammarName=./src/gen/jastadd/placeTransition", delete relastOutputFiles
"--useJastAddNames", mkdir "src/gen/jastadd"
"--listClass=ArrayList", }
args "--useJastAddNames",
"--grammarName=src/gen/jastadd/pnml/placeTransition",
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList", "--jastAddList=JastAddList",
"--resolverHelper", "--resolverHelper",
"--file", '--file'
relastFile, args relastInputFiles
"../pnml-relast-base/src/main/jastadd/marking/Marking.relast",
"../pnml-relast-base/src/main/jastadd/io/IoPN.relast", inputs.files relastInputFiles
"../pnml-relast-base/src/main/jastadd/clauses/expressions.relast" outputs.files relastOutputFiles
}*/ }
jastadd { jastadd {
configureModuleBuild() configureModuleBuild()
modules { modules {
module("pnml-splitter") {
module("pnml") {
java { java {
basedir "src/" basedir "src/"
...@@ -143,37 +165,31 @@ jastadd { ...@@ -143,37 +165,31 @@ jastadd {
jastadd { jastadd {
basedir ".." basedir ".."
// include "pnml-relast-splitter/src/main/jastadd/**/*.ast" include "pnml-relast-splitter/src/main/jastadd/**/**/*.ast"
include "pnml-relast-splitter/src/main/jastadd/**/*.jadd" include "pnml-relast-splitter/src/main/jastadd/**/**/*.jadd"
// include "pnml-relast-splitter/src/main/jastadd/**/*.jrag" include "pnml-relast-splitter/src/main/jastadd/**/**/*.jrag"
include "pnml-relast-splitter/src/gen/jastadd/**/**/*.ast"
// include "pnml-relast-base/src/main/jastadd/**/*.ast" include "pnml-relast-splitter/src/gen/jastadd/**/**/*.jadd"
include "pnml-relast-base/src/main/jastadd/**/*.jadd" include "pnml-relast-splitter/src/gen/jastadd/**/**/*.jrag"
include "pnml-relast-base/src/main/jastadd/**/*.jrag"
include "pnml-relast-base/src/gen/jastadd/**/*.ast"
include "pnml-relast-base/src/gen/jastadd/**/*.jadd"
include "pnml-relast-base/src/gen/jastadd/**/*.jrag"
} }
scanner { scanner {
basedir ".." include "src/main/jastadd/base/clauses/expressions.flex"
// include "pnml-relast-base/main/jastadd/PnmlScanner.flex"
include "pnml-relast-base/src/main/jastadd/clauses/expressions.flex"
} }
parser { parser {
basedir ".." basedir ".."
// include "pnml-relast-base/jastadd/PnmlParser.parser"
} }
} }
} }
cleanGen.doFirst { cleanGen.doFirst {
delete "src/gen/java/de" delete "src/gen/java/de"
delete "src/gen-res/BuildInfo.properties" delete "src/gen-res/BuildInfo.properties"
} }
module = "pnml" module = "pnml-splitter"
astPackage = 'de.tudresden.inf.st.pnml.jastadd.model' astPackage = 'de.tudresden.inf.st.pnml.jastadd.model'
...@@ -190,8 +206,11 @@ jastadd { ...@@ -190,8 +206,11 @@ jastadd {
// Workflow configuration for phases // Workflow configuration for phases
//relastToJastAdd.dependsOn ":pnml-relast-base:ecoreToRelast" //relastToJastAdd.dependsOn ":pnml-relast-base:ecoreToRelast"
generateAst.dependsOn ":pnml-relast-base:relastToJastAdd" //generateAst.dependsOn ":pnml-relast-base:relastToJastAdd"
compileJava.dependsOn ":pnml-relast-base:generateBeaver" //compileJava.dependsOn ":pnml-relast-base:generateBeaver"
//// always run jastadd //// always run jastadd
//jastadd.outputs.upToDateWhen {false} //jastadd.outputs.upToDateWhen {false}
relastToJastAdd.dependsOn ecoreToRelast
generateAst.dependsOn relastToJastAdd
compileJava.dependsOn generateExpressionBeaver
\ No newline at end of file
jackson_version = 2.9.8 jackson_version = 2.9.8
apache_httpcomponents_version = 4.5.8 apache_httpcomponents_version = 4.5.8
relast_version = 0.3.0-137
../../../../../pnml-relast-base/src/main/jastadd/base
\ No newline at end of file
aspect PrimitivesConversion {
syn fr.lip6.move.pnml.ptnet.hlapi.TransitionHLAPI InputSignalTransition.convertToPnmlObject(){
return de.tudresden.inf.st.pnml.splitter.export.PrimitiveElementsConverter.convertTransitionToPnmlObject(this);
}
syn fr.lip6.move.pnml.ptnet.hlapi.PlaceHLAPI OutputSignalPlace.convertToPnmlObject(){
return de.tudresden.inf.st.pnml.splitter.export.PrimitiveElementsConverter.convertPlaceToPnmlObject(this);
}
//syn fr.lip6.move.pnml.ptnet.hlapi.ArcHLAPI Arc.convertToPnmlObject(){
// return de.tudresden.inf.st.export.PrimitiveElementsConverter.convertArcToPnmlObject(this);
//}
}
\ No newline at end of file
../../../../../../../../../../pnml-relast-base/src/data/java/de/tudresden/inf/st/pnml/base
\ No newline at end of file
package de.tudresden.inf.st.pnml.splitter; package de.tudresden.inf.st.pnml.splitter;
import de.tudresden.inf.st.pnml.base.parsing.PnmlParser;
import de.tudresden.inf.st.pnml.splitter.export.PnmlExporter;
import de.tudresden.inf.st.pnml.jastadd.model.*; import de.tudresden.inf.st.pnml.jastadd.model.*;
import de.tudresden.inf.st.pnml.splitter.postprocessing.GlobalToLocalNetsPostProcessor; import de.tudresden.inf.st.pnml.splitter.postprocessing.GlobalToLocalNetsPostProcessor;
import de.tudresden.inf.st.pnml.splitter.postprocessing.PostProcessingUtils; import de.tudresden.inf.st.pnml.splitter.postprocessing.PostProcessingUtils;
......
package de.tudresden.inf.st.pnml.splitter.data;
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;
}
}
\ No newline at end of file
package de.tudresden.inf.st.pnml.splitter.data;
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
package de.tudresden.inf.st.pnml.splitter.export;
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.PNType;
import fr.lip6.move.pnml.ptnet.hlapi.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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() == PNType.PTNET_VALUE){
pn.setTypeHLAPI(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;
}
}
}
package de.tudresden.inf.st.pnml.splitter.export;
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.*;
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
package de.tudresden.inf.st.pnml.splitter.export;
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.*;
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;
}
}
...@@ -2,8 +2,6 @@ package de.tudresden.inf.st.pnml.splitter.postprocessing; ...@@ -2,8 +2,6 @@ package de.tudresden.inf.st.pnml.splitter.postprocessing;
import de.tudresden.inf.st.pnml.splitter.constants.SplitterPnmlConstants; import de.tudresden.inf.st.pnml.splitter.constants.SplitterPnmlConstants;
import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; import de.tudresden.inf.st.pnml.base.constants.PnmlConstants;
import de.tudresden.inf.st.pnml.splitter.export.PnmlExporter;
import de.tudresden.inf.st.pnml.base.parsing.*;
import de.tudresden.inf.st.pnml.jastadd.model.*; 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.InvalidIDException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
......
...@@ -2,7 +2,6 @@ package de.tudresden.inf.st.pnml.splitter.postprocessing; ...@@ -2,7 +2,6 @@ package de.tudresden.inf.st.pnml.splitter.postprocessing;
import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; import de.tudresden.inf.st.pnml.base.constants.PnmlConstants;
import de.tudresden.inf.st.pnml.splitter.copy.CopyPrimitiveElements; import de.tudresden.inf.st.pnml.splitter.copy.CopyPrimitiveElements;
import de.tudresden.inf.st.pnml.splitter.data.Tuple3;
import de.tudresden.inf.st.pnml.jastadd.model.*; import de.tudresden.inf.st.pnml.jastadd.model.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment