Exemplo n.º 1
0
  /*
   * Work down the children tree
   * @param parent
   * @param el
   */
  private void processChildren(ESBNodeWithChildren parent, Element el) {
    el.normalize();
    parent.setData(el);

    if (parent.getEsbObjectType() == null) {
      String tag = el.getTagName();
      if (tag.endsWith("-bus") && el.getAttribute("busid") != null) { // $NON-NLS-1$ //$NON-NLS-2$
        parent.setEsbObjectType(ESBType.BUS);
      } else if (tag.endsWith("-listener")
          && el.getAttribute("busidref") != null) { // $NON-NLS-1$ //$NON-NLS-2$
        parent.setEsbObjectType(ESBType.LISTENER);
      } else if (tag.endsWith("-provider")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.PROVIDER);
      } else if (tag.equalsIgnoreCase("service")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.SERVICE);
      } else if (tag.equalsIgnoreCase("listeners")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.LISTENER);
      } else if (tag.equalsIgnoreCase("Actions")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.ACTION);
      } else if (tag.equalsIgnoreCase("action")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.ACTION);
      } else if (tag.equalsIgnoreCase("property")) { // $NON-NLS-1$
        parent.setEsbObjectType(ESBType.PROPERTY);
        return;
      }
    }
    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      if (children.item(i) instanceof Element) {
        Element child = (Element) children.item(i);
        String name = child.getAttribute("name"); // $NON-NLS-1$
        if (name == null || name.trim().length() == 0) {
          name = child.getAttribute("busid"); // $NON-NLS-1$
        }
        if (name == null || name.trim().length() == 0) {
          name = child.getAttribute("dest-name"); // $NON-NLS-1$
        }
        if (name == null || name.trim().length() == 0) {
          name = child.getTagName();
        }
        if (name.equalsIgnoreCase("actions")) { // $NON-NLS-1$
          name = JBossESBUIMessages.ESBDomParser_Actions_Node_Label;
        } else if (name.equalsIgnoreCase("listeners")) { // $NON-NLS-1$
          name = JBossESBUIMessages.ESBDomParser_Listeners_Node_Label;
        }

        ESBNodeWithChildren childNode = new ESBNodeWithChildren(name);
        String ref = child.getAttribute("busidref"); // $NON-NLS-1$
        if (ref != null && ref.trim().length() > 0) {
          childNode.setRef(ref);
        }
        processChildren(childNode, child);
        if (childNode.getEsbObjectType() != null
            && !childNode.getEsbObjectType().equals(ESBType.PROPERTY)) {
          parent.addChild(childNode);
          childNode.setEsbObjectType(parent.getEsbObjectType());
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Parse the file into the nodes
   *
   * @param filepath
   */
  public void parseXmlFile(String filepath) {

    root = new ESBNodeWithChildren("Invisible Root"); // $NON-NLS-1$

    // get the factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    try {

      // Using factory get an instance of document builder
      DocumentBuilder db = dbf.newDocumentBuilder();

      try {
        if (filepath == null) {
          Bundle bundle = ESBProjectPlugin.getDefault().getBundle();
          IPath path = new Path("META-INF/jboss-esb.xml"); // $NON-NLS-1$
          URL setupUrl = FileLocator.find(bundle, path, Collections.EMPTY_MAP);
          File setupFile = new File(FileLocator.toFileURL(setupUrl).toURI());
          if (setupFile.exists() && setupFile.canRead()) filepath = setupFile.getAbsolutePath();
          else return;
        }
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }

      // parse using builder to get DOM representation of the XML file
      dom = db.parse(filepath);
      dom.getDocumentElement().normalize();
      java.io.File tempFile = new java.io.File(filepath);
      String filename = tempFile.getName();
      root.setName(filename);
      root.setEsbObjectType(ESBType.ESB);
      File setupFile = new File(filepath);
      root.setData(setupFile);

      parseDocument();

    } catch (ParserConfigurationException pce) {
      pce.printStackTrace();
    } catch (SAXException se) {
      se.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }