63
63
public class TapnXmlLoader {
64
64
private static final String PLACENAME_ERROR_MESSAGE = "The keywords \"true\" and \"false\" are reserved and can not be used as place names.\nPlaces with these names will be renamed to \"_true\" and \"_false\" respectively.\n\n Note that any queries using these places may not be parsed correctly.";
65
private HashMap<TimedTransitionComponent, TimedTransportArcComponent> presetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
66
private HashMap<TimedTransitionComponent, TimedTransportArcComponent> postsetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
67
private HashMap<TimedTransportArcComponent, TimeInterval> transportArcsTimeIntervals = new HashMap<TimedTransportArcComponent, TimeInterval>();
69
private NameGenerator nameGenerator = new NameGenerator();
66
private final HashMap<TimedTransitionComponent, TimedTransportArcComponent> presetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
67
private final HashMap<TimedTransitionComponent, TimedTransportArcComponent> postsetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
68
private final HashMap<TimedTransportArcComponent, TimeInterval> transportArcsTimeIntervals = new HashMap<TimedTransportArcComponent, TimeInterval>();
70
private final NameGenerator nameGenerator = new NameGenerator();
70
71
private boolean firstInhibitorIntervalWarning = true;
71
72
private boolean firstPlaceRenameWarning = true;
72
private IdResolver idResolver = new IdResolver();
73
private final IdResolver idResolver = new IdResolver();
74
private final Collection<String> messages = new ArrayList<>(10);
74
76
private boolean isTimed;
75
77
private boolean isGame;
76
78
private boolean hasUncontrollableTransitions = false;
78
80
public TapnXmlLoader() {
81
84
public LoadedModel load(InputStream file) throws FormatException {
133
136
parseFeature(doc, network);
135
return new LoadedModel(network, templates, queries, isTimed, isGame);
138
return new LoadedModel(network, templates, queries,messages, isTimed, isGame);
138
142
private void parseBound(Document doc, TimedArcPetriNetNetwork network){
187
191
if(name.toLowerCase().equals("true") || name.toLowerCase().equals("false")) {
188
192
name = "_" + name;
189
193
if(firstPlaceRenameWarning) {
190
JOptionPane.showMessageDialog(CreateGui.getApp(), PLACENAME_ERROR_MESSAGE, "Invalid Place Name", JOptionPane.INFORMATION_MESSAGE);
194
messages.add(PLACENAME_ERROR_MESSAGE);
191
195
firstPlaceRenameWarning = false;
344
348
String text = annotation.getTextContent();
346
350
if (positionXTempStorage.length() > 0) {
347
positionXInput = Integer.valueOf(positionXTempStorage) + 1;
351
positionXInput = Integer.parseInt(positionXTempStorage) + 1;
350
354
if (positionYTempStorage.length() > 0) {
351
positionYInput = Integer.valueOf(positionYTempStorage) + 1;
355
positionYInput = Integer.parseInt(positionYTempStorage) + 1;
354
358
if (widthTemp.length() > 0) {
355
widthInput = Integer.valueOf(widthTemp) + 1;
359
widthInput = Integer.parseInt(widthTemp) + 1;
358
362
if (heightTemp.length() > 0) {
359
heightInput = Integer.valueOf(heightTemp) + 1;
363
heightInput = Integer.parseInt(heightTemp) + 1;
362
366
if (borderTemp.length() > 0) {
363
borderInput = Boolean.valueOf(borderTemp);
367
borderInput = Boolean.parseBoolean(borderTemp);
365
369
borderInput = true;
443
447
if(nameInput.toLowerCase().equals("true") || nameInput.toLowerCase().equals("false")) {
444
448
nameInput = "_" + nameInput;
445
449
if(firstPlaceRenameWarning) {
446
JOptionPane.showMessageDialog(CreateGui.getApp(), PLACENAME_ERROR_MESSAGE, "Invalid Place Name", JOptionPane.INFORMATION_MESSAGE);
450
messages.add(PLACENAME_ERROR_MESSAGE);
447
451
firstPlaceRenameWarning = false;
547
551
PlaceTransitionObject targetIn,
548
552
int _endx, int _endy, Template template, Weight weight) throws FormatException {
550
TimedOutputArcComponent tempArc = new TimedOutputArcComponent(
551
sourceIn, targetIn, (!inscriptionTempStorage.equals("") ? Integer.valueOf(inscriptionTempStorage) : 1), idInput);
554
TimedOutputArcComponent tempArc = new TimedOutputArcComponent(sourceIn, targetIn, (!inscriptionTempStorage.equals("") ? Integer.parseInt(inscriptionTempStorage) : 1), idInput);
553
556
TimedPlace place = template.model().getPlaceByName(targetIn.getName());
554
557
TimedTransition transition = template.model().getTransitionByName(sourceIn.getName());
675
678
TimeInterval interval = TimeInterval.parse(inscriptionTempStorage, constants);
677
680
if(!interval.equals(TimeInterval.ZERO_INF) && firstInhibitorIntervalWarning) {
678
JOptionPane.showMessageDialog(CreateGui.getApp(), "The chosen model contained inhibitor arcs with unsupported intervals.\n\nTAPAAL only supports inhibitor arcs with intervals [0,inf).\n\nAny other interval on inhibitor arcs will be replaced with [0,inf).", "Unsupported Interval Detected on Inhibitor Arc", JOptionPane.INFORMATION_MESSAGE);
681
messages.add("The chosen model contained inhibitor arcs with unsupported intervals.\n\nTAPAAL only supports inhibitor arcs with intervals [0,inf).\n\nAny other interval on inhibitor arcs will be replaced with [0,inf).");
679
682
firstInhibitorIntervalWarning = false;
703
706
// Wierd naming convention in pipe: this represents if
704
707
// the arc point is a curve point or not
705
708
String arcTempType = element.getAttribute("arcPointType");
706
double arcPointX = Double.valueOf(arcTempX);
707
double arcPointY = Double.valueOf(arcTempY);
709
double arcPointX = Double.parseDouble(arcTempX);
710
double arcPointY = Double.parseDouble(arcTempY);
708
711
arcPointX += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
709
712
arcPointY += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
710
boolean arcPointType = Boolean.valueOf(arcTempType);
713
boolean arcPointType = Boolean.parseBoolean(arcTempType);
711
714
tempArc.getArcPath().addPoint(arcPointX, arcPointY, arcPointType);