donaldp     2002/08/19 06:22:15

  Modified:    containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        AbstractServiceKernel.java
  Added:       containerkit/src/java/org/apache/excalibur/containerkit/processor
                        DependencyMap.java
  Removed:     containerkit/src/java/org/apache/excalibur/containerkit/dependency
                        DependencyMap.java package.html
               
containerkit/src/java/org/apache/excalibur/containerkit/dependency/doc-files
                        DependencyMap.gif
  Log:
  Moved DependencyMap between packages.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/processor/DependencyMap.java
  
  Index: DependencyMap.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.containerkit.processor;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  import org.apache.avalon.framework.info.DependencyDescriptor;
  import org.apache.excalibur.containerkit.kernel.ComponentEntry;
  import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  import org.apache.excalibur.containerkit.metadata.DependencyMetaData;
  import org.apache.excalibur.containerkit.store.ComponentStore;
  
  /**
   * Utility class to help aquire a ordered graph of
   * consumers and providers for specific components.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/19 13:22:15 $
   */
  public class DependencyMap
  {
      /**
       * Get the serilized graph of {@link 
org.apache.excalibur.containerkit.kernel.ComponentEntry} objects
       * required when starting up all the components. This makes sure
       * that all providers occur before their coresponding
       * consumers in graph.
       *
       * @return the ordered list of components
       */
      public ComponentEntry[] getStartupGraph( final ComponentStore store )
      {
          return walkGraph( true, store );
      }
  
      /**
       * Get the serilized graph of {@link 
org.apache.excalibur.containerkit.kernel.ComponentEntry} objects
       * required when shutting down all the components. This makes
       * sure that all consumers occur before their coresponding
       * providers in graph.
       *
       * @return the ordered list of components
       */
      public ComponentEntry[] getShutdownGraph( final ComponentStore store )
      {
          return walkGraph( false, store );
      }
  
      /**
       * Get the serilized graph of {@link 
org.apache.excalibur.containerkit.kernel.ComponentEntry} objects
       * that use services of specified component.
       *
       * @param component the component
       * @return the ordered list of consumers
       */
      public ComponentEntry[] getConsumerGraph( final ComponentEntry component,
                                                final ComponentStore store )
      {
          return getComponentGraph( component, false, store );
      }
  
      /**
       * Get the serilized graph of {@link 
org.apache.excalibur.containerkit.kernel.ComponentEntry} objects
       * that provide specified component with services.
       *
       * @param component the component
       * @return the ordered list of providers
       */
      public ComponentEntry[] getProviderGraph( final ComponentEntry component,
                                                final ComponentStore store )
      {
          return getComponentGraph( component, true, store );
      }
  
      /**
       * Get the graph of a single component.
       *
       * @param component the component
       * @param providers true if traversing providers, false if consumers
       * @return the list of components in graph
       */
      private ComponentEntry[] getComponentGraph( final ComponentEntry component,
                                                  final boolean providers,
                                                  final ComponentStore store )
      {
          final ArrayList result = new ArrayList();
          visitcomponent( component,
                          providers,
                          new ArrayList(),
                          result,
                          store );
  
          final ComponentEntry[] returnValue = new ComponentEntry[ result.size() ];
          return (ComponentEntry[])result.toArray( returnValue );
      }
  
      /**
       * Method to generate an ordering of nodes to traverse.
       * It is expected that the specified components have passed
       * verification tests and are well formed.
       *
       * @param providers true if forward dependencys traced, false if dependencies 
reversed
       * @return the ordered node names
       */
      private ComponentEntry[] walkGraph( final boolean providers,
                                          final ComponentStore store )
      {
          final ArrayList result = new ArrayList();
          final ArrayList done = new ArrayList();
  
          final Collection components = store.getComponents();
          final ComponentEntry[] entrySet =
              (ComponentEntry[])components.toArray( new ComponentEntry[ 
components.size() ] );
          for( int i = 0; i < entrySet.length; i++ )
          {
              final ComponentEntry component = entrySet[ i ];
              visitcomponent( component,
                              providers,
                              done,
                              result,
                              store );
          }
  
          final ComponentEntry[] returnValue = new ComponentEntry[ result.size() ];
          return (ComponentEntry[])result.toArray( returnValue );
      }
  
      /**
       * Visit a component when traversing dependencies.
       *
       * @param component the component
       * @param providers true if walking tree looking for providers, else false
       * @param done those nodes already traversed
       * @param order the order in which nodes have already been
       *             traversed
       */
      private void visitcomponent( final ComponentEntry component,
                                   final boolean providers,
                                   final ArrayList done,
                                   final ArrayList order,
                                   final ComponentStore store )
      {
          //If already visited this component then bug out early
          if( done.contains( component ) )
          {
              return;
          }
          done.add( component );
  
          if( providers )
          {
              visitProviders( component, done, order, store );
          }
          else
          {
              visitConsumers( component, done, order, store );
          }
  
          order.add( component );
      }
  
      /**
       * Traverse graph of components that provide services to
       * the specified component.
       *
       * @param component the ComponentEntry
       */
      private void visitProviders( final ComponentEntry component,
                                   final ArrayList done,
                                   final ArrayList order,
                                   final ComponentStore store )
      {
          final DependencyDescriptor[] descriptors =
              component.getInfo().getDependencies();
          final ComponentMetaData metaData = component.getMetaData();
  
          for( int i = 0; i < descriptors.length; i++ )
          {
              final DependencyMetaData dependency =
                  metaData.getDependency( descriptors[ i ].getRole() );
  
              // added != null clause to catch cases where an optional
              // dependency exists and the dependecy has not been bound
              // to a provider
  
              if( dependency != null )
              {
                  final ComponentEntry other =
                      getComponent( dependency.getProviderName(), store );
                  visitcomponent( other, true, done, order, store );
              }
          }
      }
  
      /**
       * Traverse all Consumers of component. ie Anyone that uses
       * service provided by component.
       *
       * @param component the ComponentEntry
       */
      private void visitConsumers( final ComponentEntry component,
                                   final ArrayList done,
                                   final ArrayList order,
                                   final ComponentStore store )
      {
          final String name = component.getMetaData().getName();
  
          final Collection components = store.getComponents();
          final ComponentEntry[] entrySet =
              (ComponentEntry[])components.toArray( new ComponentEntry[ 
components.size() ] );
          for( int i = 0; i < entrySet.length; i++ )
          {
              final ComponentEntry other = entrySet[ i ];
              final DependencyMetaData[] roles =
                  other.getMetaData().getDependencies();
  
              for( int j = 0; j < roles.length; j++ )
              {
                  final String depends = roles[ j ].getProviderName();
                  if( depends.equals( name ) )
                  {
                      visitcomponent( other, false, done, order, store );
                  }
              }
          }
  
          final List childStores = store.getChildStores();
          final int childCount = childStores.size();
          for( int i = 0; i < childCount; i++ )
          {
              final ComponentStore child = (ComponentStore)childStores.get( i );
              visitConsumers( component, done, order, child );
          }
      }
  
      /**
       * Utility method to get component with specified name from specified array.
       *
       * @param name the name of component
       * @return the component
       */
      private ComponentEntry getComponent( final String name,
                                           final ComponentStore store )
      {
          final ComponentEntry component = store.getComponent( name );
          if( null != component )
          {
              return component;
          }
  
          final ComponentStore parent = store.getParent();
          if( null != parent )
          {
              return parent.getComponent( name );
          }
  
          //Should never happen if Verifier passed checks
          throw new IllegalStateException();
      }
  }
  
  
  
  1.24      +3 -3      
jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/AbstractServiceKernel.java
  
  Index: AbstractServiceKernel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/AbstractServiceKernel.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- AbstractServiceKernel.java        19 Aug 2002 12:58:58 -0000      1.23
  +++ AbstractServiceKernel.java        19 Aug 2002 13:22:15 -0000      1.24
  @@ -15,7 +15,7 @@
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.excalibur.containerkit.dependency.DependencyMap;
  +import org.apache.excalibur.containerkit.processor.DependencyMap;
   import org.apache.excalibur.containerkit.factory.ComponentFactory;
   import org.apache.excalibur.containerkit.lifecycle.LifecycleHelper;
   import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
  @@ -57,7 +57,7 @@
        */
       private final ComponentStore m_store = new ComponentStore();
       /**
  -     * The {@link DependencyMap} via which dependency graph is
  +     * The {@link org.apache.excalibur.containerkit.processor.DependencyMap} via 
which dependency graph is
        * produced.
        */
       private final DependencyMap m_dependencyMap = new DependencyMap();
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to