001: /*
002: * Copyright (c) 1998-2007 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 Scott Ferguson
028: */
029:
030: package javax.xml.soap;
031:
032: import org.w3c.dom.*;
033: import javax.xml.namespace.*;
034: import java.util.WeakHashMap;
035:
036: public abstract class SOAPFactory {
037: private static final WeakHashMap<ClassLoader, Class> _factoryMap = new WeakHashMap<ClassLoader, Class>();
038:
039: public SOAPFactory() {
040: }
041:
042: public abstract Detail createDetail() throws SOAPException;
043:
044: public SOAPElement createElement(Element domElement)
045: throws SOAPException {
046: throw new UnsupportedOperationException();
047: }
048:
049: public abstract SOAPElement createElement(Name name)
050: throws SOAPException;
051:
052: public SOAPElement createElement(QName qname) throws SOAPException {
053: throw new UnsupportedOperationException();
054: }
055:
056: public abstract SOAPElement createElement(String localName)
057: throws SOAPException;
058:
059: public abstract SOAPElement createElement(String localName,
060: String prefix, String uri) throws SOAPException;
061:
062: public abstract SOAPFault createFault() throws SOAPException;
063:
064: public abstract SOAPFault createFault(String reasonText,
065: QName faultCode) throws SOAPException;
066:
067: public abstract Name createName(String localName)
068: throws SOAPException;
069:
070: public abstract Name createName(String localName, String prefix,
071: String uri) throws SOAPException;
072:
073: public static SOAPFactory newInstance() throws SOAPException {
074: // XXX synchronize?
075:
076: try {
077: ClassLoader classLoader = Thread.currentThread()
078: .getContextClassLoader();
079:
080: Class cl = _factoryMap.get(classLoader);
081:
082: if (cl == null) {
083: FactoryLoader factoryLoader = FactoryLoader
084: .getFactoryLoader("javax.xml.soap.SOAPFactory");
085:
086: cl = factoryLoader.newClass(classLoader);
087:
088: if (cl != null)
089: _factoryMap.put(classLoader, cl);
090: else
091: return newInstance(SOAPConstants.DEFAULT_SOAP_PROTOCOL);
092: }
093:
094: return (SOAPFactory) cl.newInstance();
095: } catch (Exception e) {
096: throw new SOAPException(e);
097: }
098: }
099:
100: public static SOAPFactory newInstance(String protocol)
101: throws SOAPException {
102: return SAAJMetaFactory.getInstance().newSOAPFactory(protocol);
103: }
104: }
|