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: * Initial Developer : Delplanque Xavier & Sauthier Guillaume
022: * --------------------------------------------------------------------------
023: * $Id: JServiceFactoryFinder.java 4799 2004-05-25 14:26:36Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ws;
026:
027: import org.objectweb.jonas.common.JProp;
028:
029: /**
030: * Used to retrieve from jonas.properties the factory to
031: * use for Service creation (WebServices)
032: *
033: * @author Guillaume Sauthier
034: */
035: public class JServiceFactoryFinder {
036: /**
037: * JProp instance
038: */
039: private static JProp props = null;
040:
041: /**
042: * JOnAS ClassLoader
043: */
044: private static ClassLoader jonasCL = Thread.currentThread()
045: .getContextClassLoader();
046:
047: /**
048: * Property name
049: */
050: private static final String JONAS_SERVICE_FACTORY = "jonas.service.ws.factory.class";
051:
052: /**
053: * Private empty constructor for utility class
054: */
055: private JServiceFactoryFinder() {
056: }
057:
058: /**
059: * Factory class name
060: */
061: private static String factoryClassName = null;
062:
063: /**
064: * Return the JServiceFactory specified in jonas.properties
065: *
066: * @return the JServiceFactory specified in jonas.properties
067: *
068: * @throws WSServiceException When JServiceFactory instantiation fails
069: */
070: public static JServiceFactory getJOnASServiceFactory()
071: throws WSServiceException {
072: JServiceFactory factory = null;
073:
074: if (props == null) {
075: try {
076: props = JProp.getInstance();
077: factoryClassName = props
078: .getValue(JONAS_SERVICE_FACTORY);
079: } catch (Exception e) {
080: String err = "Error when trying to get jonas property '"
081: + JONAS_SERVICE_FACTORY + "'";
082: throw new WSServiceException(err, e);
083: }
084: }
085:
086: if (factoryClassName == null) {
087: String err = "jonas property '" + JONAS_SERVICE_FACTORY
088: + "' must be set!";
089: throw new WSServiceException(err);
090: }
091:
092: // instanciation
093: try {
094: factory = (JServiceFactory) jonasCL.loadClass(
095: factoryClassName).newInstance();
096: } catch (ClassNotFoundException cnfe) {
097: String err = "ClassNotFound '" + factoryClassName
098: + "' in JOnAS ClassLoader";
099: throw new WSServiceException(err);
100: } catch (InstantiationException ie) {
101: String err = "Instantiation error for new '"
102: + factoryClassName + "'";
103: throw new WSServiceException(err);
104: } catch (IllegalAccessException ie) {
105: String err = "Illegal Access for new '" + factoryClassName
106: + "'";
107: throw new WSServiceException(err);
108: }
109:
110: return factory;
111:
112: }
113: }
|