ilkka 01/07/16 05:12:53
Modified: src/java/org/apache/turbine Turbine.java
Log:
Changed initialization methods to static ones to support non-servlet environments
(fields and getters were already static).
Revision Changes Path
1.73 +139 -122 jakarta-turbine/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- Turbine.java 2001/07/15 18:25:12 1.72
+++ Turbine.java 2001/07/16 12:12:53 1.73
@@ -112,7 +112,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: Turbine.java,v 1.72 2001/07/15 18:25:12 mpoeschl Exp $
+ * @version $Id: Turbine.java,v 1.73 2001/07/16 12:12:53 ilkka Exp $
*/
public class Turbine
extends HttpServlet
@@ -177,126 +177,8 @@
try
{
- // Set the applicationRoot for this webapp.
- setApplicationRoot(getServletContext().getRealPath("/"));
-
- // This is for our log4j setup. We are embedding
- // the log4j configuration in the TRP but log4j
- // must be initialized with a Properties object.
- // We load it here so that we can add a "webapp"
- // property that will be used in the form of
- // ${webapp} in log4j properties. We need this
- // so that the log files can be placed in
- // the webapp space.
- Properties p = new Properties();
-
- p.load(new FileInputStream(
- getApplicationRoot() + DEFAULT_TURBINE_RESOURCES));
-
- p.setProperty("webapp", getApplicationRoot());
-
- // We are still using our Log facade but we
- // should move toward using log4j correctly.
- Log.setProperties(p);
- Log.init();
-
- // We want to save the ServletConfig and
- // ServletContext so that we can share these objects
- // with parts of Turbine that may need access and
- // have no direct contact with RunData. Right now
- // the ServletService is providing this information,
- // but that service could disappear and client code
- // could use the methods now provided in the Turbine
- // class.
- setTurbineServletConfig(getServletConfig());
- setTurbineServletContext(getServletContext());
-
- // Get the instance of the service manager
- ServiceManager serviceManager = TurbineServices.getManager();
-
- // Set the service managers application root. In our
- // case it is the webapp context.
- serviceManager.setApplicationRoot(getApplicationRoot());
-
- // This should eventually be a Configuration
- // interface so that service and app configuration
- // can be stored anywhere.
- configuration = new Configuration(
- getApplicationRoot() + DEFAULT_TURBINE_RESOURCES);
-
- serviceManager.setConfiguration(configuration);
-
- // We are using the 'default' category for logging
- // when a category isn't specified. The 'default'
- // category must be setup in the TRP.
- serviceManager.setCategory(Category.getInstance("default"));
-
- // The TurbineResourceService needs to access the
- // whole configuration file because it really has
- // no configuration of its own.
- serviceManager.setServiceObject("configuration", configuration);
-
- // Initialize the service manager. Services
- // that have its 'earlyInit' property set to
- // a value of 'true' will be started when
- // the service manager is initialized.
- serviceManager.init();
-
- // Set up the module loader for Turbine. Eventually
- // an instance of ModuleLoader will be used for each
- // application running under Turbine but we are trying,
- // for the time being to work in a BC fashion.
- moduleLoader = new ModuleLoader();
-
- Configuration moduleTypes = configuration.subset("module.default");
- if (moduleTypes == null)
- {
- throw new TurbineException
- ("module.default subset is missing from TR.props");
- }
-
- Iterator j = moduleTypes.getKeys();
-
- // Make container for default modules
- defaultModules = new Hashtable();
-
- while (j.hasNext())
- {
- String moduleType = (String) j.next();
- String defaultModule = moduleTypes.getString(moduleType);
-
- Log.debug("Adding module type " + moduleType +
- " with a default of " + defaultModule);
-
- moduleLoader.addModuleType(moduleType);
-
- // Add the default module for the particular
- // module type to our container for module defaults.
- defaultModules.put(moduleType, defaultModule);
- }
-
- // Add the default set of modules which live within
- // the org.apache.turbine.module namespace.
- moduleLoader.addModulePackage(DEFAULT_MODULE_PACKAGE);
-
- // Grab our list of module packages so that we can
- // add them to the search list of the ModuleLoader.
- Vector modulePackages = configuration.getVector(MODULE_PACKAGES);
-
- Iterator i = modulePackages.iterator();
-
- while (i.hasNext())
- {
- moduleLoader.addModulePackage((String) i.next());
- }
-
- // Setup the default pipeline. There will be a pipeline
- // per (sub)app, just like there will be a module loader
- // per app, but we'll set a standard one up here for
- // now.
- pipeline = (Pipeline) Class.forName(configuration.getString(
-
"pipeline.default","org.apache.turbine.pipeline.ClassicPipeline"))
- .newInstance();
+ // call the static configuration method.
+ configure(config,getServletContext());
}
catch ( Exception e )
{
@@ -774,6 +656,141 @@
private static Pipeline pipeline;
/**
+ * A static configuration method that is called by the Turbine servlet
+ * or by non-servlet applications for configuring Turbine. It loads
+ * the default resources from a properties file.
+ *
+ * @param config typical Servlet initialization parameter.
+ * @param context typical Servlet initialization parameter.
+ * @exception Exception a generic exception.
+ */
+ public static synchronized void configure(ServletConfig config,
+ ServletContext context)
+ throws Exception
+ {
+ // Set the applicationRoot for this webapp.
+ setApplicationRoot(context.getRealPath("/"));
+
+ // This is for our log4j setup. We are embedding
+ // the log4j configuration in the TRP but log4j
+ // must be initialized with a Properties object.
+ // We load it here so that we can add a "webapp"
+ // property that will be used in the form of
+ // ${webapp} in log4j properties. We need this
+ // so that the log files can be placed in
+ // the webapp space.
+ Properties p = new Properties();
+
+ p.load(new FileInputStream(
+ getApplicationRoot() + DEFAULT_TURBINE_RESOURCES));
+
+ p.setProperty("webapp", getApplicationRoot());
+
+ // We are still using our Log facade but we
+ // should move toward using log4j correctly.
+ Log.setProperties(p);
+ Log.init();
+
+ // We want to save the ServletConfig and
+ // ServletContext so that we can share these objects
+ // with parts of Turbine that may need access and
+ // have no direct contact with RunData. Right now
+ // the ServletService is providing this information,
+ // but that service could disappear and client code
+ // could use the methods now provided in the Turbine
+ // class.
+ setTurbineServletConfig(config);
+ setTurbineServletContext(context);
+
+ // Get the instance of the service manager
+ ServiceManager serviceManager = TurbineServices.getManager();
+
+ // Set the service managers application root. In our
+ // case it is the webapp context.
+ serviceManager.setApplicationRoot(getApplicationRoot());
+
+ // This should eventually be a Configuration
+ // interface so that service and app configuration
+ // can be stored anywhere.
+ configuration = new Configuration(
+ getApplicationRoot() + DEFAULT_TURBINE_RESOURCES);
+
+ serviceManager.setConfiguration(configuration);
+
+ // We are using the 'default' category for logging
+ // when a category isn't specified. The 'default'
+ // category must be setup in the TRP.
+ serviceManager.setCategory(Category.getInstance("default"));
+
+ // The TurbineResourceService needs to access the
+ // whole configuration file because it really has
+ // no configuration of its own.
+ serviceManager.setServiceObject("configuration", configuration);
+
+ // Initialize the service manager. Services
+ // that have its 'earlyInit' property set to
+ // a value of 'true' will be started when
+ // the service manager is initialized.
+ serviceManager.init();
+
+ // Set up the module loader for Turbine. Eventually
+ // an instance of ModuleLoader will be used for each
+ // application running under Turbine but we are trying,
+ // for the time being to work in a BC fashion.
+ moduleLoader = new ModuleLoader();
+
+ Configuration moduleTypes = configuration.subset("module.default");
+ if (moduleTypes == null)
+ {
+ throw new TurbineException
+ ("module.default subset is missing from TR.props");
+ }
+
+ Iterator j = moduleTypes.getKeys();
+
+ // Make container for default modules
+ defaultModules = new Hashtable();
+
+ while (j.hasNext())
+ {
+ String moduleType = (String) j.next();
+ String defaultModule = moduleTypes.getString(moduleType);
+
+ Log.debug("Adding module type " + moduleType +
+ " with a default of " + defaultModule);
+
+ moduleLoader.addModuleType(moduleType);
+
+ // Add the default module for the particular
+ // module type to our container for module defaults.
+ defaultModules.put(moduleType, defaultModule);
+ }
+
+ // Add the default set of modules which live within
+ // the org.apache.turbine.module namespace.
+ moduleLoader.addModulePackage(DEFAULT_MODULE_PACKAGE);
+
+ // Grab our list of module packages so that we can
+ // add them to the search list of the ModuleLoader.
+ Vector modulePackages = configuration.getVector(MODULE_PACKAGES);
+
+ Iterator i = modulePackages.iterator();
+
+ while (i.hasNext())
+ {
+ moduleLoader.addModulePackage((String) i.next());
+ }
+
+ // Setup the default pipeline. There will be a pipeline
+ // per (sub)app, just like there will be a module loader
+ // per app, but we'll set a standard one up here for
+ // now.
+ pipeline = (Pipeline) Class.forName(configuration.getString(
+ "pipeline.default","org.apache.turbine.pipeline.ClassicPipeline"))
+ .newInstance();
+ }
+
+ /**
* Get the ModuleLoader for this Turbine webapp.
* Eventually we will want to be able to grab a ModuleLoader
* by app name, or app identifier.
@@ -792,7 +809,7 @@
*
* @param RunData
*/
- public void saveServletInfo(RunData data)
+ public static synchronized void saveServletInfo(RunData data)
{
serverName = data.getRequest().getServerName();
serverPort = new Integer(data.getRequest().getServerPort()).toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]