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

improvements on nav and parsing

parent 74db660d
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,9 @@ aspect Navigation { ...@@ -60,6 +60,9 @@ aspect Navigation {
syn boolean PnObject.isPageNode() = false; syn boolean PnObject.isPageNode() = false;
eq Page.isPageNode() = true; eq Page.isPageNode() = true;
syn boolean PnObject.isArcNode() = false;
eq Arc.isArcNode() = true;
syn boolean PnObject.isPlaceObject() = false; syn boolean PnObject.isPlaceObject() = false;
eq Place.isPlaceObject() = true; eq Place.isPlaceObject() = true;
...@@ -129,6 +132,9 @@ aspect Navigation { ...@@ -129,6 +132,9 @@ aspect Navigation {
syn Page PnObject.asPage() = null; syn Page PnObject.asPage() = null;
eq Page.asPage() = this; eq Page.asPage() = this;
syn Arc PnObject.asArc() = null;
eq Arc.asArc() = this;
syn DinerosPlace PnObject.asDinerosPlace() = null; syn DinerosPlace PnObject.asDinerosPlace() = null;
eq DinerosPlace.asDinerosPlace() = this; eq DinerosPlace.asDinerosPlace() = this;
......
...@@ -6,6 +6,8 @@ import fr.lip6.move.pnml.framework.utils.exception.ImportException; ...@@ -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.framework.utils.exception.InvalidIDException;
import fr.lip6.move.pnml.ptnet.hlapi.PetriNetDocHLAPI; 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.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -17,9 +19,28 @@ aspect PnmlParser { ...@@ -17,9 +19,28 @@ aspect PnmlParser {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PnmlParser.class); 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; HLAPIRootClass document = null;
...@@ -28,7 +49,7 @@ aspect PnmlParser { ...@@ -28,7 +49,7 @@ aspect PnmlParser {
//logger.info(document.toPNML()); //logger.info(document.toPNML());
} catch (ImportException | InvalidIDException e) { } 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); logger.error("Exception was thrown!", e);
System.exit(-1); System.exit(-1);
} }
......
...@@ -52,20 +52,16 @@ aspect ToolSpecificsParser{ ...@@ -52,20 +52,16 @@ aspect ToolSpecificsParser{
id = id.split("-INSTANCE")[0]; id = id.split("-INSTANCE")[0];
} }
HashMap<String, ArrayList<String>> res = new HashMap<String, ArrayList<String>>();
try { try {
Document doc = parseToolSpecifics(toolInfos); Document doc = parseToolSpecifics(toolInfos);
org.w3c.dom.NodeList portDefList = doc.getElementsByTagName(PnmlConstants.CHANNEL_PORT_KEY); org.w3c.dom.NodeList portDefList = doc.getElementsByTagName(PnmlConstants.CHANNEL_PORT_KEY);
for(int i = 0; i < portDefList.getLength(); i++){ for(int i = 0; i < portDefList.getLength(); i++){
Element portElem = (Element) portDefList.item(i); Element portElem = (Element) portDefList.item(i);
if(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_KEY).equals(id)){ if(portElem.getTextContent().equals(id)){
if(res.containsKey(portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY))){
return Integer.valueOf(portElem.getAttribute(PnmlConstants.CHANNEL_LIMIT_KEY)); return Integer.valueOf(portElem.getAttribute(PnmlConstants.CHANNEL_LIMIT_KEY));
} }
} }
}
} catch(ParserConfigurationException | SAXException | IOException e){ } catch(ParserConfigurationException | SAXException | IOException e){
logger.error(e.getMessage()); logger.error(e.getMessage());
...@@ -136,11 +132,14 @@ aspect ToolSpecificsParser{ ...@@ -136,11 +132,14 @@ aspect ToolSpecificsParser{
Element portElem = (Element) portDefList.item(i); Element portElem = (Element) portDefList.item(i);
if(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_TYPE_KEY).equals(channelTypeKey)){ if(portElem.getAttribute(PnmlConstants.CHANNEL_PLACE_TYPE_KEY).equals(channelTypeKey)){
if(res.containsKey(portElem.getAttribute(PnmlConstants.CHANNEL_NAME_KEY))){ 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 { } else {
ArrayList<String> placeList = new ArrayList<>(); 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); 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{ ...@@ -511,6 +510,7 @@ aspect ToolSpecificsParser{
if (toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.SUBNET_KEY) > 0 || if (toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.SUBNET_KEY) > 0 ||
toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.TYPE_KEY) > 0 || toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.TYPE_KEY) > 0 ||
toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.INPUT_SIGNALS_DEF) > 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) { toolInfo.getFormattedXMLBuffer().indexOf(PnmlConstants.ARC_TYPE_KEY) > 0) {
ti = toolInfo; ti = toolInfo;
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment