Ejemplo n.º 1
0
  /**
   * Private helper used by the function factory code to load a specific target, condition, or
   * general section.
   */
  private void functionParserHelper(Node root, FunctionFactory factory) throws ParsingException {
    // go through all elements in the section
    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      String name = child.getNodeName();

      if (name.equals("function")) {
        // a function section is a simple class element
        Function function = (Function) (loadClass("function", child));
        try {
          factory.addFunction(function);
        } catch (IllegalArgumentException iae) {
          throw new ParsingException("duplicate function", iae);
        }
      } else if (name.equals("abstractFunction")) {
        // an abstract function is a class with an identifier
        URI identifier = null;
        try {
          identifier = new URI(child.getAttributes().getNamedItem("identifier").getNodeValue());
        } catch (URISyntaxException urise) {
          throw new ParsingException("invalid function identifier", urise);
        }

        FunctionProxy proxy = (FunctionProxy) (loadClass("abstract function", child));
        try {
          factory.addAbstractFunction(proxy, identifier);
        } catch (IllegalArgumentException iae) {
          throw new ParsingException("duplicate abstract function", iae);
        }
      } else if (name.equals("functionCluster")) {
        // a cluster is a class that will give us a collection of
        // functions that need to be added one by one into the factory
        FunctionCluster cluster = (FunctionCluster) (loadClass("function cluster", child));

        for (Function function : cluster.getSupportedFunctions()) {
          try {
            factory.addFunction(function);
          } catch (IllegalArgumentException iae) {
            throw new ParsingException("duplicate function", iae);
          }
        }
      }
    }
  }