예제 #1
0
 public Iterator getAllAttributes() {
   Iterator i = getAllAttributesFrom(this);
   ArrayList list = new ArrayList();
   while (i.hasNext()) {
     Name name = (Name) i.next();
     if (!"xmlns".equalsIgnoreCase(name.getPrefix())) list.add(name);
   }
   return list.iterator();
 }
예제 #2
0
  protected SOAPElement findChild(NameImpl name) {
    Iterator eachChild = getChildElementNodes();
    while (eachChild.hasNext()) {
      SOAPElement child = (SOAPElement) eachChild.next();
      if (child.getElementName().equals(name)) {
        return child;
      }
    }

    return null;
  }
예제 #3
0
  protected static SOAPElement replaceElementWithSOAPElement(Element element, ElementImpl copy) {

    Iterator eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
      Name name = (Name) eachAttribute.next();
      copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator eachChild = getChildElementsFrom(element);
    while (eachChild.hasNext()) {
      Node nextChild = (Node) eachChild.next();
      copy.insertBefore(nextChild, null);
    }

    Node parent = element.getParentNode();
    if (parent != null) {
      parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
  }
예제 #4
0
  public SOAPElement addChildElement(SOAPElement element) throws SOAPException {

    // check if Element falls in SOAP 1.1 or 1.2 namespace.
    String elementURI = element.getElementName().getURI();
    String localName = element.getLocalName();

    if ((SOAPConstants.URI_NS_SOAP_ENVELOPE).equals(elementURI)
        || (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE).equals(elementURI)) {

      if ("Envelope".equalsIgnoreCase(localName)
          || "Header".equalsIgnoreCase(localName)
          || "Body".equalsIgnoreCase(localName)) {
        log.severe("SAAJ0103.impl.cannot.add.fragements");
        throw new SOAPExceptionImpl(
            "Cannot add fragments which contain elements " + "which are in the SOAP namespace");
      }

      if ("Fault".equalsIgnoreCase(localName) && !"Body".equalsIgnoreCase(this.getLocalName())) {
        log.severe("SAAJ0154.impl.adding.fault.to.nonbody");
        throw new SOAPExceptionImpl("Cannot add a SOAPFault as a child of " + this.getLocalName());
      }

      if ("Detail".equalsIgnoreCase(localName) && !"Fault".equalsIgnoreCase(this.getLocalName())) {
        log.severe("SAAJ0155.impl.adding.detail.nonfault");
        throw new SOAPExceptionImpl("Cannot add a Detail as a child of " + this.getLocalName());
      }

      if ("Fault".equalsIgnoreCase(localName)) {
        // if body is not empty throw an exception
        if (!elementURI.equals(this.getElementName().getURI())) {
          log.severe("SAAJ0158.impl.version.mismatch.fault");
          throw new SOAPExceptionImpl(
              "SOAP Version mismatch encountered when trying to add SOAPFault to SOAPBody");
        }
        Iterator it = this.getChildElements();
        if (it.hasNext()) {
          log.severe("SAAJ0156.impl.adding.fault.error");
          throw new SOAPExceptionImpl("Cannot add SOAPFault as a child of a non-Empty SOAPBody");
        }
      }
    }

    // preserve the encodingStyle attr as it may get lost in the import
    String encodingStyle = element.getEncodingStyle();

    ElementImpl importedElement = (ElementImpl) importElement(element);
    addNode(importedElement);

    if (encodingStyle != null) importedElement.setEncodingStyle(encodingStyle);

    return convertToSoapElement(importedElement);
  }
예제 #5
0
 protected javax.xml.soap.Node getValueNode() {
   Iterator i = getChildElements();
   while (i.hasNext()) {
     javax.xml.soap.Node n = (javax.xml.soap.Node) i.next();
     if (n.getNodeType() == org.w3c.dom.Node.TEXT_NODE
         || n.getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE) {
       // TODO: Hack to fix text node split into multiple lines.
       normalize();
       // Should remove the normalization step when this gets fixed in
       // DOM/Xerces.
       return (javax.xml.soap.Node) n;
     }
   }
   return null;
 }