private void checkForDuplicatePlacesInSubModel( PrTPanel parentNet, PipeTransition pipeTransition, PrTPanel childNet) { // composition places ArrayList<String> compositionPlaceNames = getInputPlaces(pipeTransition); for (String inhibitorPlaceName : getInhibitorPlaces(pipeTransition)) if (!compositionPlaceNames.contains(inhibitorPlaceName)) compositionPlaceNames.add(inhibitorPlaceName); for (String outputPlaceName : getOutputPlaces(pipeTransition)) if (!compositionPlaceNames.contains(outputPlaceName)) compositionPlaceNames.add(outputPlaceName); ArrayList<String> placeNamesInParentNet = new ArrayList<String>(); PipePlace[] placesInParentNet = parentNet.getModel().getPlaces(); for (int i = 0; i < placesInParentNet.length; i++) placeNamesInParentNet.add(placesInParentNet[i].getName()); // check non-composition places PipePlace[] placesInChildNet = childNet.getModel().getPlaces(); for (int i = 0; i < placesInChildNet.length; i++) { String placeName = placesInChildNet[i].getName(); if (!compositionPlaceNames.contains(placeName) && placeNamesInParentNet.contains(placeName)) editor.printInConsoleArea( LocaleBundle.bundleString("Warning") + ": " + modelNameMessage(childNet) + placeName + ": " + LocaleBundle.bundleString("PLACE_OCCURRED_IN_BOTH_LEVELS")); } }
public void saveModel(File xmidFile, Sheet sheet, CellStyle lineWrapStyle) { int rowIndex = saveModelHeader(sheet, lineWrapStyle); String separateModelFileName = FileUtil.getDefaultSeparateModelFileName(xmidFile); File separateModelFile = new File(xmidFile.getParent() + File.separator + separateModelFileName); rowIndex = XMIDProcessor.createTableModelTypeRow( editor.getModelType(), separateModelFileName, sheet, rowIndex); mainNet.setFile(separateModelFile); mainNet.saveNet(); }
private void parseTokens(Marking marking, PipePlace place) throws ParseException { String activeTokenClassID = CreateGui.getModel().getActiveTokenClassID(); DataLayerInterface net = mainNet.getModel(); int pos = net.getPosInList(activeTokenClassID, place.getCurrentMarking()); if (pos >= 0) { String tokenString = place.getCurrentMarking().get(pos).getCurrentMarking().trim(); if (tokenString != null && !tokenString.equals("")) { ArrayList<Tuple> tokenList = new ArrayList<Tuple>(); try { tokenList = MIDParser.parseTokenString(tokenString); } catch (ParseException e) { throw new ParseException(place.getName() + ": " + tokenString + ". " + e.toString()); } if (tokenList.size() > 0) { // check arity consistency int firstArity = tokenList.get(0).arity(); for (int index = 1; index < tokenList.size(); index++) if (tokenList.get(0).arity() != firstArity) throw new ParseException( place.getName() + " " + LocaleBundle.bundleString("has inconsistent token length")); // check duplication checkDuplicateTokens(tokenList, place.getName(), tokenString); } marking.addTuples(place.getName(), tokenList); } } }
private void checkForDuplicateEvents() { if (editor.getKernel().getSystemOptions().isNetHierarchyEnabled()) { ArrayList<String> events = new ArrayList<String>(); PipeTransition[] mainTransitions = mainNet.getModel().getTransitions(); for (int i = 0; i < mainTransitions.length; i++) events.add(mainTransitions[i].getName()); for (JPanel subModel : editor.getSubModels()) if (subModel instanceof PrTPanel) { PipeTransition[] subTransitions = ((PrTPanel) subModel).getModel().getTransitions(); for (int i = 0; i < subTransitions.length; i++) { if (events.contains(subTransitions[i].getName())) { editor.printInConsoleArea( LocaleBundle.bundleString("Warning") + ": " + modelNameMessage((PrTPanel) subModel) + subTransitions[i].getName() + ": " + LocaleBundle.bundleString("TRANSITION_OCCURRED_IN_MULTIPLE_MODELS")); } } for (int i = 0; i < subTransitions.length; i++) { events.add(subTransitions[i].getName()); } } } }
private ArrayList<Predicate> parseGlobalPredicates(MID mid, PrTPanel prtNet) throws ParseException { String GLOBAL_KEYWORD = "GLOBAL"; ArrayList<Predicate> globalPredicates = new ArrayList<Predicate>(); DataLayerInterface net = prtNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(GLOBAL_KEYWORD)) { String globalPredicateString = text.substring(GLOBAL_KEYWORD.length()).trim(); try { // abuse transition declaration for global predicate - same syntax Predicate signaturePredicate = MIDParser.parseTransitionSignatureString(globalPredicateString); globalPredicates.add(signaturePredicate); mid.addPlace(signaturePredicate.getName()); } catch (ParseException e) { throw new ParseException( modelNameMessage(prtNet) + text + ": " + LocaleBundle.bundleString("Incorrect GLOBAL annotation")); } } } return globalPredicates; }
private Marking parsePlaces(MID mid, PrTPanel netModel) throws ParseException { DataLayerInterface net = netModel.getModel(); Marking initialMarking = new Marking(); PipePlace[] places = net.getPlaces(); for (int i = 0; i < places.length; i++) { // System.out.println("Place ID: "+places[i].getId()+" Name: "+places[i].getName()); String placeName = places[i].getName(); if (!MIDParser.isIdentifier(placeName)) throw new ParseException( modelNameMessage(netModel) + placeName + " - " + LocaleBundle.bundleString("should start with a letter")); if (!places[i].getConnectFromIterator().hasNext() && !places[i].getConnectToIterator().hasNext()) throw new ParseException( modelNameMessage(netModel) + placeName + " - " + LocaleBundle.bundleString("is not connected")); parseTokens(initialMarking, places[i]); mid.addPlace(placeName); } return initialMarking; }
private int numberOfNumerationAnnotations(PrTPanel prtNet) { int numberOfEnumerations = 0; DataLayerInterface net = prtNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.ENUM_KEYWORD)) numberOfEnumerations++; } return numberOfEnumerations; }
private void parseMarkingAnnotations(MID mid) throws ParseException { DataLayerInterface net = mainNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.INIT_KEYWORD)) parseMainModelAnnotationMarking(mid, text); } if (editor.getKernel().getSystemOptions().isNetHierarchyEnabled()) parseSubModelMarkingAnnotations(mid); }
private void parseConstantsAnnotations(PrTPanel prtNet) throws ParseException { DataLayerInterface net = prtNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.CONSTANTS_KEYWORD)) parseConstants(text, XMIDProcessor.CONSTANTS_KEYWORD); else if (text.startsWith(XMIDProcessor.ENUM_KEYWORD)) parseEnumeration(text, XMIDProcessor.ENUM_KEYWORD); } }
protected ArrayList<Marking> parseSubModelMarkingAnnotations( PrTPanel subPrtPanel, String markingKeyword) throws ParseException { ArrayList<Marking> markings = new ArrayList<Marking>(); DataLayerInterface net = subPrtPanel.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(markingKeyword)) { Marking marking = parseSubModelAnnotationMarking(text, markingKeyword); if (marking != null) markings.add(marking); } } return markings; }
private void parseAssertionPropertyAnnotations(MID mid) throws ParseException { DataLayerInterface net = mainNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.ASSERTION_KEYWORD)) { String assertionString = text.substring(XMIDProcessor.ASSERTION_KEYWORD.length()); if (!assertionString.trim().equals("")) { try { AssertionProperty assertion = MIDParser.parseAssertionPropertyString(assertionString); mid.addAssertionProperty(assertion); } catch (ParseException e) { throw new ParseException(text + ". " + e.toString()); } } } } }
private void parseTransitions(MID mid, PrTPanel prtNet) throws ParseException { ArrayList<Predicate> globalPredicates = parseGlobalPredicates(mid, prtNet); DataLayerInterface net = prtNet.getModel(); PipeTransition[] pipeTransitions = net.getTransitions(); for (int i = 0; i < pipeTransitions.length; i++) { PipeTransition pipeTransition = pipeTransitions[i]; if (pipeTransition.hasValidSubnetFile() && editor.getKernel().getSystemOptions().isNetHierarchyEnabled()) { PrTPanel subModel = editor.findPrTPanelForFile(pipeTransition.getSubnetFileHandler()); if (subModel != null) { // check composition rules, e.g., place names checkForCompositionErrors(prtNet, pipeTransition, subModel); parseTransitions(mid, subModel); } } else parsePipeTransition(mid, prtNet, pipeTransition, globalPredicates); // System.out.println("Transition ID: "+pipeTransitions[i].getId()+" Name: // "+pipeTransitions[i].getName()); } }
private void parseOtherAnnotations(MID mid, PrTPanel prtNet) throws ParseException { DataLayerInterface net = prtNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.UNITTESTS_KEYWORD)) parseUnitTests(mid, text, XMIDProcessor.UNITTESTS_KEYWORD); else if (text.startsWith(XMIDProcessor.SINKS_KEYWORD)) parseSinkEvents(mid, text, XMIDProcessor.SINKS_KEYWORD); else if (text.startsWith(XMIDProcessor.SINK_KEYWORD)) parseSinkEvents(mid, text, XMIDProcessor.SINK_KEYWORD); else if (text.startsWith(XMIDProcessor.NONNEGATIVE_KEYWORD)) parseNonNegativeEvents(mid, text, XMIDProcessor.NONNEGATIVE_KEYWORD); else if (text.startsWith(XMIDProcessor.SEQUENCESFILE_KEYWORD)) parseSequencesFile(mid, text, XMIDProcessor.SEQUENCESFILE_KEYWORD); else if (text.startsWith(XMIDProcessor.SEQUENCES_KEYWORD)) parseSequencesFile(mid, text, XMIDProcessor.SEQUENCES_KEYWORD); } }
private void parseDataAnnotations(MID mid) throws ParseException { DataLayerInterface net = mainNet.getModel(); AnnotationNote[] annotationNotes = net.getLabels(); for (AnnotationNote annotation : annotationNotes) { String text = annotation.getText(); if (text.startsWith(XMIDProcessor.DATA_KEYWORD)) { String dataPath = text.substring(XMIDProcessor.DATA_KEYWORD.length()).trim(); try { ExcelTestDataLoader excelTestDataLoader = new ExcelTestDataLoader( editor.midFile.getParent() + File.separator + dataPath, mid.getPlaces()); for (Marking initMarking : excelTestDataLoader.getInitMarkings()) { mid.addInitialMarking(initMarking); } } catch (Exception e) { throw new ParseException(text + " -> " + e.getMessage()); } } } }
@Override public JMenu getModelMenu() { return editor.createModelMenu(mainNet.getPrTMenu()); }
private String modelNameMessage(PrTPanel netModel) { return editor.getSubModels().size() > 0 ? "[" + netModel.getFile().getName() + "] " : ""; }
public boolean isModelChanged() { return mainNet.isNetChanged() || editor.areSubModelsChanged(); }
private PipePlace pipePlaceInSubNet(String placeName, PrTPanel childNetPanel) { DataLayerInterface net = childNetPanel.getModel(); for (PipePlace pipePlace : net.getPlaces()) if (pipePlace.getName().equals(placeName)) return pipePlace; return null; }
@Override public JToolBar getAdditionalToolBar() { return mainNet.getPaletteToolBar(); }