Here's the patch.  It should be noted that there is a minor repercussion
here in that a badly configured classname is not discovered until the
actual instantiation of the global instance.  I also removed the Class
object from the ToolData class, so the session and request components must
instantiate the class by name.  I don't believe this will pose a
performance issue.

***
//c/turbine/jakarta-turbine/src/java/org/apache/turbine/services/pull/TurbinePullService.java

Thu Jun  7 21:27:46 2001
---
//c/sandbox/turbine/src/java/org/apache/turbine/services/pull/TurbinePullService.java

Thu Jun 14 18:58:57 2001
***************
*** 77,82 ****
--- 77,83 ----
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.ServletUtils;
+ import org.apache.turbine.services.factory.FactoryService;

  /**
   * <p>
***************
*** 147,153 ****
   *
   * @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.24 2001/06/08 01:27:46 jon
Exp $
   */
  public class TurbinePullService extends TurbineBaseService
      implements PullService
--- 148,154 ----
   *
   * @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.3 2001/06/14 22:58:57
cfelaco Exp $
   */
  public class TurbinePullService extends TurbineBaseService
      implements PullService
***************
*** 171,183 ****
      {
          String toolName;
          String toolClassName;
-         Class  toolClass;

!         public ToolData(String toolName, String toolClassName, Class
toolClass)
          {
              this.toolName      = toolName;
              this.toolClassName = toolClassName;
-             this.toolClass     = toolClass;
          }
      }

--- 172,182 ----
      {
          String toolName;
          String toolClassName;

!         public ToolData(String toolName, String toolClassName)
          {
              this.toolName      = toolName;
              this.toolClassName = toolClassName;
          }
      }

***************
*** 369,384 ****
              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));

!                 Log.info("Instantiated tool class " + toolClassName
                          + " to add to the context as '$"  + toolName +
"'");
              }
              catch (Exception e)
--- 368,378 ----
              try
              {
                  /*
                   * Add the tool to the list being built.
                   */
!                 classes.add(new ToolData(toolName, toolClassName));

!                 Log.info("Setup tool class " + toolClassName
                          + " to add to the context as '$"  + toolName +
"'");
              }
              catch (Exception e)
***************
*** 433,445 ****
       */
      private void populateWithGlobalTools(Context context)
      {
          Iterator it = globalTools.iterator();
          while (it.hasNext())
          {
              ToolData toolData = (ToolData)it.next();
              try
              {
!                 Object tool = toolData.toolClass.newInstance();
                  if (tool instanceof ApplicationTool)
                  {
                      // global tools are init'd with a null data parameter
--- 427,443 ----
       */
      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 =
factoryService.getInstance(toolData.toolClassName);
                  if (tool instanceof ApplicationTool)
                  {
                      // global tools are init'd with a null data parameter
***************
*** 476,482 ****
              ToolData toolData = (ToolData)it.next();
              try
              {
!                 Object tool = pool.getInstance(toolData.toolClass);
                  if (tool instanceof ApplicationTool)
                  {
                      // request tools are init'd with a RunData object
--- 474,480 ----
              ToolData toolData = (ToolData)it.next();
              try
              {
!                 Object tool = pool.getInstance(toolData.toolClassName);
                  if (tool instanceof ApplicationTool)
                  {
                      // request tools are init'd with a RunData object
***************
*** 531,537 ****
                      {
                          // if not there, an instance must be fetched from
                          // the pool
!                         tool = pool.getInstance(toolData.toolClass);
                          if (tool instanceof ApplicationTool)
                          {
                              // session tools are init'd with the User
object
--- 529,535 ----
                      {
                          // if not there, an instance must be fetched from
                          // the pool
!                         tool = pool.getInstance(toolData.toolClassName);
                          if (tool instanceof ApplicationTool)
                          {
                              // session tools are init'd with the User
object

Chris Felaco
Sr. Software Developer
Blue Dolphin Group
(508) 358-6758



                                                                                       
                    
                    Jon Stevens                                                        
                    
                    <jon@latchkey        To:     turbine-dev 
<[EMAIL PROTECTED]>              
                    .com>                cc:                                           
                    
                                         Subject:     Re: Should the 
TurbinePullService use the            
                    06/15/2001           FactoryService to      construct global 
services?                 
                    02:03 PM                                                           
                    
                    Please                                                             
                    
                    respond to                                                         
                    
                    turbine-dev                                                        
                    
                                                                                       
                    
                                                                                       
                    




on 6/15/01 10:48 AM, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:

> I had a specific need in my application to setup a global tool using pull
> that needed to be constructed using the FactoryService.  I was surprised
to
> learn that the PullService was simply using class.forName
(...).newInstance
> ().  So I changed it to use the FactoryService.  It works fine for me.
> Unless there's some reason why this is not appropriate, I'll submit the
> patch.  I'd like to know either way, if there's something I'm missing
here.

Nope. You got it right. +1

Submit a patch.

-jon

--
"Open source is not available to commercial companies."
            -Steve Ballmer, CEO Microsoft
<http://www.suntimes.com/output/tech/cst-fin-micro01.html>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to