ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace DefaultTaskContext.java
Date Thu, 23 May 2002 06:48:49 GMT
donaldp     02/05/22 23:48:49

  Modified:    container/src/java/org/apache/myrmidon/components/workspace
                        DefaultTaskContext.java
  Log:
  Internal touchups
  
  Revision  Changes    Path
  1.47      +61 -47    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
  
  Index: DefaultTaskContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- DefaultTaskContext.java	23 May 2002 04:32:37 -0000	1.46
  +++ DefaultTaskContext.java	23 May 2002 06:48:49 -0000	1.47
  @@ -28,7 +28,7 @@
    * Default implementation of TaskContext.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.46 $ $Date: 2002/05/23 04:32:37 $
  + * @version $Revision: 1.47 $ $Date: 2002/05/23 06:48:49 $
    */
   public class DefaultTaskContext
       implements TaskContext
  @@ -106,57 +106,55 @@
        * task is determined by the container. The returned service
        * <b>MUST</b> implement the specified interface.
        *
  -     * @param serviceClass the interface class that defines the service
  +     * @param clazz the interface class that defines the service
        * @return an instance of the service implementing interface specified by parameter
        * @throws TaskException is thrown when the service is unavailable or not supported
        */
  -    public Object getService( final Class serviceClass )
  +    public Object getService( final Class clazz )
           throws TaskException
       {
           //TODO: Should not occur but done for the time being to simplify evolution.
  -        if( serviceClass == ExecutionFrame.class )
  +        if( clazz == ExecutionFrame.class )
           {
               return m_frame;
           }
   
  -        final String serviceClassName = serviceClass.getName();
  +        final String classname = clazz.getName();
           final ServiceManager serviceManager = m_frame.getServiceManager();
  -
  -        if( serviceManager != null )
  +        try
           {
  -            try
  +            // Map the service class to the role name for that service
  +            final RoleManager roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE
);
  +            final RoleInfo roleInfo = roleManager.getRoleByImplementationClass( clazz );
  +
  +            // If the role is not found, use the classname
  +            final String roleName;
  +            if( roleInfo != null )
               {
  -                // Map the service class to the role name for that service
  -                final RoleManager roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE
);
  -                final RoleInfo roleInfo = roleManager.getRoleByImplementationClass( serviceClass
);
  -
  -                // If the role is not found, use the classname
  -                final String roleName;
  -                if( roleInfo != null )
  -                {
  -                    roleName = roleInfo.getName();
  -                }
  -                else
  -                {
  -                    roleName = serviceClassName;
  -                }
  -
  -                // Lookup the service by role name.  Note that this will chain
  -                // up to parent ServiceManagers (if any)
  -                if( serviceManager.hasService( roleName ) )
  -                {
  -                    return serviceManager.lookup( roleName );
  -                }
  +                roleName = roleInfo.getName();
               }
  -            catch( final ServiceException e )
  +            else
  +            {
  +                roleName = classname;
  +            }
  +
  +            // Lookup the service by role name.  Note that this will chain
  +            // up to parent ServiceManagers (if any)
  +            if( serviceManager.hasService( roleName ) )
               {
  -                final String message = REZ.getString( "bad-find-service.error", serviceClassName
);
  -                throw new TaskException( message, e );
  +                return serviceManager.lookup( roleName );
               }
           }
  +        catch( final ServiceException e )
  +        {
  +            final String message =
  +                REZ.getString( "bad-find-service.error", classname );
  +            throw new TaskException( message, e );
  +        }
   
           // Not found
  -        final String message = REZ.getString( "bad-find-service.error", serviceClassName
);
  +        final String message =
  +            REZ.getString( "bad-find-service.error", classname );
           throw new TaskException( message );
       }
   
  @@ -190,9 +188,8 @@
           try
           {
               final PropertyResolver propertyResolver =
  -                (PropertyResolver)m_frame.getServiceManager().lookup( PropertyResolver.ROLE
);
  -            final Object object =
  -                propertyResolver.resolveProperties( value, this );
  +                (PropertyResolver)getService( PropertyResolver.class );
  +            final Object object = propertyResolver.resolveProperties( value, this );
               if( null == object )
               {
                   final String message = REZ.getString( "null-resolved-value.error", value
);
  @@ -235,8 +232,7 @@
       public Map getProperties()
           throws TaskException
       {
  -        final PropertyStore store = m_frame.getPropertyStore();
  -        return store.getProperties();
  +        return getPropertyStore().getProperties();
       }
   
       /**
  @@ -248,8 +244,7 @@
       public void setProperty( final String name, final Object value )
           throws TaskException
       {
  -        final PropertyStore store = m_frame.getPropertyStore();
  -        store.setProperty( name, value );
  +        getPropertyStore().setProperty( name, value );
       }
   
       /**
  @@ -279,7 +274,7 @@
                                  message,
                                  throwable,
                                  0 );
  -            m_eventManager.fireTaskMessage( event );
  +            getEventManager().fireTaskMessage( event );
           }
       }
   
  @@ -309,7 +304,7 @@
        * @param message the message
        * @param throwable the throwable
        */
  -    public void verbose( String message, Throwable throwable )
  +    public void verbose( final String message, final Throwable throwable )
       {
           if( isVerboseEnabled() )
           {
  @@ -320,9 +315,8 @@
                                  message,
                                  throwable,
                                  0 );
  -            m_eventManager.fireTaskMessage( event );
  +            getEventManager().fireTaskMessage( event );
           }
  -
       }
   
       /**
  @@ -362,7 +356,7 @@
                                  message,
                                  throwable,
                                  0 );
  -            m_eventManager.fireTaskMessage( event );
  +            getEventManager().fireTaskMessage( event );
           }
       }
   
  @@ -403,7 +397,7 @@
                                  message,
                                  throwable,
                                  0 );
  -            m_eventManager.fireTaskMessage( event );
  +            getEventManager().fireTaskMessage( event );
           }
       }
   
  @@ -444,7 +438,7 @@
                                  message,
                                  throwable,
                                  0 );
  -            m_eventManager.fireTaskMessage( event );
  +            getEventManager().fireTaskMessage( event );
           }
       }
   
  @@ -456,5 +450,25 @@
       public boolean isErrorEnabled()
       {
           return m_frame.getLogger().isFatalErrorEnabled();
  +    }
  +
  +    /**
  +     * Utility method to aquire PropertyStore service.
  +     *
  +     * @return the PropertyStore service
  +     */
  +    private PropertyStore getPropertyStore()
  +    {
  +        return m_frame.getPropertyStore();
  +    }
  +
  +    /**
  +     * Utility method to aquire TaskEventManager service.
  +     *
  +     * @return the TaskEventManager service
  +     */
  +    private TaskEventManager getEventManager()
  +    {
  +        return m_eventManager;
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message