avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance DefaultApplianceFactory.java
Date Sun, 20 Apr 2003 12:02:38 GMT
mcconnell    2003/04/20 05:02:38

  Modified:    merlin/assembly/src/java/org/apache/avalon/assembly/appliance
                        DefaultApplianceFactory.java
  Log:
  Linking context keys to source interfaces.
  
  Revision  Changes    Path
  1.7       +55 -28    avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceFactory.java
  
  Index: DefaultApplianceFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultApplianceFactory.java	17 Apr 2003 03:37:22 -0000	1.6
  +++ DefaultApplianceFactory.java	20 Apr 2003 12:02:38 -0000	1.7
  @@ -153,17 +153,29 @@
           // we are building a custom appliance factory
           //
   
  +        LoggingManager logging = null;
           try
           {
  -            Type type = loader.getRepository().getTypeManager()
  -                    .getType( classname );
  -            Profile profile = loader.getRepository().getProfileManager()
  -                    .getProfile( type );
  -            DefaultApplianceContext context =
  -                    new DefaultApplianceContext( profile );
  -            context.put( "urn:assembly:appliance.repository", repository );
  -            context.put( "urn:assembly:logging", system.get( "urn:assembly:logging" ) );
  +            logging = (LoggingManager) system.get( LoggingManager.KEY );
  +        }
  +        catch( ContextException e )
  +        {
  +            final String error = 
  +              "Supplied system context does not container the logging manager.";
  +            throw new ApplianceException( error, e );
  +        }
  +
  +        try
  +        {
  +            Type type = loader.getRepository().getTypeManager().getType( classname );
  +            Profile profile = 
  +              loader.getRepository().getProfileManager().getProfile( type );
  +
  +            DefaultApplianceContext context = new DefaultApplianceContext( profile );
  +            context.put( ApplianceRepository.KEY, repository );
  +            context.put( LoggingManager.KEY, logging );
               context.makeReadOnly();
  +
               Appliance appliance = loader.createAppliance( context, true );
               appliance.assemble( new DependencyGraph() );
               Object factory = appliance.resolve( loader );
  @@ -173,14 +185,15 @@
               } else
               {
                   final String error =
  -                        "Supplied classname '" + classname
  -                        + "' does not implement the ApplianceFactory interface.";
  +                  "Supplied classname '" + classname
  +                  + "' does not implement the ApplianceFactory interface.";
                   throw new ApplianceException( error );
               }
           } catch( Throwable e )
           {
               final String error =
  -                    "Could not create appliance factory using : " + classname;
  +              "Could not create appliance factory using : " 
  +              + classname;
               throw new ApplianceException( error, e );
           }
       }
  @@ -202,13 +215,13 @@
           try
           {
               DefaultLocator locator = new DefaultLocator( context );
  -            locator.put( "urn:assembly:appliance.repository", repository );
  +            locator.put( ApplianceRepository.KEY, repository );
               factory.contextualize( locator );
               factory.initialize();
           } catch( Throwable e )
           {
               final String error =
  -                    "Unexpected error while attempting to create default appliance factory.";
  +              "Unexpected error while attempting to create default appliance factory.";
               throw new ApplianceException( error, e );
           }
           return factory;
  @@ -231,7 +244,7 @@
       public void contextualize( Locator context ) throws ContextException
       {
           m_system = context;
  -        m_repository = (ApplianceRepository) context.get( "urn:assembly:appliance.repository"
);
  +        m_repository = (ApplianceRepository) context.get( ApplianceRepository.KEY );
           m_pool = (PoolManager) context.get( "urn:assembly:threads.manager" );
       }
   
  @@ -278,16 +291,28 @@
           // we are building a custom appliance
           //
   
  -        LifestyleService lifestyle = createLifestyleService( engine, m_pool );
  +        LoggingManager logging = null;
  +        try
  +        {
  +            logging = (LoggingManager) system.get( LoggingManager.KEY );
  +        }
  +        catch( ContextException e )
  +        {
  +            final String error = 
  +              "Supplied system context does not container the logging manager.";
  +            throw new ApplianceException( error, e );
  +        }
  +
  +        LifestyleService lifestyle = createLifestyleService( logging, engine, m_pool );
           DefaultLocator locator = null;
           try
           {
               locator = new DefaultLocator( context );
  +            locator.put( LifestyleService.KEY, lifestyle );
  +            locator.put( ApplianceRepository.KEY, m_repository );
  +            locator.put( ApplianceContext.KEY, context );
               locator.put( "urn:assembly:engine", engine );
  -            locator.put( "urn:assembly:lifestyle.service", lifestyle );
  -            locator.put( "urn:assembly:appliance.context", context );
               locator.put( "urn:assembly:appliance.system", system );
  -            locator.put( "urn:assembly:appliance.repository", m_repository );
               locator.put( "urn:assembly:threads.manager", m_pool );
               locator.makeReadOnly();
           } catch( Throwable e )
  @@ -335,12 +360,15 @@
                           .getProfile( type );
                   DefaultApplianceContext cntx =
                           new DefaultApplianceContext( profile, map );
  +
                   cntx.put( "urn:assembly:engine", engine );
  -                cntx.put( "urn:assembly:lifestyle.service", lifestyle );
  -                cntx.put( "urn:assembly:appliance.context", context );
  +                cntx.put( LifestyleService.KEY, lifestyle );
  +                cntx.put( ApplianceContext.KEY, context );
  +                cntx.put( ApplianceRepository.KEY, m_repository );
  +
                   cntx.put( "urn:assembly:appliance.system", system );
  -                cntx.put( "urn:assembly:appliance.repository", m_repository );
                   cntx.put( "urn:assembly:threads.manager", m_pool );
  +
                   cntx.makeReadOnly();
   
                   Appliance appliance = engine.createAppliance( cntx, false );
  @@ -372,16 +400,16 @@
        * @return the lifestyle service
        */
       private LifestyleService createLifestyleService(
  -            Engine engine, PoolManager pool ) throws ApplianceException
  +            LoggingManager logging, Engine engine, PoolManager pool ) throws ApplianceException
       {
           try
           {
  -            DeploymentService deployment = createDeploymentService();
  +            DeploymentService deployment = createDeploymentService( logging );
               DefaultLifestyleService lifestyle = new DefaultLifestyleService();
               lifestyle.enableLogging( getLogger().getChildLogger( "lifestyle" ) );
               DefaultLocator context = new DefaultLocator();
  +            context.put( DeploymentService.KEY, deployment );
               context.put( "urn:assembly:pool-manager", pool );
  -            context.put( "urn:assembly:lifecycle.deployment", deployment );
               context.put( "urn:assembly:engine.classloader", engine );
               context.makeReadOnly();
               lifestyle.contextualize( context );
  @@ -395,16 +423,15 @@
           }
       }
   
  -    private DeploymentService createDeploymentService()
  +    private DeploymentService createDeploymentService( LoggingManager logging )
               throws ApplianceException
       {
           try
           {
  -            LoggingManager logging = (LoggingManager) m_system.get( "urn:assembly:logging"
);
               DefaultDeploymentService deployment = new DefaultDeploymentService();
               deployment.enableLogging( getLogger() );
               DefaultLocator locator = new DefaultLocator();
  -            locator.put( "urn:assembly:logging.manager", logging );
  +            locator.put( LoggingManager.KEY, logging );
               deployment.contextualize( locator );
               deployment.initialize();
               return deployment;
  
  
  

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


Mime
View raw message