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); }
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); } }
private void createPlace(JSONObject modelElement, int index) throws JSONException { // Generating the id for the place. // In order to have more space (difference of the ids) between each place element I // multiply the index with 10. So the difference of the ids is always 10. // The space is needed because each place has childnodes which have also id. String resourceId = modelElement.getString("resourceId"); String placeId = "ID" + (3000 + index * 10); // Correct the Hashtable - Entry for that place getArcRelation().changePlaceId(resourceId, placeId); // Load the position of the place into the NodePositions class getNodePositions().newNodePosition(placeId, modelElement); CPNPlace place = new CPNPlace(); place.setId(placeId); place.parse(modelElement); getPlaces().add(place); }