001: /*
002: * $Id: ElementFactory.java,v 1.16 2006/01/27 12:49:35 vj135062 Exp $
003: * $Revision: 1.16 $
004: * $Date: 2006/01/27 12:49:35 $
005: */
006:
007: /*
008: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
009: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
010: *
011: * This code is free software; you can redistribute it and/or modify it
012: * under the terms of the GNU General Public License version 2 only, as
013: * published by the Free Software Foundation. Sun designates this
014: * particular file as subject to the "Classpath" exception as provided
015: * by Sun in the LICENSE file that accompanied this code.
016: *
017: * This code is distributed in the hope that it will be useful, but WITHOUT
018: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
019: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
020: * version 2 for more details (a copy is included in the LICENSE file that
021: * accompanied this code).
022: *
023: * You should have received a copy of the GNU General Public License version
024: * 2 along with this work; if not, write to the Free Software Foundation,
025: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
026: *
027: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
028: * CA 95054 USA or visit www.sun.com if you need additional information or
029: * have any questions.
030: */
031: package com.sun.xml.internal.messaging.saaj.soap.impl;
032:
033: import javax.xml.namespace.QName;
034: import javax.xml.soap.*;
035:
036: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
037: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
038: import com.sun.xml.internal.messaging.saaj.soap.ver1_1.*;
039: import com.sun.xml.internal.messaging.saaj.soap.ver1_2.*;
040:
041: public class ElementFactory {
042: public static SOAPElement createElement(
043: SOAPDocumentImpl ownerDocument, Name name) {
044: return createElement(ownerDocument, name.getLocalName(), name
045: .getPrefix(), name.getURI());
046: }
047:
048: public static SOAPElement createElement(
049: SOAPDocumentImpl ownerDocument, QName name) {
050: return createElement(ownerDocument, name.getLocalPart(), name
051: .getPrefix(), name.getNamespaceURI());
052: }
053:
054: public static SOAPElement createElement(
055: SOAPDocumentImpl ownerDocument, String localName,
056: String prefix, String namespaceUri) {
057:
058: if (ownerDocument == null) {
059: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
060: ownerDocument = new SOAPPart1_1Impl().getDocument();
061: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
062: ownerDocument = new SOAPPart1_2Impl().getDocument();
063: } else {
064: ownerDocument = new SOAPDocumentImpl(null);
065: }
066: }
067:
068: SOAPElement newElement = createNamedElement(ownerDocument,
069: localName, prefix, namespaceUri);
070:
071: return newElement != null ? newElement : new ElementImpl(
072: ownerDocument, namespaceUri, NameImpl.createQName(
073: prefix, localName));
074: }
075:
076: public static SOAPElement createNamedElement(
077: SOAPDocumentImpl ownerDocument, String localName,
078: String prefix, String namespaceUri) {
079:
080: if (prefix == null) {
081: prefix = NameImpl.SOAP_ENVELOPE_PREFIX;
082: }
083:
084: if (localName.equalsIgnoreCase("Envelope")) {
085: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
086: return new Envelope1_1Impl(ownerDocument, prefix);
087: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
088: return new Envelope1_2Impl(ownerDocument, prefix);
089: }
090: }
091: if (localName.equalsIgnoreCase("Body")) {
092: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
093: return new Body1_1Impl(ownerDocument, prefix);
094: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
095: return new Body1_2Impl(ownerDocument, prefix);
096: }
097: }
098: if (localName.equalsIgnoreCase("Header")) {
099: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
100: return new Header1_1Impl(ownerDocument, prefix);
101: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
102: return new Header1_2Impl(ownerDocument, prefix);
103: }
104: }
105: if (localName.equalsIgnoreCase("Fault")) {
106: SOAPFault fault = null;
107: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
108: fault = new Fault1_1Impl(ownerDocument, prefix);
109: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
110: fault = new Fault1_2Impl(ownerDocument, prefix);
111: }
112:
113: if (fault != null) {
114: // try {
115: // fault.addNamespaceDeclaration(
116: // NameImpl.SOAP_ENVELOPE_PREFIX,
117: // SOAPConstants.URI_NS_SOAP_ENVELOPE);
118: // fault.setFaultCode(
119: // NameImpl.create(
120: // "Server",
121: // NameImpl.SOAP_ENVELOPE_PREFIX,
122: // SOAPConstants.URI_NS_SOAP_ENVELOPE));
123: // fault.setFaultString(
124: // "Fault string, and possibly fault code, not set");
125: // } catch (SOAPException e) {
126: // }
127: return fault;
128: }
129:
130: }
131: if (localName.equalsIgnoreCase("Detail")) {
132: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
133: return new Detail1_1Impl(ownerDocument, prefix);
134: } else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
135: return new Detail1_2Impl(ownerDocument, prefix);
136: }
137: }
138: if (localName.equalsIgnoreCase("faultcode")
139: || localName.equalsIgnoreCase("faultstring")
140: || localName.equalsIgnoreCase("faultactor")) {
141: // SOAP 1.2 does not have fault(code/string/actor)
142: // So there is no else case required
143: if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
144: return new FaultElement1_1Impl(ownerDocument,
145: localName, prefix);
146: }
147: }
148:
149: return null;
150: }
151:
152: protected static void invalidCreate(String msg) {
153: throw new TreeException(msg);
154: }
155: }
|