From 74db660dcae1b03ff0b4140cd3feffb843a84bca Mon Sep 17 00:00:00 2001
From: SebastianEbert <sebastian.ebert@tu-dresden.de>
Date: Tue, 29 Aug 2023 18:06:01 +0200
Subject: [PATCH] extended export, added flattener test nets

---
 .../base/export/ComplexElementsConverter.jadd |   3 +-
 .../base/parsing/ToolSpecificsParser.jadd     |   9 +
 .../{sample => test_flattener}/TestNet1.pnml  |   0
 .../{sample => test_flattener}/TestNet2.pnml  |  14 +-
 .../nets/test_flattener/TestNet2_Cyclic.pnml  | 201 ++++++++++++++++++
 .../{sample => test_flattener}/TestNet3.pnml  |  10 +-
 .../nets/test_flattener/TestNet3_Multi.pnml   |  42 ++++
 .../{sample => test_flattener}/TestNet4.pnml  |  20 +-
 8 files changed, 266 insertions(+), 33 deletions(-)
 rename src/main/resources/nets/{sample => test_flattener}/TestNet1.pnml (100%)
 rename src/main/resources/nets/{sample => test_flattener}/TestNet2.pnml (91%)
 create mode 100644 src/main/resources/nets/test_flattener/TestNet2_Cyclic.pnml
 rename src/main/resources/nets/{sample => test_flattener}/TestNet3.pnml (77%)
 create mode 100644 src/main/resources/nets/test_flattener/TestNet3_Multi.pnml
 rename src/main/resources/nets/{sample => test_flattener}/TestNet4.pnml (92%)

