From fb17d71f18f3f3847bc807e0a70b9780271ad05a Mon Sep 17 00:00:00 2001
From: SebastianEbert <sebastian.ebert@tu-dresden.de>
Date: Thu, 14 Sep 2023 18:23:00 +0200
Subject: [PATCH] improvements on nav and parsing

---
 src/main/jastadd/base/Navigation.jrag         |  6 +++++
 src/main/jastadd/base/parsing/PnmlParser.jadd | 27 ++++++++++++++++---
 .../base/parsing/ToolSpecificsParser.jadd     | 16 +++++------
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/src/main/jastadd/base/Navigation.jrag b/src/main/jastadd/base/Navigation.jrag
index 4c7bb07..d40f4ea 100644
--- a/src/main/jastadd/base/Navigation.jrag
+++ b/src/main/jastadd/base/Navigation.jrag
@@ -60,6 +60,9 @@ aspect Navigation {
   syn boolean PnObject.isPageNode() = false;
   eq Page.isPageNode() = true;
 
+  syn boolean PnObject.isArcNode() = false;
+  eq Arc.isArcNode() = true;
+
   syn boolean PnObject.isPlaceObject() = false;
   eq Place.isPlaceObject() = true;
 
@@ -129,6 +132,9 @@ aspect Navigation {
   syn Page PnObject.asPage() = null;
   eq Page.asPage() = this;
 
+  syn Arc PnObject.asArc() = null;
+  eq Arc.asArc() = this;
+
   syn DinerosPlace PnObject.asDinerosPlace() = null;
   eq DinerosPlace.asDinerosPlace() = this;
 
diff --git a/src/main/jastadd/base/parsing/PnmlParser.jadd b/src/main/jastadd/base/parsing/PnmlParser.jadd
index ca1b900..affd86f 100644
--- a/src/main/jastadd/base/parsing/PnmlParser.jadd
+++ b/src/main/jastadd/base/parsing/PnmlParser.jadd
@@ -6,6 +6,8 @@ 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.Files;
+import java.nio.file.StandardCopyOption;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -17,9 +19,28 @@ aspect PnmlParser {
 
         private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PnmlParser.class);
 
-        public static List<PetriNet> parsePnml(String fileName) {
+        public static Path toTempPath(String ressourcePath) {
 
-            Path file = Paths.get(fileName);
+            Path tempFile = null;
+            try {
+                tempFile = Files.createTempFile(null, null);
+                Files.copy(PnmlParser.class.getResourceAsStream(ressourcePath), tempFile, StandardCopyOption.REPLACE_EXISTING);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            return tempFile;
+        }
+
+        public static List<PetriNet> parsePnml(String path, boolean useTemp) {
+
+            Path file = null;
+
+            if(useTemp){
+                file = toTempPath(path);
+            } else {
+                file = Paths.get(path);
+            }
 
             HLAPIRootClass document = null;
 
@@ -28,7 +49,7 @@ aspect PnmlParser {
 
                 //logger.info(document.toPNML());
             } catch (ImportException | InvalidIDException e) {
-                logger.error("Unable to import PNML document from file '{}'", fileName);
+                logger.error("Unable to import PNML document from file '{}'", path);
                 logger.error("Exception was thrown!", e);
                 System.exit(-1);
             }
diff --git a/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
index d1c5868..4b70cbf 100644
--- a/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
+++ b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
@@ -52,18 +52,14 @@ aspect ToolSpecificsParser{
                 id = id.split("-INSTANCE")[0];
             }
 
-            HashMap<String, ArrayList<String>> res =  new HashMap<String, ArrayList<String>>();
-
             try {
                 Document doc = parseToolSpecifics(toolInfos);
                 org.w3c.dom.NodeList portDefList = doc.getElementsByTagName(PnmlConstants.CHANNEL_PORT_KEY);
 
                 for(int i = 0; i < portDefList.getLength(); i++){
                     Element portElem = (Element) portDefList.item(i);
-                    if(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_KEY).equals(id)){
-                        if(res.containsKey(portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY))){
-                            return Integer.valueOf(portElem.getAttribute(PnmlConstants.CHANNEL_LIMIT_KEY));
-                        }
+                    if(portElem.getTextContent().equals(id)){
+                        return Integer.valueOf(portElem.getAttribute(PnmlConstants.CHANNEL_LIMIT_KEY));
                     }
                 }
 
@@ -136,11 +132,14 @@ aspect ToolSpecificsParser{
                     Element portElem = (Element) portDefList.item(i);
                     if(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_TYPE_KEY).equals(channelTypeKey)){
                         if(res.containsKey(portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY))){
-                            res.get(PnmlConstants.CHANNEL_NAME_KEY).add(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_KEY));
+                            res.get(PnmlConstants.CHANNEL_NAME_KEY).add(portElem.getTextContent());
                         } else {
                             ArrayList<String> placeList = new ArrayList<>();
-                            placeList.add(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_KEY));
+                            placeList.add(portElem.getTextContent());
                             res.put(portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY), placeList);
+                            System.out.println("[Parser] Creating mapping: " +
+                                    portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY) +
+                                    " >> " + portElem.getTextContent());
                         }
                     }
                 }
@@ -511,6 +510,7 @@ aspect ToolSpecificsParser{
                 if (toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.SUBNET_KEY) > 0 ||
                         toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.TYPE_KEY) > 0 ||
                         toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.INPUT_SIGNALS_DEF) > 0 ||
+                        toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.CHANNEL_PORT_KEY) > 0 ||
                         toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.ARC_TYPE_KEY) > 0) {
                     ti = toolInfo;
                     break;
-- 
GitLab