예제 #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;
  }
예제 #2
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);
  }