You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/06/15 20:29:05 UTC

cvs commit: avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder XMLProfileCreator.java

mcconnell    2003/06/15 11:29:05

  Modified:    merlin/meta/src/java/org/apache/avalon/meta/model/builder
                        XMLProfileCreator.java
  Log:
  Upgrading of the management of the Target meta-data to provide support for overriding logging directives.
  
  Revision  Changes    Path
  1.6       +96 -16    avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder/XMLProfileCreator.java
  
  Index: XMLProfileCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder/XMLProfileCreator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLProfileCreator.java	12 Jun 2003 18:56:20 -0000	1.5
  +++ XMLProfileCreator.java	15 Jun 2003 18:29:05 -0000	1.6
  @@ -184,7 +184,25 @@
         Type type, Configuration config, Configuration defaults  )
           throws Exception
       {
  -        return buildProfile( type, config, defaults, Mode.EXPLICIT );
  +        return createProfile( type, config, defaults, null );
  +    }
  +
  +    /**
  +     * Create an explicit {@link Profile} instances from a configuration
  +     * using a set of type defaults and overriding category directives
  +     *
  +     * @param type the component type
  +     * @param config the profile description
  +     * @param defaults a default configuration
  +     * @param logging overriding logging directives
  +     * @return the profile
  +     * @exception Exception if an error occurs during profile creation
  +     */
  +    public Profile createProfile( 
  +      Type type, Configuration config, Configuration defaults, LoggingDirective logging  )
  +        throws Exception
  +    {
  +        return buildProfile( type, config, defaults, logging, Mode.EXPLICIT );
       }
   
       /**
  @@ -221,11 +239,11 @@
           Type type, Configuration profile, Mode mode )
           throws Exception
       {
  -        return buildProfile( type, profile, null, mode );
  +        return buildProfile( type, profile, null, null, mode );
       }
   
       private Profile buildProfile(
  -        Type type, Configuration config, Configuration custom, Mode mode )
  +        Type type, Configuration config, Configuration custom, LoggingDirective logging, Mode mode )
           throws Exception
       {
   
  @@ -235,9 +253,8 @@
   
           final String name = config.getAttribute( "name" );
   
  -        LoggingDirective categories =
  -            createLoggingDirective(
  -                name, config.getChild( "categories" ) );
  +        LoggingDirective categories = createLoggingDirective(
  +                name, config.getChild( "categories" ), logging );
   
           //
           // build the profile directives
  @@ -466,7 +483,23 @@
           String name, Configuration config )
           throws Exception
       {
  -        return createLoggingDirective( name, null, config );
  +        return createLoggingDirective( name, config, null );
  +    }
  +
  +    /**
  +     * Utility method to create a new categories directive.
  +     *
  +     * @param name the categories base path
  +     * @param config the categories directive configuration
  +     * @param logging overriding category directives
  +     * @return the categories directive
  +     * @throws Exception if an error occurs
  +     */
  +    public LoggingDirective createLoggingDirective(
  +        String name, Configuration config, LoggingDirective logging )
  +        throws Exception
  +    {
  +        return createLoggingDirective( name, null, config, logging );
       }
   
       /**
  @@ -475,29 +508,42 @@
        * @param name the categories base path
        * @param level the default priority
        * @param config the categories directive configuration
  +     * @param logging overriding category directives
        * @return the categories directive
        * @throws Exception if an error occurs
        */
       public LoggingDirective createLoggingDirective(
  -        String name, String level, Configuration config )
  +        String name, String level, Configuration config, LoggingDirective logging )
           throws Exception
       {
  -        String priority;
  -        if( level != null )
  +
  +        String priority = config.getAttribute( "priority", null );
  +        if( logging != null )
  +        {
  +            if( logging.getPriority() != null )
  +            {
  +                priority = logging.getPriority();
  +            }
  +        }
  +        else if( level != null )
           {
               priority = level;
           }
  -        else
  +
  +        String target = target = config.getAttribute( "target", null );
  +        if( logging != null )
           {
  -            priority = config.getAttribute( "priority", null );
  +            if( logging.getTarget() != null )
  +            {
  +                target = logging.getTarget();
  +            }
           }
   
  -        final String target = config.getAttribute( "target", null );
           ArrayList list = new ArrayList();
           Configuration[] configs = config.getChildren( "category" );
           for( int i = 0; i < configs.length; i++ )
           {
  -            Category category = createCategory( level, configs[ i ] );
  +            Category category = createCategory( level, configs[ i ], logging );
               list.add( category );
           }
           Category[] categories =
  @@ -530,6 +576,22 @@
       protected Category createCategory( String level, Configuration config )
           throws ConfigurationException
       {
  +        return createCategory( level, config, null );
  +    }
  +
  +    /**
  +     * Utility method to create a new category directive.  Logging directives
  +     * override the overriding priority which overrides the declared priority.
  +     *
  +     * @param level a overriding priority level
  +     * @param config the category directive configuration
  +     * @param logging overriding categories directive
  +     * @return the category directive
  +     * @throws ConfigurationException if an error occurs
  +     */
  +    protected Category createCategory( String level, Configuration config, LoggingDirective logging )
  +        throws ConfigurationException
  +    {
           final String name = config.getAttribute( "name", "" );
           String priority;
           if( level != null )
  @@ -540,7 +602,25 @@
           {
               priority = config.getAttribute( "priority", null );
           }
  -        final String target = config.getAttribute( "target", null );
  +
  +        String target = config.getAttribute( "target", null );
  +
  +        if( logging != null )
  +        {
  +            if( logging.getCategory( name ) != null )
  +            {
  +                Category cat = logging.getCategory( name );
  +                if( cat.getPriority() != null )
  +                {
  +                    priority = cat.getPriority();
  +                }
  +                if( cat.getTarget() != null )
  +                {
  +                    target = cat.getTarget();
  +                }
  +            }
  +        }
  +
           return new Category( name, priority, target );
       }
   
  
  
  

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