Ejemplo n.º 1
0
 private void parseConstants(String text, String keyword) throws ParseException {
   String constantsString = text.substring(keyword.length());
   if (constantsString.equals("")) return;
   try {
     MIDParser.parseNamedIntegersString(constantsString);
   } catch (ParseException e) {
     throw new ParseException(
         XMIDProcessor.CONSTANTS_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + "\n"
             + e.toString());
   } catch (TokenMgrError e) {
     throw new ParseException(
         XMIDProcessor.CONSTANTS_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ": "
             + LocaleBundle.bundleString("Lexical error"));
   }
 }
Ejemplo n.º 2
0
 // <label1>&<label2>&...  => p(label1),p(label2),...
 private ArrayList<Predicate> getPredicateListFromArc(String placeName, Arc arc)
     throws ParseException {
   if (!MIDParser.isIdentifier(placeName))
     throw new ParseException(
         placeName + " " + LocaleBundle.bundleString("should start with a letter"));
   String activeTokenClassID = CreateGui.getModel().getActiveTokenClassID();
   int pos = CreateGui.getModel().getPosInList(activeTokenClassID, arc.getWeight());
   if (pos >= 0) {
     String arcLabel = arc.getWeight().get(pos).getCurrentMarking().trim();
     ArrayList<Predicate> predicates = new ArrayList<Predicate>();
     try {
       ArrayList<ArrayList<String>> arcLabelList = MIDParser.parseArcLabelString(arcLabel);
       for (ArrayList<String> labelArguments : arcLabelList)
         predicates.add(new Predicate(placeName, labelArguments, arc instanceof InhibitorArc));
       return predicates;
     } catch (ParseException e) {
       throw new ParseException(
           LocaleBundle.bundleString("Arc label")
               + " "
               + arcLabel
               + " ("
               + arc.getSource().getName()
               + " , "
               + arc.getTarget().getName()
               + "). "
               + e.toString());
     }
   }
   return new ArrayList<Predicate>();
 }
Ejemplo 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);
 }
Ejemplo n.º 4
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.º 5
0
 private void parseEnumeration(String text, String keyword) throws ParseException {
   String enumerationString = text.substring(keyword.length());
   if (enumerationString.equals("")) return;
   try {
     MIDParser.parseEnumerationString(enumerationString);
   } catch (ParseException e) {
     throw new ParseException(
         XMIDProcessor.ENUM_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + "\n"
             + e.toString());
   } catch (TokenMgrError e) {
     throw new ParseException(
         XMIDProcessor.ENUM_KEYWORD
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ": "
             + LocaleBundle.bundleString("Lexical error"));
   }
 }
Ejemplo n.º 6
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"));
   }
 }
Ejemplo n.º 7
0
  public void testEvaluation() {
    Lem l = new Lem();
    Model m = null;

    try {
      m = l.parse(new FileInputStream("regression/tests/AssociativityTest.lem"));
    } catch (FileNotFoundException fnfe) {
      fail("Could not find model file " + fnfe.getMessage());
    } catch (IOException e) {
      fail("Could not read model file: " + e.getMessage());
    } catch (ParseException e) {
      fail("Could not parse model file: " + e.getMessage());
    } catch (LemException e) {
      fail("Some LEMException occurred: " + e.getMessage());
    }

    Procedure p =
        m.getDomain("TestDomain")
            .getClass("A")
            .getStateMachine()
            .getState("evalTest")
            .getProcedure();

    DomainContext c = new DomainContext();
    Interpreter i = new Interpreter(null);

    try {
      i.interpret(p, c);
    } catch (LemRuntimeException e) {
      fail("Some LemRuntimeException occurred: " + e.getMessage());
    }
  }
