KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ws > ClientJServiceFactoryFinder


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ClientJServiceFactoryFinder.java,v 1.1 2004/06/02 08:46:47 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.ws;
26
27 import java.io.InputStream JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 /**
31  * Used to retrieve from jonas-client.properties the factory to use for Service
32  * creation (WebServices)
33  * @author Guillaume Sauthier
34  */

35 public class ClientJServiceFactoryFinder {
36
37     /**
38      * jonas-client properties
39      */

40     private static Properties JavaDoc props;
41
42     /**
43      * Property name
44      */

45     private static final String JavaDoc JONAS_SERVICE_FACTORY = "jonas.service.ws.factory.class";
46
47     /**
48      * Private empty constructor for utility class
49      */

50     private ClientJServiceFactoryFinder() {
51     }
52
53     /**
54      * Factory class name
55      */

56     private static String JavaDoc factoryClassName = null;
57
58     /**
59      * Return the JServiceFactory specified in jonas.properties
60      * @return the JServiceFactory specified in jonas.properties
61      * @throws WSServiceException When JServiceFactory instantiation fails
62      */

63     public static JServiceFactory getJOnASServiceFactory() throws WSServiceException {
64         JServiceFactory factory = null;
65         ClassLoader JavaDoc current = Thread.currentThread().getContextClassLoader();
66
67         if (props == null) {
68             props = new Properties JavaDoc();
69             try {
70                 InputStream JavaDoc is = current.getResourceAsStream("jonas-client.properties");
71                 if (is != null) {
72                     props.load(is);
73                     factoryClassName = props.getProperty(JONAS_SERVICE_FACTORY);
74                 } else {
75                     System.err.println("Cannot load jonas-client.properties from ClassLoader");
76                 }
77             } catch (Exception JavaDoc e) {
78                 String JavaDoc err = "Error when trying to get jonas property '" + JONAS_SERVICE_FACTORY
79                         + "' from jonas-client.properties";
80                 throw new WSServiceException(err, e);
81             }
82         }
83
84         if (factoryClassName == null) {
85             String JavaDoc err = "jonas property '" + JONAS_SERVICE_FACTORY + "' must be set! in jonas-client.properties";
86             throw new WSServiceException(err);
87         }
88
89         // instanciation
90
try {
91             factory = (JServiceFactory) current.loadClass(factoryClassName).newInstance();
92         } catch (ClassNotFoundException JavaDoc cnfe) {
93             String JavaDoc err = "ClassNotFound '" + factoryClassName + "' in JOnAS ClassLoader";
94             throw new WSServiceException(err);
95         } catch (InstantiationException JavaDoc ie) {
96             String JavaDoc err = "Instantiation error for new '" + factoryClassName + "'";
97             throw new WSServiceException(err);
98         } catch (IllegalAccessException JavaDoc ie) {
99             String JavaDoc err = "Illegal Access for new '" + factoryClassName + "'";
100             throw new WSServiceException(err);
101         }
102
103         return factory;
104
105     }
106
107 }
Popular Tags