You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by le...@apache.org on 2001/12/05 20:25:43 UTC

cvs commit: jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule WorkerThread.java

leonardr    01/12/05 11:25:43

  Modified:    src/services/java/org/apache/fulcrum/factory
                        TurbineFactoryService.java
               src/services/java/org/apache/fulcrum/schedule
                        WorkerThread.java
  Log:
  TurbineFactoryService will now respect a 'default' Factory class used when there is no class-specific Factory. Also, for greater flexibility, WorkerThread uses TurbineFactoryService instead of directly instantiating objects.
  
  Revision  Changes    Path
  1.3       +18 -3     jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/factory/TurbineFactoryService.java
  
  Index: TurbineFactoryService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/factory/TurbineFactoryService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TurbineFactoryService.java	2001/08/10 11:46:23	1.2
  +++ TurbineFactoryService.java	2001/12/05 19:25:43	1.3
  @@ -73,7 +73,7 @@
    * will be used.
    *
    * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
  - * @version $Id: TurbineFactoryService.java,v 1.2 2001/08/10 11:46:23 knielsen Exp $
  + * @version $Id: TurbineFactoryService.java,v 1.3 2001/12/05 19:25:43 leonardr Exp $
    */
   public class TurbineFactoryService
       extends BaseService
  @@ -90,6 +90,11 @@
       public static final String OBJECT_FACTORY = "factory.";
   
       /**
  +     * The name of the default factory.
  +     */
  +    protected static final String DEFAULT_FACTORY = "default";
  +
  +    /**
        * Primitive classes for reflection of constructors.
        */
       private static HashMap primitiveClasses;
  @@ -166,6 +171,7 @@
               }
   
               String key,factory;
  +
               for (Iterator i = getConfiguration().getKeys(OBJECT_FACTORY); i.hasNext();)
               {
                   key = (String) i.next();
  @@ -579,10 +585,12 @@
       }
   
       /**
  -     * Gets a customized factory for a named class.
  +     * Gets a customized factory for a named class. If no class-specific
  +     * factory is specified but a default factory is, will use the default
  +     * factory.
        *
        * @param className the name of the class to load.
  -     * @return the factory or null if not specified.
  +     * @return the factory, or null if not specified and no default.
        * @throws ServiceException if instantiation of the factory fails.
        */
       protected Factory getFactory(String className)
  @@ -590,6 +598,13 @@
       {
           HashMap factories = objectFactories;
           Object factory = factories.get(className);
  +        if (factory == null)
  +        {
  +            //No named factory for this; try the default, if one
  +            //exists.
  +            factory = factories.get(DEFAULT_FACTORY);
  +        }
  +
           if (factory != null)
           {
               if (factory instanceof String)
  
  
  
  1.3       +9 -4      jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/WorkerThread.java
  
  Index: WorkerThread.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/schedule/WorkerThread.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WorkerThread.java	2001/08/10 11:46:24	1.2
  +++ WorkerThread.java	2001/12/05 19:25:43	1.3
  @@ -1,4 +1,6 @@
   package org.apache.fulcrum.schedule;
  +import org.apache.fulcrum.factory.FactoryService;
  +import org.apache.fulcrum.TurbineServices;
   
   /* ====================================================================
    * The Apache Software License, Version 1.1
  @@ -59,7 +61,7 @@
    *
    * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @version $Id: WorkerThread.java,v 1.2 2001/08/10 11:46:24 knielsen Exp $
  + * @version $Id: WorkerThread.java,v 1.3 2001/12/05 19:25:43 leonardr Exp $
    */
   public class WorkerThread
       implements Runnable
  @@ -104,9 +106,12 @@
                   // search through them like the module
                   // loader does. This right here requires the
                   // getTask() method to return a class name.
  -                ScheduledJob sc = (ScheduledJob) Class.forName(
  -                    je.getTask()).newInstance();
  -
  +                String className = je.getTask();
  +                FactoryService factoryService = (FactoryService)
  +                    TurbineServices.getInstance().getService
  +                    (FactoryService.SERVICE_NAME);
  +                ScheduledJob sc = (ScheduledJob)
  +                    factoryService.getInstance(className);
                   sc.execute(je);
               }
           }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>