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/04/11 17:51:38 UTC

cvs commit: avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container Container.java ContainerDescriptor.java ContainerException.java ContainerRuntimeException.java StateEvent.java StateListener.java package.html

mcconnell    2003/04/11 08:51:38

  Added:       merlin/merlin-spi/src/java/org/apache/avalon/merlin/container
                        Container.java ContainerDescriptor.java
                        ContainerException.java
                        ContainerRuntimeException.java StateEvent.java
                        StateListener.java package.html
  Removed:     merlin/merlin-core/src/java/org/apache/avalon/merlin/container
                        Container.java ContainerDescriptor.java
                        ContainerException.java
                        ContainerRuntimeException.java StateEvent.java
                        StateListener.java package.html
  Log:
  Moved Container spi content from merlin-core to merlin-spi.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/Container.java
  
  Index: Container.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.assembly.appliance.DependencyGraph;
  
  /**
   * <p>A container is node in a containment heirachy. It defines a scope 
   * scope of execution for the components contained within it.</p>
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  public interface Container
  {
      public static final String KEY = Container.class.getName();
      public static final Version VERSION = Version.getVersion( "1.0" );
      public static final String PATH_SEPERATOR = "/";
  
     /**
      * Startup the components in this container and startup all subsidiary 
      * containers.
      * @exception Exception if a startup error occurs
      */
      void startup() throws Exception;
  
      /**
       * Request for the container to suspend all subsidiary containers
       * and all contained components.
       */
      void suspend();
  
      /**
       * Request for the container to resume all subsidiary containers
       * and all contained components.
       */
      void resume();
  
     /**
      * Shutdown all subsidiary containers and all components in this container.
      * @exception Exception if a shutdown error occurs
      */
      void shutdown();
  
      /**
       * Adds a <code>StateListener</code> to the container.
       * @param listener the state listener to add
       */
      void addStateListener( StateListener listener );
  
      /**
       * Removes a <code>StateListener</code> from the container.
       * @param listener the state listener to remove
       */
      void removeStateListener( StateListener listener );
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/ContainerDescriptor.java
  
  Index: ContainerDescriptor.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  import java.util.ArrayList;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.meta.info.Type;
  import org.apache.avalon.meta.model.LoggingDirective;
  import org.apache.avalon.meta.model.ContextDirective;
  import org.apache.avalon.meta.model.Mode;
  import org.apache.avalon.meta.model.Profile;
  
  /**
   * <p>A container descriptor is a description of the crieria supporting the
   * construction of a container.  It may may include multiple
   * component profile declarations, and multiple nested container declarations.</p>
   *
   * <p><b>XML</b><p>
   * A single container element is required within a kernel defintion.  Multiple
   * container declarations may appear within an enclosing container.
   * <pre>
   *    <font color="gray"><i>&lt;!--
   *    Definition of a container.  The name attribute declares bother the container
   *    name and the base logging category that will be supplied to the container
   *    by its parent.  Logging category defintions declared within the container
   *    declaration are relative to the container name.
   *    --&gt;</i></font>
   *
   *    &lt;container name="<font color="darkred">root</font>"&gt;
   *
   *      <font color="gray"><i>&lt;!--
   *      Classpath declaration.  Classes accessible to a component are constrained
   *      to the classes available in the jar files declared within the immediate
   *      classpath, together with and resources declared in any parent container.
   *      --&gt;</i></font>
   *
   *      &lt;classpath&gt;
   *        &lt;fileset dir="<font color="darkred">dist</font>"&gt;
   *          &lt;include name="<font color="darkred">demo.jar</font>"/&gt;
   *          &lt;include name="<font color="darkred">new-application-1.0.jar</font>"/&gt;
   *        &lt;/fileset&gt;
   *      &lt;/classpath&gt;
   *
   *      <font color="gray"><i>&lt;!--
   *      Logging categories declaration.  Logging categories are relative to the name of the
   *      enaclosing container. Logging priorities and targets will default to the parent
   *      containtains values if undefined.
   *      --&gt;</i></font>
   *
   *      &lt;categories priority="<font color="darkred">INFO</font>"&gt;
   *        &lt;category name="<font color="darkred">profiles</font>" /&gt;
   *        &lt;category name="<font color="darkred">lifecycle</font>" /&gt;
   *        &lt;category name="<font color="darkred">verifier</font>" /&gt;
   *      &lt;/categories&gt;
   *
   *      <font color="gray"><i>&lt;!--
   *      Multiple component profile declarations.  If a component declares dependecies,
   *      the container will attempt to resolve the dependency locally relative to any
   *      other declared components, otherwise, the container will attempt to resolve
   *      the dependecy using services established (explicitly or implicitly) in the
   *      parent containers before attempting a local implicit solution.
   *      --&gt;</i></font>
   *
   *      &lt;component name="<font color="darkred">my-component</font>"
   *         class="<font color="darkred">org.apache.excalibur.playground.SimpleComponent</font>" /&gt;
   *
   *      <font color="gray"><i>&lt;!--
   *      Multiple subsidiary container declarations.
   *      --&gt;</i></font>
   *
   *      &lt;container name="<font color="darkred">child</font>"&gt;
   *        &lt;component name="<font color="darkred">demo-component</font>" class="<font color="darkred">org.apache.excalibur.playground.BasicComponent</font>" /&gt;
   *      &lt;container&gt;
   *
   *    &lt;/container&gt;
   * </pre>
   *
   * @see org.apache.avalon.meta.model.Profile
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  public class ContainerDescriptor extends Profile
  {
      //========================================================================
      // static
      //========================================================================
  
      /**
       * Container path delimiter.
       */
      public static final String DELIMITER = "/";
  
      //========================================================================
      // state
      //========================================================================
  
      /**
       * The component described within the scope of the container.
       */
      private final ArrayList m_components = new ArrayList();
  
      /**
       * The containers described within the scope of the container.
       */
      private final ArrayList m_containers = new ArrayList();
  
      //========================================================================
      // constructors
      //========================================================================
  
      /**
       * Create a ContainerDescriptor instance.
       *
       * @param name the abstract name of component meta data instance
       * @param parameters the parameters instance to use during type instantiation
       * @param configuration the configuration instance to use during type instantiation
       * @param context the context instance to use during type instantiation
       * @param categories the logging categories descriptor
       * @param type the type of component that this profile qualifies
       * @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
       */
      public ContainerDescriptor( final String name,
                                  final Parameters parameters,
                                  final Configuration configuration,
                                  final ContextDirective context,
                                  final LoggingDirective categories,
                                  final Type type,
                                  final Mode mode )
      {
          super(
              name, parameters, configuration, context, categories, type, mode
          );
      }
  
      //========================================================================
      // implementation
      //========================================================================
  
      /**
       * Add a component profile to this container.
       *
       * @param component the component profile to add to the container
       */
      public void addComponent( Profile component )
      {
          if( !m_components.contains( component ) )
          {
              m_components.add( component );
          }
      }
  
      /**
       * Return the set of component descriptors contained within this container.
       *
       * @return the target descriptors
       */
      public Profile[] getComponents()
      {
          return (Profile[])m_components.toArray( new Profile[ 0 ] );
      }
  
      /**
       * Return the set of component descriptors contained within this container matching
       * the supplied mode.
       *
       * @param mode one of enumerated value {@link Mode#IMPLICIT}, {@link Mode#PACKAGED},
       *    or {@link Mode#EXPLICIT}
       * @param enabled TRUE to select enabled components, FALSE returns disabled components
       * @return the profiles matching the supplied creation mode
       */
      public Profile[] getComponents( Mode mode )
      {
          ArrayList list = new ArrayList();
          Profile[] components = getComponents( );
          return selectComponentsByMode( components, mode );
      }
  
      /**
       * Returns a sub-set of the supplied containers matching the supplied creation mode.
       * @param components the compoennts to select from
       * @param mode the creation mode to retrict the returned selection to
       * @param the subset of the supplied components with a creation mode matching
       *   the supplied mode value
       */
      private Profile[] selectComponentsByMode( Profile[] components, Mode mode )
      {
          ArrayList list = new ArrayList();
          for( int i = 0; i < components.length; i++ )
          {
              Profile component = components[ i ];
              if( component.getMode().equals( mode ) )
              {
                  list.add( component );
              }
          }
          return (Profile[])list.toArray( new Profile[ 0 ] );
      }
  
      /**
       * Add a container profile to this container.
       *
       * @param container the container profile to add to the container
       */
      public void addContainer( ContainerDescriptor container )
      {
          if( !m_containers.contains( container ) )
          {
              m_containers.add( container );
          }
      }
  
      /**
       * Return the set of container descriptors contained within this container.
       *
       * @return the container descriptors
       */
      public ContainerDescriptor[] getContainers()
      {
          return (ContainerDescriptor[])m_containers.toArray( new ContainerDescriptor[ 0 ] );
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/ContainerException.java
  
  Index: ContainerException.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  import org.apache.avalon.framework.CascadingException;
  
  /**
   * Exception to indicate that there was a container related error.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  public final class ContainerException
      extends CascadingException
  {
  
      /**
       * Construct a new <code>ContainerException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public ContainerException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>ContainerException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public ContainerException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/ContainerRuntimeException.java
  
  Index: ContainerRuntimeException.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  
  /**
   * Exception to indicate that there was a container related runtime error.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  public final class ContainerRuntimeException
      extends CascadingRuntimeException
  {
  
      /**
       * Construct a new <code>ContainerRuntimeException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public ContainerRuntimeException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>ContainerRuntimeException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public ContainerRuntimeException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/StateEvent.java
  
  Index: StateEvent.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  import java.util.EventObject;
  
  /**
   * The <code>StateEvent</code> is an event raised by a component
   * signally a change in state.
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  public class StateEvent extends EventObject
  {
      //============================================================
      // static
      //============================================================
  
      /**
       * Static state enumeration value indicating that the state of a container is unknown.
       */
      public static final int UNKNOWN = 0;
  
      /**
       * Static state enumeration value indicating that a container has been initialized,
       * all of its subsidiary containers have been initialized, and all component profiles
       * have been assembled.
       */
      public static final int INITIALIZED = 1;
  
      /**
       * Static state enumeration value indicating that a container has completed
       * lifecycle processing on all components requesting startup establishment.
       */
      public static final int STARTED = 2;
  
      /**
       * Static state enumeration value indicating that a container has been suspended.
       */
      public static final int SUSPENDED = 3;
  
      /**
       * Static state enumeration value indicating that a container has completed
       * the shutdown of all subsidiary containers and the internal components
       * have been shutdown.
       */
      public static final int STOPPED = 4;
  
  
      //============================================================
      // state
      //============================================================
  
      /**
       * Container state.
       */
      private final int m_state;
  
      /**
       * Error condition
       */
      private Throwable m_error;
  
      /**
       * The name of the container.
       */
      private String m_name;
  
      //============================================================
      // constructor
      //============================================================
  
      /**
       * Creation of a new StateEvent.
       *
       * @param source the source container
       * @param name the name of the soource container
       * @param state int value of (@link #INITIALIZED}, {@link #STARTED},
       *    {@link #SUSPENDED}, or {@link #STOPPED}
       */
      public StateEvent( Object source, String name, int state )
      {
          this( source, name, state, null );
      }
  
      /**
       * Creation of a new StateEvent.
       *
       * @param source the source container
       * @param name the name of the soource container
       * @param state int value of (@link #INITIALIZED}, {@link #STARTED},
       *    {@link #SUSPENDED}, or {@link #STOPPED}
       * @param error an error condition triggering the state change
       */
      public StateEvent( Object source, String name, int state, Throwable error )
      {
          super( source );
          m_state = state;
          m_name = name;
          m_error = error;
      }
  
      //============================================================
      // StateEvent
      //============================================================
  
      /**
       * Returns the name of the container raising the event.
       * @return the container name
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Returns the state that the component has raised inidicating
       * that the component has completed transitioning to that state.
       * @return the state
       */
      public int getState()
      {
          return m_state;
      }
  
      /**
       * Returns a throwable causing the state change.  This is normally a
       * null value.  If not null, the transition was a result of an error
       * condition.
       * @return the error condition
       */
      public Throwable getError()
      {
          return m_error;
      }
  
     /**
      * Return a string representation of the event.
      */
      public String toString()
      {
          return "[" + getName() + ", " + getStateAsString() + "]";
      }
  
      private String getStateAsString()
      {
          if( m_state == INITIALIZED )
          {
              return "INITIALIZED";
          }
          else if( m_state == STARTED )
          {
              return "STARTED";
          }
          else if( m_state == SUSPENDED )
          {
              return "SUSPENDED";
          }
          else if( m_state == STOPPED )
          {
              return "STOPPED";
          }
          return "UNKNOWN";
      }
  
  }
  
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/StateListener.java
  
  Index: StateListener.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.avalon.merlin.container;
  
  /**
   * A <code>StateListener</code> listens to <code>StateEvent</code> events.
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/11 15:51:38 $
   */
  
  public interface StateListener
  {
  
      /**
       * Method invoked when a container state changes.
       * @param event the state event
       */
      void stateChanged( StateEvent event );
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-spi/src/java/org/apache/avalon/merlin/container/package.html
  
  Index: package.html
  ===================================================================
  
  <body>
  <p>The container package provides support for a heirachical containment runtime environment.</p> 
  <p>
    <table border="1" cellpadding="3" cellspacing="0" width="100%">
      <tr bgcolor="#ccccff">
        <td colspan="2"><font size="+2"><b>Component Summary</b></font></td>
      <tr>
        <td width="20%" valign="top"><strong>{@link org.apache.avalon.merlin.container.impl.DefaultContainer}</strong></td>
        <td>A <code>{@link org.apache.avalon.merlin.container.Container}</code> implementation that provides support for the management of a containment heirachy.  A container manages a set of contained components together with a set of container containers.  A containment heirachy represents an implementation strategy appropriate for block level deployment.</td></tr>
      </tr>
    </table>
  </p>
  </body>
  
  
  
  

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