001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 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: GeneratorFactory.java 7609 2005-10-25 14:22:08Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.generator;
025:
026: import java.io.IOException;
027: import java.io.InputStream;
028: import java.util.Properties;
029:
030: import org.objectweb.jonas_lib.I18n;
031: import org.objectweb.jonas_lib.genbase.GenBaseException;
032: import org.objectweb.jonas_lib.genbase.archive.Archive;
033: import org.objectweb.jonas_lib.genbase.generator.Config;
034:
035: import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
036: import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
037: import org.objectweb.jonas_ws.wsgen.WsGenException;
038: import org.objectweb.jonas_ws.wsgen.ddmodifier.WebServicesDDModifier;
039: import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
040: import org.objectweb.jonas_ws.wsgen.ddmodifier.WsEndpointDDModifier;
041:
042: import org.objectweb.jonas.common.Log;
043:
044: import org.objectweb.util.monolog.api.BasicLevel;
045: import org.objectweb.util.monolog.api.Logger;
046:
047: /**
048: * a <code>GeneratorFactory</code> has to be extended by specific generation
049: * mecanism. It will look in <code>jonas.properties</code> file for a property
050: * named :<code>jonas.service.ws.wsgen.generator.factory</code> that is a
051: * classname extending <code>GeneratorFactory</code>. By default Axis
052: * GeneratorFactory is used.
053: *
054: * @author Guillaume Sauthier
055: */
056: public abstract class GeneratorFactory implements
057: org.objectweb.jonas_lib.genbase.generator.GeneratorFactory {
058:
059: /**
060: * Generator Factory property name in jonas.properties
061: */
062: public static final String GENERATOR_FACTORY = "jonas.service.ws.wsgen.generator.factory";
063:
064: /**
065: * Default GeneratorFactory impl to use
066: */
067: public static final String GENERATOR_FACTORY_DEFAULT = "org.objectweb.jonas_ws.wsgen.generator.ews.EWSGeneratorFactory";
068:
069: /** <code>GeneratorFactory</code> unique instance */
070: private static GeneratorFactory instance = null;
071:
072: /** i18n */
073: private static I18n i18n = I18n.getInstance(GeneratorFactory.class);
074:
075: /** logger */
076: private static Logger logger = Log
077: .getLogger(Log.JONAS_WSGEN_PREFIX);
078:
079: /** Configuration to set on instanciated Generator */
080: private Config configuration;
081:
082: /**
083: * Returns the unique GeneratorFactory instance.
084: *
085: * @return the unique GeneratorFactory instance.
086: *
087: * @throws WsGenException When instanciation fails
088: */
089: public static GeneratorFactory getInstance() throws WsGenException {
090: if (instance == null) {
091: instance = newInstance();
092: }
093:
094: return instance;
095: }
096:
097: /**
098: * Create a new generatorFactory instance by looking up in
099: * <code>jonas.properties</code> and load class specified with
100: * <code>jonas.service.ws.wsgen.generator-factory</code> property. If not
101: * set, Axis GeneratorFactory is the default Factory returned.
102: *
103: * @return a new generatorFactory instance.
104: *
105: * @throws WsGenException when Exception occurs when dynamiccaly
106: * instantiating GeneratorFactory subclass
107: */
108: private static GeneratorFactory newInstance() throws WsGenException {
109:
110: String classname = null;
111:
112: ClassLoader cl = Thread.currentThread().getContextClassLoader();
113: InputStream is = cl.getResourceAsStream("jonas.properties");
114:
115: if (is == null) {
116: // Should be on the client side
117: // use default value
118: classname = GENERATOR_FACTORY_DEFAULT;
119: } else {
120: Properties jprop = new Properties();
121: try {
122: jprop.load(is);
123: classname = jprop.getProperty(GENERATOR_FACTORY,
124: GENERATOR_FACTORY_DEFAULT);
125: } catch (IOException e) {
126: // cannot read properties, use default value
127: logger.log(BasicLevel.WARN, "Cannot get '"
128: + GENERATOR_FACTORY
129: + "' value, default used : '"
130: + GENERATOR_FACTORY_DEFAULT + "'");
131: classname = GENERATOR_FACTORY_DEFAULT;
132: } finally {
133: try {
134: is.close();
135: } catch (IOException e) {
136: // use default if it was not set
137: if (classname == null) {
138: classname = GENERATOR_FACTORY_DEFAULT;
139: }
140: }
141: }
142: }
143:
144: // instanciate
145: GeneratorFactory gf = null;
146:
147: try {
148: Class gfc = cl.loadClass(classname);
149: gf = (GeneratorFactory) gfc.newInstance();
150: } catch (Exception e) {
151: String err = i18n.getMessage(
152: "GeneratorFactory.newInstance.instance", classname);
153: throw new WsGenException(err, e);
154: }
155:
156: return gf;
157:
158: }
159:
160: /**
161: * Return a new WsClientGenerator for the specific generation mecanism.
162: *
163: * @param serviceRef the service-ref containing information for client side
164: * generation process.
165: * @param ddm the XML modifier.
166: * @param archive the Archive to be modified
167: *
168: * @return a new WsClientGenerator.
169: *
170: * @throws GenBaseException When Factory cannot instanciate WsClientGenerator
171: */
172: public abstract WsClientGenerator newGenerator(
173: ServiceRefDesc serviceRef, WsClientDDModifier ddm,
174: Archive archive) throws GenBaseException;
175:
176: /**
177: * Return a new WsEndpointGenerator for the specific generation mecanism.
178: *
179: * @param serviceDesc the webservice-description containing information for
180: * server side generation process.
181: * @param ddm the XML modifier.
182: * @param wsddm the Webservices.xml DD modifier
183: * @param arch The archive to modify
184: *
185: * @return a new WsEndpointGenerator.
186: *
187: * @throws GenBaseException When Factory cannot instanciate WsEndpointGenerator
188: */
189: public abstract WsEndpointGenerator newGenerator(
190: ServiceDesc serviceDesc, WsEndpointDDModifier ddm,
191: WebServicesDDModifier wsddm, Archive arch)
192: throws GenBaseException;
193:
194: /**
195: * Set the Configuration to use with newly created Generator.
196: *
197: * @param config the Configuration to use with newly created Generator.
198: */
199: public void setConfiguration(Config config) {
200: this .configuration = config;
201: }
202:
203: /**
204: * Get the Configuration to use with newly created Generator.
205: *
206: * @return the Configuration to use with newly created Generator
207: */
208: public Config getConfiguration() {
209: return configuration;
210: }
211: }
|