Пример #1
0
  private void createTransition(JSONObject modelElement, int index) throws JSONException {
    // See comments above in createPlace(...)
    String resourceId = modelElement.getString("resourceId");
    String transId = "ID" + (4000 + index * 10);

    getArcRelation().changeTransitionId(resourceId, transId);
    getNodePositions().newNodePosition(transId, modelElement);

    CPNTransition transition = new CPNTransition();
    transition.setId(transId);
    transition.parse(modelElement);

    getTransitions().add(transition);
  }
Пример #2
0
  public static void registerMapping(XStream xstream) {
    // In the XML the class is represented as a page - tag
    xstream.alias("page", CPNPage.class);

    xstream.useAttributeFor(CPNPage.class, "idattri");
    xstream.aliasAttribute(CPNPage.class, "idattri", "id");

    // In order not to display the places / transitions / arcs tag, but simply show
    // the page tags one after another.
    xstream.addImplicitCollection(CPNPage.class, "places", CPNPlace.class);
    xstream.addImplicitCollection(CPNPage.class, "transitions", CPNTransition.class);
    xstream.addImplicitCollection(CPNPage.class, "arcs", CPNArc.class);

    // Sometimes XStream cannot translate elements into a XML structure.
    // Therefore exists the possibility to create and register a converter for that element.
    xstream.registerConverter(new CPNTextConverter());

    // These instance variables are not needed for the mapping, that's why they are excluded
    xstream.omitField(CPNPage.class, "arcRelation");
    xstream.omitField(CPNPage.class, "nodePositions");

    // Giving all fields a concrete name for the XML
    xstream.aliasField("Aux", CPNPage.class, "auxtag");
    xstream.aliasField("group", CPNPage.class, "grouptag");
    xstream.aliasField("vguidelines", CPNPage.class, "vguidelines");
    xstream.aliasField("hguidelines", CPNPage.class, "hguidelines");

    CPNPageattr.registerMapping(xstream);
    CPNModellingThing.registerMapping(xstream);
    CPNPlace.registerMapping(xstream);
    CPNTransition.registerMapping(xstream);
    CPNArc.registerMapping(xstream);
    CPNLittleProperty.registerMapping(xstream);
  }
Пример #3
0
  public void readJSONchildShapes(JSONObject modelElement) throws JSONException {
    // See the comment in the first line

    // Creating a queue
    JSONArray arcs = new JSONArray();

    // Get all childshapes
    JSONArray childShapes = modelElement.optJSONArray("childShapes");

    if (childShapes != null) {
      int i;
      for (i = 0; i < childShapes.length(); i++) {
        JSONObject childShape = childShapes.getJSONObject(i);
        String stencil = childShape.getJSONObject("stencil").getString("id");

        // Looking whether it is a transition, place or an arc
        if (CPNTransition.handlesStencil(stencil)) createTransition(childShape, i);
        else if (CPNPlace.handlesStencil(stencil)) createPlace(childShape, i);

        // Putting every arc in the queue in order to wait that every
        // place and transition is mapped.
        else if (CPNArc.handlesStencil(stencil)) arcs.put(childShape);
      }

      // After every place and transition is mapped,
      // we can begin to map the arcs in the queue.
      for (i = 0; i < arcs.length(); i++) createArc(arcs.getJSONObject(i), i);
    }
  }