001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: SOAPFactoryImpl.java,v 1.2 2007/07/16 16:41:22 ofung Exp $
022: * $Revision: 1.2 $
023: * $Date: 2007/07/16 16:41:22 $
024: */
025:
026: /*
027: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
028: *
029: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
030: *
031: * The contents of this file are subject to the terms of either the GNU
032: * General Public License Version 2 only ("GPL") or the Common Development
033: * and Distribution License("CDDL") (collectively, the "License"). You
034: * may not use this file except in compliance with the License. You can obtain
035: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
036: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
037: * language governing permissions and limitations under the License.
038: *
039: * When distributing the software, include this License Header Notice in each
040: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
041: * Sun designates this particular file as subject to the "Classpath" exception
042: * as provided by Sun in the GPL Version 2 section of the License file that
043: * accompanied this code. If applicable, add the following below the License
044: * Header, with the fields enclosed by brackets [] replaced by your own
045: * identifying information: "Portions Copyrighted [year]
046: * [name of copyright owner]"
047: *
048: * Contributor(s):
049: *
050: * If you wish your version of this file to be governed by only the CDDL or
051: * only the GPL Version 2, indicate your decision by adding "[Contributor]
052: * elects to include this software in this distribution under the [CDDL or GPL
053: * Version 2] license." If you don't indicate a single choice of license, a
054: * recipient has the option to distribute your version of this file under
055: * either the CDDL, the GPL Version 2 or to extend the choice of license to
056: * its licensees as provided above. However, if you add GPL Version 2 code
057: * and therefore, elected the GPL Version 2 license, then the option applies
058: * only if the new code is made subject to such option by the copyright
059: * holder.
060: */
061: package com.sun.xml.messaging.saaj.soap;
062:
063: import java.util.logging.Logger;
064: import java.util.logging.Level;
065:
066: import javax.xml.namespace.QName;
067: import javax.xml.soap.*;
068:
069: import com.sun.xml.messaging.saaj.soap.impl.ElementFactory;
070: import com.sun.xml.messaging.saaj.soap.impl.ElementImpl;
071: import com.sun.xml.messaging.saaj.soap.name.NameImpl;
072: import com.sun.xml.messaging.saaj.util.*;
073:
074: import org.w3c.dom.Element;
075: import org.w3c.dom.Document;
076: import org.w3c.dom.NodeList;
077: import org.w3c.dom.NamedNodeMap;
078: import org.w3c.dom.Attr;
079:
080: public abstract class SOAPFactoryImpl extends SOAPFactory {
081:
082: protected static Logger log = Logger.getLogger(
083: LogDomainConstants.SOAP_DOMAIN,
084: "com.sun.xml.messaging.saaj.soap.LocalStrings");
085:
086: protected abstract SOAPDocumentImpl createDocument();
087:
088: public SOAPElement createElement(String tagName)
089: throws SOAPException {
090: if (tagName == null) {
091: log.log(Level.SEVERE, "SAAJ0567.soap.null.input",
092: new Object[] { "tagName",
093: "SOAPFactory.createElement" });
094: throw new SOAPException(
095: "Null tagName argument passed to createElement");
096: }
097: return ElementFactory.createElement(createDocument(), NameImpl
098: .createFromTagName(tagName));
099: }
100:
101: public SOAPElement createElement(Name name) throws SOAPException {
102: // @since SAAJ 1.3
103: // If the Name was null it would cause a NullPointerException in earlier release
104: if (name == null) {
105: log
106: .log(Level.SEVERE, "SAAJ0567.soap.null.input",
107: new Object[] { "name",
108: "SOAPFactory.createElement" });
109: throw new SOAPException(
110: "Null name argument passed to createElement");
111: }
112: return ElementFactory.createElement(createDocument(), name);
113: }
114:
115: public SOAPElement createElement(QName qname) throws SOAPException {
116: if (qname == null) {
117: log
118: .log(Level.SEVERE, "SAAJ0567.soap.null.input",
119: new Object[] { "qname",
120: "SOAPFactory.createElement" });
121: throw new SOAPException(
122: "Null qname argument passed to createElement");
123: }
124: return ElementFactory.createElement(createDocument(), qname);
125: }
126:
127: public SOAPElement createElement(String localName, String prefix,
128: String uri) throws SOAPException {
129:
130: // @since SAAJ 1.3
131: // if prefix !=null but localName== null then in earlier releases it would create
132: // a Qualified Name <prefix>:null which is not meaningful
133: if (localName == null) {
134: log.log(Level.SEVERE, "SAAJ0567.soap.null.input",
135: new Object[] { "localName",
136: "SOAPFactory.createElement" });
137: throw new SOAPException(
138: "Null localName argument passed to createElement");
139: }
140: return ElementFactory.createElement(createDocument(),
141: localName, prefix, uri);
142: }
143:
144: public Name createName(String localName, String prefix, String uri)
145: throws SOAPException {
146: // @since SAAJ 1.3
147: // if localName==null, earlier impl would create Name with localName=""
148: // which is absurd.
149: if (localName == null) {
150: log.log(Level.SEVERE, "SAAJ0567.soap.null.input",
151: new Object[] { "localName",
152: "SOAPFactory.createName" });
153: throw new SOAPException(
154: "Null localName argument passed to createName");
155: }
156: return NameImpl.create(localName, prefix, uri);
157: }
158:
159: public Name createName(String localName) throws SOAPException {
160: // @since SAAJ 1.3
161: // if localName==null, earlier impl would create Name with localName=null
162: // which is absurd.
163: if (localName == null) {
164: log.log(Level.SEVERE, "SAAJ0567.soap.null.input",
165: new Object[] { "localName",
166: "SOAPFactory.createName" });
167: throw new SOAPException(
168: "Null localName argument passed to createName");
169: }
170: return NameImpl.createFromUnqualifiedName(localName);
171: }
172:
173: // Note: the child elements might still be org.w3c.dom.Element's, but the
174: // getChildElements will do the conversion to SOAPElement when called.
175: public SOAPElement createElement(Element domElement)
176: throws SOAPException {
177: if (domElement == null) {
178: return null;
179: }
180: return convertToSoapElement(domElement);
181: }
182:
183: private SOAPElement convertToSoapElement(Element element)
184: throws SOAPException {
185:
186: if (element instanceof SOAPElement) {
187: return (SOAPElement) element;
188: }
189:
190: SOAPElement copy = createElement(element.getLocalName(),
191: element.getPrefix(), element.getNamespaceURI());
192:
193: Document ownerDoc = copy.getOwnerDocument();
194:
195: NamedNodeMap attrMap = element.getAttributes();
196: for (int i = 0; i < attrMap.getLength(); i++) {
197: Attr nextAttr = (Attr) attrMap.item(i);
198: Attr importedAttr = (Attr) ownerDoc.importNode(nextAttr,
199: true);
200: copy.setAttributeNodeNS(importedAttr);
201: }
202:
203: NodeList nl = element.getChildNodes();
204: for (int i = 0; i < nl.getLength(); i++) {
205: org.w3c.dom.Node next = nl.item(i);
206: org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
207: copy.appendChild(imported);
208: }
209:
210: return copy;
211: }
212:
213: public Detail createDetail() throws SOAPException {
214: throw new UnsupportedOperationException();
215: }
216:
217: public SOAPFault createFault(String reasonText, QName faultCode)
218: throws SOAPException {
219: throw new UnsupportedOperationException();
220: }
221:
222: public SOAPFault createFault() throws SOAPException {
223: throw new UnsupportedOperationException();
224: }
225:
226: }
|