KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > generator > GeneratorFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2004 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: GeneratorFactory.java,v 1.8 2005/01/21 13:35:50 pelletib Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ws.wsgen.generator;
27
28 import org.objectweb.jonas_lib.I18n;
29 import org.objectweb.jonas_lib.genbase.GenBaseException;
30 import org.objectweb.jonas_lib.genbase.archive.Archive;
31 import org.objectweb.jonas_lib.genbase.generator.Config;
32
33 import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
34 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
35 import org.objectweb.jonas_ws.wsgen.WsGenException;
36 import org.objectweb.jonas_ws.wsgen.ddmodifier.WebServicesDDModifier;
37 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
38 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsEndpointDDModifier;
39
40 import org.objectweb.jonas.common.JProp;
41 import org.objectweb.jonas.common.Log;
42
43 import org.objectweb.util.monolog.api.BasicLevel;
44 import org.objectweb.util.monolog.api.Logger;
45
46 /**
47  * a <code>GeneratorFactory</code> has to be extended by specific generation
48  * mecanism. It will look in <code>jonas.properties</code> file for a property
49  * named :<code>jonas.service.ws.wsgen.generator.factory</code> that is a
50  * classname extending <code>GeneratorFactory</code>. By default Axis
51  * GeneratorFactory is used.
52  *
53  * @author Guillaume Sauthier
54  */

55 public abstract class GeneratorFactory implements org.objectweb.jonas_lib.genbase.generator.GeneratorFactory {
56
57     /**
58      * Generator Factory property name in jonas.properties
59      */

60     public static final String JavaDoc GENERATOR_FACTORY = "jonas.service.ws.wsgen.generator.factory";
61
62     /**
63      * Default GeneratorFactory impl to use
64      */

65     public static final String JavaDoc GENERATOR_FACTORY_DEFAULT = "org.objectweb.jonas_ws.wsgen.generator.axis.AxisGeneratorFactory";
66
67     /** <code>GeneratorFactory</code> unique instance */
68     private static GeneratorFactory instance = null;
69
70     /** i18n */
71     private static I18n i18n = I18n.getInstance(GeneratorFactory.class);
72
73     /** logger */
74     private static Logger logger = Log.getLogger(Log.JONAS_WSGEN_PREFIX);
75
76     /** Configuration to set on instanciated Generator */
77     private Config configuration;
78
79     /**
80      * Returns the unique GeneratorFactory instance.
81      *
82      * @return the unique GeneratorFactory instance.
83      *
84      * @throws WsGenException When instanciation fails
85      */

86     public static GeneratorFactory getInstance() throws WsGenException {
87         if (instance == null) {
88             instance = newInstance();
89         }
90
91         return instance;
92     }
93
94     /**
95      * Create a new generatorFactory instance by looking up in
96      * <code>jonas.properties</code> and load class specified with
97      * <code>jonas.service.ws.wsgen.generator-factory</code> property. If not
98      * set, Axis GeneratorFactory is the default Factory returned.
99      *
100      * @return a new generatorFactory instance.
101      *
102      * @throws WsGenException when Exception occurs when dynamiccaly
103      * instantiating GeneratorFactory subclass
104      */

105     private static GeneratorFactory newInstance() throws WsGenException {
106         // Lookup property
107
JProp jp;
108         String JavaDoc classname = null;
109
110         try {
111             jp = JProp.getInstance();
112             classname = jp.getValue(GENERATOR_FACTORY, GENERATOR_FACTORY_DEFAULT);
113         } catch (Exception JavaDoc e) {
114             // do nothing, just log a warning a continue with default values...
115
logger.log(BasicLevel.WARN, "Cannot get '" + GENERATOR_FACTORY + "' value, default used : '"
116                     + GENERATOR_FACTORY_DEFAULT + "'");
117             classname = GENERATOR_FACTORY_DEFAULT;
118         }
119
120         // instanciate
121
GeneratorFactory gf = null;
122
123         try {
124             ClassLoader JavaDoc jcl = Thread.currentThread().getContextClassLoader();
125             Class JavaDoc gfc = jcl.loadClass(classname);
126             gf = (GeneratorFactory) gfc.newInstance();
127         } catch (Exception JavaDoc e) {
128             String JavaDoc err = i18n.getMessage("GeneratorFactory.newInstance.instance", classname);
129             throw new WsGenException(err, e);
130         }
131
132         return gf;
133
134     }
135
136     /**
137      * Return a new WsClientGenerator for the specific generation mecanism.
138      *
139      * @param serviceRef the service-ref containing information for client side
140      * generation process.
141      * @param ddm the XML modifier.
142      * @param archive the Archive to be modified
143      *
144      * @return a new WsClientGenerator.
145      *
146      * @throws GenBaseException When Factory cannot instanciate WsClientGenerator
147      */

148     public abstract WsClientGenerator newGenerator(ServiceRefDesc serviceRef, WsClientDDModifier ddm, Archive archive)
149             throws GenBaseException;
150
151     /**
152      * Return a new WsEndpointGenerator for the specific generation mecanism.
153      *
154      * @param serviceDesc the webservice-description containing information for
155      * server side generation process.
156      * @param ddm the XML modifier.
157      * @param wsddm the Webservices.xml DD modifier
158      *
159      * @return a new WsEndpointGenerator.
160      *
161      * @throws GenBaseException When Factory cannot instanciate WsEndpointGenerator
162      */

163     public abstract WsEndpointGenerator newGenerator(ServiceDesc serviceDesc, WsEndpointDDModifier ddm,
164             WebServicesDDModifier wsddm, Archive arch) throws GenBaseException;
165
166     /**
167      * Set the Configuration to use with newly created Generator.
168      *
169      * @param config the Configuration to use with newly created Generator.
170      */

171     public void setConfiguration(Config config) {
172         this.configuration = config;
173     }
174
175     /**
176      * Get the Configuration to use with newly created Generator.
177      *
178      * @return the Configuration to use with newly created Generator
179      */

180     public Config getConfiguration() {
181         return configuration;
182     }
183 }
Popular Tags