avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/logging/logkit/test/conf logging.xml
Date Wed, 28 Jan 2004 10:02:08 GMT
mcconnell    2004/01/28 02:02:07

  Modified:    merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLoggingFactory.java Resources.properties
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        MulticastTargetFactory.java
               merlin/logging/logkit/test/conf logging.xml
  Log:
  Elimination of factory declarations.
  
  Revision  Changes    Path
  1.5       +197 -148  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java
  
  Index: DefaultLoggingFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultLoggingFactory.java	27 Jan 2004 19:27:23 -0000	1.4
  +++ DefaultLoggingFactory.java	28 Jan 2004 10:01:54 -0000	1.5
  @@ -38,6 +38,9 @@
   import org.apache.avalon.logging.provider.LoggingManager;
   import org.apache.avalon.logging.data.CategoriesDirective;
   import org.apache.avalon.logging.data.CategoryDirective;
  +import org.apache.avalon.logging.logkit.factory.FileTargetFactory;
  +import org.apache.avalon.logging.logkit.factory.StreamTargetFactory;
  +import org.apache.avalon.logging.logkit.factory.MulticastTargetFactory;
   
   import org.apache.avalon.repository.provider.InitialContext;
   import org.apache.avalon.repository.provider.Factory;
  @@ -157,15 +160,15 @@
           // setup the logging target factories
           //
   
  -        final Configuration factoriesConfig = config.getChild( "factories" );
  -        setupTargetFactories( factoriesMap, factoriesConfig );
  +        //final Configuration factoriesConfig = config.getChild( "factories" );
  +        //setupTargetFactories( factoriesMap, factoriesConfig );
   
           //
           // setup the logging targets
           //
   
           final Configuration targetsConfig = config.getChild( "targets" );
  -        setupTargets( targetsMap, targetsConfig );
  +        setupTargets( factoriesMap, targetsMap, targetsConfig );
   
           //
           // setup the logging categories directive
  @@ -223,50 +226,6 @@
           }
       }
   
  -    /**
  -     * Create the log target factories.
  -     *
  -     * @param config the factory configuration element.
  -     * @throws LoggingException if an error occurs in factor directive parsing
  -     */
  -    private void setupTargetFactories( 
  -      final Map factories, final Configuration config )
  -      throws LoggingException
  -    {
  -        Configuration[] children = config.getChildren();
  -        for( int i = 0; i < children.length; i++ )
  -        {
  -            Configuration child = children[i];
  -            if( child.getName().equalsIgnoreCase( "factory" ) )
  -            {
  -                final String key = getFactoryKey( child );
  -                try
  -                {
  -                    LogTargetFactory factory =
  -                      createLogTargetFactory( child );
  -                    factories.put( key, factory );
  -                }
  -                catch( LoggingException e )
  -                {
  -                    final String error = 
  -                     REZ.getString( "factory.target-factory.load.error", key );
  -                    m_logger.error( error, e );
  -                }
  -            }
  -            else
  -            {
  -                final String name = child.getName();
  -                final String listing = ConfigurationUtil.list( child ); 
  -                final String error = 
  -                  REZ.getString( 
  -                    "factory.target-factory.unknown-element", 
  -                    name, 
  -                    listing );
  -                m_logger.error( error );
  -            }
  -        }
  -    }
  -
      /**
       * Setup of the log targets declared in the logging configuration.
       * @param logger the logging channel to log establishment events
  @@ -274,17 +233,17 @@
       *    are resolved
       * @param config the log targets configuration
       */
  -    private void setupTargets( final Map targets, final Configuration config )
  +    private void setupTargets( final Map factories, final Map targets, final Configuration
config )
         throws LoggingException
       {
           Configuration[] children = config.getChildren();
           for( int i = 0; i < children.length; i++ )
           {
               Configuration child = children[i];
  +            final String id = getTargetId( child );
               try
               {
  -                final String id = getTargetId( child );
  -                final LogTarget target = createLogTarget( child );
  +                final LogTarget target = createLogTarget( factories, id, child );
                   targets.put( id, target );
                   final String message = 
                     REZ.getString( "target.notice.add", id );
  @@ -292,11 +251,9 @@
               }
               catch( Throwable e )
               {
  -                final String message = 
  -                  REZ.getString( "target.notice.fail", child.getName() );
                   final String error = 
  -                  "Could not load a declared log target.";
  -                m_logger.error( error, e );
  +                  REZ.getString( "target.notice.fail", id );
  +                throw new LoggingException( error, e );
               }
           }
       }
  @@ -308,43 +265,52 @@
       * @return the logging target
       * @exception Exception if an error occurs during factory creation
       */ 
  -    private LogTarget createLogTarget( final Configuration config )
  +    private LogTarget createLogTarget( Map factories, final String id, final Configuration
config )
         throws LoggingException
       {
  -         final String key = getTargetFactoryKey( config );
  -         final LogTargetFactory factory = m_factories.getLogTargetFactory( key );
  -         if( factory == null )
  -         {
  -            final String message = 
  -              REZ.getString( "target.error.missing-factory", key );
  -            throw new LoggingException( message );
  -         }
  -         else
  -         {
  -            return factory.createTarget( config );
  -         }
  +        final String key = getTargetFactoryKey( config );
  +        final LogTargetFactory factory = getLogTargetFactory( factories, key );
  +        return factory.createTarget( config );
       }
   
  -   /**
  -    * Return the identitying key associated with the log target factory.
  -    * @param config the log target factory configuration
  -    * @return the unique key
  -    */ 
  -    private String getFactoryKey( Configuration config )
  +    private LogTargetFactory getLogTargetFactory( Map factories, String key )
         throws LoggingException
       {
  -        try
  +        final LogTargetFactory factory = m_factories.getLogTargetFactory( key );
  +        if( factory != null )
           {
  -            return config.getAttribute( "type" );
  +            return factory;
           }
  -        catch( ConfigurationException e )
  +        else
           {
  -            final String listing = ConfigurationUtil.list( config );
  -            final String error = 
  -              REZ.getString( 
  -                "target.error.missing-type", 
  -                listing );
  -           throw new LoggingException( error );
  +            Class clazz = getLogTargetFactoryClass( key );
  +            LogTargetFactory newFactory = 
  +              buildLogTargetFactoryViaConstructor( clazz );
  +            factories.put( key, newFactory );
  +            return newFactory;
  +        }
  +    }
  +
  +    private Class getLogTargetFactoryClass( final String key )
  +      throws LoggingException
  +    {
  +        if( key.equals( "file" ) )
  +        {
  +            return FileTargetFactory.class;
  +        }
  +        else if( key.equals( "stream" ) )
  +        {
  +            return StreamTargetFactory.class;
  +        }
  +        else if( key.equals( "multicast" ) )
  +        {
  +            return MulticastTargetFactory.class;
  +        }
  +        else
  +        {
  +            final String message = 
  +              REZ.getString( "factory.error.unknown", key );
  +            throw new LoggingException( message );
           }
       }
   
  @@ -383,72 +349,6 @@
           }
       }
   
  -   /**
  -    * Return the class attribute from a factory element.
  -    * @param config the target factory configuration
  -    * @return the target classname
  -    * @exception LoggingException if the class attribute is not declared
  -    */
  -    private String getFactoryClassname( Configuration config )
  -      throws LoggingException
  -    { 
  -        try
  -        {
  -            return config.getAttribute( "class" );
  -        }
  -        catch( ConfigurationException e )
  -        {
  -            final String listing = ConfigurationUtil.list( config );
  -            final String error = 
  -              REZ.getString( 
  -                "target.error.missing-class", 
  -                listing );
  -            throw new LoggingException( error );
  -        }
  -    }
  -
  -   /**
  -    * Load a factory class using a supplied factory classname.
  -    * @param factory the factory classname
  -    * @return the factory class
  -    * @exception LoggingException if a factory class loading error occurs
  -    */
  -    protected Class loadFactoryClass( String classname )
  -        throws LoggingException
  -    {
  -        try
  -        {
  -            return m_classloader.loadClass( classname );
  -        }
  -        catch( ClassNotFoundException e )
  -        {
  -            final String error = 
  -              REZ.getString( 
  -                "target.error.class-not-found", 
  -                classname );
  -            throw new LoggingException( error, e );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -              REZ.getString( 
  -                "target.error.class-load", 
  -                classname );
  -            throw new LoggingException( error, e );
  -        }
  -    }
  -
  -   /**
  -    * Create a new logging target factory instance.
  -    */
  -    private LogTargetFactory createLogTargetFactory( Configuration config ) 
  -      throws LoggingException
  -    {
  -        String classname = getFactoryClassname( config );
  -        Class clazz = loadFactoryClass( classname );
  -        return buildLogTargetFactoryViaConstructor( clazz );
  -    }
  -
       private LogTargetFactory buildLogTargetFactoryViaConstructor( Class clazz ) 
         throws LoggingException
       {
  @@ -600,4 +500,153 @@
           final String target = config.getAttribute( "target", null );
           return new CategoryDirective( name, priority, target );
       }
  +
  +    //--------------------------------------------------------------------------
  +    // junk
  +    //--------------------------------------------------------------------------
  +
  +   /**
  +    * Return the identitying key associated with the log target factory.
  +    * @param config the log target factory configuration
  +    * @return the unique key
  +    */
  +    /*
  +    private String getFactoryKey( Configuration config )
  +      throws LoggingException
  +    {
  +        try
  +        {
  +            return config.getAttribute( "type" );
  +        }
  +        catch( ConfigurationException e )
  +        {
  +            final String listing = ConfigurationUtil.list( config );
  +            final String error = 
  +              REZ.getString( 
  +                "target.error.missing-type", 
  +                listing );
  +           throw new LoggingException( error );
  +        }
  +    }
  +    */
  +
  +
  +   /**
  +    * Return the class attribute from a factory element.
  +    * @param config the target factory configuration
  +    * @return the target classname
  +    * @exception LoggingException if the class attribute is not declared
  +    */
  +    /*
  +    private String getFactoryClassname( Configuration config )
  +      throws LoggingException
  +    { 
  +        try
  +        {
  +            return config.getAttribute( "class" );
  +        }
  +        catch( ConfigurationException e )
  +        {
  +            final String listing = ConfigurationUtil.list( config );
  +            final String error = 
  +              REZ.getString( 
  +                "target.error.missing-class", 
  +                listing );
  +            throw new LoggingException( error );
  +        }
  +    }
  +    */
  +
  +   /**
  +    * Load a factory class using a supplied factory classname.
  +    * @param factory the factory classname
  +    * @return the factory class
  +    * @exception LoggingException if a factory class loading error occurs
  +    */
  +    /*
  +    protected Class loadFactoryClass( String classname )
  +        throws LoggingException
  +    {
  +        try
  +        {
  +            return m_classloader.loadClass( classname );
  +        }
  +        catch( ClassNotFoundException e )
  +        {
  +            final String error = 
  +              REZ.getString( 
  +                "target.error.class-not-found", 
  +                classname );
  +            throw new LoggingException( error, e );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              REZ.getString( 
  +                "target.error.class-load", 
  +                classname );
  +            throw new LoggingException( error, e );
  +        }
  +    }
  +    */
  +
  +   /**
  +    * Create a new logging target factory instance.
  +    */
  +    /*
  +    private LogTargetFactory createLogTargetFactory( Configuration config ) 
  +      throws LoggingException
  +    {
  +        String classname = getFactoryClassname( config );
  +        Class clazz = loadFactoryClass( classname );
  +        return buildLogTargetFactoryViaConstructor( clazz );
  +    }
  +    */
  +
  +    /**
  +     * Create the log target factories.
  +     *
  +     * @param config the factory configuration element.
  +     * @throws LoggingException if an error occurs in factor directive parsing
  +     */
  +    /*
  +    private void setupTargetFactories( 
  +      final Map factories, final Configuration config )
  +      throws LoggingException
  +    {
  +        Configuration[] children = config.getChildren();
  +        for( int i = 0; i < children.length; i++ )
  +        {
  +            Configuration child = children[i];
  +            if( child.getName().equalsIgnoreCase( "factory" ) )
  +            {
  +                final String key = getFactoryKey( child );
  +                try
  +                {
  +                    LogTargetFactory factory =
  +                      createLogTargetFactory( child );
  +                    factories.put( key, factory );
  +                }
  +                catch( LoggingException e )
  +                {
  +                    final String error = 
  +                     REZ.getString( "factory.target-factory.load.error", key );
  +                    m_logger.error( error, e );
  +                }
  +            }
  +            else
  +            {
  +                final String name = child.getName();
  +                final String listing = ConfigurationUtil.list( child ); 
  +                final String error = 
  +                  REZ.getString( 
  +                    "factory.target-factory.unknown-element", 
  +                    name, 
  +                    listing );
  +                m_logger.error( error );
  +            }
  +        }
  +    }
  +    */
  +
   }
  
  
  
  1.5       +1 -0      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/Resources.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties	27 Jan 2004 19:27:23 -0000	1.4
  +++ Resources.properties	28 Jan 2004 10:01:56 -0000	1.5
  @@ -21,6 +21,7 @@
   
   criteria.artifact.default.error=Unable to resolve cononical representation of the file
