001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ClientJServiceFactoryFinder.java 4882 2004-06-02 08:46:48Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.ws;
025:
026: import java.io.InputStream;
027: import java.util.Properties;
028:
029: /**
030: * Used to retrieve from jonas-client.properties the factory to use for Service
031: * creation (WebServices)
032: * @author Guillaume Sauthier
033: */
034: public class ClientJServiceFactoryFinder {
035:
036: /**
037: * jonas-client properties
038: */
039: private static Properties props;
040:
041: /**
042: * Property name
043: */
044: private static final String JONAS_SERVICE_FACTORY = "jonas.service.ws.factory.class";
045:
046: /**
047: * Private empty constructor for utility class
048: */
049: private ClientJServiceFactoryFinder() {
050: }
051:
052: /**
053: * Factory class name
054: */
055: private static String factoryClassName = null;
056:
057: /**
058: * Return the JServiceFactory specified in jonas.properties
059: * @return the JServiceFactory specified in jonas.properties
060: * @throws WSServiceException When JServiceFactory instantiation fails
061: */
062: public static JServiceFactory getJOnASServiceFactory()
063: throws WSServiceException {
064: JServiceFactory factory = null;
065: ClassLoader current = Thread.currentThread()
066: .getContextClassLoader();
067:
068: if (props == null) {
069: props = new Properties();
070: try {
071: InputStream is = current
072: .getResourceAsStream("jonas-client.properties");
073: if (is != null) {
074: props.load(is);
075: factoryClassName = props
076: .getProperty(JONAS_SERVICE_FACTORY);
077: } else {
078: System.err
079: .println("Cannot load jonas-client.properties from ClassLoader");
080: }
081: } catch (Exception e) {
082: String err = "Error when trying to get jonas property '"
083: + JONAS_SERVICE_FACTORY
084: + "' from jonas-client.properties";
085: throw new WSServiceException(err, e);
086: }
087: }
088:
089: if (factoryClassName == null) {
090: String err = "jonas property '" + JONAS_SERVICE_FACTORY
091: + "' must be set! in jonas-client.properties";
092: throw new WSServiceException(err);
093: }
094:
095: // instanciation
096: try {
097: factory = (JServiceFactory) current.loadClass(
098: factoryClassName).newInstance();
099: } catch (ClassNotFoundException cnfe) {
100: String err = "ClassNotFound '" + factoryClassName
101: + "' in JOnAS ClassLoader";
102: throw new WSServiceException(err);
103: } catch (InstantiationException ie) {
104: String err = "Instantiation error for new '"
105: + factoryClassName + "'";
106: throw new WSServiceException(err);
107: } catch (IllegalAccessException ie) {
108: String err = "Illegal Access for new '" + factoryClassName
109: + "'";
110: throw new WSServiceException(err);
111: }
112:
113: return factory;
114:
115: }
116:
117: }
|