avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo DirectoryBlock.java DirectoryBlock.xinfo ReferralBlock.java
Date Mon, 04 Mar 2002 04:39:37 GMT
mcconnell    02/03/03 20:39:37

  Modified:    enterprise/tools build.xml
               enterprise/tools/lib merlin.jar
               enterprise/tools/src/java/org/apache/avalon/excalibur/service
                        PipelineException.java
                        PipelineRuntimeException.java ServiceContext.java
                        ServiceFactory.java ServiceLoader.java
                        ServiceRegistry.java
               enterprise/tools/src/java/org/apache/demo
                        DirectoryBlock.java DirectoryBlock.xinfo
                        ReferralBlock.java
  Log:
  updated error reporting (should be 1.2 compliant)
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-avalon-apps/enterprise/tools/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml	3 Mar 2002 23:08:26 -0000	1.2
  +++ build.xml	4 Mar 2002 04:39:37 -0000	1.3
  @@ -144,7 +144,7 @@
         <copy todir="${build}/demo">
           <fileset dir="${src}/java">
             <include name="org/apache/demo/**/*.xinfo"/>
  -          <include name="org/apache/demo/**/*.xml"/>
  +          <include name="org/apache/demo/**/*.conf"/>
           </fileset>
         </copy>
         <jar jarfile="${dist}/examples.jar" basedir="${build}/demo" manifest="${etc}/demo.mf"
