You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/05/12 15:18:18 UTC

cvs commit: jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin ServiceLoader.java

donaldp     02/05/12 06:18:18

  Modified:    merlin/src/java/org/apache/excalibur/merlin
                        ServiceLoader.java
  Log:
  Fixed a javadoc error and
  removed some unused variables.
  
  Revision  Changes    Path
  1.2       +102 -105  jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.java
  
  Index: ServiceLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceLoader.java	10 May 2002 17:53:09 -0000	1.1
  +++ ServiceLoader.java	12 May 2002 13:18:18 -0000	1.2
  @@ -35,7 +35,6 @@
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.activity.Disposable;
   
  @@ -68,51 +67,51 @@
    * <td width="20%" valign="top">Contextualizable</td>
    * <td>
    * The contextualization phase hadles the capture of runtime context information
  - * needed by the pipeline processor.  This information must be provided in the 
  + * needed by the pipeline processor.  This information must be provided in the
    * for of a <code>ServiceLoaderContext</code> otherwise the contextualize method will
  - * throw an exception.  The following information is provided by the 
  + * throw an exception.  The following information is provided by the
    * <code>ServiceLoaderContext</code>:
    * <p><table border="0" cellpadding="3" cellspacing="0" width="100%">
    * <tr>
    * <td width="30%" valign="top"><code>ARGS_KEY</code></td>
    * <td>
  - * Contains the command line arguments as a <code>String[]</code>. 
  + * Contains the command line arguments as a <code>String[]</code>.
    * </td></tr>
    * <tr>
    * <td valign="top"><code>BASE_DIRECTORY_KEY</code></td>
    * <td>
  - * Contains the application base directory <code>File</code>. 
  + * Contains the application base directory <code>File</code>.
    * </td></tr>
    * <tr>
    * <td valign="top"><code>TARGET_KEY</code></td>
    * <td>
  - * Contains the name of the target class to be instantiated. 
  + * Contains the name of the target class to be instantiated.
    * </td></tr>
    * <tr>
    * <td valign="top"><code>INCLUDES_KEY</code></td>
    * <td>
    * Contains an array of jar files that will be added to the pipeline classloader.
  - * Jar files included in the array will be checked for block manifest entries.  If 
  + * Jar files included in the array will be checked for block manifest entries.  If
    * block entries exist that will be registered as potetentially available services
  - * that may be instantiated during the recursive dependecy resolution process. 
  + * that may be instantiated during the recursive dependecy resolution process.
    * </td></tr>
    * <tr>
    * <td valign="top"><code>DISPOSAL_POLICY_KEY</code></td>
    * <td>
  - * A <code>Boolean</code> value that is applied on completionof the startup of a 
  - * <code>Startable</code> component.  If the value TRUE, the component is stopped 
  + * A <code>Boolean</code> value that is applied on completionof the startup of a
  + * <code>Startable</code> component.  If the value TRUE, the component is stopped
    * and disposed of (including termination of all dependencies) immediately following
    * startup.  This policy only applies to <code>Startable</code> components.  Setting
    * policy value to FALSE ensures that the component can respond as a server.  Non
  - * <code>Startable</code> target component are immediately terminated (providing a 
  + * <code>Startable</code> target component are immediately terminated (providing a
    * useful for component testing during development cycles).
    * </td></tr>
    * <tr>
    * <td valign="top"><code>VERBOSE_POLICY_KEY</code></td>
    * <td>
  - * If this value is TRUE, debug logging entries from the pipeline processor will be 
  - * if the overall logging priority permits this. If FALSE (the default), the logging 
  - * entires generated by the pipeline processor will be limited to WARN, ERROR, 
  + * If this value is TRUE, debug logging entries from the pipeline processor will be
  + * if the overall logging priority permits this. If FALSE (the default), the logging
  + * entires generated by the pipeline processor will be limited to WARN, ERROR,
    * and FATAL_ERROR.
    * </td></tr>
    * </table>
  @@ -121,29 +120,28 @@
    * <tr><td width="20%">Initalizable</td>
    * <td>
    * The initilization phase handles the creation of a new instance of the supplied
  - * target class, resolves any service dependencies, and runs the instance through 
  - * the lifecycle pipeline. 
  + * target class, resolves any service dependencies, and runs the instance through
  + * the lifecycle pipeline.
    * </td></tr>
    * <tr><td width="20%" valign="top">Disposable</td>
    * <td>
  - * Cleanup and disposal of state members following termination and diposal of 
  + * Cleanup and disposal of state members following termination and diposal of
    * all current components.
    * </td></tr>
    * </table>
    * @author Stephen McConnell <mc...@osm.net>
    */
  -public class ServiceLoader extends AbstractLogEnabled implements PipelineService
  +public class ServiceLoader
  +    extends AbstractLogEnabled
  +    implements PipelineService
   {
  -    private static final String DEFAULT_FORMAT = 
  +    private static final String DEFAULT_FORMAT =
          "[%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
       private static OutputStream c_out = System.out;
   
  -    private String[] m_args;
       private PipelineClassLoader m_classloader;
   
       private File m_root;
  -    private String m_target;
  -    private Object m_object;
       private File[] m_includes;
       private boolean m_policy = true;
       private boolean m_verbose = false;
  @@ -153,15 +151,14 @@
   
       private ServiceFactory m_factory;
       private Configuration m_config;
  -    private ServiceManager m_manager;
   
  -    
  +
      /**
  -    * Command line entry point supporting establishment and initalization of a service 
  +    * Command line entry point supporting establishment and initalization of a service
       * loader instance with a supplied target component and supporting services.
       *
       *   <p><strong>java -jar form</strong></p>
  -    *   <p>Execution using java -jar pattern requires the presence 
  +    *   <p>Execution using java -jar pattern requires the presence
       *   of the following files under the same directory:</p>
       *       <ul>
       *         <li><code>merlin.jar</code>
  @@ -170,21 +167,21 @@
       *       </ul>
       *   <p>An example command line is shown below:</p>
       *   <pre>
  -    * $ java -jar <strong>merlin.jar</strong> &lt;space-sep-list-of-supporting-jar-files&gt; 
  -    *     -target &lt;class-name&gt; 
  +    * $ java -jar <strong>merlin.jar</strong> &lt;space-sep-list-of-supporting-jar-files&gt;
  +    *     -target &lt;class-name&gt;
       *   </pre>
       *   <p><strong>java -classpath form</strong></p>
  -    *   <p>Execution using java -classpath pattern requires the inclusions 
  -    *   of the pipeline, framework and logkit jar files in the classpath 
  +    *   <p>Execution using java -classpath pattern requires the inclusions
  +    *   of the pipeline, framework and logkit jar files in the classpath
       *   statement.</p>
       *   <p>An example command line is shown below:</p>
       *   <pre>
  -    * $ java -classpath merlin.jar;avalon-framework.jar;logkit.jar 
  +    * $ java -classpath merlin.jar;avalon-framework.jar;logkit.jar
       *     <strong>org.apache.excalibur.merlin.ServiceLoader</strong>
  -    *      &lt;space-sep-list-of-supporting-jar-files&gt; -target &lt;class-name&gt; 
  +    *      &lt;space-sep-list-of-supporting-jar-files&gt; -target &lt;class-name&gt;
       *   </pre>
       * </ul>
  -    * 
  +    *
       * <p><table border="1" cellpadding="3" cellspacing="0" width="80%">
       * <tr bgcolor="#ccccff">
       * <td colspan="2"><b>Command Line Parameters and Arguments</b></td>
  @@ -193,8 +190,8 @@
       * <td valign="top"><code>-target &lt;class-name&gt;</code></td>
       * <td>
       * <p>The class to instantiate.  If the class exposes any Avalon lifecycle interface
  -    * (such as <code>Configurable</code>, <code>Contextualizable</code>, <code>Serviceable</code>,  
  -    * <code>Initializable</code>, <code>Startable</code>, or <code>Disposable</code>, the 
  +    * (such as <code>Configurable</code>, <code>Contextualizable</code>, <code>Serviceable</code>,
  +    * <code>Initializable</code>, <code>Startable</code>, or <code>Disposable</code>, the
       * pipeline will automate lifecycle processing and termination.
       * </p>
       * </td></tr>
  @@ -210,7 +207,7 @@
       * <td>
       * <p>A value of <code>true</code> will force debug level logging of the actual pipeline
       * processor.  A value of <code>false</code> will disable pipeline debug priority logging.
  -    * Visibility of logging infomration is dependent on the level supplied under the 
  +    * Visibility of logging infomration is dependent on the level supplied under the
       * <code>priority</code parameter.</p>
       * </td></tr>
       * <tr><td valign="top"><code>-priority &lt;priority&gt;</code></td>
  @@ -220,8 +217,8 @@
       * </td></tr>
       * <tr><td valign="top"><code>-dispose &lt;boolean&gt;</code></td>
       * <td>
  -    * If the target component is <code>Startable</code>, and the dispose argument 
  -    * is <code>FALSE</code> the component will be treated as a server and will continue 
  +    * If the target component is <code>Startable</code>, and the dispose argument
  +    * is <code>FALSE</code> the component will be treated as a server and will continue
       * to run following initialization. Otherwise, the component will be disposed of.
       * </td></tr>
       * <tr><td valign="top"><code>-configuration &lt;file-path&gt;</code></td>
  @@ -230,7 +227,7 @@
       * </td></tr>
       * </table>
       *
  -    * @param args a array of <code>String</code> argument values passed under the command line. 
  +    * @param args a array of <code>String</code> argument values passed under the command line.
       */
       public static void main( String[] args )
       {
  @@ -249,7 +246,7 @@
               if( target == null )
               {
                   merlin.warn(
  -                   "missing parameter: " + 
  +                   "missing parameter: " +
                      "-target <required-target-classname>" );
                   merlin.warn("cannot proceed");
                   return;
  @@ -262,7 +259,7 @@
               {
                   config = getRuntimeConfiguration( path );
               }
  -            if( config == null ) 
  +            if( config == null )
               {
                   config = new DefaultConfiguration("profile", null );
               }
  @@ -279,11 +276,11 @@
           catch( IllegalParameterException ipe )
           {
               System.err.println( ipe.getMessage() );
  -        }        
  +        }
           catch( PipelineException e )
           {
               logger.error( e.getMessage() + e.toString() );
  -            if( pipeline != null ) 
  +            if( pipeline != null )
               {
                   pipeline.dispose();
               }
  @@ -291,7 +288,7 @@
           catch( PipelineRuntimeException e )
           {
               logger.error( e.getMessage() + e.toString() );
  -            if( pipeline != null ) 
  +            if( pipeline != null )
               {
                   pipeline.dispose();
               }
  @@ -299,7 +296,7 @@
           catch( Throwable e )
           {
               e.printStackTrace();
  -            if( pipeline != null ) 
  +            if( pipeline != null )
               {
                   pipeline.dispose();
               }
  @@ -338,21 +335,21 @@
       * arguments, include files, target class, and related execution policies.
       * @param context the pipeline context
       * @exception ContextException if the supplied context is not an instance
  -    *   of ServiceLoaderContext, or if an internal error occurs while resolving 
  +    *   of ServiceLoaderContext, or if an internal error occurs while resolving
       *   context information.
       * @see ServiceLoaderContext
       */
       public void contextualize( Context context ) throws ContextException
       {
  -        if( context instanceof ServiceLoaderContext ) 
  +        if( context instanceof ServiceLoaderContext )
           {
               try
  -            { 
  +            {
                   ServiceLoaderContext c = (ServiceLoaderContext) context;
                   m_includes = c.getIncludes();
                   m_verbose = c.getVerbose();
                   m_policy = c.getDisposalPolicy();
  -                m_target = c.getTarget();
  +                c.getTarget();
               }
               catch( Throwable e )
               {
  @@ -364,7 +361,7 @@
           {
               try
               {
  -                m_includes = (File[]) context.get( 
  +                m_includes = (File[]) context.get(
                     ServiceLoaderContext.INCLUDES_KEY );
               }
               catch( ContextException e )
  @@ -374,7 +371,7 @@
   
               try
               {
  -                m_verbose = ((Boolean)context.get( 
  +                m_verbose = ((Boolean)context.get(
                     ServiceLoaderContext.VERBOSE_POLICY_KEY )).booleanValue();
               }
               catch( ContextException e )
  @@ -384,7 +381,7 @@
   
               try
               {
  -                m_policy = ((Boolean)context.get( 
  +                m_policy = ((Boolean)context.get(
                      ServiceLoaderContext.DISPOSAL_POLICY_KEY )).booleanValue();
               }
               catch( ContextException e )
  @@ -413,7 +410,7 @@
   
           try
           {
  -            if( m_classloader == null ) 
  +            if( m_classloader == null )
               {
                   m_classloader = createClassloader();
               }
  @@ -437,7 +434,7 @@
   
           Vector list = new Vector();
           Vector stack = new Vector();
  -        for (int i=0; i<m_includes.length; i++) 
  +        for (int i=0; i<m_includes.length; i++)
           {
               File target = m_includes[i];
               stack.add( target );
  @@ -451,7 +448,7 @@
           catch( Throwable e )
           {
               final String error = "Include failure during initialization.";
  -            throw new PipelineException( error, e ); 
  +            throw new PipelineException( error, e );
           }
   
           // build the registry of available services
  @@ -463,7 +460,7 @@
           catch( Throwable e )
           {
               final String error = "Factory registration failure.";
  -            throw new PipelineException( error, e ); 
  +            throw new PipelineException( error, e );
           }
       }
   
  @@ -472,7 +469,7 @@
       //=======================================================================
   
      /**
  -    * Initates execution of the loading of supporting services derived from a 
  +    * Initates execution of the loading of supporting services derived from a
       * target.
       * @param target the name of the class to process
       * @return Object a fully prepared service instance
  @@ -489,7 +486,7 @@
           try
           {
               info = new UnitInfo( target.replace('.','/'), m_config, m_root );
  -            if( getVerbose() && getLogger().isDebugEnabled() ) 
  +            if( getVerbose() && getLogger().isDebugEnabled() )
               {
                   getLogger().debug( "validating target");
               }
  @@ -506,7 +503,7 @@
           catch( Throwable e )
           {
               final String error = "Service loader exception encounter while preparing services.";
  -            throw new PipelineException( error, e ); 
  +            throw new PipelineException( error, e );
           }
   
           //
  @@ -520,7 +517,7 @@
           catch( Throwable e )
           {
               final String error = "Service loader exception encounter during target execution.";
  -            throw new PipelineException( error, e ); 
  +            throw new PipelineException( error, e );
           }
       }
   
  @@ -529,15 +526,15 @@
       //=======================================================================
   
      /**
  -    * Handles association of a shutdown hook prior to execution of a normal 
  +    * Handles association of a shutdown hook prior to execution of a normal
       * pipeline process.
       * @param target the name of the component class
  -    * @param policy if TRUE then terminate following initialization 
  +    * @param policy if TRUE then terminate following initialization
       * @exception PipelineException if a component execution error occurs
       */
       private void pipeline( String target, boolean policy ) throws PipelineException
       {
  -        if( getVerbose() && (getLogger() != null) && getLogger().isDebugEnabled() ) 
  +        if( getVerbose() && (getLogger() != null) && getLogger().isDebugEnabled() )
           {
               getLogger().debug("pipelining: " + target );
           }
  @@ -548,7 +545,7 @@
           // add a shutdown hook so we can stop services and target and invoke disposal
           //
   
  -        Runtime.getRuntime().addShutdownHook( 
  +        Runtime.getRuntime().addShutdownHook(
             new Thread()
             {
                 public void run()
  @@ -557,7 +554,7 @@
                     {
                         if( getLogger() != null)
                         {
  -                          if( getLogger().isDebugEnabled() ) 
  +                          if( getLogger().isDebugEnabled() )
                             {
                                 getLogger().debug("shutdown initiated");
                             }
  @@ -590,19 +587,19 @@
       */
       private void terminate( Object object )
       {
  -        if( m_terminated ) 
  +        if( m_terminated )
           {
               return;
           }
           m_terminated = true;
  -        if( object == null ) 
  +        if( object == null )
           {
               return;
           }
   
  -        if( getVerbose() && getLogger().isDebugEnabled() ) 
  +        if( getVerbose() && getLogger().isDebugEnabled() )
           {
  -            getLogger().debug( 
  +            getLogger().debug(
                "terminating " + object.getClass().getName() );
           }
   
  @@ -615,7 +612,7 @@
               catch( Throwable e )
               {
                   final String warning = "Ignoring error while stopping target.";
  -                if( getLogger().isWarnEnabled() ) 
  +                if( getLogger().isWarnEnabled() )
                   {
                       getLogger().warn( warning, e );
                   }
  @@ -631,7 +628,7 @@
               catch( Throwable e )
               {
                   final String warning = "Ignoring error while disposing of target.";
  -                if( getLogger().isWarnEnabled() ) 
  +                if( getLogger().isWarnEnabled() )
                   {
                       getLogger().warn( warning, e );
                   }
  @@ -644,14 +641,14 @@
       */
       public void dispose()
       {
  -        if( m_disposed ) 
  +        if( m_disposed )
           {
               return;
           }
           m_disposed = true;
  -        if( getVerbose() && getLogger().isDebugEnabled() ) 
  +        if( getVerbose() && getLogger().isDebugEnabled() )
           {
  -            getLogger().debug( 
  +            getLogger().debug(
                "loader disposal" );
           }
           if( m_factory instanceof Disposable )
  @@ -671,7 +668,7 @@
       //==========================================================
       // classloader
       //==========================================================
  -    
  +
       private PipelineClassLoader createClassloader()
       {
           try
  @@ -694,7 +691,7 @@
               super( new URL[0], Thread.currentThread().getContextClassLoader() );
           }
   
  -        protected void addURL( URL url ) 
  +        protected void addURL( URL url )
           {
               try
               {
  @@ -710,12 +707,12 @@
           protected Class loadClass( String name, boolean resolve ) throws ClassNotFoundException
           {
               return super.loadClass( name, resolve );
  -        } 
  +        }
       }
   
      /**
       * Load the supplied jar files under the pipeline classloader.
  -    * For each entry in the stack, try to load it and 
  +    * For each entry in the stack, try to load it and
       * if sucessfull, remove it from the stack - on completion
       * the stack should be less than its original size - recursivly
       * invoke load until the stack is empty.
  @@ -725,7 +722,7 @@
       private void load( Vector stack )
       {
           int size = stack.size();
  -        if( getVerbose() ) 
  +        if( getVerbose() )
           {
               getLogger().debug( "Loading stack: " + stack.size() );
           }
  @@ -734,7 +731,7 @@
           while( enum.hasMoreElements() )
           {
               File file = (File) enum.nextElement();
  -            if( getVerbose() ) 
  +            if( getVerbose() )
               {
                   getLogger().debug( "Loading resource: " + file );
               }
  @@ -745,15 +742,15 @@
               }
               catch( Throwable error )
               {
  -                if( getVerbose() ) 
  +                if( getVerbose() )
                   {
  -                    getLogger().warn( 
  +                    getLogger().warn(
                         "Encountered error while loading resource: " + file, error );
                   }
                   errors.put( file, error );
               }
           }
  -        if( stack.size() == 0 ) 
  +        if( stack.size() == 0 )
           {
               return;
           }
  @@ -768,7 +765,7 @@
               while( keys.hasMoreElements() )
               {
                   File key = (File) keys.nextElement();
  -                getLogger().error( 
  +                getLogger().error(
                      "Error while loading file."
                      + "\n\tfile: " + key.toString(), (Throwable) errors.get( key ) );
               }
  @@ -781,25 +778,25 @@
       //==========================================================
   
      /**
  -    * Get client configuration from a file. 
  -    */ 
  -    private static Configuration getRuntimeConfiguration( final File file ) 
  +    * Get client configuration from a file.
  +    */
  +    private static Configuration getRuntimeConfiguration( final File file )
       {
           try
           {
  -            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder( ); 
  +            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder( );
               InputStream is = new FileInputStream( file );
  -            if( is == null ) 
  +            if( is == null )
               {
  -                throw new Exception( 
  -                  "Could not load the configuration resource \"" + file + "\"" ); 
  +                throw new Exception(
  +                  "Could not load the configuration resource \"" + file + "\"" );
               }
  -            return builder.build( is ); 
  +            return builder.build( is );
           }
           catch( Throwable e )
           {
               final String error = "Unable to create configuration from file: " + file;
  -            throw new CascadingRuntimeException( error, e ); 
  +            throw new CascadingRuntimeException( error, e );
           }
       }
   
  @@ -812,7 +809,7 @@
           try
           {
               Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
  -            hierarchy.setDefaultLogTarget( 
  +            hierarchy.setDefaultLogTarget(
                  new StreamTarget( c_out, new AvalonFormatter( DEFAULT_FORMAT ) ) );
               hierarchy.setDefaultPriority( priority );
               return hierarchy;
  @@ -830,14 +827,14 @@
      /**
       * Exception thorwn by the command line handler.
       */
  -    private static class IllegalParameterException extends Exception 
  +    private static class IllegalParameterException extends Exception
       {
          /**
  -        * Construct a new <code>IllegalParameterException</code> instance with the 
  +        * Construct a new <code>IllegalParameterException</code> instance with the
           * supplied message parameter.
           * @param message Message summarising the exception.
           */
  -        public IllegalParameterException( final String message ) 
  +        public IllegalParameterException( final String message )
           {
              super( message );
           }
  @@ -858,7 +855,7 @@
   
          /**
           * Creation of a new command line handler.
  -        * @param String[] args the command line arguments to parse
  +        * @param args the command line arguments to parse
           */
           public CLI( String[] args ) throws IllegalParameterException
           {
  @@ -872,7 +869,7 @@
   
                   if( arg.startsWith("-tar") )
                   {
  -                    if( i+1 < m_args.length ) 
  +                    if( i+1 < m_args.length )
                       {
                           m_target = m_args[i+1];
                           i = i+1;
  @@ -885,7 +882,7 @@
                   }
                   else if( arg.startsWith("-conf") )
                   {
  -                    if( i+1 < m_args.length ) 
  +                    if( i+1 < m_args.length )
                       {
                           m_path = new File( m_args[i+1] );
                           i = i+1;
  @@ -898,7 +895,7 @@
                   }
                   else if( arg.startsWith("-pri") )
                   {
  -                    if( i+1 < m_args.length ) 
  +                    if( i+1 < m_args.length )
                       {
                           m_priority = Priority.getPriorityForName( m_args[i+1].toUpperCase() );
                           i = i+1;
  @@ -911,7 +908,7 @@
                   }
                   else if( arg.startsWith("-dis") )
                   {
  -                    if( i+1 < m_args.length ) 
  +                    if( i+1 < m_args.length )
                       {
                           m_policy = (m_args[i+1].toUpperCase().equals("TRUE"));
                           i = i+1;
  @@ -924,7 +921,7 @@
                   }
                   else if( arg.startsWith("-ver") )
                   {
  -                    if( i+1 < m_args.length ) 
  +                    if( i+1 < m_args.length )
                       {
                           m_verbose = (m_args[i+1].toUpperCase().equals("TRUE"));
                           i = i+1;
  @@ -941,9 +938,9 @@
                       throw new IllegalParameterException( error );
                   }
                   else
  -                {    
  +                {
                       final File file = new File( m_args[i] );
  -                    if( file.exists() ) 
  +                    if( file.exists() )
                       {
                           vector.add( file );
                       }
  
  
  

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