Ejemplo n.º 8
0
  public void testAssociations() {
    Lem l = new Lem();
    Model m = null;

    try {
      m = l.parse(new FileInputStream("regression/tests/AssociationTest.lem"));
    } catch (FileNotFoundException fnfe) {
      fail("Could not find model file " + fnfe.getMessage());
    } catch (IOException e) {
      fail("Could not read model file: " + e.getMessage());
    } catch (ParseException e) {
      fail("Could not parse model file: " + e.getMessage());
    } catch (LemException e) {
      fail("Some LEMException occurred: " + e.getMessage());
    }

    org.jdns.xtuml.metamodel.Class a = m.getDomain("TestDomain").getClass("A");
    org.jdns.xtuml.metamodel.Class b = m.getDomain("TestDomain").getClass("B");
    org.jdns.xtuml.metamodel.Class c = m.getDomain("TestDomain").getClass("C");

    assertEquals("Class A participates in 1 association", 1, a.getAssociations().size());
    assertEquals("Class B participates in 1 association", 1, b.getAssociations().size());
    assertEquals(
        "Class C participates in 1 (reflexive) association", 1, c.getAssociations().size());
  }
Ejemplo n.º 9
0
  public void testSignalGeneration() {
    Lem l = new Lem();
    Model m = null;

    try {
      m = l.parse(new FileInputStream("regression/tests/SignalTest.lem"));
    } catch (FileNotFoundException fnfe) {
      fail("Could not find model file " + fnfe.getMessage());
    } catch (IOException e) {
      fail("Could not read model file: " + e.getMessage());
    } catch (ParseException e) {
      fail("Could not parse model file: " + e.getMessage());
    } catch (LemException e) {
      fail("Some LEMException occurred: " + e.getMessage());
    }

    CreateAction create =
        (CreateAction)
            m.getDomain("TestDomain")
                .getClass("main")
                .getStateMachine()
                .getState("sigInit")
                .getProcedure()
                .getActionBlock()
                .getActions()
                .getFirst();

    Procedure mainProc =
        m.getDomain("TestDomain")
            .getClass("main")
            .getStateMachine()
            .getState("sigTest")
            .getProcedure();

    DomainContext c = new DomainContext();
    Interpreter i = new Interpreter(null);

    try {
      org.jdns.xtuml.runtime.Object obj = i.executeCreateAction(create, c);
      i = new Interpreter(obj);
      i.interpret(mainProc, c);
    } catch (LemRuntimeException e) {
      fail("Some LemRuntimeException occurred: " + e.getMessage());
    }
  }
Ejemplo n.º 10
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());
   }
 }
Ejemplo n.º 11
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.º 12
0
 protected Marking parseSubModelAnnotationMarking(String text, String markingKeyword)
     throws ParseException {
   String markingString = text.substring(markingKeyword.length());
   if (markingString.trim().equals("")) return null;
   Marking marking = null;
   try {
     marking = MIDParser.parseMarkingString(markingString);
   } catch (ParseException e) {
     throw new ParseException(
         markingKeyword
             + " "
             + LocaleBundle.bundleString("annotation")
             + " "
             + text
             + ". "
             + e.toString());
   }
   return marking;
 }
Ejemplo n.º 13
0
  private void openItemActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_openItemActionPerformed
    // Present the user with a file chooser

    File selectedFile;
    Model m = null;

    JFileChooser jfc = new JFileChooser(workingDirectory);
    jfc.setFileFilter(
        new FileFilter() {
          public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith(".lem");
          }

          public String getDescription() {
            return "LEM model files (*.lem)";
          }
        });

    jfc.setCurrentDirectory(workingDirectory);

    jfc.showDialog(this, "Load");

    selectedFile = jfc.getSelectedFile();
    if (selectedFile != null) {
      try {
        m = loadModel(selectedFile);
        if (m != null) {
          models.add(m);
          JOptionPane.showMessageDialog(
              this, "Model loaded successfully.", "Success!", JOptionPane.INFORMATION_MESSAGE);
          workingDirectory = jfc.getSelectedFile().getParentFile();
          getContentPane().remove(MTP);
          MTP = new ModelTreePanel(m);
          getContentPane().add(MTP, BorderLayout.CENTER);
          try {
            ObjectOutputStream Out =
                new ObjectOutputStream(
                    new FileOutputStream(System.getProperty("user.home") + "/" + "WorkSpace.dat"));
            Out.writeObject(new WorkSpace(workingDirectory.getAbsolutePath()));
            Out.close();
          } catch (FileNotFoundException ex) {
          }
        }
      } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(
            this,
            "Could not open the model file: " + fnfe.getMessage(),
            "File not found",
            JOptionPane.ERROR_MESSAGE);
      } catch (ParseException pe) {
        JOptionPane.showMessageDialog(
            this,
            "There was an error in parsing the given model: " + pe.getMessage(),
            "Parse error",
            JOptionPane.ERROR_MESSAGE);

      } catch (LemException le) {
        JOptionPane.showMessageDialog(
            this,
            "There was an error in parsing the given model: " + le.getMessage(),
            "Parse error",
            JOptionPane.ERROR_MESSAGE);
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "An input/output error occured while trying to read the model: " + ioe.getMessage(),
            "Read error",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    setVisible(true);

    /*        metamodel.Procedure p = m.getDomain( "Publications" ).getClass( "Manuscript" ).getStateMachine().getState("Adding").getProcedure();
    runtime.ModelInstance i = new runtime.ModelInstance();

    p.execute(i); */

  } // GEN-LAST:event_openItemActionPerformed