[{0}].
   
  +factory.error.unknown=Unknown log target type [{0}].
   factory.error.unrecognized-parameter=Unrecognized parameter class [{0}] declared by the
log target factory [{1}] .
   factory.error.no-constructor=No constructor declared in log target factory [{0}].
   factory.bad-criteria=Unrecognized criteria class [{0}].
  
  
  
  1.2       +9 -4      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/MulticastTargetFactory.java
  
  Index: MulticastTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/MulticastTargetFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MulticastTargetFactory.java	27 Jan 2004 19:27:23 -0000	1.1
  +++ MulticastTargetFactory.java	28 Jan 2004 10:02:00 -0000	1.2
  @@ -38,6 +38,8 @@
   import org.apache.avalon.logging.logkit.LogTargetException;
   import org.apache.avalon.logging.logkit.LogTargetFactory;
   import org.apache.avalon.logging.logkit.LogTargetManager;
  +import org.apache.avalon.logging.logkit.MissingIdException;
  +import org.apache.avalon.logging.logkit.UnknownLogTargetException;
   
   
   /**
  @@ -75,7 +77,10 @@
        * Create a LogTarget based on a supplied configuration
        * @param conf the target coonfiguration
        * @return the malticast target
  -     * @exception LogTargetException if a target creation error occurs
  +     * @exception MissingIdException if a nested target reference 
  +     *    does not declare an id attribute
  +     * @exception UnknownLogTargetException if nasted target reference 
  +     *    references an unknown target id
        */
       public LogTarget createTarget( final Configuration config )
           throws LogTargetException
  @@ -90,21 +95,21 @@
               {
                   final String error = 
                     REZ.getString( "multicast.error.missing-id" );
  -                throw new LogTargetException( error );
  +                throw new MissingIdException( error );
               }
               LogTarget target = m_manager.getLogTarget( id );
               if( null == target ) 
               {
                   final String error = 
                     REZ.getString( "multicast.error.unknown-id", id );
  -                throw new LogTargetException( error );
  +                throw new UnknownLogTargetException( error );
               }
               targets[i] = target;
           }
           return new MulticastLogTarget( targets );
       }
   
  -    public class MulticastLogTarget implements LogTarget
  +    private final class MulticastLogTarget implements LogTarget
       {
           private final LogTarget[] m_targets;
   
  
  
  
  1.4       +2 -15     avalon/merlin/logging/logkit/test/conf/logging.xml
  
  Index: logging.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/test/conf/logging.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- logging.xml	27 Jan 2004 19:27:23 -0000	1.3
  +++ logging.xml	28 Jan 2004 10:02:04 -0000	1.4
  @@ -3,20 +3,7 @@
   <logging debug="false">
   
     <!--
  -  Declaration of the log target factories.
  -  -->
  -
  -  <factories>
  -    <factory type="file" 
  -      class="org.apache.avalon.logging.logkit.factory.FileTargetFactory"/>
  -    <factory type="stream" 
  -      class="org.apache.avalon.logging.logkit.factory.StreamTargetFactory"/>
  -    <factory type="multicast" 
  -      class="org.apache.avalon.logging.logkit.factory.MulticastTargetFactory"/>
  -  </factories>
  -
  -  <!--
  -  Declaration of the named log target.
  +  Declaration of the log target.
     -->
   
     <targets>
  @@ -52,7 +39,7 @@
   
     <!--
     Selection of the logging channel for use by the logging
  -  system following establishment.
  +  system following establishment of inital targets and categories.
     -->
   
     <logger name="kernel.logger"/>
  
  
  

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


Mime
View raw message