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) { 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); for (int i = elements.size() - 1; i >= 0; i--) { ElementDefn e = elements.get(i); if (nameMatches(n, e, throughChoice)) return t == null ? e : e.getElementByName(t); } return null; }
private ElementDefn getElementForPath(String pathname) throws Exception { String[] path = pathname.split("\\."); ElementDefn res = definitions.getElementDefn(path[0]); for (int i = 1; i < path.length; i++) { String en = path[i]; if (en.length() == 0) throw new Exception("Improper path " + pathname); ElementDefn t = res.getElementByName(definitions, en, true, false); if (t == null) { throw new Exception("unable to resolve " + pathname); } res = t; } return res; }
public ElementDefn getElementByName(String name) { 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); for (int i = elements.size() - 1; i >= 0; i--) { ElementDefn e = elements.get(i); if (nameMatches(n, e, false, null)) return t == null ? e : e.getElementByName(t); // if (e.getName().length() > name.length() // && e.getName().substring(0, name.length()) // .equalsIgnoreCase(name) // && e.getElements().size() == 1 // && e.getElements().get(0).getName().equalsIgnoreCase(name)) // return e.getElements().get(0); } return null; }
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; }