Ejemplo n.º 14
0
  private void importItemActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_importItemActionPerformed
    // Display a file chooser

    File selectedFile;
    Model m = null;

    JFileChooser jfc = new JFileChooser(workingDirectory);
    jfc.setFileFilter(
        new FileFilter() {
          public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith(".xmi");
          }

          public String getDescription() {
            return "XMI UML files (*.xmi)";
          }
        });

    jfc.setCurrentDirectory(workingDirectory);

    jfc.showDialog(this, "Import");

    selectedFile = jfc.getSelectedFile();
    if (selectedFile != null) {
      try {
        m = importModel(selectedFile);
        if (m != null) {
          models.add(m);
          JOptionPane.showMessageDialog(
              this, "Model loaded successfully.", "Success!", JOptionPane.INFORMATION_MESSAGE);
          workingDirectory = jfc.getSelectedFile().getParentFile();
          getContentPane().remove(MTP);
          MTP = new ModelTreePanel(m);
          getContentPane().add(MTP, BorderLayout.CENTER);
          try {
            ObjectOutputStream Out =
                new ObjectOutputStream(
                    new FileOutputStream(System.getProperty("user.home") + "/" + "WorkSpace.dat"));
            Out.writeObject(new WorkSpace(workingDirectory.getAbsolutePath()));
            Out.close();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(
            this,
            "Could not open the model file: " + fnfe.getMessage(),
            "File not found",
            JOptionPane.ERROR_MESSAGE);
      } catch (ParseException pe) {
        JOptionPane.showMessageDialog(
            this,
            "There was an error in parsing the given model: " + pe.getMessage(),
            "Parse error",
            JOptionPane.ERROR_MESSAGE);

      } catch (LemException le) {
        JOptionPane.showMessageDialog(
            this,
            "There was an error in parsing the given model: " + le.getMessage(),
            "Parse error",
            JOptionPane.ERROR_MESSAGE);
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "An input/output error occured while trying to read the model: " + ioe.getMessage(),
            "Read error",
            JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    setVisible(true);
  } // GEN-LAST:event_importItemActionPerformed
Ejemplo n.º 15
0
  public void testLinkDeletion() {
    Lem l = new Lem();
    Model m = null;

    try {
      m = l.parse(new FileInputStream("regression/tests/LinkDeletionTest.lem"));
    } catch (FileNotFoundException fnfe) {
      fail("Could not find model file " + fnfe.getMessage());
    } catch (IOException e) {
      fail("Could not read model file: " + e.getMessage());
    } catch (ParseException e) {
      fail("Could not parse model file: " + e.getMessage());
    } catch (LemException e) {
      fail("Some LEMException occurred: " + e.getMessage());
    }

    CreateAction create =
        (CreateAction)
            m.getDomain("TestDomain")
                .getClass("TestClass")
                .getStateMachine()
                .getState("createTestClass")
                .getProcedure()
                .getActionBlock()
                .getActions()
                .getFirst();

    Procedure mainProc =
        m.getDomain("TestDomain")
            .getClass("TestClass")
            .getStateMachine()
            .getState("unrelateTestClass")
            .getProcedure();

    DomainContext c = new DomainContext();
    Interpreter i = new Interpreter(null);
    int k = 0;
    try {
      org.jdns.xtuml.runtime.Object obj = i.executeCreateAction(create, c);
      i = new Interpreter(obj);
      i.interpret(mainProc, c);
    } catch (LemRuntimeException e) {
      fail(
          "Testing for deletion of association that exist.\n"
              + "Some LemRuntimeException occurred: "
              + e.getMessage());
    }
    int count = 0;
    java.util.Iterator j = c.getAssociationInstances().values().iterator();
    while (j.hasNext()) {
      count += ((java.util.LinkedList) j.next()).size();
    }
    assertEquals("Test result: An association instance has been removed", 0, count);

    c = new DomainContext();
    i = new Interpreter(null);
    mainProc =
        m.getDomain("TestDomain")
            .getClass("TestClass")
            .getStateMachine()
            .getState("unrelateTestClass2")
            .getProcedure();
    try {
      org.jdns.xtuml.runtime.Object obj = i.executeCreateAction(create, c);
      i = new Interpreter(obj);
      i.interpret(mainProc, c);
    } catch (LemRuntimeException e) {
      fail(
          "Testing for deletion of association that does not exist.\n"
              + "Some LemRuntimeException occurred: "
              + e.getMessage());
    }
  }
Ejemplo n.º 16
0
  public void testLinkCreation() {
    Lem l = new Lem();
    Model m = null;

    try {
      m = l.parse(new FileInputStream("regression/tests/LinkCreationTest.lem"));
    } catch (FileNotFoundException fnfe) {
      fail("Could not find model file " + fnfe.getMessage());
    } catch (IOException e) {
      fail("Could not read model file: " + e.getMessage());
    } catch (ParseException e) {
      fail("Could not parse model file: " + e.getMessage());
    } catch (LemException e) {
      fail("Some LEMException occurred: " + e.getMessage());
    }

    CreateAction create =
        (CreateAction)
            m.getDomain("TestDomain")
                .getClass("TestClass")
                .getStateMachine()
                .getState("createTestClass")
                .getProcedure()
                .getActionBlock()
                .getActions()
                .getFirst();

    Procedure mainProc =
        m.getDomain("TestDomain")
            .getClass("TestClass")
            .getStateMachine()
            .getState("relateTestClass")
            .getProcedure();

    DomainContext c = new DomainContext();
    Interpreter i = new Interpreter(null);
    int k = 0;
    try {
      org.jdns.xtuml.runtime.Object obj = i.executeCreateAction(create, c);
      i = new Interpreter(obj);
      i.interpret(mainProc, c);
    } catch (LemRuntimeException e) {
      fail("Some LemRuntimeException occurred: " + e.getMessage());
    }

    java.util.Iterator j = c.getAssociationInstances().values().iterator();
    AssociationInstance a = (AssociationInstance) ((java.util.LinkedList) j.next()).getFirst();
    Instance active = a.getActiveInstance();
    Instance passive = a.getPassiveInstance();
    int count = 0;
    j = c.getAssociationInstances().values().iterator();
    while (j.hasNext()) {
      count += ((java.util.LinkedList) j.next()).size();
    }
    assertEquals("An association instance has been added", 2, count);
    assertEquals(
        "Active perspective instance is of class A", "A", active.getInstanceClass().getName());
    assertEquals(
        "Passive perspective instance is of class B", "B", passive.getInstanceClass().getName());
    Instance linkobject = (Instance) a.getLinkObjectInstance().getInstances().iterator().next();
    assertEquals(
        "Link object instance is of class D", "D", linkobject.getInstanceClass().getName());
    AssociationInstance aI_active =
        (AssociationInstance) active.getAssociationInstances(a.getAssociation()).iterator().next();
    assertEquals("Instance of class A has the correct association instance", a, aI_active);
    AssociationInstance aI_passive =
        (AssociationInstance) passive.getAssociationInstances(a.getAssociation()).iterator().next();
    assertEquals("Instance of class A has the correct association instance", a, aI_passive);

    mainProc =
        m.getDomain("TestDomain")
            .getClass("TestClass")
            .getStateMachine()
            .getState("relateTestClass2")
            .getProcedure();

    c = new DomainContext();
    i = new Interpreter(null);
    try {
      org.jdns.xtuml.runtime.Object obj = i.executeCreateAction(create, c);
      i = new Interpreter(obj);
      i.interpret(mainProc, c);
    } catch (LemRuntimeException e) {

      fail(
          "Testing for creation of association that already exist.\n"
              + "Some LemRuntimeException occurred: "
              + e.getMessage());
    }
  }