001: /*
002: * Copyright (c) 1998-2004 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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.xml.rpc;
030:
031: import javax.xml.namespace.QName;
032: import java.io.BufferedReader;
033: import java.io.InputStream;
034: import java.io.InputStreamReader;
035: import java.io.Reader;
036: import java.net.URL;
037: import java.util.Properties;
038:
039: /**
040: * Abstract implementation of a XML-RPC service.
041: */
042: abstract public class ServiceFactory {
043: public final static String SERVICEFACTORY_PROPERTY = "javax.xml.rpc.ServiceFactory";
044:
045: private final static String DEFAULT_FACTORY = "com.caucho.soap.rpc.ServiceFactory";
046:
047: /**
048: * Constructor.
049: */
050: protected ServiceFactory() {
051: }
052:
053: /**
054: * Creates an instance of the factory.
055: */
056: public static ServiceFactory newInstance() throws ServiceException {
057: String className = getFactoryClassName();
058:
059: Class cl = null;
060:
061: try {
062: ClassLoader loader = Thread.currentThread()
063: .getContextClassLoader();
064: if (loader != null)
065: cl = Class.forName(className, false, loader);
066: } catch (NoSuchMethodError e) {
067: } catch (ClassNotFoundException e) {
068: throw new ServiceException(e);
069: }
070:
071: if (cl == null) {
072: try {
073: cl = Class.forName(className);
074: } catch (ClassNotFoundException e) {
075: throw new ServiceException(e);
076: }
077: }
078:
079: try {
080: return (ServiceFactory) cl.newInstance();
081: } catch (IllegalAccessException e) {
082: throw new ServiceException(e);
083: } catch (InstantiationException e) {
084: throw new ServiceException(e);
085: }
086: }
087:
088: /**
089: * Finds the configured parser factory.
090: *
091: * <ol>
092: * <li>System.getProperty("javax.xml.parsers.SAXParserFactory");
093: * <li>META-INF/services/javax.xml.parsers.SAXParserFactory
094: * <li>$JAVA_HOME/lib/jaxp.properties
095: * </ol>
096: */
097: private static String getFactoryClassName() {
098: String className = null;
099:
100: try {
101: className = System.getProperty(SERVICEFACTORY_PROPERTY);
102: if (className != null)
103: return className;
104: } catch (SecurityException e) {
105: }
106:
107: String serviceName = "META-INF/services/"
108: + SERVICEFACTORY_PROPERTY;
109:
110: try {
111: ClassLoader loader = Thread.currentThread()
112: .getContextClassLoader();
113: InputStream is;
114:
115: if (loader != null)
116: is = loader.getResourceAsStream(serviceName);
117: else
118: is = ClassLoader.getSystemResourceAsStream(serviceName);
119:
120: Reader rawReader = new InputStreamReader(is);
121: BufferedReader reader = new BufferedReader(rawReader);
122:
123: className = reader.readLine();
124: reader.close();
125: is.close();
126:
127: if (className != null)
128: className = className.trim();
129: if (className != null && !"".equals(className))
130: return className;
131: } catch (Throwable e) {
132: }
133:
134: return DEFAULT_FACTORY;
135: }
136:
137: /**
138: * Creates an instance of the factory.
139: */
140: public abstract Service createService(URL wsdlDocumentLocation,
141: QName serviceName) throws ServiceException;
142:
143: /**
144: * Creates an instance of the factory.
145: */
146: public abstract Service createService(QName serviceName)
147: throws ServiceException;
148:
149: /**
150: * Creates an instance of the factory.
151: */
152: public abstract Service loadService(Class serviceInterface)
153: throws ServiceException;
154:
155: /**
156: * Creates an instance of the factory.
157: */
158: public abstract Service loadService(URL wsdlDocumentLocation,
159: Class serviceInterface, Properties properties)
160: throws ServiceException;
161:
162: /**
163: * Loads the service.
164: */
165: public abstract Service loadService(URL wsdlDocumentLocation,
166: QName serviceName, Properties properties)
167: throws ServiceException;
168: }
|