jon 01/06/17 18:01:52
Modified: src/java/org/apache/turbine/services/pull
TurbinePullService.java
Log:
fixed documentation
applied patch for having the factory service be used instead of
class.forname()
thanks to: <[EMAIL PROTECTED]>
Revision Changes Path
1.26 +80 -100
jakarta-turbine/src/java/org/apache/turbine/services/pull/TurbinePullService.java
Index: TurbinePullService.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/pull/TurbinePullService.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- TurbinePullService.java 2001/06/14 14:42:12 1.25
+++ TurbinePullService.java 2001/06/18 01:01:51 1.26
@@ -69,6 +69,7 @@
import org.apache.turbine.services.BaseService;
import org.apache.turbine.services.InitializationException;
import org.apache.turbine.services.TurbineServices;
+import org.apache.turbine.services.factory.FactoryService;
import org.apache.turbine.services.pool.PoolService;
import org.apache.turbine.services.pull.ApplicationTool;
@@ -90,7 +91,7 @@
* templates. You list the tools in the following way:
* </p>
* <pre>
- * tool.<scope>.<id> = <classname>
+ * services.PullService.tool.<scope>.<id> = <classname>
*
* <scope> is the tool scope: global, request, session
* or persistent (see below for more details)
@@ -105,10 +106,10 @@
*
* For example:
*
- * tool.global.ui = org.apache.turbine.util.pull.UIManager
- * tool.global.mm = org.apache.turbine.util.pull.MessageManager
- * tool.request.link = org.apache.turbine.util.template.TemplateLink
- * tool.request.page = org.apache.turbine.util.template.TemplatePageAttributes
+ * services.PullService.tool.global.ui = org.apache.turbine.util.pull.UIManager
+ * services.PullService.tool.global.mm =
org.apache.turbine.util.pull.MessageManager
+ * services.PullService.tool.request.link =
org.apache.turbine.util.template.TemplateLink
+ * services.PullService.tool.request.page =
org.apache.turbine.util.template.TemplatePageAttributes
*
* Then:
*
@@ -148,7 +149,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sean Legassick</a>
- * @version $Id: TurbinePullService.java,v 1.25 2001/06/14 14:42:12 jvanzyl Exp $
+ * @version $Id: TurbinePullService.java,v 1.26 2001/06/18 01:01:51 jon Exp $
*/
public class TurbinePullService
extends BaseService
@@ -173,14 +174,21 @@
{
String toolName;
String toolClassName;
- Class toolClass;
- public ToolData(String toolName, String toolClassName, Class toolClass)
+ public ToolData(String toolName, String toolClassName)
{
this.toolName = toolName;
this.toolClassName = toolClassName;
this.toolClass = toolClass;
}
+
+ /**
+ * @deprecated toolClass is no longer stored in ToolData
+ */
+ public ToolData(String toolName, String toolClassName, Class toolClass)
+ {
+ this(toolName, toolCassName);
+ }
}
/**
@@ -249,13 +257,61 @@
{
try
{
- /*
- * Make sure to setInit(true) *inside* initPull()
- * because Tools may make calls back to the TurbinePull
- * static methods which may cause a recursive init
- * thing to happen.
- */
- initPull();
+ /*
+ * Get the resources directory that is specificed
+ * in the TR.props or default to "/resources".
+ */
+ resourcesDirectory = getConfiguration().getString(
+ TOOL_RESOURCES_DIR,
+ TOOL_RESOURCES_DIR_DEFAULT);
+
+ /*
+ * Get absolute path to the resources directory.
+ *
+ * This should be done before the tools initialized
+ * because a tool might need to know this value
+ * for it to initialize correctly.
+ */
+ absolutePathToResourcesDirectory = getRealPath(resourcesDirectory);
+
+ /*
+ * Should we refresh the tool box on a per
+ * request basis.
+ */
+ refreshToolsPerRequest = getConfiguration()
+ .getBoolean(TOOLS_PER_REQUEST_REFRESH);
+
+ /*
+ * Log the fact that the application tool box will
+ * be refreshed on a per request basis.
+ */
+ if (refreshToolsPerRequest)
+ {
+ getCategory().info("Pull Model tools will "
+ + "be refreshed on a per request basis.");
+ }
+
+ /*
+ * Make sure to set init true because Tools may make
+ * calls back to the TurbinePull static methods which
+ * may cause a recursive init thing to happen.
+ */
+ setInit(true);
+
+ /*
+ * Grab each list of tools that are to be used (for global scope,
+ * request scope, session scope and persistent scope tools).
+ */
+ globalTools = getTools(GLOBAL_TOOL);
+ requestTools = getTools(REQUEST_TOOL);
+ sessionTools = getTools(SESSION_TOOL);
+ persistentTools = getTools(PERSISTENT_TOOL);
+
+ /*
+ * Create and populate the global context right now
+ */
+ globalContext = new VelocityContext();
+ populateWithGlobalTools(globalContext);
}
catch (Exception e)
{
@@ -265,81 +321,6 @@
}
/**
- * Initialize the pull system
- *
- * @exception Exception, a generic exception.
- */
- private void initPull() throws Exception
- {
- /*
- * Get the resources directory that is specificed
- * in the TR.props or default to "/resources".
- */
- resourcesDirectory = getConfiguration().getString(
- TOOL_RESOURCES_DIR,
- TOOL_RESOURCES_DIR_DEFAULT);
-
- /*
- * Get absolute path to the resources directory.
- *
- * This should be done before the tools initialized
- * because a tool might need to know this value
- * for it to initialize correctly.
- */
- absolutePathToResourcesDirectory = getRealPath(resourcesDirectory);
-
- /*
- * Should we refresh the tool box on a per
- * request basis.
- */
- refreshToolsPerRequest = getConfiguration()
- .getBoolean(TOOLS_PER_REQUEST_REFRESH);
-
- /*
- * Log the fact that the application tool box will
- * be refreshed on a per request basis.
- */
- if (refreshToolsPerRequest)
- {
- getCategory().info("Pull Model tools will "
- + "be refreshed on a per request basis.");
- }
-
- /*
- * Make sure to set init true because Tools may make
- * calls back to the TurbinePull static methods which
- * may cause a recursive init thing to happen.
- */
- setInit(true);
-
- /*
- * Grab each list of tools that are to be used (for global scope,
- * request scope, session scope and persistent scope tools).
- * They are specified respectively in the TR.props like this:
- *
- * tool.global.ui = org.apache.turbine.util.pull.UIManager
- * tool.global.mm = org.apache.turbine.util.pull.MessageManager
- *
- * tool.request.link = org.apache.turbine.util.template.TemplateLink;
- *
- * tool.session.basket = org.sample.util.ShoppingBasket;
- *
- * tool.persistent.ui =
org.apache.turbine.services.pull.util.PersistentUIManager
- */
-
- globalTools = getTools(GLOBAL_TOOL);
- requestTools = getTools(REQUEST_TOOL);
- sessionTools = getTools(SESSION_TOOL);
- persistentTools = getTools(PERSISTENT_TOOL);
-
- /*
- * Create and populate the global context right now
- */
- globalContext = new VelocityContext();
- populateWithGlobalTools(globalContext);
- }
-
- /**
* Retrieve the tool names and classes for the tools definied
* in the properties file with the prefix given.
*
@@ -369,17 +350,12 @@
try
{
- /*
- * Create an instance of the tool class.
- */
- Class toolClass = Class.forName(toolClassName);
-
/*
* Add the tool to the list being built.
*/
- classes.add(new ToolData(toolName, toolClassName, toolClass));
+ classes.add(new ToolData(toolName, toolClassName));
- getCategory().info("Instantiated tool class " + toolClassName
+ getCategory().info("Setup tool class " + toolClassName
+ " to add to the context as '$" + toolName + "'");
}
catch (Exception e)
@@ -434,13 +410,17 @@
*/
private void populateWithGlobalTools(Context context)
{
+ // Use the FactoryService to get instances for much more flexibility
+ FactoryService factoryService = (FactoryService)
+ TurbineServices.getInstance().getService(FactoryService.SERVICE_NAME);
+
Iterator it = globalTools.iterator();
while (it.hasNext())
{
ToolData toolData = (ToolData)it.next();
try
{
- Object tool = toolData.toolClass.newInstance();
+ Object tool = factoryService.getInstance(toolData.toolClassName);
if (tool instanceof ApplicationTool)
{
// global tools are init'd with a null data parameter
@@ -477,7 +457,7 @@
ToolData toolData = (ToolData)it.next();
try
{
- Object tool = pool.getInstance(toolData.toolClass);
+ Object tool = pool.getInstance(toolData.toolClassName);
if (tool instanceof ApplicationTool)
{
// request tools are init'd with a RunData object
@@ -532,7 +512,7 @@
{
// if not there, an instance must be fetched from
// the pool
- tool = pool.getInstance(toolData.toolClass);
+ tool = pool.getInstance(toolData.toolClassName);
if (tool instanceof ApplicationTool)
{
// session tools are init'd with the User object
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]