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/assembly/src/java/org/apache/excalibur/merlin/model/builder XMLProfileCreator.java
Date Sat, 13 Jul 2002 15:35:25 GMT
mcconnell    2002/07/13 08:35:25

  Modified:    assembly/demo/src/java/org/apache/excalibur/playground
                        ComplexComponent.java
               assembly/src/etc kernel.xml
               assembly/src/java/org/apache/excalibur/merlin/container
                        DefaultContainer.java ProfileRegistry.java
               assembly/src/java/org/apache/excalibur/merlin/model
                        ComponentProfile.java ContainerDescriptor.java
                        Profile.java
               assembly/src/java/org/apache/excalibur/merlin/model/builder
                        XMLProfileCreator.java
  Log:
  added support for the declaration of disabled/enabled components in an assembly
  
  Revision  Changes    Path
  1.6       +1 -1      jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ComplexComponent.java
  
  Index: ComplexComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ComplexComponent.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ComplexComponent.java	13 Jul 2002 00:09:44 -0000	1.5
  +++ ComplexComponent.java	13 Jul 2002 15:35:25 -0000	1.6
  @@ -103,7 +103,7 @@
                   {
                       try
                       {
  -                        Thread.currentThread().sleep( 1000 );
  +                        Thread.currentThread().sleep( 100 );
                       }
                       catch( Throwable e )
                       {
  
  
  
  1.10      +4 -3      jakarta-avalon-excalibur/assembly/src/etc/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/etc/kernel.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- kernel.xml	12 Jul 2002 15:16:37 -0000	1.9
  +++ kernel.xml	13 Jul 2002 15:35:25 -0000	1.10
  @@ -158,10 +158,11 @@
   
         <!--
         including the next entry demonstrates the resolution of a dependency via a profile
  -      resolved from a parent container. SimpleComponent needs BasicService with is availble
  -      from either TerminalComponent or BasicComponent.
  +      resolved from a parent container. SimpleComponent needs BasicService with is available
  +      from either TerminalComponent or BasicComponent implicitly created in the parent

  +      container path (due to a depenency declared by ComplexComponent).
         -->
  -      <component name="simple2" class="org.apache.excalibur.playground.SimpleComponent"/>
  +      <component name="simple2" class="org.apache.excalibur.playground.SimpleComponent"
enabled="true"/>
   
        </container>
        <container name="empty"/>
  
  
  
  1.6       +17 -4     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.java
  
  Index: DefaultContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/DefaultContainer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultContainer.java	13 Jul 2002 13:39:00 -0000	1.5
  +++ DefaultContainer.java	13 Jul 2002 15:35:25 -0000	1.6
  @@ -70,6 +70,7 @@
   import org.apache.excalibur.merlin.model.CategoryDescriptor;
   import org.apache.excalibur.merlin.model.verifier.AssemblyVerifier;
   import org.apache.excalibur.merlin.model.verifier.MetaDataVerifier;
  +import org.apache.excalibur.merlin.model.builder.ProfileBuilder;
   import org.apache.excalibur.merlin.kernel.ContainerClassLoader;
   import org.apache.excalibur.merlin.kernel.DefaultLoggerManager;
   import org.apache.excalibur.merlin.Verifiable;
  @@ -164,6 +165,9 @@
   
       private Hashtable m_profileToObjectMap = new Hashtable();
   
  +    private ProfileBuilder m_builder = new ProfileBuilder();
  +
  +
       //=======================================================================
       // Contextualizable
       //=======================================================================
  @@ -221,21 +225,30 @@
           //
   
           getLogger().debug("explicit profile registration");
  -        ComponentProfile[] children = m_descriptor.getComponents();
  +        ComponentProfile[] children = m_descriptor.getComponents( Profile.EXPLICIT, true
);
           for( int i=0; i<children.length; i++ )
           {
               m_profiles.register( children[i] );
           }
   
           // 
  -        // packaged and implict profile registration
  +        // add packaged and implict profile registration
           //
   
           getLogger().debug("packaged and implicit profile registration");
           Type[] types = m_classloader.getTypes();
           for( int i=0; i<types.length; i++ )
           {
  -            m_profiles.register( types[i] );
  +            Profile[] profiles = m_builder.build( types[i], m_classloader );
  +            for( int j=0; j<profiles.length; j++ )
  +            {
  +                Profile profile = profiles[j];
  +                if( profile instanceof ComponentProfile )
  +                {
  +                    m_descriptor.addComponent( (ComponentProfile) profile );
  +                    m_profiles.register( profile );
  +                }
  +            }
           }
   
           try
  
  
  
  1.6       +32 -23    jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/ProfileRegistry.java
  
  Index: ProfileRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/ProfileRegistry.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProfileRegistry.java	13 Jul 2002 13:39:00 -0000	1.5
  +++ ProfileRegistry.java	13 Jul 2002 15:35:25 -0000	1.6
  @@ -114,7 +114,7 @@
       public Profile[] getProviders( ServiceDesignator designator )
       {
           ArrayList list = new ArrayList();
  -        ComponentProfile[] local = m_descriptor.getComponents();
  +        ComponentProfile[] local = m_descriptor.getComponents( true );
           for( int i=0; i<local.length; i++ )
           {
               Profile profile = local[i];
  @@ -133,8 +133,9 @@
   
      /**
       * Register a potential supplier component type.  The implementation will
  -    * create a component type instance for the entry if not already known and 
  -    * return the existing or new instance to the invoking client.
  +    * create a component profile instance for the type if not already known and 
  +    * return the existing or new instance to the invoking client based on packaged
  +    * profiles associated with the type.
       *
       * @param classname the component class name
       * @return the component type
  @@ -145,17 +146,35 @@
           for( int i=0; i<profiles.length; i++ )
           {
               Profile profile = profiles[i];
  +            
               register( profile );
           }
           return profiles;
       }
   
      /**
  +    * Register the type resulting in the cross-referencing of the type with the set of

  +    * service tables that the type is is capable of supporting.
  +    */
  +    public Profile register( Profile profile )
  +    {
  +        String name = profile.getName();
  +        m_profiles.put( name, profile );
  +        getLogger().debug( "" + profile );
  +        ServiceDescriptor[] services = profile.getType().getServices();
  +        for( int i=0; i<services.length; i++ )
  +        {
  +            register( services[i].getService(), profile );
  +        }
  +        return profile;
  +    }
  +
  +   /**
       * For all of the explicity declared profiles, initiate dependency correlation.
       */
       public void assembleProfiles() throws Exception
       {
  -        Profile[] profiles = m_descriptor.getComponents();
  +        Profile[] profiles = m_descriptor.getComponents( Profile.EXPLICIT, true );
           for( int i=0; i<profiles.length; i++ )
           {
               Profile profile = profiles[i];
  @@ -200,28 +219,12 @@
           return (Profile) m_profiles.get( name );
       }
   
  -   /**
  -    * Register the type resulting in the cross-referencing of the type with the set of

  -    * service tables that the type is is capable of supporting.
  -    */
  -    public Profile register( Profile profile )
  -    {
  -        String name = profile.getName();
  -        m_profiles.put( name, profile );
  -        getLogger().debug( "" + profile );
  -        ServiceDescriptor[] services = profile.getType().getServices();
  -        for( int i=0; i<services.length; i++ )
  -        {
  -            register( services[i].getService(), profile );
  -        }
  -        return profile;
  -    }
  -
       private void assemble( Profile profile, List visited, String pad ) throws Exception
       {
           getLogger().debug( pad + "assemble: " + profile );
           String pad2 = pad + "  ";
           visited.add( profile );
  +        String warning = null;
           DependencyDescriptor[] dependencies = profile.getType().getDependencies();
           for( int i=0; i<dependencies.length; i++ )
           {
  @@ -233,7 +236,13 @@
                   Profile[] facilities = getFacilities( dependency.getService() );
                   Profile provider = selectProfile( dependency, facilities, candidates );
                   if( provider == null )
  -                  throw new UnresolvedProviderException("no available provider", dependency
);
  +                {
  +                    profile.setEnabled( false );
  +                    warning = "Disabling profile '" + profile.getName() 
  +                     + "' due to non-resolution of a provider for the role '" 
  +                     + role + "'.";
  +                    throw new UnresolvedProviderException( warning, dependency );
  +                }
                   profile.addProvider( provider, role );
                   if( isLocalProfile( provider ) ) 
                   {
  
  
  
  1.2       +3 -2      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ComponentProfile.java
  
  Index: ComponentProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ComponentProfile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComponentProfile.java	12 Jul 2002 16:30:38 -0000	1.1
  +++ ComponentProfile.java	13 Jul 2002 15:35:25 -0000	1.2
  @@ -38,9 +38,10 @@
                              final Context context,
                              final CategoryDescriptor loggers,
                              final Type type,
  +                           final boolean enabled,
                              final int mode )
       {
  -        super( name, parameters, configuration, context, loggers, type, mode );
  +        super( name, parameters, configuration, context, loggers, type, enabled, mode );
       }
   
   }
  
  
  
  1.4       +58 -1     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContainerDescriptor.java
  
  Index: ContainerDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContainerDescriptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ContainerDescriptor.java	13 Jul 2002 13:39:00 -0000	1.3
  +++ ContainerDescriptor.java	13 Jul 2002 15:35:25 -0000	1.4
  @@ -132,6 +132,63 @@
       }
   
       /**
  +     * Return the set of enabled or disable components based on the supplied criteria.
  +     * @param enabled TRUE to select enabled components, FALSE returs disabled components

  +     * @return the descriptors matching the supplied enabled status
  +     */
  +    public ComponentProfile[] getComponents( boolean enabled )
  +    {
  +        ArrayList list = new ArrayList();
  +        ComponentProfile[] components = getComponents();
  +        for( int i=0; i<components.length; i++ )
  +        {
  +            ComponentProfile component = components[i];
  +            if( component.isEnabled() == enabled )
  +              list.add( component );
  +         }
  +        return (ComponentProfile[] ) list.toArray( new ComponentProfile[0] );
  +    }
  +
  +    /**
  +     * Return the set of component descriptors contained within this container matching
  +     * the supplied mode.
  +     * @param mode one of enumerated value {@link Profile#IMPLICIT}, {@link Profile#PACKAGED},

  +     *    or {@link Profile#EXPLICIT}
  +     * @param enabled TRUE to select enabled components, FALSE returs disabled compoents

  +     * @return the descriptors matching the supplied creation mode
  +     */
  +    public ComponentProfile[] getComponents( int mode, boolean enabled )
  +    {
  +        ArrayList list = new ArrayList();
  +        ComponentProfile[] components = getComponents( enabled );
  +        return selectComponentsByMode( components, mode );
  +    }
  +
  +    /**
  +     * Return the set of component descriptors contained within this container matching
  +     * the supplied mode.
  +     * @param mode one of enumerated value {@link Profile#IMPLICIT}, {@link Profile#PACKAGED},

  +     *    or {@link Profile#EXPLICIT}, 
  +     * @return the descriptors matching the supplied creation mode
  +     */
  +    public ComponentProfile[] getComponents( int mode )
  +    {
  +        return selectComponentsByMode( getComponents(), mode );
  +    }
  +
  +    private ComponentProfile[] selectComponentsByMode( ComponentProfile[] components, int
mode )
  +    {
  +        ArrayList list = new ArrayList();
  +        for( int i=0; i<components.length; i++ )
  +        {
  +            ComponentProfile component = components[i];
  +            if( component.getMode() == mode )
  +              list.add( component );
  +         }
  +        return (ComponentProfile[] ) list.toArray( new ComponentProfile[0] );
  +    }
  +
  +    /**
        * Add a container profile to this container.
        *
        * @parent the container to add
  
  
  
  1.4       +29 -1     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java
  
  Index: Profile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Profile.java	13 Jul 2002 00:09:45 -0000	1.3
  +++ Profile.java	13 Jul 2002 15:35:25 -0000	1.4
  @@ -82,6 +82,11 @@
        */
       private final int m_mode;
   
  +    /**
  +     * The enabled status of the profile.  Normally a profile is enabled however, a 
  +     * failure to assemble will result in the disabling of the profile.
  +     */
  +    private boolean m_enabled = true;
   
       /**
        * Create a Profile instance.
  @@ -96,6 +101,7 @@
                              final Context context,
                              final CategoryDescriptor loggers,
                              final Type type,
  +                           final boolean enabled,
                              final int mode )
       {
           if( null == name )
  @@ -117,7 +123,29 @@
           m_type = type;
           m_context = context;
           m_loggers = loggers;
  +        m_enabled = enabled;
           m_mode = mode;
  +    }
  +
  +    /**
  +     * Test is this profile is enabled.  A profile is enabled unless explicitly disabled
by an
  +     * assembly directive, or implicity disabled as a result of an assembly failure.
  +     *
  +     * @return TRUE if the profile is enabled.
  +     * @see #isAvailable()
  +     */
  +    public boolean isEnabled()
  +    {
  +        return m_enabled;
  +    }
  +
  +   /**
  +    * Set the enabled status of the profile to the supplied value.
  +    * @param value the enabled status - TRUE or FALSE
  +    */
  +    public void setEnabled( boolean value )
  +    {
  +        m_enabled = value;
       }
   
       /**
  
  
  
  1.3       +4 -3      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java
  
  Index: XMLProfileCreator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLProfileCreator.java	12 Jul 2002 19:09:27 -0000	1.2
  +++ XMLProfileCreator.java	13 Jul 2002 15:35:25 -0000	1.3
  @@ -84,7 +84,7 @@
                 type.getInfo().getName(), null, null );
   
               return new Profile[]{ 
  -               new ComponentProfile( null, null, null, null, loggers, type, Profile.IMPLICIT
 ) };
  +               new ComponentProfile( null, null, null, null, loggers, type, true, Profile.IMPLICIT
 ) };
           }
           for( int i=0; i<profiles.length; i++ )
           {
  @@ -106,13 +106,14 @@
           {
               name = profile.getAttribute("name");
           }
  +        boolean enabled = profile.getAttributeAsBoolean( "enabled", true );
           Parameters params = Parameters.fromConfiguration( profile.getChild("parameters")
);
           Configuration config = profile.getChild("configuration");
           Configuration loggersConfig = profile.getChild("loggers");
           CategoryDescriptor loggers = createCategoryDescriptor( loggersConfig, name );
           Context context = ContextFactory.createContextFromConfiguration( 
             null, profile.getChild("context") );
  -        return new ComponentProfile( name, params, config, context, loggers, type, mode
 );
  +        return new ComponentProfile( name, params, config, context, loggers, type, enabled,
mode  );
       }
   
       public CategoryDescriptor createCategoryDescriptor( Configuration config, String fallback
) 
  
  
  

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