Beispiel #1
0
  void parseArrows(NodeList list) {
    int len = list.getLength();
    for (int i = 0; i < len; i++) {
      if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element node = (Element) list.item(i);
        String name = node.getAttribute("name");
        String desc = node.getAttribute("description");
        String cls = node.getAttribute("class");
        String catg = node.getAttribute("category");
        String from = null;
        String to = null;
        String icon = null;

        NodeDesc ndfrom, ndto;
        ndfrom = formalism.getNodeDesc(node.getAttribute("from"));
        // System.err.println(nd);
        if (ndfrom == null) ndfrom = formalism.getConnectorDesc(node.getAttribute("from"));
        if (ndfrom != null) from = ndfrom.getElementClass();

        ndto = formalism.getNodeDesc(node.getAttribute("to"));
        if (ndto == null) ndto = formalism.getConnectorDesc(node.getAttribute("to"));
        if (ndto != null) to = ndto.getElementClass();

        NodeList icontag = node.getElementsByTagName("icon");
        if (icontag.getLength() > 0) icon = ((Element) icontag.item(0)).getAttribute("url");

        ArrowDesc ad =
            new ArrowDesc(
                name, desc, cls, icon, from, to, ndfrom,
                ndto); // formalism.getNodeDesc(from), formalism.getNodeDesc(to));
        //			System.err.println("LOADXF"+from+to+"|"+ndfrom+
        //	   " /"+ ndto+" "+
        //   formalism.getNodeDescList());
        ad.setCategory(catg);
        formalism.addArrowDesc(ad);
        ad.setFormalism(formalism);

        NodeList graphic = node.getElementsByTagName("graphic-element");
        if (graphic.getLength() > 0) {
          String graphicClass = ((Element) graphic.item(0)).getAttribute("class");
          if (!graphicClass.equals("")) ad.setGraphicClass(graphicClass);
          // System.err.println("calsselementpost"+ad.getGraphicClass());
          NodeList proplist = ((Element) graphic.item(0)).getElementsByTagName("property");
          if (proplist.getLength() > 0) ad.setGraphicProperties(getProperties(proplist));
          node.removeChild(graphic.item(0));
        }

        NodeList proplist = node.getElementsByTagName("property");
        if (proplist.getLength() > 0)
          try {
            ReflectorUtil.setProperties(ad, getProperties(proplist));
          } catch (Exception e) {
            Utils.log("setProperties failed:" + e);
          }
        NodeList actionList = node.getElementsByTagName("action");
        for (int j = 0; j < actionList.getLength(); j++)
          if (actionList.item(j).getNodeType() == Node.ELEMENT_NODE)
            ad.addActionDesc(parseAction((Element) actionList.item(j)));
      }
    }
  }
