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-excalibur/src/scratchpad/org/apache/avalon/excalibur/service PipelineException.java PipelineRuntimeException.java ServiceFactory.java ServiceLoader.java ServiceRegistry.java
Date Mon, 04 Mar 2002 04:38:22 GMT
mcconnell    02/03/03 20:38:22

  Modified:    src/scratchpad/org/apache/avalon/excalibur/service
                        PipelineException.java
                        PipelineRuntimeException.java ServiceFactory.java
                        ServiceLoader.java ServiceRegistry.java
  Log:
  restored prev. functionality re error reporting while maintaining 1.2 compliance
  
  Revision  Changes    Path
  1.3       +22 -4     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/PipelineException.java
  
  Index: PipelineException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/PipelineException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PipelineException.java	4 Mar 2002 03:40:13 -0000	1.2
  +++ PipelineException.java	4 Mar 2002 04:38:22 -0000	1.3
  @@ -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 
  @@ -47,7 +49,7 @@
       {
           super( message, cause );
       }
  -/*
  +
       public String toString()
       {
           final StringBuffer sb = new StringBuffer();
  @@ -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
           {
  @@ -97,6 +100,21 @@
   
           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.3       +22 -4     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/PipelineRuntimeException.java
  
  Index: PipelineRuntimeException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/PipelineRuntimeException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PipelineRuntimeException.java	4 Mar 2002 03:40:13 -0000	1.2
  +++ PipelineRuntimeException.java	4 Mar 2002 04:38:22 -0000	1.3
  @@ -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 
  @@ -47,7 +49,7 @@
       {
           super( message, cause );
       }
  -/*
  +
       public String toString()
       {
           final StringBuffer sb = new StringBuffer();
  @@ -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
           {
  @@ -97,6 +100,21 @@
   
           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.4       +3 -6      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/ServiceFactory.java
  
  Index: ServiceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/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:35:58 -0000	1.3
  +++ ServiceFactory.java	4 Mar 2002 04:38:22 -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.4       +22 -13    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/ServiceLoader.java
  
  Index: ServiceLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/ServiceLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceLoader.java	4 Mar 2002 03:40:13 -0000	1.3
  +++ ServiceLoader.java	4 Mar 2002 04:38:22 -0000	1.4
  @@ -268,12 +268,18 @@
           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();
  @@ -281,12 +287,18 @@
           catch( IllegalParameterException ipe )
           {
               System.err.println( "IPE: " + ipe.getMessage() );
  +        }        
  +        catch( PipelineException e )
  +        {
  +            System.err.println( e );
  +        }
  +        catch( PipelineRuntimeException e )
  +        {
  +            System.err.println( e );
           }
           catch( Throwable e )
           {
  -            System.out.println( "MAIN: " + e.toString() );
  -            e.printStackTrace();
  -            //ExceptionUtil.printStackTrace( e, true ); // something wrong in ExceptionUtil
!!
  +            ExceptionUtil.printStackTrace( e, true );
           }
           finally
           {
  @@ -347,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 )
           {
  @@ -665,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 ); 
           }
       }
   
  @@ -674,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.3       +1 -1      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/ServiceRegistry.java
  
  Index: ServiceRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/service/ServiceRegistry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceRegistry.java	4 Mar 2002 03:40:13 -0000	1.2
  +++ ServiceRegistry.java	4 Mar 2002 04:38:22 -0000	1.3
  @@ -241,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 ); 
           } 
       }
   }
  
  
  

--
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