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/registry DefaultRegistry.java
Date Wed, 03 Jul 2002 00:53:15 GMT
mcconnell    2002/07/02 17:53:15

  Modified:    assembly/src/java/org/apache/excalibur/merlin/registry
                        DefaultRegistry.java
  Log:
  enhanced profile aggregation approach
  
  Revision  Changes    Path
  1.3       +143 -76   jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/DefaultRegistry.java
  
  Index: DefaultRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/DefaultRegistry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultRegistry.java	1 Jul 2002 20:14:35 -0000	1.2
  +++ DefaultRegistry.java	3 Jul 2002 00:53:15 -0000	1.3
  @@ -98,6 +98,13 @@
       //=======================================================================
   
      /**
  +    * The parent registry to this registry.
  +    * (not currently in use - will come into effect as registry hierachies as 
  +    * dealt with).
  +    */
  +    private Registry m_parent;
  +
  +   /**
       * The context argument supplied by the container.
       */
       private Context m_context;
  @@ -158,7 +165,34 @@
       public void contextualize( Context context ) throws ContextException
       {
           m_context = context;
  -        m_classloaderParent = (ClassLoader) context.get( CLASSLOADER_KEY );
  +
  +        //
  +        // use the supplied classloader or none supplied get the context
  +        // classloader
  +        //
  +
  +        try
  +        {
  +            m_classloaderParent = (ClassLoader) context.get( CLASSLOADER_KEY );
  +        }
  +        catch( ContextException ce )
  +        {
  +            m_classloaderParent = Thread.currentThread().getContextClassLoader();
  +        }
  +
  +        //
  +        // use the supplied extension manager or none supplied create an empty
  +        // manager
  +        //
  +
  +        try
  +        {
  +            m_repository = (PackageRepository) context.get( Registry.EXTENSIONS_KEY );
  +        }
  +        catch( ContextException ce )
  +        {
  +            m_repository = new DefaultPackageRepository( new File[0] );
  +        }
       }
   
       //=======================================================================
  @@ -180,16 +214,21 @@
   
      /**
       * Invoked by the container to establish services that this component
  -    * is dependent on.  The implementation receives the singelton extensions
  -    * repository which will be used during initalization to construct the 
  -    * registry classloader.
  +    * is dependent on.  The implementation will attempt to locate a parent
  +    * registry (optional dependency).
       *
  -    * @param manager a component manager
  -    * @exception ServiceException if a servicing error occurs
  +    * @param manager a service manager
       */
  -    public void service( ServiceManager manager ) throws ServiceException
  +    public void service( ServiceManager manager )
       {
  -        m_repository = (PackageRepository) manager.lookup( PackageRepository.ROLE );
  +        try
  +        {
  +            m_parent = (Registry) manager.lookup( Registry.ROLE );
  +        }
  +        catch( ServiceException se )
  +        {
  +            m_parent = null;
  +        }
       }
   
       //=======================================================================
  @@ -223,9 +262,8 @@
   
           try
           {
  -
               //
  -            // register all of the the componet providers implied by the classpath
  +            // register all of the the component providers implied by the classpath
               // manifest declarations
               //
   
  @@ -233,6 +271,8 @@
               {
                   // initialize the component type defintions
                   final String classname = blocks[i].replace('/','.');
  +                getLogger().debug("");
  +                getLogger().debug("register classname: " + classname );
                   m_services.register( classname );
               }
   
  @@ -243,19 +283,27 @@
               // construct the application context
               //
   
  -            //getLogger().debug("profile:\n " + ConfigurationUtil.list( m_config ));
               Configuration factories = m_config.getChild("factories");
               Configuration[] entries = factories.getChildren();
               for( int i=0; i<entries.length; i++ )
               {
                   final Configuration factory = entries[i];
  -                getLogger().debug("factory: \n" + ConfigurationUtil.list( factory ));
                   final String name = factory.getAttribute("name");
                   final String classname = factory.getAttribute("class");
                   final String mode = factory.getName();
                   if( mode.equals("component") )
                   {
  -                    m_services.install( classname, name );
  +                    getLogger().debug("install: \n" + ConfigurationUtil.list( factory ));
  +                    Profile profile = m_services.install( classname, name );
  +
  +                    listProfile( profile );
  +
  +                    //
  +                    // create a dependency graph for this component
  +                    //
  +
  +                    DependencyMap map = buildDependencyMap( profile );
  +                    list( map );
                   }
                   else
                   {
  @@ -271,9 +319,32 @@
               final String error = "Internal registry initialization failure.";
               throw new RegistryException( error, e );
           }
  +    }
   
  +    private DependencyMap buildDependencyMap( Profile profile )
  +    {
  +        DependencyMap map = new DependencyMap();
  +        map.add( profile );
  +        DependencyMetaData[] dependencies = profile.getDependencies();
  +        for( int j=0; j<dependencies.length; j++ )
  +        {
  +            populate( map, dependencies[j] );
  +        }
  +        return map;
  +    }
  +
  +    private void populate( DependencyMap map, DependencyMetaData dependency )
  +    {
  +        Profile profile = m_services.getInstalledProfile( dependency.getProviderName()
);
  +        map.add( profile );
  +        DependencyMetaData[] dependencies = profile.getDependencies();
  +        for( int j=0; j<dependencies.length; j++ )
  +        {
  +            populate( map, dependencies[j] );
  +        }
       }
   
  +
       //=======================================================================
       // Executable
       //=======================================================================
  @@ -287,69 +358,7 @@
       */
       public void execute() throws Exception
       {
  -
  -        getLogger().info(
  -           "\n"
  -         + "\n=============================================================="
  -         + "\nBased on the component declared in the profile.xml file "
  -         + "\nlist of the components implied by dependecies to supports "
  -         + "\nexecution." 
  -         + "\n=============================================================="
  -        );
  -
  -        //
  -        // the m_profiles table contain all of the profiles that
  -        // have been selected to act as potential service provider for all of the 
  -        // dependecies - from this point we need to buid the set of profiles needed
  -        // to execute the targets
  -        //
  -
  -        Vector vector = new Vector();
  -        DependencyMap map = new DependencyMap();
  -        Profile[] profiles = m_services.getInstalledProfiles();
  -        for( int i=0; i<profiles.length; i++ )
  -        {
  -            vector.add( profiles[i] );
  -            getLogger().debug("profile: " + profiles[i] );
  -            map.add( (ComponentMetaData) profiles[i] );
  -        }
  -
  -        getLogger().info(
  -           "\n"
  -         + "\n=============================================================="
  -         + "\nVerify the assembly of componentn using the containerkit "
  -         + "\nverification tools."
  -         + "\n=============================================================="
  -        );
  -
  -        ComponentMetaData[] context = (ComponentMetaData[]) vector.toArray(new ComponentMetaData[0]
);
  -        verify( context );
  -
  -        //
  -        // build the ordered sequence of dependecies
  -        //        
  -
  -        getLogger().info(
  -           "\n"
  -         + "\n=============================================================="
  -         + "\nPrepare the component startup ordering.  This is not currently  "
  -         + "\nmaking sense - probably using a wrong approach to DependencyMap "
  -         + "\nusage - more work needed here."
  -         + "\n=============================================================="
  -        );
  -
  -        getLogger().debug("startup sequence");
  -        ComponentMetaData[] startup = map.getStartupGraph();
  -        for( int i=0; i<startup.length; i++ )
  -        {
  -            getLogger().debug("  start: " + startup[i] );
  -        }
  -        getLogger().debug("shutdown sequence");
  -        ComponentMetaData[] shutdown = map.getShutdownGraph();
  -        for( int i=0; i<shutdown.length; i++ )
  -        {
  -            getLogger().debug("  stop: " + shutdown[i] );
  -        }
  +       // nothing to do yet - need to sort out the DependecyMap issue
       }
   
       //=======================================================================
  @@ -466,6 +475,64 @@
               final String error = "Could not load implementation class for service type:
"
                 + classname;
               throw new RegistryException( error, e );
  +        }
  +    }
  +
  +    private void listProfile( Profile profile )
  +    {
  +        List reported = new LinkedList();
  +        listProfile( profile, reported );
  +    }
  +
  +    private void listProfile( Profile profile, List reported )
  +    {
  +        if( !reported.contains( profile ) )
  +        {
  +            getLogger().debug( profile.report() );
  +            reported.add( profile );
  +        }
  +        DependencyMetaData[] dependencies = profile.getDependencies();
  +        for( int j=0; j<dependencies.length; j++ )
  +        {
  +            Profile p = m_services.getInstalledProfile( dependencies[j].getProviderName()
);
  +            listProfile( p, reported );
  +        }
  +    }
  +
  +    private void list( DependencyMap map )
  +    {
  +        try
  +        {
  +            getLogger().debug("DependencyMap listing");
  +            getLogger().debug("startup sequence");
  +            ComponentMetaData[] startup = map.getStartupGraph();
  +            for( int i=0; i<startup.length; i++ )
  +            {
  +                getLogger().debug("  start: " + startup[i] );
  +                //getLogger().debug("    consumers");
  +                //ComponentMetaData[] consumers = map.getConsumerGraph( startup[i] );
  +                //for( int j=0; j<consumers.length; j++ )
  +                //{
  +                //    getLogger().debug("      consumer: " + consumers[j].getName() );
  +                //}
  +                //getLogger().debug("    providers");
  +                //ComponentMetaData[] providers = map.getConsumerGraph( startup[i] );
  +                //for( int j=0; j<providers.length; j++ )
  +                //{
  +                //    getLogger().debug("      provider: " + providers[j].getName() );
  +                //}
  +
  +            }
  +            getLogger().debug("shutdown sequence");
  +            ComponentMetaData[] shutdown = map.getShutdownGraph();
  +            for( int i=0; i<shutdown.length; i++ )
  +            {
  +                getLogger().debug("  stop: " + shutdown[i] );
  +            }
  +        }
  +        catch( Throwable e )
  +        {
  +            getLogger().error("map error", e );
           }
       }
   
  
  
  

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