diff --git a/src/main/jastadd/base/export/ComplexElementsConverter.jadd b/src/main/jastadd/base/export/ComplexElementsConverter.jadd
index de231e8..0b0e6d8 100644
--- a/src/main/jastadd/base/export/ComplexElementsConverter.jadd
+++ b/src/main/jastadd/base/export/ComplexElementsConverter.jadd
@@ -50,7 +50,8 @@ aspect ComplexElementsConverter{
                 }
 
                 for (int i = 0; i < petriNet.getNumToolspecific(); i++) {
-                    if (petriNet.getToolspecific(i).getFormattedXMLBuffer().indexOf("</toolspecific>") > -1) {
+                    if (petriNet.getToolspecific(i).getFormattedXMLBuffer() != null &&
+                            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(),
diff --git a/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
index 1a05ee5..d1c5868 100644
--- a/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
+++ b/src/main/jastadd/base/parsing/ToolSpecificsParser.jadd
@@ -158,6 +158,11 @@ aspect ToolSpecificsParser{
 
             try {
                 Document doc = parseToolSpecifics(toolInfos);
+
+                if(doc == null){
+                    return inputSignalDefs;
+                }
+
                 org.w3c.dom.NodeList sDefList = doc.getElementsByTagName(PnmlConstants.INPUT_SIGNALS_DEF);
 
                 if (sDefList.getLength() > 0 && sDefList.item(0) != null) {
@@ -496,6 +501,10 @@ aspect ToolSpecificsParser{
 
         private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException {
 
+            if (toolInfos == null || toolInfos.getNumChild() == 0 || toolInfos.getChild(0).getFormattedXMLBuffer() == null) {
+                return null;
+            }
+
             ToolInfo ti = null;
 
             for (ToolInfo toolInfo : toolInfos) {
diff --git a/src/main/resources/nets/sample/TestNet1.pnml b/src/main/resources/nets/test_flattener/TestNet1.pnml
similarity index 100%
rename from src/main/resources/nets/sample/TestNet1.pnml
rename to src/main/resources/nets/test_flattener/TestNet1.pnml
diff --git a/src/main/resources/nets/sample/TestNet2.pnml b/src/main/resources/nets/test_flattener/TestNet2.pnml
similarity index 91%
rename from src/main/resources/nets/sample/TestNet2.pnml
rename to src/main/resources/nets/test_flattener/TestNet2.pnml
index 3ceccac..5b1e840 100644
--- a/src/main/resources/nets/sample/TestNet2.pnml
+++ b/src/main/resources/nets/test_flattener/TestNet2.pnml
@@ -6,16 +6,6 @@
             <text>ServiceNet</text>
         </name>
         <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
-       <!--     <communicators>
-                <communicator>
-                    <cType>serviceClient</cType>
-                    <cSubnet>s1</cSubnet>
-                </communicator>
-                <communicator>
-                    <cType>serviceServer</cType>
-                    <cSubnet>s2</cSubnet>
-                </communicator>
-            </communicators>-->
         </toolspecific>
         <page id="top">
             <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
@@ -62,7 +52,7 @@
                     <serviceName>sampleService</serviceName>
                     <serverInput>serverIn</serverInput>
                     <serverOutput>serverOut</serverOutput>
-                    <serverCapacity>16</serverCapacity>
+                    <serverCapacity>1</serverCapacity>
                     <channels>
                         <channel>
                             <cid>c1</cid>
@@ -119,4 +109,4 @@
             </page>
         </page>
     </net>
-</pnml>
\ No newline at end of file
+</pnml>
diff --git a/src/main/resources/nets/test_flattener/TestNet2_Cyclic.pnml b/src/main/resources/nets/test_flattener/TestNet2_Cyclic.pnml
new file mode 100644
index 0000000..3c36108
--- /dev/null
+++ b/src/main/resources/nets/test_flattener/TestNet2_Cyclic.pnml
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pnml
+        xmlns="http://www.pnml.org/version-2009/grammar/pnml">
+    <net id="n-E2D0-BCF46-0" type="http://www.pnml.org/version-2009/grammar/ptnet">
+        <name>
+            <text>ServiceNet</text>
+        </name>
+        <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+        </toolspecific>
+        <page id="top">
+            <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                <type>dinerosPage</type>
+            </toolspecific>
+            <page id="sourcePage">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <type>serverPrototype</type>
+                    <serviceName>sampleService0</serviceName>
+                </toolspecific>
+                <place id="serverIn0">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n2</node>
+                        <subnet>s2</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>serverIn0</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="serverOut0">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n2</node>
+                        <subnet>s2</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>serverOut0</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="req0">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n1</node>
+                        <subnet>s1</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>req0</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="res0">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n1</node>
+                        <subnet>s1</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>res0</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+            </page>
+            
+            <transition id="serviceTransition0">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <type>serviceTransitionType</type>
+                    <serviceName>sampleService0</serviceName>
+                    <serverInput>serverIn0</serverInput>
+                    <serverOutput>serverOut0</serverOutput>
+                    <serverCapacity>1</serverCapacity>
+                    <channels>
+                        <channel>
+                            <cid>c1</cid>
+                            <request>req1</request>
+                            <response>res1</response>
+                        </channel>
+                    </channels>
+                </toolspecific>
+                <name>
+                    <text>serviceTransition0</text>
+                    <graphics>
+                        <offset x="0" y="0" />
+                    </graphics>
+                </name>
+                <graphics>
+                    <position x="0" y="0" />
+                </graphics>
+            </transition>
+            <transition id="serviceTransition1">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <type>serviceTransitionType</type>
+                    <serviceName>sampleService1</serviceName>
+                    <serverInput>serverIn1</serverInput>
+                    <serverOutput>serverOut1</serverOutput>
+                    <serverCapacity>1</serverCapacity>
+                    <channels>
+                        <channel>
+                            <cid>c1</cid>
+                            <request>req0</request>
+                            <response>res0</response>
+                        </channel>
+                    </channels>
+                </toolspecific>
+                <name>
+                    <text>serviceTransition1</text>
+                    <graphics>
+                        <offset x="0" y="0" />
+                    </graphics>
+                </name>
+                <graphics>
+                    <position x="0" y="0" />
+                </graphics>
+            </transition>
+            
+            <page id="targetPage">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <type>serverPrototype</type>
+                    <serviceName>sampleService1</serviceName>
+                </toolspecific>
+                <place id="serverIn1">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n2</node>
+                        <subnet>s2</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>serverIn1</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="serverOut1">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n2</node>
+                        <subnet>s2</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>serverOut1</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="req1">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n1</node>
+                        <subnet>s1</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>req1</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                <place id="res1">
+                    <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                        <node>n1</node>
+                        <subnet>s1</subnet>
+                    </toolspecific>
+                    <name>
+                        <text>res1</text>
+                        <graphics>
+                            <offset x="0" y="0" />
+                        </graphics>
+                    </name>
+                    <graphics>
+                        <position x="0" y="0" />
+                    </graphics>
+                </place>
+                
+            </page>
+        </page>
+    </net>
+</pnml>
diff --git a/src/main/resources/nets/sample/TestNet3.pnml b/src/main/resources/nets/test_flattener/TestNet3.pnml
similarity index 77%
rename from src/main/resources/nets/sample/TestNet3.pnml
rename to src/main/resources/nets/test_flattener/TestNet3.pnml
index 15362bc..fdb6574 100644
--- a/src/main/resources/nets/sample/TestNet3.pnml
+++ b/src/main/resources/nets/test_flattener/TestNet3.pnml
@@ -16,6 +16,14 @@
                     <inputsignalID>is2</inputsignalID>
                     <initialvalue>false</initialvalue>
                 </inputsignal>
+                <inputsignal>
+                    <inputsignalID>is3</inputsignalID>
+                    <initialvalue>true</initialvalue>
+                </inputsignal>
+                <inputsignal>
+                    <inputsignalID>is4</inputsignalID>
+                    <initialvalue>false</initialvalue>
+                </inputsignal>
             </inputsignals>
         </toolspecific>
         <page id="top">
@@ -24,7 +32,7 @@
                     <node>n1</node>
                     <subnet>s1</subnet>
                     <type>discreteTransitionType</type>
-                    <inputsignalclause>(is1 OR NOT is2) AND (is1 OR is2)</inputsignalclause>
+                    <inputsignalclause>(is1 OR NOT is2) AND (is3 OR is4)</inputsignalclause>
                 </toolspecific>
                 <name>
                     <text>transition</text>
diff --git a/src/main/resources/nets/test_flattener/TestNet3_Multi.pnml b/src/main/resources/nets/test_flattener/TestNet3_Multi.pnml
new file mode 100644
index 0000000..86365f8
--- /dev/null
+++ b/src/main/resources/nets/test_flattener/TestNet3_Multi.pnml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pnml
+        xmlns="http://www.pnml.org/version-2009/grammar/pnml">
+    <net id="n-E2D0-BCF46-0" type="http://www.pnml.org/version-2009/grammar/ptnet">
+        <name>
+            <text>SignalNet</text>
+        </name>
+        <!-- read via attribute -->
+        <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+            <inputsignals>
+                <inputsignal>
+                    <inputsignalID>is1</inputsignalID>
+                    <initialvalue>true</initialvalue>
+                </inputsignal>
+            </inputsignals>
+        </toolspecific>
+        <page id="top">
+            <transition id="t1">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <node>n1</node>
+                    <subnet>s1</subnet>
+                    <type>discreteTransitionType</type>
+                    <inputsignalclause>(is1)</inputsignalclause>
+                </toolspecific>
+                <name>
+                    <text>t1</text>
+                </name>
+            </transition>
+            <transition id="t2">
+                <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
+                    <node>n1</node>
+                    <subnet>s1</subnet>
+                    <type>discreteTransitionType</type>
+                    <inputsignalclause>(is1)</inputsignalclause>
+                </toolspecific>
+                <name>
+                    <text>t2</text>
+                </name>
+            </transition>
+        </page>
+    </net>
+</pnml>
diff --git a/src/main/resources/nets/sample/TestNet4.pnml b/src/main/resources/nets/test_flattener/TestNet4.pnml
similarity index 92%
rename from src/main/resources/nets/sample/TestNet4.pnml
rename to src/main/resources/nets/test_flattener/TestNet4.pnml
index 5ea8aa7..9b760ed 100644
--- a/src/main/resources/nets/sample/TestNet4.pnml
+++ b/src/main/resources/nets/test_flattener/TestNet4.pnml
@@ -6,24 +6,6 @@
             <text>ServiceNet2</text>
         </name>
         <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
-      <!--      <communicators>
-                <communicator>
-                    <cType>serviceClient</cType>
-                    <cSubnet>s1</cSubnet>
-                </communicator>
-                <communicator>
-                    <cType>serviceClient</cType>
-                    <cSubnet>s2</cSubnet>
-                </communicator>
-                <communicator>
-                    <cType>serviceServer</cType>
-                    <cSubnet>s2</cSubnet>
-                </communicator>
-                <communicator>
-                    <cType>serviceServer</cType>
-                    <cSubnet>s3</cSubnet>
-                </communicator>
-            </communicators>-->
         </toolspecific>
         <page id="top">
             <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1">
@@ -220,4 +202,4 @@
             </page>
         </page>
     </net>
-</pnml>
\ No newline at end of file
+</pnml>
-- 
GitLab