001 /*
002 * $Id: SAAJMetaFactory.java,v 1.2.2.15 2005/02/11 07:26:15 vj135062 Exp $
003 * $Revision: 1.2.2.15 $
004 * $Date: 2005/02/11 07:26:15 $
005 */
006
007 /*
008 * Copyright 2005-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 javax.xml.soap;
032
033 /**
034 * The access point for the implementation classes of the factories defined in the
035 * SAAJ API. All of the <code>newInstance</code> methods defined on factories in
036 * SAAJ 1.3 defer to instances of this class to do the actual object creation.
037 * The implementations of <code>newInstance()</code> methods (in SOAPFactory and MessageFactory)
038 * that existed in SAAJ 1.2 have been updated to also delegate to the SAAJMetaFactory when the SAAJ 1.2
039 * defined lookup fails to locate the Factory implementation class name.
040 *
041 * <p>
042 * SAAJMetaFactory is a service provider interface. There are no public methods on this
043 * class.
044 *
045 * @author SAAJ RI Development Team
046 * @since SAAJ 1.3
047 */
048
049 public abstract class SAAJMetaFactory {
050 static private final String META_FACTORY_CLASS_PROPERTY = "javax.xml.soap.MetaFactory";
051 static private final String DEFAULT_META_FACTORY_CLASS = "com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl";
052
053 static private SAAJMetaFactory instance = null;
054
055 /**
056 * Creates a new instance of a concrete <code>SAAJMetaFactory</code> object.
057 * The SAAJMetaFactory is an SPI, it pulls the creation of the other factories together into a
058 * single place. Changing out the SAAJMetaFactory has the effect of changing out the entire SAAJ
059 * implementation. Service providers provide the name of their <code>SAAJMetaFactory</code>
060 * implementation.
061 *
062 * This method uses the following ordered lookup procedure to determine the SAAJMetaFactory implementation class to load:
063 * <UL>
064 * <LI> Use the javax.xml.soap.MetaFactory system property.
065 * <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
066 * java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
067 * system property defined above.
068 * <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
069 * will look for a classname in the file META-INF/services/javax.xml.soap.MetaFactory in jars available to the runtime.
070 * <LI> Default to com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl.
071 * </UL>
072 *
073 * @return a concrete <code>SAAJMetaFactory</code> object
074 * @exception SOAPException if there is an error in creating the <code>SAAJMetaFactory</code>
075 */
076 static synchronized SAAJMetaFactory getInstance()
077 throws SOAPException {
078 if (instance == null) {
079 try {
080 instance = (SAAJMetaFactory) FactoryFinder.find(
081 META_FACTORY_CLASS_PROPERTY,
082 DEFAULT_META_FACTORY_CLASS);
083 } catch (Exception e) {
084 throw new SOAPException(
085 "Unable to create SAAJ meta-factory"
086 + e.getMessage());
087 }
088 }
089
090 return instance;
091 }
092
093 protected SAAJMetaFactory() {
094 }
095
096 /**
097 * Creates a <code>MessageFactory</code> object for
098 * the given <code>String</code> protocol.
099 *
100 * @param protocol a <code>String</code> indicating the protocol
101 * @exception SOAPException if there is an error in creating the
102 * MessageFactory
103 * @see SOAPConstants#SOAP_1_1_PROTOCOL
104 * @see SOAPConstants#SOAP_1_2_PROTOCOL
105 * @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL
106 */
107 protected abstract MessageFactory newMessageFactory(String protocol)
108 throws SOAPException;
109
110 /**
111 * Creates a <code>SOAPFactory</code> object for
112 * the given <code>String</code> protocol.
113 *
114 * @param protocol a <code>String</code> indicating the protocol
115 * @exception SOAPException if there is an error in creating the
116 * SOAPFactory
117 * @see SOAPConstants#SOAP_1_1_PROTOCOL
118 * @see SOAPConstants#SOAP_1_2_PROTOCOL
119 * @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL
120 */
121 protected abstract SOAPFactory newSOAPFactory(String protocol)
122 throws SOAPException;
123 }
|