Beispiel #2
0
  void parseNodes(NodeList list) {
    int len = list.getLength();
    for (int i = 0; i < len; i++) {
      Hashtable prophash = new Hashtable();
      NodeDesc nd = null;

      if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element node = (Element) list.item(i);
        String name = node.getAttribute("name");
        String catg = node.getAttribute("category");
        String desc = node.getAttribute("description");
        String cls = node.getAttribute("class");
        String icon = null;

        NodeList childs = node.getChildNodes();
        boolean component = false;
        for (int j = 0; j < childs.getLength(); j++)
          if (childs.item(j).getNodeType() == Node.ELEMENT_NODE) {
            Element child = (Element) childs.item(j);
            if (child.getNodeName().equals("module")) component = true;
          }
        if (component) nd = new ComponentDesc(name, desc, cls);
        else nd = new NodeDesc(name, desc, cls);
        nd.setFormalism(formalism);

        for (int j = 0; j < childs.getLength(); j++)
          if (childs.item(j).getNodeType() == Node.ELEMENT_NODE) {
            Element child = (Element) childs.item(j);
            if (child.getNodeName().equals("icon")) {
              // NodeList icontag = node.getElementsByTagName("icon");
              //	  if (icontag.getLength() > 0)
              // (Element)
              icon = child.getAttribute("url");
              nd.setIcon(icon);
            }
            if (child.getNodeName().equals("module")) {
              String type = child.getAttribute("type");
              //					    System.err.println("Module detected:"+type);
              int codemodule = 0;

              if (type.toLowerCase().equals("free")) codemodule = ComponentDesc.MODULE_FREE;
              if (type.toLowerCase().equals("template")) codemodule = ComponentDesc.MODULE_TEMPLATE;
              if (type.toLowerCase().equals("fixed")) codemodule = ComponentDesc.MODULE_FIXED;

              String layout = child.getAttribute("layout");
              // System.err.println("Module layout detected:"+layout);
              int codelayout = 0;

              if (layout.toLowerCase().equals("auto"))
                codelayout = ComponentDesc.MODULE_PLACEMENT_AUTO;
              if (layout.toLowerCase().equals("justified"))
                codelayout = ComponentDesc.MODULE_PLACEMENT_JUSTIFIED;
              if (layout.toLowerCase().equals("manual"))
                codelayout = ComponentDesc.MODULE_PLACEMENT_MANUAL;

              // nd = new ComponentDesc(name, desc, cls, icon, codemodule, codelayout);
              ((ComponentDesc) nd).setModule(codemodule);
              ((ComponentDesc) nd).setLayout(codelayout);

              NodeList connlist = child.getChildNodes();
              for (int k = 0; k < connlist.getLength(); k++)
                if (connlist.item(k).getNodeType() == Node.ELEMENT_NODE) {
                  Element prop = (Element) connlist.item(k);
                  if (connlist.item(k).getNodeType() == Node.ELEMENT_NODE) {
                    String cref = prop.getAttribute("type");
                    String cname = prop.getAttribute("name");
                    String pside = prop.getAttribute("side");
                    String pratio = prop.getAttribute("ratio");

                    int codeside = ConnectorPlacement.UNSPECIFIED;
                    if (pside.toLowerCase().equals("left")) codeside = ConnectorPlacement.LEFT;
                    if (pside.toLowerCase().equals("right")) codeside = ConnectorPlacement.RIGHT;
                    if (pside.toLowerCase().equals("top")) codeside = ConnectorPlacement.TOP;
                    if (pside.toLowerCase().equals("bottom")) codeside = ConnectorPlacement.BOTTOM;
                    double ratio = -1;
                    if ((pratio != null) && (!pratio.equals("")))
                      ratio = (new Double(pratio)).doubleValue();

                    ConnectorPlacement cp;
                    if ((ratio < 0) || (ratio > 1)) cp = new ConnectorPlacement(codeside);
                    else cp = new ConnectorPlacement(codeside, ratio);

                    ConnectorDesc cnx;
                    cnx = formalism.getConnectorDesc(cref);
                    // System.err.println("got cnx+"+cref+"("+cname+")"+cnx+" Pl "+cp);

                    ((ComponentDesc) nd).addModuleConnector(cname, cnx, cp);
                  }
                }
            }
            if (child.getNodeName().equals("graphic-element")) {
              String graphicClass = child.getAttribute("class");
              if (!graphicClass.equals("")) nd.setGraphicClass(graphicClass);
              // System.err.println("nodeselement2"+name+" "+nd.getGraphicClass());
              Hashtable graphprop = new Hashtable();
              NodeList graphproplist = child.getChildNodes();
              for (int m = 0; m < graphproplist.getLength(); m++)
                if (graphproplist.item(m).getNodeType() == Node.ELEMENT_NODE) {
                  Element prop = (Element) graphproplist.item(m);
                  if (prop.getNodeName().equals("property")) addProperty(graphprop, prop);
                }
              nd.setGraphicProperties(graphprop);
              // System.err.println(i+" "+j+" "+"IN PazeROPERTY NDGR"+child+
              // proplist.getLength()+" "+
              //		  nd.getGraphicProperties());
            }
            if (child.getNodeName().equals("property")) {
              addProperty(prophash, child);
              nd.setProperties(prophash);
            }
            if (child.getNodeName().equals("action")) nd.addActionDesc(parseAction(child));
          }
        if (nd != null) {
          nd.setCategory(catg);
          formalism.addNodeDesc(nd);
          try {
            ReflectorUtil.setProperties(nd, prophash);
          } catch (Exception e) {
            Utils.log("setProperties failed:" + e);
          }
        }
      }
    }
  }