Exemplo n.º 1
0
  /*
   * findElementAccessor:
   * 	This method finds an accessor for a given soda element.
   *
   * Intput:
   * 	sodaelement: This is the element to find an accessor for.
   * accessor: This is the accessor to find for the given element.
   *
   * Output:
   * 	returns a string with the given accessor if one exists, else null.
   *
   */
  private String findElementAccessor(SodaElements sodaelement, String accessor) {
    String result = null;
    int len = types.size() - 1;
    SodaHash foundType = null;
    SodaHash accessors = null;

    for (int i = 0; i <= len; i++) {
      if (types.get(i).get("type") == sodaelement) {
        foundType = types.get(i);
        break;
      }
    }

    if (foundType == null) {
      System.out.printf("foundType == null!\n");
      return null;
    }

    if (!foundType.containsKey("accessor_attributes")) {
      return null;
    }

    accessors = (SodaHash) foundType.get("accessor_attributes");
    if (accessors.containsKey(accessor)) {
      result = accessor;
    }

    return result;
  }
Exemplo n.º 2
0
  /*
   * processAttributes:
   * 	This method gets all of the attributes for a given soda element.
   *
   * Intput:
   * 	map: This is the soda element's map.
   *  node: This is the xml node for the given element.
   *
   * Output:
   * 	returns a SodaHash object filled with the node's attributes if it has any.  If there are
   * 	no attributes then an empty SodaHash is returned.
   *
   */
  private SodaHash processAttributes(SodaHash map, Node node) {
    int len = node.getAttributes().getLength();

    if (node.hasAttributes()) {
      for (int i = 0; i <= len - 1; i++) {
        Node tmp = node.getAttributes().item(i);
        String name = tmp.getNodeName();
        String value = tmp.getNodeValue();
        String accessor = findElementAccessor((SodaElements) map.get("type"), name);
        map.put(name, value);

        if (accessor != null) {
          map.put("how", accessor);
        }
      }
    }

    return map;
  }
Exemplo n.º 3
0
  /*
   * parse:
   * 	This method parses all the xml nodes into a SodaEvents object.
   *
   * Input:
   * 	node:  This is a node list from the soda xml test.
   *
   * Output:
   * 	returns a SodaEvents object.
   */
  private SodaEvents parse(NodeList node) throws Exception {
    SodaHash data = null;
    SodaEvents dataList = null;
    boolean err = false;
    int len = 0;

    dataList = new SodaEvents();

    len = node.getLength();
    for (int i = 0; i <= len - 1; i++) {
      Node child = node.item(i);
      String name = child.getNodeName();

      if (name.startsWith("#")) {
        continue;
      }

      if (!sodaTypes.isValid(name)) {
        if (this.reporter == null) {
          System.err.printf("Error: Invalid Soda Element: '%s'!\n", name);
        } else {
          this.reporter.ReportError(String.format("Error: Invalid Soda Element: '%s'!", name));
        }

        err = true;
        break;
      }

      data = new SodaHash();
      data.put("do", name);
      data.put("type", SodaElements.valueOf(name.toUpperCase()));

      if (child.hasAttributes()) {
        data = processAttributes(data, child);
      }

      if (name.contains("javascript")) {
        String tmp = child.getTextContent();
        if (!tmp.isEmpty()) {
          data.put("content", tmp);
        }
      }

      if (child.hasChildNodes()) {
        if (name.contains("execute")) {
          String[] list = processArgs(child.getChildNodes());
          data.put("args", list);
        } else {
          SodaEvents tmp = parse(child.getChildNodes());
          if (tmp != null) {
            data.put("children", tmp);
          } else {
            err = true;
            break;
          }
        }
      }

      if (!data.isEmpty()) {
        dataList.add(data);
      } else {
        System.out.printf("Note: No data found.\n");
      }
    }

    if (err) {
      dataList = null;
    }

    return dataList;
  }