Exemplo n.º 1
0
  private Ref xmlPrimaryReference(Context cx, XMLName xmlName, Scriptable scope) {
    XMLObjectImpl xmlObj;
    XMLObjectImpl firstXml = null;
    for (; ; ) {
      // XML object can only present on scope chain as a wrapper
      // of XMLWithScope
      if (scope instanceof XMLWithScope) {
        xmlObj = (XMLObjectImpl) scope.getPrototype();
        if (xmlObj.hasXMLProperty(xmlName)) {
          break;
        }
        if (firstXml == null) {
          firstXml = xmlObj;
        }
      }
      scope = scope.getParentScope();
      if (scope == null) {
        xmlObj = firstXml;
        break;
      }
    }

    // xmlObj == null corresponds to undefined as the target of
    // the reference
    if (xmlObj != null) {
      xmlName.initXMLObject(xmlObj);
    }
    return xmlName;
  }