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: ElementFactory.java,v 1.2 2007/07/16 16:41:23 ofung Exp $
022: * $Revision: 1.2 $
023: * $Date: 2007/07/16 16:41:23 $
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.impl;
062:
063: import javax.xml.namespace.QName;
064: import javax.xml.soap.*;
065:
066: import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl;
067: import com.sun.xml.messaging.saaj.soap.name.NameImpl;
068: import com.sun.xml.messaging.saaj.soap.ver1_1.*;
069: import com.sun.xml.messaging.saaj.soap.ver1_2.*;
070:
071: public class ElementFactory {
072: public static SOAPElement createElement(
073: SOAPDocumentImpl ownerDocument, Name name) {
074: return createElement(ownerDocument, name.getLocalName(), name
075: .getPrefix(), name.getURI());
076: }
077:
078: public static SOAPElement createElement(
079: SOAPDocumentImpl ownerDocument, QName name) {
080: return createElement(ownerDocument, name.getLocalPart(), name
081: .getPrefix(), name.getNamespaceURI());
082: }
083:
084: public static SOAPElement createElement(
085: SOAPDocumentImpl ownerDocument, String localName,
086: String prefix, String namespaceUri) {
087:
088: if (ownerDocument == null) {
089: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
090: ownerDocument = new SOAPPart1_1Impl().getDocument();
091: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
092: ownerDocument = new SOAPPart1_2Impl().getDocument();
093: } else {
094: ownerDocument = new SOAPDocumentImpl(null);
095: }
096: }
097:
098: SOAPElement newElement = createNamedElement(ownerDocument,
099: localName, prefix, namespaceUri);
100:
101: return newElement != null ? newElement : new ElementImpl(
102: ownerDocument, namespaceUri, NameImpl.createQName(
103: prefix, localName));
104: }
105:
106: public static SOAPElement createNamedElement(
107: SOAPDocumentImpl ownerDocument, String localName,
108: String prefix, String namespaceUri) {
109:
110: if (prefix == null) {
111: prefix = NameImpl.SOAP_ENVELOPE_PREFIX;
112: }
113:
114: if (localName.equalsIgnoreCase("Envelope")) {
115: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
116: return new Envelope1_1Impl(ownerDocument, prefix);
117: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
118: return new Envelope1_2Impl(ownerDocument, prefix);
119: }
120: }
121: if (localName.equalsIgnoreCase("Body")) {
122: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
123: return new Body1_1Impl(ownerDocument, prefix);
124: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
125: return new Body1_2Impl(ownerDocument, prefix);
126: }
127: }
128: if (localName.equalsIgnoreCase("Header")) {
129: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
130: return new Header1_1Impl(ownerDocument, prefix);
131: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
132: return new Header1_2Impl(ownerDocument, prefix);
133: }
134: }
135: if (localName.equalsIgnoreCase("Fault")) {
136: SOAPFault fault = null;
137: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
138: fault = new Fault1_1Impl(ownerDocument, prefix);
139: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
140: fault = new Fault1_2Impl(ownerDocument, prefix);
141: }
142:
143: if (fault != null) {
144: // try {
145: // fault.addNamespaceDeclaration(
146: // NameImpl.SOAP_ENVELOPE_PREFIX,
147: // SOAPConstants.URI_NS_SOAP_ENVELOPE);
148: // fault.setFaultCode(
149: // NameImpl.create(
150: // "Server",
151: // NameImpl.SOAP_ENVELOPE_PREFIX,
152: // SOAPConstants.URI_NS_SOAP_ENVELOPE));
153: // fault.setFaultString(
154: // "Fault string, and possibly fault code, not set");
155: // } catch (SOAPException e) {
156: // }
157: return fault;
158: }
159:
160: }
161: if (localName.equalsIgnoreCase("Detail")) {
162: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
163: return new Detail1_1Impl(ownerDocument, prefix);
164: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
165: return new Detail1_2Impl(ownerDocument, prefix);
166: }
167: }
168: if (localName.equalsIgnoreCase("faultcode")
169: || localName.equalsIgnoreCase("faultstring")
170: || localName.equalsIgnoreCase("faultactor")) {
171: // SOAP 1.2 does not have fault(code/string/actor)
172: // So there is no else case required
173: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
174: return new FaultElement1_1Impl(ownerDocument,
175: localName, prefix);
176: }
177: }
178:
179: return null;
180: }
181:
182: protected static void invalidCreate(String msg) {
183: throw new TreeException(msg);
184: }
185: }
|