Esempio n. 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));
    }
  }