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