ohair@286: /* alanb@368: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: /** ohair@286: * ohair@286: * @author SAAJ RI Development Team ohair@286: */ ohair@286: package com.sun.xml.internal.messaging.saaj.soap; ohair@286: ohair@286: import java.util.logging.Logger; ohair@286: ohair@286: import com.sun.org.apache.xerces.internal.dom.DocumentImpl; ohair@286: import org.w3c.dom.*; ohair@286: ohair@286: import com.sun.xml.internal.messaging.saaj.soap.impl.*; ohair@286: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; ohair@286: import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; ohair@286: ohair@286: public class SOAPDocumentImpl extends DocumentImpl implements SOAPDocument { ohair@286: ohair@286: private static final String XMLNS = "xmlns".intern(); ohair@286: protected static final Logger log = ohair@286: Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, ohair@286: "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); ohair@286: ohair@286: SOAPPartImpl enclosingSOAPPart; ohair@286: ohair@286: public SOAPDocumentImpl(SOAPPartImpl enclosingDocument) { ohair@286: this.enclosingSOAPPart = enclosingDocument; ohair@286: } ohair@286: ohair@286: // public SOAPDocumentImpl(boolean grammarAccess) { ohair@286: // super(grammarAccess); ohair@286: // } ohair@286: // ohair@286: // public SOAPDocumentImpl(DocumentType doctype) { ohair@286: // super(doctype); ohair@286: // } ohair@286: // ohair@286: // public SOAPDocumentImpl(DocumentType doctype, boolean grammarAccess) { ohair@286: // super(doctype, grammarAccess); ohair@286: // } ohair@286: ohair@286: public SOAPPartImpl getSOAPPart() { ohair@286: if (enclosingSOAPPart == null) { ohair@286: log.severe("SAAJ0541.soap.fragment.not.bound.to.part"); ohair@286: throw new RuntimeException("Could not complete operation. Fragment not bound to SOAP part."); ohair@286: } ohair@286: return enclosingSOAPPart; ohair@286: } ohair@286: ohair@286: public SOAPDocumentImpl getDocument() { ohair@286: return this; ohair@286: } ohair@286: ohair@286: public DocumentType getDoctype() { ohair@286: // SOAP means no DTD, No DTD means no doctype (SOAP 1.2 only?) ohair@286: return null; ohair@286: } ohair@286: ohair@286: public DOMImplementation getImplementation() { ohair@286: return super.getImplementation(); ohair@286: } ohair@286: ohair@286: public Element getDocumentElement() { ohair@286: // This had better be an Envelope! ohair@286: getSOAPPart().doGetDocumentElement(); ohair@286: return doGetDocumentElement(); ohair@286: } ohair@286: ohair@286: protected Element doGetDocumentElement() { ohair@286: return super.getDocumentElement(); ohair@286: } ohair@286: ohair@286: public Element createElement(String tagName) throws DOMException { ohair@286: return ElementFactory.createElement( ohair@286: this, ohair@286: NameImpl.getLocalNameFromTagName(tagName), ohair@286: NameImpl.getPrefixFromTagName(tagName), ohair@286: null); ohair@286: } ohair@286: ohair@286: public DocumentFragment createDocumentFragment() { ohair@286: return new SOAPDocumentFragment(this); ohair@286: } ohair@286: ohair@286: public org.w3c.dom.Text createTextNode(String data) { ohair@286: return new TextImpl(this, data); ohair@286: } ohair@286: ohair@286: public Comment createComment(String data) { ohair@286: return new CommentImpl(this, data); ohair@286: } ohair@286: ohair@286: public CDATASection createCDATASection(String data) throws DOMException { ohair@286: return new CDATAImpl(this, data); ohair@286: } ohair@286: ohair@286: public ProcessingInstruction createProcessingInstruction( ohair@286: String target, ohair@286: String data) ohair@286: throws DOMException { ohair@286: log.severe("SAAJ0542.soap.proc.instructions.not.allowed.in.docs"); ohair@286: throw new UnsupportedOperationException("Processing Instructions are not allowed in SOAP documents"); ohair@286: } ohair@286: ohair@286: public Attr createAttribute(String name) throws DOMException { ohair@286: boolean isQualifiedName = (name.indexOf(":") > 0); ohair@286: if (isQualifiedName) { ohair@286: String nsUri = null; ohair@286: String prefix = name.substring(0, name.indexOf(":")); ohair@286: //cannot do anything to resolve the URI if prefix is not ohair@286: //XMLNS. ohair@286: if (XMLNS.equals(prefix)) { ohair@286: nsUri = ElementImpl.XMLNS_URI; ohair@286: return createAttributeNS(nsUri, name); ohair@286: } ohair@286: } ohair@286: ohair@286: return super.createAttribute(name); ohair@286: } ohair@286: ohair@286: public EntityReference createEntityReference(String name) ohair@286: throws DOMException { ohair@286: log.severe("SAAJ0543.soap.entity.refs.not.allowed.in.docs"); ohair@286: throw new UnsupportedOperationException("Entity References are not allowed in SOAP documents"); ohair@286: } ohair@286: ohair@286: public NodeList getElementsByTagName(String tagname) { ohair@286: return super.getElementsByTagName(tagname); ohair@286: } ohair@286: ohair@286: public org.w3c.dom.Node importNode(Node importedNode, boolean deep) ohair@286: throws DOMException { ohair@286: return super.importNode(importedNode, deep); ohair@286: } ohair@286: ohair@286: public Element createElementNS(String namespaceURI, String qualifiedName) ohair@286: throws DOMException { ohair@286: return ElementFactory.createElement( ohair@286: this, ohair@286: NameImpl.getLocalNameFromTagName(qualifiedName), ohair@286: NameImpl.getPrefixFromTagName(qualifiedName), ohair@286: namespaceURI); ohair@286: } ohair@286: ohair@286: public Attr createAttributeNS(String namespaceURI, String qualifiedName) ohair@286: throws DOMException { ohair@286: return super.createAttributeNS(namespaceURI, qualifiedName); ohair@286: } ohair@286: ohair@286: public NodeList getElementsByTagNameNS( ohair@286: String namespaceURI, ohair@286: String localName) { ohair@286: return super.getElementsByTagNameNS(namespaceURI, localName); ohair@286: } ohair@286: ohair@286: public Element getElementById(String elementId) { ohair@286: return super.getElementById(elementId); ohair@286: } ohair@286: ohair@286: public Node cloneNode(boolean deep) { ohair@286: SOAPPartImpl newSoapPart = getSOAPPart().doCloneNode(); ohair@286: super.cloneNode(newSoapPart.getDocument(), deep); ohair@286: return newSoapPart; ohair@286: } ohair@286: ohair@286: public void cloneNode(SOAPDocumentImpl newdoc, boolean deep) { ohair@286: super.cloneNode(newdoc, deep); ohair@286: } ohair@286: }