src/share/classes/com/sun/xml/internal/messaging/saaj/soap/SOAPFactoryImpl.java

changeset 1
0961a4a21176
child 45
31822b475baa
equal deleted inserted replaced
-1:000000000000 1:0961a4a21176
1 /*
2 * $Id: SOAPFactoryImpl.java,v 1.21 2006/01/27 12:49:29 vj135062 Exp $
3 * $Revision: 1.21 $
4 * $Date: 2006/01/27 12:49:29 $
5 */
6
7 /*
8 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Sun designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Sun in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
28 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * have any questions.
30 */
31 package com.sun.xml.internal.messaging.saaj.soap;
32
33 import java.util.logging.Logger;
34 import java.util.logging.Level;
35
36 import javax.xml.namespace.QName;
37 import javax.xml.soap.*;
38
39 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
40 import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
41 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
42 import com.sun.xml.internal.messaging.saaj.util.*;
43
44 import org.w3c.dom.Element;
45 import org.w3c.dom.Document;
46 import org.w3c.dom.NodeList;
47 import org.w3c.dom.NamedNodeMap;
48 import org.w3c.dom.Attr;
49
50 public abstract class SOAPFactoryImpl extends SOAPFactory {
51
52 protected static Logger
53 log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
54 "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
55
56 protected abstract SOAPDocumentImpl createDocument();
57
58 public SOAPElement createElement(String tagName) throws SOAPException {
59 if (tagName == null) {
60 log.log(
61 Level.SEVERE,"SAAJ0567.soap.null.input",
62 new Object[] {"tagName","SOAPFactory.createElement"});
63 throw new SOAPException("Null tagName argument passed to createElement");
64 }
65 return ElementFactory.createElement(createDocument(),
66 NameImpl.createFromTagName(tagName));
67 }
68
69 public SOAPElement createElement(Name name) throws SOAPException {
70 // @since SAAJ 1.3
71 // If the Name was null it would cause a NullPointerException in earlier release
72 if (name == null) {
73 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
74 new Object[] {"name","SOAPFactory.createElement"});
75 throw new SOAPException("Null name argument passed to createElement");
76 }
77 return ElementFactory.createElement(createDocument(), name);
78 }
79
80 public SOAPElement createElement(QName qname) throws SOAPException {
81 if (qname == null) {
82 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
83 new Object[] {"qname","SOAPFactory.createElement"});
84 throw new SOAPException("Null qname argument passed to createElement");
85 }
86 return ElementFactory.createElement(createDocument(),qname);
87 }
88
89 public SOAPElement createElement(
90 String localName,
91 String prefix,
92 String uri) throws SOAPException {
93
94 // @since SAAJ 1.3
95 // if prefix !=null but localName== null then in earlier releases it would create
96 // a Qualified Name <prefix>:null which is not meaningful
97 if (localName == null) {
98 log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
99 new Object[] {"localName","SOAPFactory.createElement"});
100 throw new SOAPException("Null localName argument passed to createElement");
101 }
102 return ElementFactory.createElement(createDocument(), localName, prefix, uri);
103 }
104
105 public Name createName(String localName, String prefix, String uri)
106 throws SOAPException {
107 // @since SAAJ 1.3
108 // if localName==null, earlier impl would create Name with localName=""
109 // which is absurd.
110 if (localName == null) {
111 log.log(
112 Level.SEVERE,"SAAJ0567.soap.null.input",
113 new Object[] {"localName","SOAPFactory.createName"});
114 throw new SOAPException("Null localName argument passed to createName");
115 }
116 return NameImpl.create(localName, prefix, uri);
117 }
118
119 public Name createName(String localName) throws SOAPException {
120 // @since SAAJ 1.3
121 // if localName==null, earlier impl would create Name with localName=null
122 // which is absurd.
123 if (localName == null) {
124 log.log(
125 Level.SEVERE,"SAAJ0567.soap.null.input",
126 new Object[] {"localName","SOAPFactory.createName"});
127 throw new SOAPException("Null localName argument passed to createName");
128 }
129 return NameImpl.createFromUnqualifiedName(localName);
130 }
131
132 // Note: the child elements might still be org.w3c.dom.Element's, but the
133 // getChildElements will do the conversion to SOAPElement when called.
134 public SOAPElement createElement(Element domElement) throws SOAPException {
135 if (domElement == null) {
136 return null;
137 }
138 return convertToSoapElement(domElement);
139 }
140
141 private SOAPElement convertToSoapElement(Element element) throws SOAPException {
142
143 if (element instanceof SOAPElement) {
144 return (SOAPElement) element;
145 }
146
147 SOAPElement copy = createElement(
148 element.getLocalName(),
149 element.getPrefix(),
150 element.getNamespaceURI());
151
152 Document ownerDoc = copy.getOwnerDocument();
153
154 NamedNodeMap attrMap = element.getAttributes();
155 for (int i=0; i < attrMap.getLength(); i++) {
156 Attr nextAttr = (Attr)attrMap.item(i);
157 Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true);
158 copy.setAttributeNodeNS(importedAttr);
159 }
160
161
162 NodeList nl = element.getChildNodes();
163 for (int i=0; i < nl.getLength(); i++) {
164 org.w3c.dom.Node next = nl.item(i);
165 org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
166 copy.appendChild(imported);
167 }
168
169 return copy;
170 }
171
172 public Detail createDetail() throws SOAPException {
173 throw new UnsupportedOperationException();
174 }
175
176 public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException {
177 throw new UnsupportedOperationException();
178 }
179
180 public SOAPFault createFault() throws SOAPException {
181 throw new UnsupportedOperationException();
182 }
183
184 }

mercurial