avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system AbstractContainer.java
Date Tue, 29 Jan 2002 19:11:17 GMT
bloritsch    02/01/29 11:11:17

  Modified:    src/scratchpad/org/apache/avalon/excalibur/system
                        AbstractContainer.java
  Log:
  added some error trapping on init and dispose code
  
  Revision  Changes    Path
  1.3       +59 -16    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractContainer.java	29 Jan 2002 16:18:53 -0000	1.2
  +++ AbstractContainer.java	29 Jan 2002 19:11:17 -0000	1.3
  @@ -13,6 +13,7 @@
   import org.apache.avalon.framework.context.*;
   import org.apache.avalon.framework.logger.*;
   
  +import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
   import org.apache.avalon.excalibur.command.*;
   import org.apache.avalon.excalibur.system.handler.*;
   import org.apache.avalon.excalibur.logger.LoggerManager;
  @@ -33,12 +34,19 @@
    * Manager can expose that to the instantiating class.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2002/01/29 16:18:53 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/01/29 19:11:17 $
    */
   public abstract class AbstractContainer
      extends AbstractLogEnabled
      implements Contextualizable, Composable, Configurable, Initializable, Disposable
   {
  +    private final static Class[] HANDLER_CONSTRUCTOR = new Class[] {
  +        Class.class,
  +        Configuration.class,
  +        ComponentManager.class,
  +        Context.class
  +    };
  +
       private final ComponentStateValidator  m_validator = new ComponentStateValidator( this
);
   
       private Context                m_context;
  @@ -137,13 +145,41 @@
           m_validator.checkInitialized();
   
           Iterator i = m_components.iterator();
  +        FixedSizeBuffer buffer = new FixedSizeBuffer( m_components.size() );
   
           while ( i.hasNext() )
           {
  -            m_commandQueue.enqueue(
  -                new InitComponentHandlerCommand( (ComponentHandler) i.next(),
  -                                                 getLogger() )
  -            );
  +            try
  +            {
  +                if ( null != m_commandQueue )
  +                {
  +                    m_commandQueue.enqueue(
  +                        new InitComponentHandlerCommand( (ComponentHandler) i.next(),
  +                                                         getLogger() )
  +                    );
  +                }
  +                else
  +                {
  +                    ( (ComponentHandler) i.next() ).initialize();
  +                }
  +            }
  +            catch ( Exception e )
  +            {
  +                getLogger().warn( "Could not initialize component", e );
  +                buffer.add( e );
  +            }
  +        }
  +
  +        if ( buffer.size() > 0 )
  +        {
  +            StringBuffer message = new StringBuffer();
  +
  +            while ( ! buffer.isEmpty() )
  +            {
  +                message.append( ( (Exception) buffer.remove() ).getMessage() );
  +            }
  +
  +            throw new Exception( message.toString() );
           }
       }
   
  @@ -158,21 +194,28 @@
   
           while ( i.hasNext() )
           {
  -            try
  +            if ( null != m_commandQueue )
               {
  -                m_commandQueue.enqueue(
  -                    new DisposeComponentHandlerCommand( (ComponentHandler) i.next(),
  -                                                        getLogger() )
  -                );
  +                try
  +                {
  +                    m_commandQueue.enqueue(
  +                        new DisposeComponentHandlerCommand( (ComponentHandler) i.next(),
  +                                                            getLogger() )
  +                    );
   
  -                i.remove();
  -            }
  -            catch ( Exception e )
  -            {
  -                if ( getLogger().isWarnEnabled() )
  +                    i.remove();
  +                }
  +                catch ( Exception e )
                   {
  -                    getLogger().warn( "Could not dispose component", e );
  +                    if ( getLogger().isWarnEnabled() )
  +                    {
  +                        getLogger().warn( "Could not dispose component", e );
  +                    }
                   }
  +            }
  +            else
  +            {
  +                ( (ComponentHandler) i.next() ).dispose();
               }
           }
       }
  
  
  

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