Esempio 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;
  }
Esempio 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;
 }
Esempio n. 3
0
 private void parseUnitTests(MID mid, String text, String keyword) throws ParseException {
   String unitTestString = text.substring(keyword.length());
   if (unitTestString.trim().equals("")) return;
   ArrayList<Predicate> unitTests = null;
   try {
     unitTests = MIDParser.parseConditionString(unitTestString);
   } catch (ParseException e) {
     throw new ParseException(
         keyword
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + "\n"
             + e.toString());
   } catch (TokenMgrError e) {
     throw new ParseException(
         keyword
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ": "
             + LocaleBundle.bundleString("Lexical error"));
   }
   for (Predicate test : unitTests) mid.addUnitTest(test);
 }
Esempio n. 4
0
 private void parseNonNegativeEvents(MID mid, String text, String keyword) throws ParseException {
   String nonNegativeEventsString = text.substring(keyword.length());
   if (nonNegativeEventsString.equals("")) return;
   try {
     ArrayList<String> nonNegativeEvents =
         MIDParser.parseIdentifierListString(nonNegativeEventsString);
     mid.setNonNegativeEvents(nonNegativeEvents);
   } catch (ParseException e) {
     throw new ParseException(
         XMIDProcessor.NONNEGATIVE_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + "\n"
             + e.toString());
   } catch (TokenMgrError e) {
     throw new ParseException(
         XMIDProcessor.NONNEGATIVE_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ": "
             + LocaleBundle.bundleString("Lexical error"));
   }
 }
Esempio n. 5
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());
       }
     }
   }
 }
Esempio n. 6
0
 private void parseSubModelMarkingAnnotations(MID mid) throws ParseException {
   for (JPanel subModel : editor.getSubModels())
     if (subModel instanceof PrTPanel) {
       // deal with initial markings
       ArrayList<Marking> initMarkings =
           parseSubModelMarkingAnnotations((PrTPanel) subModel, XMIDProcessor.INIT_KEYWORD);
       Marking nonAnnotationInitMarking =
           subModelNonAnnotationInitialMarkings.get((PrTPanel) subModel);
       if (nonAnnotationInitMarking != null) initMarkings.add(0, nonAnnotationInitMarking);
       if (initMarkings.size() > 1)
         throw new ParseException(
             LocaleBundle.bundleString("Warning")
                 + ": "
                 + modelNameMessage((PrTPanel) subModel)
                 + LocaleBundle.bundleString("SUBMODEL_HAS_MORE_THAN_ONE_INITIAL_MARKINGS"));
       if (initMarkings.size() > 0) {
         if (mid.getInitialMarkings().size() == 0) mid.addInitialMarking(initMarkings.get(0));
         else mid.getInitialMarkings().get(0).merge(initMarkings.get(0));
       }
     }
 }
Esempio n. 7
0
 private void parsePlaces(MID mid) throws ParseException {
   Marking initialMarking = parsePlaces(mid, mainNet);
   if (initialMarking.getPlaces().size() > 0) mid.addInitialMarking(initialMarking);
   if (editor.getKernel().getSystemOptions().isNetHierarchyEnabled()) {
     for (JPanel subModel : editor.getSubModels())
       if (subModel instanceof PrTPanel) {
         Marking subInitMarking = parsePlaces(mid, (PrTPanel) subModel);
         if (subInitMarking.getPlaces().size() > 0)
           subModelNonAnnotationInitialMarkings.put((PrTPanel) subModel, subInitMarking);
       }
   }
 }
Esempio n. 8
0
 protected void parseMainModelAnnotationMarking(MID mid, String text) throws ParseException {
   String markingString = text.substring(XMIDProcessor.INIT_KEYWORD.length());
   if (markingString.trim().equals("")) return;
   Marking marking = null;
   try {
     marking = MIDParser.parseMarkingString(markingString);
     mid.addInitialMarking(marking);
   } catch (ParseException e) {
     throw new ParseException(
         XMIDProcessor.INIT_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ". "
             + e.toString());
   }
 }
Esempio n. 9
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());
         }
       }
     }
   }
 }
Esempio n. 10
0
  private void parsePipeTransition(
      MID mid,
      PrTPanel prtNet,
      PipeTransition pipeTransition,
      ArrayList<Predicate> globalPredicates)
      throws ParseException {
    String transitionSignature = pipeTransition.getName();
    Transition istaTransition = null;
    Predicate signaturePredicate = null;
    try {
      signaturePredicate = MIDParser.parseTransitionSignatureString(transitionSignature);
      istaTransition = new Transition(signaturePredicate.getName());
      istaTransition.setArguments(signaturePredicate.getArguments());
    } catch (Exception e) {
      throw new ParseException(e.toString());
    }
    ArrayList<Predicate> precondition = getPrecondition(pipeTransition);
    ArrayList<Predicate> postcondition = getPostcondition(pipeTransition);
    if (globalPredicates.size() > 0) {
      for (int index = globalPredicates.size() - 1; index >= 0; index--) {
        Predicate global = globalPredicates.get(index);
        precondition.add(0, global);
        postcondition.add(0, global);
      }
    }
    istaTransition.setPrecondition(precondition);
    istaTransition.setPostcondition(postcondition);
    try {
      String whenString = pipeTransition.getGuard().trim();
      if (whenString != null && !whenString.equals("")) {
        MIDParser.parseWhenCondition(istaTransition, whenString);
      }
    } catch (Exception e) {
      throw new ParseException(
          modelNameMessage(prtNet)
              + transitionSignature
              + " "
              + LocaleBundle.bundleString("Guard condition")
              + ":"
              + e.toString());
    }
    MIDParser.checkTransitionArguments(
        transitionSignature,
        signaturePredicate.getArguments(),
        precondition,
        istaTransition.getWhenCondition());
    MIDParser.checkWhenConditionVariables(precondition, istaTransition.getWhenCondition());

    try {
      String effectString = pipeTransition.getEffect().trim();
      ArrayList<Predicate> effect = MIDParser.parseConditionString(effectString);
      istaTransition.setEffect(effect);
    } catch (Exception e) {
      throw new ParseException(
          modelNameMessage(prtNet)
              + transitionSignature
              + " "
              + LocaleBundle.bundleString("Effect")
              + ": "
              + e.toString());
    }

    istaTransition.collectAllVariables();
    MIDParser.checkPostconditionVariables(istaTransition);
    istaTransition.setId(pipeTransition.getId());
    mid.addTransition(istaTransition);
    mid.putPipeTransition(istaTransition, pipeTransition);
  }
Esempio n. 11
0
 private void parseSequencesFile(MID mid, String text, String keyword) throws ParseException {
   String fileString = text.substring(keyword.length());
   if (!fileString.trim().equals(""))
     mid.setSequencesFile(text.substring(keyword.length()).trim());
 }