예제 #1
0
  @Override
  void putXMLProperty(XMLName xmlName, Object value) {
    // Log("put property: " + name);

    // Special-case checks for undefined and null
    if (value == null) {
      value = "null";
    } else if (value instanceof Undefined) {
      value = "undefined";
    }

    if (length() > 1) {
      throw ScriptRuntime.typeError("Assignment to lists with more than one item is not supported");
    } else if (length() == 0) {
      // Secret sauce for super-expandos.
      // We set an element here, and then add ourselves to our target.
      if (targetObject != null
          && targetProperty != null
          && targetProperty.getLocalName() != null
          && targetProperty.getLocalName().length() > 0) {
        // Add an empty element with our targetProperty name and
        // then set it.
        XML xmlValue = newTextElementXML(null, targetProperty, null);
        addToList(xmlValue);

        if (xmlName.isAttributeName()) {
          setAttribute(xmlName, value);
        } else {
          XML xml = item(0);
          xml.putXMLProperty(xmlName, value);

          // Update the list with the new item at location 0.
          replace(0, item(0));
        }

        // Now add us to our parent
        XMLName name2 =
            XMLName.formProperty(
                targetProperty.getNamespace().getUri(), targetProperty.getLocalName());
        targetObject.putXMLProperty(name2, this);
        replace(0, targetObject.getXML().getLastXmlChild());
      } else {
        throw ScriptRuntime.typeError("Assignment to empty XMLList without targets not supported");
      }
    } else if (xmlName.isAttributeName()) {
      setAttribute(xmlName, value);
    } else {
      XML xml = item(0);
      xml.putXMLProperty(xmlName, value);

      // Update the list with the new item at location 0.
      replace(0, item(0));
    }
  }
예제 #2
0
  @Override
  public Ref nameRef(
      Context cx, Object namespace, Object name, Scriptable scope, int memberTypeFlags) {
    XMLName xmlName = XMLName.create(toNodeQName(cx, namespace, name), false, false);

    //    No idea what is coming in from the parser in this case; is it detecting the "@"?
    if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
      if (!xmlName.isAttributeName()) {
        xmlName.setAttributeName();
      }
    }

    return xmlPrimaryReference(cx, xmlName, scope);
  }
예제 #3
0
  private XMLList getPropertyList(XMLName name) {
    XMLList propertyList = newXMLList();
    XmlNode.QName qname = null;

    if (!name.isDescendants() && !name.isAttributeName()) {
      // Only set the targetProperty if this is a regular child get
      // and not a descendant or attribute get
      qname = name.toQname();
    }

    propertyList.setTargets(this, qname);

    for (int i = 0; i < length(); i++) {
      propertyList.addToList(getXmlFromAnnotation(i).getPropertyList(name));
    }

    return propertyList;
  }