コード例 #1
0
ファイル: draw.java プロジェクト: bossiernesto/jvmbytecodes
  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
コード例 #2
0
  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;
  }
コード例 #3
0
  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;
          }
        }
      }
    }
  }
コード例 #4
0
  public void addHeader(Element inRoot) {
    Element id = new Element("identification");

    String mfg = inRoot.getChild("decoder").getChild("family").getAttributeValue("mfg");
    id.addContent(new Element("manufacturer").addContent(mfg));

    String name = inRoot.getChild("decoder").getChild("family").getAttributeValue("name");
    id.addContent(new Element("model").addContent(name));
    id.addContent(new Element("hardwareVersion"));
    id.addContent(new Element("softwareVersion"));

    // add models in map, if any
    Element map = new Element("map");
    for (Object o : inRoot.getChild("decoder").getChild("family").getChildren("model")) {
      Element e = (Element) o;
      Element relation = new Element("relation");
      relation.addContent(new Element("property").addContent("Model"));
      relation.addContent(new Element("value").addContent(e.getAttributeValue("model")));
      map.addContent(relation);
    }
    id.addContent(map);

    root.addContent(id);
  }
コード例 #5
0
ファイル: draw.java プロジェクト: bossiernesto/jvmbytecodes
 private StructureType assignStructureType(Element structure) throws VisualizerLoadException {
   String name = structure.getName().toLowerCase();
   if (name.compareTo("graph") == 0) {
     if (structure.getAttributeValue("weighted").compareTo("true") == 0)
       return new Graph_Network("NETWORK");
     else return new Graph_Network("GRAPH");
   } else if (name.equals("array")) return new MD_Array();
   else if (name.equals("no3darray")) return new No3darray();
   else if (name.equals("linkedlist")) return new VisLinkedList();
   else if (name.equals("no3dlinkedlist")) return new No3dLinkedList();
   else if (name.equals("linkedlistnonull")) return new VisLinkedListNoNull();
   else if (name.equals("bargraph")) return new BarScat("BAR");
   else if (name.equals("scattergraph"))
     return new BarScat(
         "SCAT"); // not implemented in xml dtd, and does not have a load-from-xml method defined
   else if (name.equals("stack")) return new Stack();
   else if (name.equals("queue")) return new Queue();
   else if (name.equals("tree")) {
     if (structure.getChild("binary_node") != null) return new BinaryTree();
     else return new GeneralTree();
   } else if (name.equals("text")) return new TextStructure();
   // if the XML element name is different from your structure's name, you can do something like
   // this:
   // 	else if( name.equalsIgnoreCase("node"))
   // 	    return new Node();
   else if (name.equals("legend")) return new LegendofColors();
   else {
     // try dynamic typing
     try {
       return assignStructureType(name);
     } catch (Exception e) {
       throw new VisualizerLoadException(
           "Unable to instantiate class \"" + name + "\":\n" + e.getMessage());
     }
   }
 }