示例#1
0
  private void createArc(JSONObject modelElement, int index) throws JSONException {
    String resourceId = modelElement.getString("resourceId");
    // Getting source and target of the arc
    String target = getArcRelation().getTargetValue(resourceId);
    String source = getArcRelation().getSourceValue(resourceId);
    String arcId = "ID" + (5000 + index * 10);

    String transend, placeend, orientation;

    // Setting the orientation of the arc
    if (isTransition(target)) {
      transend = target;
      placeend = source;
      orientation = "PtoT";
    } else {
      transend = source;
      placeend = target;
      orientation = "TtoP";
    }

    modelElement.put("transend", transend);
    modelElement.put("placeend", placeend);
    modelElement.put("orientation", orientation);

    CPNArc arc = new CPNArc();

    arc.setId(arcId);
    arc.parse(modelElement);

    arc.positionAnnotation(getNodePositions());
    arc.organizeBendpoints();

    getArcs().add(arc);
  }
示例#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);
    }
  }