< prev index next >

jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/SOAPDocumentImpl.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27 *
  28 * @author SAAJ RI Development Team
  29 */
  30 package com.sun.xml.internal.messaging.saaj.soap;
  31 
  32 import com.sun.xml.internal.messaging.saaj.soap.impl.CDATAImpl;
  33 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
  34 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;


  35 import com.sun.xml.internal.messaging.saaj.soap.impl.SOAPCommentImpl;
  36 import com.sun.xml.internal.messaging.saaj.soap.impl.SOAPTextImpl;
  37 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  38 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
  39 import com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
  40 import org.w3c.dom.Attr;
  41 import org.w3c.dom.CDATASection;

  42 import org.w3c.dom.Comment;
  43 import org.w3c.dom.DOMConfiguration;
  44 import org.w3c.dom.DOMException;
  45 import org.w3c.dom.DOMImplementation;
  46 import org.w3c.dom.Document;
  47 import org.w3c.dom.DocumentFragment;
  48 import org.w3c.dom.DocumentType;
  49 import org.w3c.dom.Element;
  50 import org.w3c.dom.EntityReference;
  51 import org.w3c.dom.NamedNodeMap;
  52 import org.w3c.dom.Node;
  53 import org.w3c.dom.NodeList;
  54 import org.w3c.dom.ProcessingInstruction;

  55 import org.w3c.dom.UserDataHandler;
  56 
  57 import javax.xml.parsers.DocumentBuilder;
  58 import javax.xml.parsers.DocumentBuilderFactory;
  59 import javax.xml.parsers.ParserConfigurationException;
  60 import javax.xml.soap.SOAPElement;
  61 import javax.xml.soap.SOAPException;

  62 import java.text.MessageFormat;
  63 import java.util.HashMap;
  64 import java.util.Map;
  65 import java.util.logging.Logger;
  66 
  67 public class SOAPDocumentImpl implements SOAPDocument, javax.xml.soap.Node, Document {
  68 


  69     private static final String XMLNS = "xmlns".intern();
  70     protected static final Logger log =
  71         Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
  72                          "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
  73 
  74     SOAPPartImpl enclosingSOAPPart;
  75 
  76     private Document document;
  77 
  78     private Map<Node, javax.xml.soap.Node> domToSoap = new HashMap<>();
  79 
  80     public SOAPDocumentImpl(SOAPPartImpl enclosingDocument) {
  81         document = createDocument();
  82         this.enclosingSOAPPart = enclosingDocument;
  83         register(this);
  84     }
  85 
  86     private Document createDocument() {
  87         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", SAAJUtil.getSystemClassLoader());
  88         try {
  89             final DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();
  90             return documentBuilder.newDocument();
  91         } catch (ParserConfigurationException e) {
  92             throw new RuntimeException("Error creating xml document", e);
  93         }
  94     }
  95 
  96     //    public SOAPDocumentImpl(boolean grammarAccess) {
  97     //        super(grammarAccess);
  98     //    }
  99     //
 100     //    public SOAPDocumentImpl(DocumentType doctype) {
 101     //        super(doctype);
 102     //    }
 103     //
 104     //    public SOAPDocumentImpl(DocumentType doctype, boolean grammarAccess) {
 105     //        super(doctype, grammarAccess);
 106     //    }
 107 

 108     public SOAPPartImpl getSOAPPart() {
 109         if (enclosingSOAPPart == null) {
 110             log.severe("SAAJ0541.soap.fragment.not.bound.to.part");
 111             throw new RuntimeException("Could not complete operation. Fragment not bound to SOAP part.");
 112         }
 113         return enclosingSOAPPart;
 114     }
 115 

 116     public SOAPDocumentImpl getDocument() {
 117         return this;
 118     }
 119 

 120     public DocumentType getDoctype() {
 121         // SOAP means no DTD, No DTD means no doctype (SOAP 1.2 only?)
 122         return null;
 123     }
 124 

 125     public DOMImplementation getImplementation() {
 126         return document.getImplementation();
 127     }
 128 

 129     public Element getDocumentElement() {
 130         // This had better be an Envelope!
 131         getSOAPPart().doGetDocumentElement();
 132         return doGetDocumentElement();
 133     }
 134 
 135     protected Element doGetDocumentElement() {
 136         return document.getDocumentElement();
 137     }
 138 

 139     public Element createElement(String tagName) throws DOMException {
 140         return ElementFactory.createElement(
 141             this,
 142             NameImpl.getLocalNameFromTagName(tagName),
 143             NameImpl.getPrefixFromTagName(tagName),
 144             null);
 145     }
 146 

 147     public DocumentFragment createDocumentFragment() {
 148         return document.createDocumentFragment();
 149     }
 150 

 151     public org.w3c.dom.Text createTextNode(String data) {
 152         return new SOAPTextImpl(this, data);
 153     }
 154 

 155     public Comment createComment(String data) {
 156         return new SOAPCommentImpl(this, data);
 157     }
 158 

 159     public CDATASection createCDATASection(String data) throws DOMException {
 160         return new CDATAImpl(this, data);
 161     }
 162 

 163     public ProcessingInstruction createProcessingInstruction(
 164         String target,
 165         String data)
 166         throws DOMException {
 167         log.severe("SAAJ0542.soap.proc.instructions.not.allowed.in.docs");
 168         throw new UnsupportedOperationException("Processing Instructions are not allowed in SOAP documents");
 169     }
 170 

 171     public Attr createAttribute(String name) throws DOMException {
 172         boolean isQualifiedName = (name.indexOf(":") > 0);
 173         if (isQualifiedName) {
 174             String nsUri = null;
 175             String prefix = name.substring(0, name.indexOf(":"));
 176             //cannot do anything to resolve the URI if prefix is not
 177             //XMLNS.
 178             if (XMLNS.equals(prefix)) {
 179                 nsUri = ElementImpl.XMLNS_URI;
 180                 return createAttributeNS(nsUri, name);
 181             }
 182         }
 183 
 184         return document.createAttribute(name);
 185     }
 186 

 187     public EntityReference createEntityReference(String name)
 188         throws DOMException {
 189             log.severe("SAAJ0543.soap.entity.refs.not.allowed.in.docs");
 190             throw new UnsupportedOperationException("Entity References are not allowed in SOAP documents");
 191     }
 192 

 193     public NodeList getElementsByTagName(String tagname) {
 194         return document.getElementsByTagName(tagname);
 195     }
 196 

 197     public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
 198         throws DOMException {
 199         final Node node = document.importNode(getDomNode(importedNode), deep);
 200         return node instanceof Element ?
 201             ElementFactory.createElement(this, (Element) node)
 202                 : node;










































 203     }
 204 

 205     public Element createElementNS(String namespaceURI, String qualifiedName)
 206         throws DOMException {
 207         return ElementFactory.createElement(
 208             this,
 209             NameImpl.getLocalNameFromTagName(qualifiedName),
 210             NameImpl.getPrefixFromTagName(qualifiedName),
 211             namespaceURI);
 212     }
 213 

 214     public Attr createAttributeNS(String namespaceURI, String qualifiedName)
 215         throws DOMException {
 216         return document.createAttributeNS(namespaceURI, qualifiedName);
 217     }
 218 

 219     public NodeList getElementsByTagNameNS(
 220         String namespaceURI,
 221         String localName) {
 222         return document.getElementsByTagNameNS(namespaceURI, localName);
 223     }
 224 

 225     public Element getElementById(String elementId) {
 226         return document.getElementById(elementId);
 227     }
 228 
 229     @Override
 230     public String getInputEncoding() {
 231         return document.getInputEncoding();
 232     }
 233 
 234     @Override
 235     public String getXmlEncoding() {
 236         return document.getXmlEncoding();
 237     }
 238 
 239     @Override
 240     public boolean getXmlStandalone() {
 241         return document.getXmlStandalone();
 242     }
 243 
 244     @Override
 245     public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
 246         document.setXmlStandalone(xmlStandalone);


 276         document.setDocumentURI(documentURI);
 277     }
 278 
 279     @Override
 280     public Node adoptNode(Node source) throws DOMException {
 281         return document.adoptNode(source);
 282     }
 283 
 284     @Override
 285     public DOMConfiguration getDomConfig() {
 286         return document.getDomConfig();
 287     }
 288 
 289     @Override
 290     public void normalizeDocument() {
 291         document.normalizeDocument();
 292     }
 293 
 294     @Override
 295     public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
 296         return document.renameNode(n, namespaceURI, qualifiedName);
 297     }
 298 
 299     @Override
 300     public String getNodeName() {
 301         return document.getNodeName();
 302     }
 303 
 304     @Override
 305     public String getNodeValue() throws DOMException {
 306         return document.getNodeValue();
 307     }
 308 
 309     @Override
 310     public void setNodeValue(String nodeValue) throws DOMException {
 311         document.setNodeValue(nodeValue);
 312     }
 313 
 314     @Override
 315     public short getNodeType() {
 316         return document.getNodeType();
 317     }
 318 
 319     @Override
 320     public Node getParentNode() {
 321         return document.getParentNode();
 322     }
 323 
 324     @Override
 325     public NodeList getChildNodes() {
 326         return document.getChildNodes();
 327     }
 328 
 329     @Override
 330     public Node getFirstChild() {
 331         return document.getFirstChild();
 332     }
 333 
 334     @Override
 335     public Node getLastChild() {
 336         return document.getLastChild();
 337     }
 338 
 339     @Override
 340     public Node getPreviousSibling() {
 341         return document.getPreviousSibling();
 342     }
 343 
 344     @Override
 345     public Node getNextSibling() {
 346         return document.getNextSibling();
 347     }
 348 
 349     @Override
 350     public NamedNodeMap getAttributes() {
 351         return document.getAttributes();
 352     }
 353 
 354     @Override
 355     public Document getOwnerDocument() {
 356         return document.getOwnerDocument();
 357     }
 358 
 359     @Override
 360     public Node insertBefore(Node newChild, Node refChild) throws DOMException {
 361         return document.insertBefore(getDomNode(newChild), getDomNode(refChild));
 362     }
 363 
 364     @Override
 365     public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
 366         return document.replaceChild(getDomNode(newChild), getDomNode(oldChild));
 367     }
 368 
 369     @Override
 370     public Node removeChild(Node oldChild) throws DOMException {
 371         return document.removeChild(getDomNode(oldChild));
 372     }
 373 
 374     @Override
 375     public Node appendChild(Node newChild) throws DOMException {
 376         return document.appendChild(getDomNode(newChild));
 377     }
 378 
 379     @Override
 380     public boolean hasChildNodes() {
 381         return document.hasChildNodes();
 382     }
 383 
 384     @Override
 385     public Node cloneNode(boolean deep) {
 386         return document.cloneNode(deep);


 387     }
 388 
 389     @Override
 390     public void normalize() {
 391         document.normalize();
 392     }
 393 
 394     @Override
 395     public boolean isSupported(String feature, String version) {
 396         return document.isSupported(feature, version);
 397     }
 398 
 399     @Override
 400     public String getNamespaceURI() {
 401         return document.getNamespaceURI();
 402     }
 403 
 404     @Override
 405     public String getPrefix() {
 406         return document.getPrefix();


 411         document.setPrefix(prefix);
 412     }
 413 
 414     @Override
 415     public String getLocalName() {
 416         return document.getLocalName();
 417     }
 418 
 419     @Override
 420     public boolean hasAttributes() {
 421         return document.hasAttributes();
 422     }
 423 
 424     @Override
 425     public String getBaseURI() {
 426         return document.getBaseURI();
 427     }
 428 
 429     @Override
 430     public short compareDocumentPosition(Node other) throws DOMException {
 431         return document.compareDocumentPosition(other);
 432     }
 433 
 434     @Override
 435     public String getTextContent() throws DOMException {
 436         return document.getTextContent();
 437     }
 438 
 439     @Override
 440     public void setTextContent(String textContent) throws DOMException {
 441         document.setTextContent(textContent);
 442     }
 443 
 444     @Override
 445     public boolean isSameNode(Node other) {
 446         return document.isSameNode(other);
 447     }
 448 
 449     @Override
 450     public String lookupPrefix(String namespaceURI) {
 451         return document.lookupPrefix(namespaceURI);
 452     }
 453 
 454     @Override
 455     public boolean isDefaultNamespace(String namespaceURI) {
 456         return document.isDefaultNamespace(namespaceURI);
 457     }
 458 
 459     @Override
 460     public String lookupNamespaceURI(String prefix) {
 461         return document.lookupNamespaceURI(prefix);
 462     }
 463 
 464     @Override
 465     public boolean isEqualNode(Node arg) {
 466         return document.isEqualNode(arg);
 467     }
 468 
 469     @Override
 470     public Object getFeature(String feature, String version) {
 471         return document.getFeature(feature, version);
 472     }
 473 
 474     @Override
 475     public Object setUserData(String key, Object data, UserDataHandler handler) {
 476         return document.setUserData(key, data, handler);
 477     }
 478 
 479     @Override
 480     public Object getUserData(String key) {
 481         return document.getUserData(key);
 482     }
 483 
 484     public Document getDomDocument() {
 485         return document;
 486     }
 487 
 488     /**
 489      * Insert a mapping information for {@link org.w3c.dom.Node} - {@link javax.xml.soap.Node}.
 490      *
 491      * In SAAJ, elements in DOM are expected to be interfaces of SAAJ, on the other hand in JDKs Xerces,
 492      * they are casted to internal impl classes. After removal of SAAJ dependency
 493      * to JDKs internal classes elements in DOM can never be both of them.
 494      *
 495      * @param node SAAJ wrapper node for w3c DOM node
 496      */
 497     public void register(javax.xml.soap.Node node) {
 498         final Node domElement = getDomNode(node);
 499         if (domToSoap.containsKey(domElement)) {
 500             throw new IllegalStateException("Element " + domElement.getNodeName()
 501                     + " is already registered");
 502         }
 503         domToSoap.put(domElement, node);
 504     }
 505 
 506     /**
 507      * Find a soap wrapper for w3c dom node.
 508      *
 509      * @param node w3c dom node nullable
 510      * @return soap wrapper for w3c dom node
 511      *
 512      * @throws
 513      */
 514     public javax.xml.soap.Node find(Node node) {
 515         return find(node, true);
 516     }
 517 
 518     private javax.xml.soap.Node find(Node node, boolean required) {
 519         if (node == null) {
 520             return null;
 521         }
 522         if (node instanceof javax.xml.soap.Node) {
 523             return (javax.xml.soap.Node) node;
 524         }
 525         final javax.xml.soap.Node found = domToSoap.get(node);
 526         if (found == null && required) {
 527             throw new IllegalArgumentException(MessageFormat.format("Cannot find SOAP wrapper for element {0}", node));
 528         }
 529         return found;
 530     }
 531 
 532     /**
 533      * If corresponding soap wrapper exists for w3c dom node it is returned,
 534      * if not passed dom element is returned.
 535      *
 536      * @param node w3c dom node
 537      * @return soap wrapper or passed w3c dom node if not found
 538      */
 539     public Node findIfPresent(Node node) {
 540         final javax.xml.soap.Node found = find(node, false);
 541         return found != null ? found : node;
 542     }
 543 
 544     /**
 545      * Extracts w3c dom node from corresponding soap wrapper.
 546      *
 547      * @param node soap or dom nullable
 548      * @return dom node
 549      */
 550     public Node getDomNode(Node node) {
 551         if (node instanceof SOAPDocumentImpl) {
 552             return ((SOAPDocumentImpl)node).getDomElement();
 553         } else if (node instanceof ElementImpl) {
 554             return ((ElementImpl) node).getDomElement();
 555         } else if (node instanceof SOAPTextImpl) {
 556             return ((SOAPTextImpl)node).getDomElement();
 557         } else if (node instanceof SOAPCommentImpl) {
 558             return ((SOAPCommentImpl)node).getDomElement();
 559         } else if (node instanceof CDATAImpl) {
 560             return ((CDATAImpl) node).getDomElement();
 561         }
 562         return node;
 563     }


















 564 
 565     public Document getDomElement() {
 566         return document;
 567     }
 568 
 569     @Override
 570     public String getValue() {
 571         throw new UnsupportedOperationException();
 572     }
 573 
 574     @Override
 575     public void setValue(String value) {
 576         throw new UnsupportedOperationException();
 577     }
 578 
 579     @Override
 580     public void setParentElement(SOAPElement parent) throws SOAPException {
 581         throw new UnsupportedOperationException();
 582     }
 583 


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27 *
  28 * @author SAAJ RI Development Team
  29 */
  30 package com.sun.xml.internal.messaging.saaj.soap;
  31 
  32 import com.sun.xml.internal.messaging.saaj.soap.impl.CDATAImpl;
  33 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
  34 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
  35 import com.sun.xml.internal.messaging.saaj.soap.impl.NamedNodeMapImpl;
  36 import com.sun.xml.internal.messaging.saaj.soap.impl.NodeListImpl;
  37 import com.sun.xml.internal.messaging.saaj.soap.impl.SOAPCommentImpl;
  38 import com.sun.xml.internal.messaging.saaj.soap.impl.SOAPTextImpl;
  39 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  40 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
  41 import com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
  42 import org.w3c.dom.Attr;
  43 import org.w3c.dom.CDATASection;
  44 import org.w3c.dom.CharacterData;
  45 import org.w3c.dom.Comment;
  46 import org.w3c.dom.DOMConfiguration;
  47 import org.w3c.dom.DOMException;
  48 import org.w3c.dom.DOMImplementation;
  49 import org.w3c.dom.Document;
  50 import org.w3c.dom.DocumentFragment;
  51 import org.w3c.dom.DocumentType;
  52 import org.w3c.dom.Element;
  53 import org.w3c.dom.EntityReference;
  54 import org.w3c.dom.NamedNodeMap;
  55 import org.w3c.dom.Node;
  56 import org.w3c.dom.NodeList;
  57 import org.w3c.dom.ProcessingInstruction;
  58 import org.w3c.dom.Text;
  59 import org.w3c.dom.UserDataHandler;
  60 
  61 import javax.xml.parsers.DocumentBuilder;
  62 import javax.xml.parsers.DocumentBuilderFactory;
  63 import javax.xml.parsers.ParserConfigurationException;
  64 import javax.xml.soap.SOAPElement;
  65 import javax.xml.soap.SOAPException;
  66 import java.lang.reflect.Constructor;
  67 import java.text.MessageFormat;


  68 import java.util.logging.Logger;
  69 
  70 public class SOAPDocumentImpl implements SOAPDocument, javax.xml.soap.Node, Document {
  71 
  72     public static final String SAAJ_NODE = "javax.xml.soap.Node";
  73 
  74     private static final String XMLNS = "xmlns".intern();
  75     protected static final Logger log =
  76         Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
  77                          "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
  78 
  79     SOAPPartImpl enclosingSOAPPart;
  80 
  81     private Document document;
  82 


  83     public SOAPDocumentImpl(SOAPPartImpl enclosingDocument) {
  84         document = createDocument();
  85         this.enclosingSOAPPart = enclosingDocument;
  86         register(this);
  87     }
  88 
  89     private Document createDocument() {
  90         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", SAAJUtil.getSystemClassLoader());
  91         try {
  92             final DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();
  93             return documentBuilder.newDocument();
  94         } catch (ParserConfigurationException e) {
  95             throw new RuntimeException("Error creating xml document", e);
  96         }
  97     }
  98 
  99     //    public SOAPDocumentImpl(boolean grammarAccess) {
 100     //        super(grammarAccess);
 101     //    }
 102     //
 103     //    public SOAPDocumentImpl(DocumentType doctype) {
 104     //        super(doctype);
 105     //    }
 106     //
 107     //    public SOAPDocumentImpl(DocumentType doctype, boolean grammarAccess) {
 108     //        super(doctype, grammarAccess);
 109     //    }
 110 
 111     @Override
 112     public SOAPPartImpl getSOAPPart() {
 113         if (enclosingSOAPPart == null) {
 114             log.severe("SAAJ0541.soap.fragment.not.bound.to.part");
 115             throw new RuntimeException("Could not complete operation. Fragment not bound to SOAP part.");
 116         }
 117         return enclosingSOAPPart;
 118     }
 119 
 120     @Override
 121     public SOAPDocumentImpl getDocument() {
 122         return this;
 123     }
 124 
 125     @Override
 126     public DocumentType getDoctype() {
 127         // SOAP means no DTD, No DTD means no doctype (SOAP 1.2 only?)
 128         return null;
 129     }
 130 
 131     @Override
 132     public DOMImplementation getImplementation() {
 133         return document.getImplementation();
 134     }
 135 
 136     @Override
 137     public Element getDocumentElement() {
 138         // This had better be an Envelope!
 139         getSOAPPart().doGetDocumentElement();
 140         return doGetDocumentElement();
 141     }
 142 
 143     protected Element doGetDocumentElement() {
 144         return document.getDocumentElement();
 145     }
 146 
 147     @Override
 148     public Element createElement(String tagName) throws DOMException {
 149         return ElementFactory.createElement(
 150             this,
 151             NameImpl.getLocalNameFromTagName(tagName),
 152             NameImpl.getPrefixFromTagName(tagName),
 153             null);
 154     }
 155 
 156     @Override
 157     public DocumentFragment createDocumentFragment() {
 158         return new SOAPDocumentFragment(this);
 159     }
 160 
 161     @Override
 162     public org.w3c.dom.Text createTextNode(String data) {
 163         return new SOAPTextImpl(this, data);
 164     }
 165 
 166     @Override
 167     public Comment createComment(String data) {
 168         return new SOAPCommentImpl(this, data);
 169     }
 170 
 171     @Override
 172     public CDATASection createCDATASection(String data) throws DOMException {
 173         return new CDATAImpl(this, data);
 174     }
 175 
 176     @Override
 177     public ProcessingInstruction createProcessingInstruction(
 178         String target,
 179         String data)
 180         throws DOMException {
 181         log.severe("SAAJ0542.soap.proc.instructions.not.allowed.in.docs");
 182         throw new UnsupportedOperationException("Processing Instructions are not allowed in SOAP documents");
 183     }
 184 
 185     @Override
 186     public Attr createAttribute(String name) throws DOMException {
 187         boolean isQualifiedName = (name.indexOf(":") > 0);
 188         if (isQualifiedName) {
 189             String nsUri = null;
 190             String prefix = name.substring(0, name.indexOf(":"));
 191             //cannot do anything to resolve the URI if prefix is not
 192             //XMLNS.
 193             if (XMLNS.equals(prefix)) {
 194                 nsUri = ElementImpl.XMLNS_URI;
 195                 return createAttributeNS(nsUri, name);
 196             }
 197         }
 198 
 199         return document.createAttribute(name);
 200     }
 201 
 202     @Override
 203     public EntityReference createEntityReference(String name)
 204         throws DOMException {
 205             log.severe("SAAJ0543.soap.entity.refs.not.allowed.in.docs");
 206             throw new UnsupportedOperationException("Entity References are not allowed in SOAP documents");
 207     }
 208 
 209     @Override
 210     public NodeList getElementsByTagName(String tagname) {
 211         return new NodeListImpl(this, document.getElementsByTagName(tagname));
 212     }
 213 
 214     @Override
 215     public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
 216         throws DOMException {
 217         Node domNode = getDomNode(importedNode);
 218         final Node newNode = document.importNode(domNode, deep);
 219 
 220         if (importedNode instanceof javax.xml.soap.Node) {
 221             Node newSoapNode = createSoapNode(importedNode.getClass(), newNode);
 222             newNode.setUserData(SAAJ_NODE, newSoapNode, null);
 223             if (deep && importedNode.hasChildNodes()) {
 224                 NodeList childNodes = importedNode.getChildNodes();
 225                 for (int i = 0; i < childNodes.getLength(); i++) {
 226                     registerChildNodes(childNodes.item(i), deep);
 227                 }
 228             }
 229             return newSoapNode;
 230         }
 231 
 232         registerChildNodes(newNode, deep);
 233         return findIfPresent(newNode);
 234     }
 235 
 236     //If the parentNode is not registered to domToSoap, create soap wapper for parentNode and register it to domToSoap
 237     //If deep = true, also register all children of parentNode to domToSoap map.
 238     public void registerChildNodes(Node parentNode, boolean deep) {
 239         if (parentNode.getUserData(SAAJ_NODE) == null) {
 240             if (parentNode instanceof Element) {
 241                 ElementFactory.createElement(this, (Element) parentNode);
 242             } else if (parentNode instanceof CharacterData) {
 243                 switch (parentNode.getNodeType()) {
 244                     case CDATA_SECTION_NODE:
 245                         new CDATAImpl(this, (CharacterData) parentNode);
 246                         break;
 247                     case COMMENT_NODE:
 248                         new SOAPCommentImpl(this, (CharacterData) parentNode);
 249                         break;
 250                     case TEXT_NODE:
 251                         new SOAPTextImpl(this, (CharacterData) parentNode);
 252                         break;
 253                 }
 254             }
 255         }
 256         if (deep) {
 257             NodeList nodeList = parentNode.getChildNodes();
 258             for (int i = 0; i < nodeList.getLength(); i++) {
 259                 Node nextChild = nodeList.item(i);
 260                 registerChildNodes(nextChild, true);
 261             }
 262         }
 263     }
 264 
 265     @Override
 266     public Element createElementNS(String namespaceURI, String qualifiedName)
 267         throws DOMException {
 268         return ElementFactory.createElement(
 269             this,
 270             NameImpl.getLocalNameFromTagName(qualifiedName),
 271             NameImpl.getPrefixFromTagName(qualifiedName),
 272             namespaceURI);
 273     }
 274 
 275     @Override
 276     public Attr createAttributeNS(String namespaceURI, String qualifiedName)
 277         throws DOMException {
 278         return document.createAttributeNS(namespaceURI, qualifiedName);
 279     }
 280 
 281     @Override
 282     public NodeList getElementsByTagNameNS(
 283         String namespaceURI,
 284         String localName) {
 285         return new NodeListImpl(this, document.getElementsByTagNameNS(namespaceURI, localName));
 286     }
 287 
 288     @Override
 289     public Element getElementById(String elementId) {
 290         return (Element) findIfPresent(document.getElementById(elementId));
 291     }
 292 
 293     @Override
 294     public String getInputEncoding() {
 295         return document.getInputEncoding();
 296     }
 297 
 298     @Override
 299     public String getXmlEncoding() {
 300         return document.getXmlEncoding();
 301     }
 302 
 303     @Override
 304     public boolean getXmlStandalone() {
 305         return document.getXmlStandalone();
 306     }
 307 
 308     @Override
 309     public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
 310         document.setXmlStandalone(xmlStandalone);


 340         document.setDocumentURI(documentURI);
 341     }
 342 
 343     @Override
 344     public Node adoptNode(Node source) throws DOMException {
 345         return document.adoptNode(source);
 346     }
 347 
 348     @Override
 349     public DOMConfiguration getDomConfig() {
 350         return document.getDomConfig();
 351     }
 352 
 353     @Override
 354     public void normalizeDocument() {
 355         document.normalizeDocument();
 356     }
 357 
 358     @Override
 359     public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
 360         return findIfPresent(document.renameNode(n, namespaceURI, qualifiedName));
 361     }
 362 
 363     @Override
 364     public String getNodeName() {
 365         return document.getNodeName();
 366     }
 367 
 368     @Override
 369     public String getNodeValue() throws DOMException {
 370         return document.getNodeValue();
 371     }
 372 
 373     @Override
 374     public void setNodeValue(String nodeValue) throws DOMException {
 375         document.setNodeValue(nodeValue);
 376     }
 377 
 378     @Override
 379     public short getNodeType() {
 380         return document.getNodeType();
 381     }
 382 
 383     @Override
 384     public Node getParentNode() {
 385         return findIfPresent(document.getParentNode());
 386     }
 387 
 388     @Override
 389     public NodeList getChildNodes() {
 390         return new NodeListImpl(this, document.getChildNodes());
 391     }
 392 
 393     @Override
 394     public Node getFirstChild() {
 395         return findIfPresent(document.getFirstChild());
 396     }
 397 
 398     @Override
 399     public Node getLastChild() {
 400         return findIfPresent(document.getLastChild());
 401     }
 402 
 403     @Override
 404     public Node getPreviousSibling() {
 405         return findIfPresent(document.getPreviousSibling());
 406     }
 407 
 408     @Override
 409     public Node getNextSibling() {
 410         return findIfPresent(document.getNextSibling());
 411     }
 412 
 413     @Override
 414     public NamedNodeMap getAttributes() {
 415         return new NamedNodeMapImpl(document.getAttributes(), this);
 416     }
 417 
 418     @Override
 419     public Document getOwnerDocument() {
 420         return document.getOwnerDocument();
 421     }
 422 
 423     @Override
 424     public Node insertBefore(Node newChild, Node refChild) throws DOMException {
 425         return document.insertBefore(getDomNode(newChild), getDomNode(refChild));
 426     }
 427 
 428     @Override
 429     public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
 430         return document.replaceChild(getDomNode(newChild), getDomNode(oldChild));
 431     }
 432 
 433     @Override
 434     public Node removeChild(Node oldChild) throws DOMException {
 435         return document.removeChild(getDomNode(oldChild));
 436     }
 437 
 438     @Override
 439     public Node appendChild(Node newChild) throws DOMException {
 440         return document.appendChild(getDomNode(newChild));
 441     }
 442 
 443     @Override
 444     public boolean hasChildNodes() {
 445         return document.hasChildNodes();
 446     }
 447 
 448     @Override
 449     public Node cloneNode(boolean deep) {
 450         Node node = document.cloneNode(deep);
 451         registerChildNodes(node, deep);
 452         return findIfPresent(node);
 453     }
 454 
 455     @Override
 456     public void normalize() {
 457         document.normalize();
 458     }
 459 
 460     @Override
 461     public boolean isSupported(String feature, String version) {
 462         return document.isSupported(feature, version);
 463     }
 464 
 465     @Override
 466     public String getNamespaceURI() {
 467         return document.getNamespaceURI();
 468     }
 469 
 470     @Override
 471     public String getPrefix() {
 472         return document.getPrefix();


 477         document.setPrefix(prefix);
 478     }
 479 
 480     @Override
 481     public String getLocalName() {
 482         return document.getLocalName();
 483     }
 484 
 485     @Override
 486     public boolean hasAttributes() {
 487         return document.hasAttributes();
 488     }
 489 
 490     @Override
 491     public String getBaseURI() {
 492         return document.getBaseURI();
 493     }
 494 
 495     @Override
 496     public short compareDocumentPosition(Node other) throws DOMException {
 497         return document.compareDocumentPosition(getDomNode(other));
 498     }
 499 
 500     @Override
 501     public String getTextContent() throws DOMException {
 502         return document.getTextContent();
 503     }
 504 
 505     @Override
 506     public void setTextContent(String textContent) throws DOMException {
 507         document.setTextContent(textContent);
 508     }
 509 
 510     @Override
 511     public boolean isSameNode(Node other) {
 512         return document.isSameNode(getDomNode(other));
 513     }
 514 
 515     @Override
 516     public String lookupPrefix(String namespaceURI) {
 517         return document.lookupPrefix(namespaceURI);
 518     }
 519 
 520     @Override
 521     public boolean isDefaultNamespace(String namespaceURI) {
 522         return document.isDefaultNamespace(namespaceURI);
 523     }
 524 
 525     @Override
 526     public String lookupNamespaceURI(String prefix) {
 527         return document.lookupNamespaceURI(prefix);
 528     }
 529 
 530     @Override
 531     public boolean isEqualNode(Node arg) {
 532         return document.isEqualNode(getDomNode(arg));
 533     }
 534 
 535     @Override
 536     public Object getFeature(String feature, String version) {
 537         return document.getFeature(feature, version);
 538     }
 539 
 540     @Override
 541     public Object setUserData(String key, Object data, UserDataHandler handler) {
 542         return document.setUserData(key, data, handler);
 543     }
 544 
 545     @Override
 546     public Object getUserData(String key) {
 547         return document.getUserData(key);
 548     }
 549 
 550     public Document getDomDocument() {
 551         return document;
 552     }
 553 
 554     /**
 555      * Insert a mapping information for {@link org.w3c.dom.Node} - {@link javax.xml.soap.Node}.
 556      *
 557      * In SAAJ, elements in DOM are expected to be interfaces of SAAJ, on the other hand in JDKs Xerces,
 558      * they are casted to internal impl classes. After removal of SAAJ dependency
 559      * to JDKs internal classes elements in DOM can never be both of them.
 560      *
 561      * @param node SAAJ wrapper node for w3c DOM node
 562      */
 563     public void register(javax.xml.soap.Node node) {
 564         final Node domElement = getDomNode(node);
 565         if (domElement.getUserData(SAAJ_NODE) != null) {
 566             throw new IllegalStateException("Element " + domElement.getNodeName()
 567                     + " is already registered");
 568         }
 569         domElement.setUserData(SAAJ_NODE, node, null);
 570     }
 571 
 572     /**
 573      * Find a soap wrapper for w3c dom node.
 574      *
 575      * @param node w3c dom node nullable
 576      * @return soap wrapper for w3c dom node
 577      *
 578      * @throws
 579      */
 580     public javax.xml.soap.Node find(Node node) {
 581         return find(node, true);
 582     }
 583 
 584     private javax.xml.soap.Node find(Node node, boolean required) {
 585         if (node == null) {
 586             return null;
 587         }
 588         if (node instanceof javax.xml.soap.Node) {
 589             return (javax.xml.soap.Node) node;
 590         }
 591         final javax.xml.soap.Node found = (javax.xml.soap.Node) node.getUserData(SAAJ_NODE);
 592         if (found == null && required) {
 593             throw new IllegalArgumentException(MessageFormat.format("Cannot find SOAP wrapper for element {0}", node));
 594         }
 595         return found;
 596     }
 597 
 598     /**
 599      * If corresponding soap wrapper exists for w3c dom node it is returned,
 600      * if not passed dom element is returned.
 601      *
 602      * @param node w3c dom node
 603      * @return soap wrapper or passed w3c dom node if not found
 604      */
 605     public Node findIfPresent(Node node) {
 606         final javax.xml.soap.Node found = find(node, false);
 607         return found != null ? found : node;
 608     }
 609 
 610     /**
 611      * Extracts w3c dom node from corresponding soap wrapper.
 612      *
 613      * @param node soap or dom nullable
 614      * @return dom node
 615      */
 616     public Node getDomNode(Node node) {
 617         if (node instanceof SOAPDocumentImpl) {
 618             return ((SOAPDocumentImpl)node).getDomElement();
 619         } else if (node instanceof ElementImpl) {
 620             return ((ElementImpl) node).getDomElement();
 621         } else if (node instanceof SOAPTextImpl) {
 622             return ((SOAPTextImpl)node).getDomElement();
 623         } else if (node instanceof SOAPCommentImpl) {
 624             return ((SOAPCommentImpl)node).getDomElement();
 625         } else if (node instanceof CDATAImpl) {
 626             return ((CDATAImpl) node).getDomElement();
 627         }
 628         return node;
 629     }
 630 
 631 
 632     private Node createSoapNode(Class nodeType, Node node) {
 633         if (SOAPTextImpl.class.isAssignableFrom(nodeType)) {
 634             return new SOAPTextImpl(this, (Text) node);
 635         } else if (SOAPCommentImpl.class.isAssignableFrom(nodeType)) {
 636             return new SOAPCommentImpl(this, (Comment) node);
 637         } else if (CDATAImpl.class.isAssignableFrom(nodeType)) {
 638             return new CDATAImpl(this, (CDATASection) node);
 639         }
 640         try {
 641             Constructor<Node> constructor = nodeType.getConstructor(SOAPDocumentImpl.class, Element.class);
 642             return constructor.newInstance(this, node);
 643         } catch (Exception e) {
 644             throw new IllegalStateException(e);
 645         }
 646     }
 647 
 648 
 649     public Document getDomElement() {
 650         return document;
 651     }
 652 
 653     @Override
 654     public String getValue() {
 655         throw new UnsupportedOperationException();
 656     }
 657 
 658     @Override
 659     public void setValue(String value) {
 660         throw new UnsupportedOperationException();
 661     }
 662 
 663     @Override
 664     public void setParentElement(SOAPElement parent) throws SOAPException {
 665         throw new UnsupportedOperationException();
 666     }
 667 
< prev index next >