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 {
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;
......
......@@ -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);
}
......
......@@ -52,20 +52,16 @@ 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))){
if(portElem.getTextContent().equals(id)){
return Integer.valueOf(portElem.getAttribute(PnmlConstants.CHANNEL_LIMIT_KEY));
}
}
}
} catch(ParserConfigurationException | SAXException | IOException e){
logger.error(e.getMessage());
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment