Skip to content
Snippets Groups Projects
Commit 7da5a7ae authored by Johannes Mey's avatar Johannes Mey
Browse files

throw exceptions instead of exiting on errors

parent 3921e9d2
No related branches found
No related tags found
No related merge requests found
Pipeline #14700 passed
...@@ -37,22 +37,18 @@ public class PnmlParser { ...@@ -37,22 +37,18 @@ public class PnmlParser {
* @param fileName the file name of a *.pnml file * @param fileName the file name of a *.pnml file
* @return a list of Petri nets * @return a list of Petri nets
*/ */
public static List<PetriNet> parsePnml(String fileName) { public static List<PetriNet> parsePnml(String fileName) throws PnmlParseException {
Path file = Paths.get(fileName); Path file = Paths.get(fileName);
HLAPIRootClass document = null; HLAPIRootClass document = null;
try { try {
document = PNMLUtils.importPnmlDocument(file.toFile(), false); document = PNMLUtils.importPnmlDocument(file.toFile(), false);
logger.debug(document.toPNML());
logger.info(document.toPNML());
} catch (ImportException | InvalidIDException e) { } catch (ImportException | InvalidIDException e) {
logger.error("Unable to import PNML document from file '{}'", fileName); throw new PnmlParseException("Unable to import PNML document from file '" + fileName + "'", e);
logger.error("Exception was thrown!", e);
System.exit(-1);
} }
logger.info("Imported document workspace ID: {}", ModelRepository.getInstance().getCurrentDocWSId()); logger.info("Imported document workspace ID: {}", ModelRepository.getInstance().getCurrentDocWSId());
List<PetriNet> petriNets = new ArrayList<>(); List<PetriNet> petriNets = new ArrayList<>();
...@@ -60,18 +56,12 @@ public class PnmlParser { ...@@ -60,18 +56,12 @@ public class PnmlParser {
fr.lip6.move.pnml.framework.general.PNType type = PNMLUtils.determinePNType(document); fr.lip6.move.pnml.framework.general.PNType type = PNMLUtils.determinePNType(document);
switch (type) { switch (type) {
case PTNET: case PTNET:
PetriNetDocHLAPI ptDoc = PetriNetDocHLAPI ptDoc = (PetriNetDocHLAPI) document;
(PetriNetDocHLAPI) document;
for (fr.lip6.move.pnml.ptnet.PetriNet pmnlNet : ptDoc.getNets()) { for (fr.lip6.move.pnml.ptnet.PetriNet pmnlNet : ptDoc.getNets()) {
PnmlParser parser; PnmlParser parser;
try { parser = new PnmlParser(pmnlNet);
parser = new PnmlParser(pmnlNet); petriNets.add(parser.getPetriNet());
petriNets.add(parser.getPetriNet());
} catch (PnmlParseException e) {
logger.error("Parsing the Petri net using the PNML framework failed.", e);
}
} }
break; break;
...@@ -80,7 +70,7 @@ public class PnmlParser { ...@@ -80,7 +70,7 @@ public class PnmlParser {
case HLPN: case HLPN:
case PTHLPN: case PTHLPN:
default: default:
logger.error("Petri net is of unsupported type {}.", type.getLiteral()); throw new PnmlParseException("Petri net is of unsupported type " + type.getLiteral() + ".");
} }
return petriNets; return petriNets;
} }
......
...@@ -2,6 +2,7 @@ package de.tudresden.inf.st.pnml; ...@@ -2,6 +2,7 @@ package de.tudresden.inf.st.pnml;
import de.tudresden.inf.st.pnml.jastadd.model.PNType; import de.tudresden.inf.st.pnml.jastadd.model.PNType;
import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; import de.tudresden.inf.st.pnml.jastadd.model.PetriNet;
import de.tudresden.inf.st.pnml.jastadd.model.PnmlParseException;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -17,7 +18,7 @@ class PnmlTest { ...@@ -17,7 +18,7 @@ class PnmlTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"src/test/resources/minimal.pnml", "src/test/resources/philo.pnml", "src/test/resources/haddadin_automaton_flat.pnml"}) @ValueSource(strings = {"src/test/resources/minimal.pnml", "src/test/resources/philo.pnml", "src/test/resources/haddadin_automaton_flat.pnml"})
void parsePnml(String fileName) { void parsePnml(String fileName) throws PnmlParseException {
List<PetriNet> result = PnmlParser.parsePnml(fileName); List<PetriNet> result = PnmlParser.parsePnml(fileName);
assertThat(result).asList() assertThat(result).asList()
.isNotEmpty() .isNotEmpty()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment