Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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);
     }
   }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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);
   }
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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());
         }
       }
     }
   }
 }
Ejemplo n.º 9
0
 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);
   }
 }
Ejemplo n.º 10
0
 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());
   }
 }
Ejemplo n.º 11
0
 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());
       }
     }
   }
 }
Ejemplo n.º 12
0
 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;
 }