KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Initial Developer : Delplanque Xavier & Sauthier Guillaume
22  * --------------------------------------------------------------------------
23  * $Id: JServiceFactoryFinder.java,v 1.2 2004/05/25 14:26:33 sauthieg Exp $
24  * --------------------------------------------------------------------------
25 */

26
27 package org.objectweb.jonas.ws;
28
29 import org.objectweb.jonas.common.JProp;
30
31 /**
32  * Used to retrieve from jonas.properties the factory to
33  * use for Service creation (WebServices)
34  *
35  * @author Guillaume Sauthier
36  */

37 public class JServiceFactoryFinder {
38     /**
39      * JProp instance
40      */

41     private static JProp props = null;
42
43     /**
44      * JOnAS ClassLoader
45      */

46     private static ClassLoader JavaDoc jonasCL =
47         Thread.currentThread().getContextClassLoader();
48
49     /**
50      * Property name
51      */

52     private static final String JavaDoc JONAS_SERVICE_FACTORY =
53         "jonas.service.ws.factory.class";
54
55     /**
56      * Private empty constructor for utility class
57      */

58     private JServiceFactoryFinder() { }
59
60     /**
61      * Factory class name
62      */

63     private static String JavaDoc factoryClassName = null;
64
65     /**
66      * Return the JServiceFactory specified in jonas.properties
67      *
68      * @return the JServiceFactory specified in jonas.properties
69      *
70      * @throws WSServiceException When JServiceFactory instantiation fails
71      */

72     public static JServiceFactory getJOnASServiceFactory()
73         throws WSServiceException {
74         JServiceFactory factory = null;
75
76         if (props == null) {
77             try {
78                 props = JProp.getInstance();
79                 factoryClassName = props.getValue(JONAS_SERVICE_FACTORY);
80             } catch (Exception JavaDoc e) {
81                 String JavaDoc err =
82                     "Error when trying to get jonas property '"
83                     + JONAS_SERVICE_FACTORY + "'";
84                 throw new WSServiceException(err, e);
85             }
86         }
87
88         if (factoryClassName == null) {
89             String JavaDoc err =
90                 "jonas property '" + JONAS_SERVICE_FACTORY + "' must be set!";
91             throw new WSServiceException(err);
92         }
93
94         // instanciation
95
try {
96             factory =
97                 (JServiceFactory) jonasCL.loadClass(factoryClassName)
98                                          .newInstance();
99         } catch (ClassNotFoundException JavaDoc cnfe) {
100             String JavaDoc err =
101                 "ClassNotFound '" + factoryClassName + "' in JOnAS ClassLoader";
102             throw new WSServiceException(err);
103         } catch (InstantiationException JavaDoc ie) {
104             String JavaDoc err =
105                 "Instantiation error for new '" + factoryClassName + "'";
106             throw new WSServiceException(err);
107         } catch (IllegalAccessException JavaDoc ie) {
108             String JavaDoc err = "Illegal Access for new '" + factoryClassName + "'";
109             throw new WSServiceException(err);
110         }
111
112         return factory;
113
114     }
115 }
116
Popular Tags