/>
  
  
  
  1.4       +85 -74    jakarta-avalon-apps/enterprise/tools/lib/merlin.jar
  
  	<<Binary file>>
  
  
  1.2       +20 -10    jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/PipelineException.java
  
  Index: PipelineException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/PipelineException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PipelineException.java	3 Mar 2002 15:45:58 -0000	1.1
  +++ PipelineException.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -10,8 +10,10 @@
   import java.io.StringWriter;
   import java.util.StringTokenizer;
   import java.io.PrintWriter;
  +import java.lang.reflect.Method;
   
   import org.apache.avalon.framework.CascadingException;
  +import org.apache.avalon.framework.CascadingThrowable;
   
   /**
    * Thrown by an Pipeline as a result of an unexpected error 
  @@ -63,9 +65,10 @@
           if( cause == null ) return;
   	  buffer.append( "\nCause: " + cause.getClass().getName() 
             + ", " + cause.getMessage() );
  -	  if( cause.getCause() != null )
  +        Throwable sub_cause = resolveCause( cause );
  +	  if( sub_cause != null )
           {
  -            appendCause( buffer, cause.getCause() );
  +            appendCause( buffer, sub_cause );
           }
           else
           {
  @@ -85,14 +88,6 @@
           return splitString( sw.toString(), "\n" );
       }
   
  -    /**
  -     * Splits the string on every token into an array of stack frames.
  -     *
  -     * @param string the string
  -     * @param onToken the token
  -     * @return the resultant array
  -     * @deprecated This is an internal utility method that should not be used
  -     */
       private static String[] splitString( final String string, final String onToken )
       {
           final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
  @@ -106,5 +101,20 @@
           return result;
       }
   
  +    private static Throwable resolveCause( Throwable target )
  +    {
  +        if( target instanceof CascadingThrowable ) return ((CascadingThrowable)target).getCause();
  +        
  +        try
  +        {
  +            Method method = target.getClass().getMethod( "getCause", new Class[0] );
  +            if( method != null ) return (Throwable) method.invoke( target, new Object[0]
);
  +            return null;
  +        }
  +        catch( Throwable e )
  +        {
  +            return null;
  +        }
  +    }
   }
   
  
  
  
  1.2       +20 -10    jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/PipelineRuntimeException.java
  
  Index: PipelineRuntimeException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/PipelineRuntimeException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PipelineRuntimeException.java	3 Mar 2002 15:45:58 -0000	1.1
  +++ PipelineRuntimeException.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -10,8 +10,10 @@
   import java.io.StringWriter;
   import java.util.StringTokenizer;
   import java.io.PrintWriter;
  +import java.lang.reflect.Method;
   
   import org.apache.avalon.framework.CascadingRuntimeException;
  +import org.apache.avalon.framework.CascadingThrowable;
   
   /**
    * Thrown by an Pipeline as a result of an unexpected runtime error 
  @@ -63,9 +65,10 @@
           if( cause == null ) return;
   	  buffer.append( "\nCause: " + cause.getClass().getName() 
             + ", " + cause.getMessage() );
  -	  if( cause.getCause() != null )
  +        Throwable sub_cause = resolveCause( cause );
  +	  if( sub_cause != null )
           {
  -            appendCause( buffer, cause.getCause() );
  +            appendCause( buffer, sub_cause );
           }
           else
           {
  @@ -85,14 +88,6 @@
           return splitString( sw.toString(), "\n" );
       }
   
  -    /**
  -     * Splits the string on every token into an array of stack frames.
  -     *
  -     * @param string the string
  -     * @param onToken the token
  -     * @return the resultant array
  -     * @deprecated This is an internal utility method that should not be used
  -     */
       private static String[] splitString( final String string, final String onToken )
       {
           final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
  @@ -106,5 +101,20 @@
           return result;
       }
   
  +    private static Throwable resolveCause( Throwable target )
  +    {
  +        if( target instanceof CascadingThrowable ) return ((CascadingThrowable)target).getCause();
  +        
  +        try
  +        {
  +            Method method = target.getClass().getMethod( "getCause", new Class[0] );
  +            if( method != null ) return (Throwable) method.invoke( target, new Object[0]
);
  +            return null;
  +        }
  +        catch( Throwable e )
  +        {
  +            return null;
  +        }
  +    }
   }
   
  
  
  
  1.2       +2 -13     jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceContext.java
  
  Index: ServiceContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceContext.java	3 Mar 2002 15:45:58 -0000	1.1
  +++ ServiceContext.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -8,7 +8,6 @@
   package org.apache.avalon.excalibur.service;
   
   import java.io.File;
  -import org.apache.avalon.phoenix.BlockContext;
   import org.apache.avalon.framework.logger.Logger;
   
   import org.apache.avalon.framework.context.DefaultContext;
  @@ -20,11 +19,11 @@
    * @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
    */
   
  -public class ServiceContext extends DefaultContext implements BlockContext
  +public class ServiceContext extends DefaultContext 
   {
   
       public static final String ARGS_KEY = "ARGS";
  -    public static final String BASE_DIRECTORY_KEY = "APP_DIR";
  +    public static final String BASE_DIRECTORY_KEY = "app.home";
   
       private String[] m_args;
       private File m_root;
  @@ -49,15 +48,5 @@
       public File getBaseDirectory()
       {
           return m_root;
  -    }
  -
  -    public Logger getLogger( String name )
  -    {
  -        throw new RuntimeException("Not implemented.");
  -    }
  -
  -    public String getName()
  -    {
  -        return m_name;   
       }
   }
  
  
  
  1.4       +3 -6      jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceFactory.java
  
  Index: ServiceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceFactory.java	3 Mar 2002 23:34:40 -0000	1.3
  +++ ServiceFactory.java	4 Mar 2002 04:39:37 -0000	1.4
  @@ -52,7 +52,6 @@
    */
   class ServiceFactory extends AbstractLogEnabled implements Disposable
   {
  -    private Hierarchy m_hierarchy;
       private ServiceRegistry m_registry;
       private Hashtable m_table = new Hashtable();
       private Hashtable m_pools = new Hashtable();
  @@ -64,9 +63,8 @@
       private Hashtable m_services = new Hashtable();
       private Hashtable m_lookup = new Hashtable();
   
  -    public ServiceFactory( Hierarchy hierarchy, Configuration config, File base, boolean
verbose ) throws Exception
  +    public ServiceFactory( Configuration config, File base, boolean verbose ) throws Exception
       {
  -        m_hierarchy = hierarchy;
           m_registry = new ServiceRegistry( verbose );
           m_table = initalizeBlockConfigurations( config );
           m_root = base;
  @@ -75,7 +73,7 @@
   
       public void enableLogging( Logger logger )
       {
  -        super.enableLogging( logger );
  +        super.enableLogging( logger.getChildLogger( "factory" ) );
           m_registry.enableLogging( logger.getChildLogger("registry") );
       }
   
  @@ -250,9 +248,8 @@
   
           if( m_object instanceof LogEnabled ) try
           {
  -            Logger logger = new LogKitLogger( m_hierarchy.getLoggerFor( role ) );
               if( m_verbose ) getLogger().debug( "applying logger to " + role );
  -            ((LogEnabled)m_object).enableLogging( logger );
  +            ((LogEnabled)m_object).enableLogging( getLogger().getChildLogger( role ) );
           }
           catch( Throwable e )
           {
  
  
  
  1.3       +21 -32    jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceLoader.java
  
  Index: ServiceLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceLoader.java	3 Mar 2002 23:08:26 -0000	1.2
  +++ ServiceLoader.java	4 Mar 2002 04:39:37 -0000	1.3
  @@ -51,6 +51,8 @@
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.ExceptionUtil;
  +import org.apache.avalon.framework.CascadingThrowable;
   
   /**
    * A service loader that loads a target class, manages full component lifecycle
  @@ -68,7 +70,7 @@
    * of a component, the pipline processor will attempt to locate a block configuration
    * based on the class name of the block.  If there is no configuration matching the 
    * class name an empty configuration will be supplied to the component or a component
  - * the the target component is depedant on (assuming the component in question 
  + * the the target component is dependent on (assuming the component in question 
    * implements the Configurable interface).
    *
    * <pre>
  @@ -266,37 +268,37 @@
           ServiceLoader pipeline = null;
           try
           {
  +
               CLI cli = new CLI( args );
  -            pipeline = new ServiceLoader();
               ServiceLoaderContext context = cli.getContext();
  +            Hierarchy hierarchy = createBootstrapLogger( context.getLoggingPriority() );
  +            Logger logger = new LogKitLogger( hierarchy.getLoggerFor( "loader" ) );
  +
               File path = cli.getConfigurationPath();
               Configuration config = new DefaultConfiguration("-", null );
               if( path != null ) config = getRuntimeConfiguration( path );
  +
  +            pipeline = new ServiceLoader();
  +            pipeline.enableLogging( logger );
               pipeline.configure( config );
               pipeline.contextualize( context );
               pipeline.initialize();
           }
           catch( IllegalParameterException ipe )
           {
  -            System.err.println( ipe.getMessage() );
  -        }
  +            System.err.println( "IPE: " + ipe.getMessage() );
  +        }        
           catch( PipelineException e )
           {
  -            final String error = "Service loader processing exception.";
  -            System.err.println( error );
               System.err.println( e );
           }
           catch( PipelineRuntimeException e )
           {
  -            final String error = "Service loader runtime exception.";
  -            System.err.println( error );
               System.err.println( e );
           }
           catch( Throwable e )
           {
  -            final String error = "Unexpected service loader exception.";
  -            System.err.println( error );
  -            e.printStackTrace();
  +            ExceptionUtil.printStackTrace( e, true );
           }
           finally
           {
  @@ -357,13 +359,10 @@
   
           try
           {
  -            Hierarchy hierarchy = createBootstrapLogger();
  -            Logger logger = new LogKitLogger( hierarchy.getLoggerFor( "loader" ) );
  -            if( getLogger() == null ) super.enableLogging( logger );
               if( m_classloader == null ) m_classloader = createClassloader();
  -            m_factory = new ServiceFactory( hierarchy, m_config,
  +            m_factory = new ServiceFactory( m_config,
                 new File( System.getProperty("user.dir") ), getVerbose() );
  -            m_factory.enableLogging( getLogger().getChildLogger("factory") );
  +            m_factory.enableLogging( getLogger() );
           }
           catch( Throwable e )
           {
  @@ -376,20 +375,10 @@
           {
               process();
           }
  -        catch( PipelineException e )
  -        {
  -            final String error = "Service loader processing exception.";
  -            getLogger().error( error );
  -        }
  -        catch( PipelineRuntimeException e )
  -        {
  -            final String error = "Service loader runtime exception.";
  -            getLogger().error( error );
  -        }
           catch( Throwable e )
           {
  -            final String error = "Unexpected pipeline exception.";
  -            getLogger().error( error, e );
  +            final String error = "Service processing error.";
  +            throw new PipelineException( error, e );
           }
           finally
           {
  @@ -685,8 +674,8 @@
           }
           catch( Throwable e )
           {
  -            final String error = "Unable to create configuration.";
  -            throw new CascadingRuntimeException( error, e );
  +            final String error = "Unable to create configuration from file: " + file;
  +            throw new CascadingRuntimeException( error, e ); 
           }
       }
   
  @@ -694,14 +683,14 @@
       // logging
       //==========================================================
   
  -    private Hierarchy createBootstrapLogger()
  +    private static Hierarchy createBootstrapLogger( Priority priority )
       {
           try
           {
               Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
               hierarchy.setDefaultLogTarget( 
                  new StreamTarget( m_out, new AvalonFormatter( DEFAULT_FORMAT ) ) );
  -            hierarchy.setDefaultPriority( m_priority );
  +            hierarchy.setDefaultPriority( priority );
               return hierarchy;
           }
           catch( Throwable e )
  
  
  
  1.2       +10 -2     jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceRegistry.java
  
  Index: ServiceRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/avalon/excalibur/service/ServiceRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceRegistry.java	3 Mar 2002 15:45:58 -0000	1.1
  +++ ServiceRegistry.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -129,6 +129,9 @@
                   final String classname = path.replace('/','.');
                   Class block = Thread.currentThread().getContextClassLoader().loadClass(
classname );
                   vector.add( new UnitInfo( block, xinfo, config ));
  +                //System.out.println("LOADED CONFIG: " + path + ".conf" + ", " + config.getName()
);
  +                //System.out.println("CHILDREN: " + config.getChildren().length );
  +                //System.out.println("PROFILE: " + config.getChild("profile").getChildren().length
);
               }
           }
           catch( Throwable e )
  @@ -148,9 +151,14 @@
           try
           {
               String path = block.getName().replace('.','/');
  -            Configuration config = loadConfiguration( path + ".config", true );
  +            Configuration config = loadConfiguration( path + ".conf", true );
               Configuration xinfo = loadConfiguration( path + ".xinfo", false );
               if( xinfo == null ) xinfo = new DefaultConfiguration("", null);
  +
  +            //System.out.println("X-LOADED CONFIG: " + path + ".conf" + ", " + config.getName()
);
  +            //System.out.println("X-CHILDREN: " + config.getChildren().length );
  +            //System.out.println("X-PROFILE: " + config.getChild("profile").getChildren().length
);
  +
               return new UnitInfo( block, xinfo, config );
           }
           catch( Throwable e )
  @@ -233,7 +241,7 @@
           catch( Throwable e )
           {
               final String error = "Unexpected exception while attempting to load a configuration
from path: ";
  -            throw new ConfigurationException( error, e ); 
  +            throw new ConfigurationException( error + path, e ); 
           } 
       }
   }
  
  
  
  1.2       +1 -3      jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/DirectoryBlock.java
  
  Index: DirectoryBlock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/DirectoryBlock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirectoryBlock.java	3 Mar 2002 15:45:59 -0000	1.1
  +++ DirectoryBlock.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -8,8 +8,6 @@
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.phoenix.BlockContext;
  -import org.apache.avalon.phoenix.Block;
   
   /**
    * This is a minimal demonstration service that returns the number of
  @@ -21,7 +19,7 @@
    */
   
   public class DirectoryBlock extends AbstractLogEnabled
  -implements Block, Disposable, DirectoryService
  +implements Disposable, DirectoryService
   {
   
      /**
  
  
  
  1.2       +8 -4      jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/DirectoryBlock.xinfo
  
  Index: DirectoryBlock.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/DirectoryBlock.xinfo,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirectoryBlock.xinfo	3 Mar 2002 15:45:59 -0000	1.1
  +++ DirectoryBlock.xinfo	4 Mar 2002 04:39:37 -0000	1.2
  @@ -24,11 +24,15 @@
     </services>
   
     <!--
  -  Implememtatiuon policy may one of the following enumerations:
  -  (a) SINGLETON, service is available for the lifetime of the manager
  -  (b) POOLED, the implementation implements Pool
  -  (c) TRANSIENT, manager is a factory of transient service instances
  +  Default configuration profile name.
     -->
  +
  +  <profile name="directory"/>
  +
  +  <!--
  +  Implementation policy.
  +  -->
  +
     <implementation policy="SINGLETON" />
   
   </blockinfo>
  
  
  
  1.2       +1 -3      jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/ReferralBlock.java
  
  Index: ReferralBlock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/tools/src/java/org/apache/demo/ReferralBlock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReferralBlock.java	3 Mar 2002 15:45:59 -0000	1.1
  +++ ReferralBlock.java	4 Mar 2002 04:39:37 -0000	1.2
  @@ -24,8 +24,6 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.phoenix.BlockContext;
  -import org.apache.avalon.phoenix.Block;
   
   
   /**
  @@ -34,7 +32,7 @@
    */
   
   public class ReferralBlock extends AbstractLogEnabled
  -implements Block, Configurable, Contextualizable, Serviceable, Initializable, Disposable,
ReferralService
  +implements Configurable, Contextualizable, Serviceable, Initializable, Disposable, ReferralService
   {
   
       private Configuration m_configuration;
  
  
  

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


Mime
View raw message