001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.saaj;
031:
032: import org.w3c.dom.*;
033: import javax.xml.soap.*;
034: import javax.xml.namespace.*;
035:
036: public class SOAPFactoryImpl extends SOAPFactory {
037: private final String _protocol;
038:
039: public SOAPFactoryImpl() throws SOAPException {
040: this (SOAPConstants.DEFAULT_SOAP_PROTOCOL);
041: }
042:
043: public SOAPFactoryImpl(String protocol) throws SOAPException {
044: if (!protocol.equals(SOAPConstants.SOAP_1_1_PROTOCOL)
045: && !protocol.equals(SOAPConstants.SOAP_1_2_PROTOCOL)
046: && !protocol
047: .equals(SOAPConstants.DYNAMIC_SOAP_PROTOCOL))
048: throw new SOAPException("Unsupported protocol : "
049: + protocol);
050:
051: _protocol = protocol;
052: }
053:
054: public Detail createDetail() throws SOAPException {
055: if (_protocol.equals(SOAPConstants.SOAP_1_1_PROTOCOL))
056: return new SOAP11DetailImpl(this );
057: else if (_protocol.equals(SOAPConstants.SOAP_1_2_PROTOCOL))
058: return new SOAP12DetailImpl(this );
059: else
060: throw new SOAPException(
061: "Cannot create detail for protocol: " + _protocol);
062: }
063:
064: public SOAPElement createElement(Element domElement)
065: throws SOAPException {
066: return new SOAPElementImpl(this , domElement);
067: }
068:
069: public SOAPElement createElement(Name name) throws SOAPException {
070: if (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE
071: .equals(name.getURI())) {
072: if ("Envelope".equals(name.getLocalName()))
073: return new SOAP11EnvelopeImpl(this );
074: else if ("Header".equals(name.getLocalName()))
075: return new SOAP11HeaderImpl(this , NameImpl
076: .fromName(name));
077: else if ("Body".equals(name.getLocalName()))
078: return new SOAP11BodyImpl(this , NameImpl.fromName(name));
079: else if ("Fault".equals(name.getLocalName()))
080: return new SOAP11FaultImpl(this , NameImpl
081: .fromName(name));
082: } else if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(name
083: .getURI())) {
084: if ("Envelope".equals(name.getLocalName()))
085: return new SOAP12EnvelopeImpl(this );
086: else if ("Header".equals(name.getLocalName()))
087: return new SOAP12HeaderImpl(this , NameImpl
088: .fromName(name));
089: else if ("Body".equals(name.getLocalName()))
090: return new SOAP12BodyImpl(this , NameImpl.fromName(name));
091: else if ("Fault".equals(name.getLocalName()))
092: return new SOAP12FaultImpl(this , NameImpl
093: .fromName(name));
094: }
095:
096: return new SOAPElementImpl(this , NameImpl.fromName(name));
097: }
098:
099: public SOAPElement createElement(QName qname) throws SOAPException {
100: return createElement((Name) NameImpl.fromQName(qname));
101: }
102:
103: public SOAPElement createElement(String localName)
104: throws SOAPException {
105: return new SOAPElementImpl(this , new NameImpl(localName));
106: }
107:
108: public SOAPElement createElement(String localName, String prefix,
109: String uri) throws SOAPException {
110: return new SOAPElementImpl(this , new NameImpl(uri, localName,
111: prefix));
112: }
113:
114: public SOAPFault createFault() throws SOAPException {
115: if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(_protocol))
116: return new SOAP11FaultImpl(this );
117: else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(_protocol))
118: return new SOAP12FaultImpl(this );
119: else
120: throw new SOAPException("Unsupported protocol: "
121: + _protocol);
122: }
123:
124: public SOAPFault createFault(String reasonText, QName faultCode)
125: throws SOAPException {
126: SOAPFault fault = createFault();
127:
128: fault.setFaultString(reasonText);
129: fault.setFaultCode(faultCode);
130:
131: return fault;
132: }
133:
134: public Name createName(String localName) throws SOAPException {
135: return new NameImpl(localName);
136: }
137:
138: public Name createName(String localName, String prefix, String uri)
139: throws SOAPException {
140: return new NameImpl(uri, localName, prefix);
141: }
142: }
|