private void load_snap_from_xml(Element snap, StructureCollection structs, LinkedList tempList) throws VisualizerLoadException { Iterator iterator = snap.getChildren().iterator(); if (!iterator.hasNext()) throw new VisualizerLoadException("Ran out of elements"); structs.loadTitle((Element) (iterator.next()), tempList, this); structs.calcDimsAndStartPts(tempList, this); if (!iterator.hasNext()) return; Element child = (Element) iterator.next(); if (child.getName().compareTo("doc_url") == 0) { // load the doc_url add_a_documentation_URL(child.getText().trim()); if (!iterator.hasNext()) return; child = (Element) iterator.next(); } if (child.getName().compareTo("pseudocode_url") == 0) { // load the psuedocode_url add_a_pseudocode_URL(child.getText().trim()); if (!iterator.hasNext()) return; child = (Element) iterator.next(); } if (child.getName().compareTo("audio_text") == 0) { // load the psuedocode_url add_audio_text(child.getText().trim()); if (!iterator.hasNext()) return; child = (Element) iterator.next(); } // create & load the individual structures, hooking them into the StructureCollection. // linespernode : calculate it at end of loadStructure call while (child.getName().compareTo("question_ref") != 0) { StructureType child_struct = assignStructureType(child); child_struct.loadStructure(child, tempList, this); structs.addChild(child_struct); if (!iterator.hasNext()) return; child = (Element) iterator.next(); } if (child.getName().compareTo("question_ref") == 0) { // set up question ref add_a_question_xml(child.getAttributeValue("ref")); } else // should never happen throw new VisualizerLoadException( "Expected question_ref element, but found " + child.getName()); if (iterator.hasNext()) { child = (Element) iterator.next(); throw new VisualizerLoadException( "Found " + child.getName() + " when expecting end of snap."); } } // load_snap_from_xml
public void addVariables(Element inRoot) throws org.jdom2.DataConversionException { Element vs = inRoot.getChild("decoder").getChild("variables"); Element segment = new Element("segment"); segment.setAttribute("space", "253"); root.addContent(segment); Iterator it = vs.getDescendants(); while (it.hasNext()) { Object o = it.next(); if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("variable")) { // get common attributes String comment = e.getAttributeValue("comment"); for (Object oc : e.getChildren("comment")) { Element ec = (Element) oc; if (ec.getAttributeValue("lang", "xml").equals("")) comment = ec.getText(); } String name = e.getAttributeValue("label"); if (name.equals("")) name = e.getAttributeValue("item"); for (Object on : e.getChildren("label")) { Element en = (Element) on; if (en.getAttributeValue("lang", "xml").equals("")) name = en.getText(); } long cv = e.getAttribute("CV").getIntValue(); // find subtype and process Element type; type = e.getChild("decVal"); if (type != null) { segment.addContent(handleDecVal(type, cv, name, comment, e.getAttributeValue("mask"))); continue; } type = e.getChild("enumVal"); if (type != null) { segment.addContent(handleEnumVal(type, cv, name, comment, e.getAttributeValue("mask"))); continue; } type = e.getChild("shortAddressVal"); if (type != null) { segment.addContent(handleShortAddressVal(type, cv, name, comment)); continue; } type = e.getChild("longAddressVal"); if (type != null) { segment.addContent(handleLongAddressVal(type, cv, name, comment)); continue; } } } } }
public Element handleEnumVal(Element type, long cv, String name, String comment, String mask) throws org.jdom2.DataConversionException { Element r; if (mask != null && !mask.equals("")) { r = new Element("bit"); r.setAttribute("size", "8"); r.setAttribute("mask", maskToInt(mask)); } else { r = new Element("int"); } r.setAttribute("origin", "" + (4278190080L + cv)); r.addContent(new Element("name").addContent(name)); if (comment != null && !comment.equals("")) r.addContent(new Element("description").addContent(comment)); Element map = new Element("map"); int counter = 0; r.addContent(map); for (Object c : type.getChildren("enumChoice")) { Element choice = (Element) c; if (choice.getAttribute("value") != null) { counter = choice.getAttribute("value").getIntValue(); } String cname = choice.getAttributeValue("choice"); for (Object oc : choice.getChildren("choice")) { Element ec = (Element) oc; if (ec.getAttributeValue("lang", "xml").equals("")) cname = ec.getText(); } Element relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("" + counter)); relation.addContent(new Element("value").addContent(cname)); counter++; } return r; }