Ejemplo n.º 1
0
  public ElementDefn getElementForPath(String pathname, Definitions definitions, String purpose)
      throws Exception {
    String[] path = pathname.split("\\.");

    if (!path[0].equals(getName()))
      throw new Exception(
          "Element Path '" + pathname + "' is not legal in this context (" + purpose + ")");

    ElementDefn res = this;

    for (int i = 1; i < path.length; i++) {
      String en = path[i];
      if (en.length() == 0) throw new Exception("Improper path " + pathname);
      ElementDefn t = null;

      if (res.typeCode().startsWith("@")) {
        res = this.getElementForPath(res.typeCode().substring(1), definitions, purpose);
      } else if (definitions.dataTypeIsSharedInfo(res.typeCode())) {
        res = definitions.getElementDefn(res.typeCode());
      } else if (definitions.hasType(res.typeCode())) {
        res = definitions.getElementDefn(res.typeCode());
      }
      t = res.getElementByName(en);
      if (t == null) {
        throw new Exception("unable to resolve " + pathname);
      }
      res = t;
    }

    return res;
  }
  public ElementDefn getElementByName(
      String name, boolean throughChoice, Definitions definitions, String purpose)
      throws Exception {
    String n = name.contains(".") ? name.substring(0, name.indexOf(".")) : name;
    String t = name.contains(".") ? name.substring(name.indexOf(".") + 1) : null;
    if (n.equals(this.name) && t != null) return getElementByName(t);

    ElementDefn focus = this;

    if (typeCode().startsWith("@")) {
      String s = typeCode().substring(1);
      focus = definitions.getElementDefn(s.substring(0, s.indexOf(".")));
      focus = focus.getElementForPath(s, definitions, purpose, throughChoice);
    }

    for (int i = focus.elements.size() - 1; i >= 0; i--) {
      ElementDefn e = focus.elements.get(i);
      if (nameMatches(n, e, throughChoice, definitions))
        return t == null ? e : e.getElementByName(t);
    }
    return null;
  }