avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel SimpleServiceKernel.java SimpleResourceProvider.java
Date Fri, 02 Aug 2002 09:39:40 GMT
donaldp     2002/08/02 02:39:40

  Modified:    containerkit/src/java/org/apache/excalibur/containerkit/kernel/components
                        Main.java
               containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        SimpleServiceKernel.java
                        SimpleResourceProvider.java
  Log:
  Use MetaData loader abstraction
  
  Revision  Changes    Path
  1.2       +8 -10     jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/components/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/components/Main.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Main.java	25 Jun 2002 07:43:24 -0000	1.1
  +++ Main.java	2 Aug 2002 09:39:40 -0000	1.2
  @@ -7,14 +7,12 @@
    */
   package org.apache.excalibur.containerkit.kernel.components;
   
  +import java.net.URL;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  -import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.excalibur.containerkit.kernel.SimpleServiceKernel;
  -import org.xml.sax.InputSource;
  -import java.io.InputStream;
   
   /**
    *
  @@ -30,12 +28,12 @@
           SimpleServiceKernel serviceKernel = new SimpleServiceKernel();
           final Logger logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
           ContainerUtil.enableLogging( serviceKernel, logger );
  -        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  -        final InputStream resourceAsStream = Main.class.getResourceAsStream( "config.xml"
);
  -        final InputSource input = new InputSource( resourceAsStream );
  -        final Configuration configuration = builder.build( input );
  -        ContainerUtil.configure( serviceKernel, configuration );
  +        final URL resource = Main.class.getResource( "config.xml" );
  +        final Parameters parameters = new Parameters();
  +        parameters.setParameter( "config-url", resource.toExternalForm() );
  +        ContainerUtil.parameterize( serviceKernel, parameters );
           ContainerUtil.initialize( serviceKernel );
           Thread.sleep( 2000 );
  +        ContainerUtil.shutdown( serviceKernel );
       }
   }
  
  
  
  1.7       +35 -76    jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/SimpleServiceKernel.java
  
  Index: SimpleServiceKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/SimpleServiceKernel.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleServiceKernel.java	19 Jul 2002 01:05:22 -0000	1.6
  +++ SimpleServiceKernel.java	2 Aug 2002 09:39:40 -0000	1.7
  @@ -7,17 +7,15 @@
    */
   package org.apache.excalibur.containerkit.kernel;
   
  -import java.util.ArrayList;
  -import java.util.HashMap;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.containerkit.infobuilder.ComponentInfoBuilder;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +import org.apache.avalon.framework.parameters.Parameterizable;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.excalibur.containerkit.factory.ComponentFactory;
  +import org.apache.excalibur.containerkit.factory.DefaultComponentFactory;
   import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
   import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  -import org.apache.excalibur.containerkit.metadata.DependencyMetaData;
  -import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
   
   /**
    * This is a simple ServiceKernel.
  @@ -31,100 +29,61 @@
    */
   public class SimpleServiceKernel
       extends AbstractServiceKernel
  -    implements Configurable
  +    implements Parameterizable
   {
  -    private final ComponentInfoBuilder m_infoBuilder = new ComponentInfoBuilder();
  +    private final static Resources REZ =
  +        ResourceManager.getPackageResources( SimpleServiceKernel.class );
   
  -    private Configuration m_configuration;
  -    private final HashMap m_infos = new HashMap();
  +    private ComponentFactory m_factory;
  +    private MetaDataBuilder m_metaDataBuilder;
  +    private String m_configURL;
   
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  +    public void parameterize( final Parameters parameters )
  +        throws ParameterException
       {
  -        m_configuration = configuration;
  -    }
  -
  -    public void enableLogging( final Logger logger )
  -    {
  -        super.enableLogging( logger );
  -        setupLogger( m_infoBuilder, "infobuilder" );
  +        m_configURL = parameters.getParameter( "config-url" );
       }
   
       public void initialize()
           throws Exception
       {
  -        super.initialize();
  +        m_factory = new DefaultComponentFactory( getClass().getClassLoader() );
  +        setupLogger( m_factory, "factory" );
   
  -        final Configuration[] children =
  -            m_configuration.getChildren( "component" );
  -        loadComponentDatas( children );
  +        m_metaDataBuilder = new SimpleMetaDataBuilder();
  +        setupLogger( m_factory, "builder" );
   
  -        startupAllComponents();
  -    }
  +        super.initialize();
   
  -    private void loadComponentDatas( final Configuration[] components )
  -        throws Exception
  -    {
  +        final ComponentMetaData[] components = m_metaDataBuilder.loadMetaData( m_configURL,
m_factory );
           for( int i = 0; i < components.length; i++ )
           {
  -            loadComponentData( components[ i ] );
  +            final ComponentMetaData component = components[ i ];
  +            addComponent( component );
           }
  -    }
   
  -    private void loadComponentData( final Configuration component )
  -        throws Exception
  -    {
  -        final String name = component.getAttribute( "name" );
  -        final String impl = component.getAttribute( "impl" );
  -        final Configuration config = component.getChild( "config" );
  -        final ComponentInfo info = getComponentInfo( impl );
  -        final DependencyMetaData[] dependencies =
  -            parseAssociations( component.getChildren( "provide" ) );
  -
  -        final ComponentMetaData profile =
  -            new ComponentMetaData( name, dependencies, null, config, info );
  -        addComponent( profile );
  +        startupAllComponents();
       }
   
  -    private DependencyMetaData[] parseAssociations( final Configuration[] provides )
  -        throws ConfigurationException
  +    public void dispose()
       {
  -        final ArrayList associations = new ArrayList();
  -        for( int i = 0; i < provides.length; i++ )
  +        try
           {
  -            final Configuration provide = provides[ i ];
  -            final String role = provide.getAttribute( "role" );
  -            final String provider = provide.getAttribute( "name" );
  -            final DependencyMetaData association = new DependencyMetaData( role, provider
);
  -            associations.add( association );
  +            shutdownAllComponents();
           }
  -        return (DependencyMetaData[])associations.toArray( new DependencyMetaData[ associations.size()
] );
  -    }
  -
  -    private ComponentInfo getComponentInfo( final String impl )
  -        throws Exception
  -    {
  -        ComponentInfo info = (ComponentInfo)m_infos.get( impl );
  -        if( null == info )
  +        catch( final Exception e )
           {
  -            info = createComponentInfo( impl );
  -            m_infos.put( impl, info );
  +            final String message =
  +                REZ.getString( "provider-shutdown.error" );
  +            getLogger().warn( message, e );
           }
  -
  -        return info;
  -    }
  -
  -    private ComponentInfo createComponentInfo( final String impl )
  -        throws Exception
  -    {
  -        final Class clazz = Class.forName( impl );
  -        return m_infoBuilder.build( clazz );
  +        super.dispose();
       }
   
       protected ResourceProvider prepareResourceProvider()
       {
           final SimpleResourceProvider resourceProvider =
  -            new SimpleResourceProvider( this );
  +            new SimpleResourceProvider( this, m_factory );
           setupLogger( resourceProvider, "provider" );
           return resourceProvider;
       }
  
  
  
  1.5       +13 -10    jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/SimpleResourceProvider.java
  
  Index: SimpleResourceProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/SimpleResourceProvider.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleResourceProvider.java	19 Jul 2002 01:05:22 -0000	1.4
  +++ SimpleResourceProvider.java	2 Aug 2002 09:39:40 -0000	1.5
  @@ -7,11 +7,12 @@
    */
   package org.apache.excalibur.containerkit.kernel;
   
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.containerkit.factory.ComponentFactory;
   import org.apache.excalibur.containerkit.lifecycle.impl.AbstractResourceProvider;
   import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  -import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
   import org.apache.excalibur.containerkit.metainfo.ComponentDescriptor;
  -import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
   
   /**
    *
  @@ -23,15 +24,18 @@
       extends AbstractResourceProvider
   {
       private final AbstractServiceKernel m_serviceKernel;
  +    private final ComponentFactory m_factory;
   
  -    public SimpleResourceProvider( final AbstractServiceKernel serviceKernel )
  +    public SimpleResourceProvider( final AbstractServiceKernel serviceKernel,
  +                                   final ComponentFactory factory )
       {
           m_serviceKernel = serviceKernel;
  +        m_factory = factory;
       }
   
  -    protected ComponentMetaData getProfile( Object entry )
  +    protected ComponentMetaData getMetaData( final Object entry )
       {
  -        return ( (ComponentEntry)entry ).getProfile();
  +        return ((ComponentEntry)entry).getProfile();
       }
   
       protected Object getService( final String name,
  @@ -50,18 +54,17 @@
       public Object createObject( final Object entry )
           throws Exception
       {
  -        final ComponentMetaData component = getProfile( entry );
  +        final ComponentMetaData component = getMetaData( entry );
           final ComponentInfo info = component.getComponentInfo();
           final ComponentDescriptor descriptor = info.getComponentDescriptor();
           final String implementationKey = descriptor.getImplementationKey();
  -        final Class clazz = Class.forName( implementationKey );
  -        return clazz.newInstance();
  +        return m_factory.createComponent( implementationKey );
       }
   
       public Logger createLogger( final Object entry )
           throws Exception
       {
  -        final ComponentMetaData component = getProfile( entry );
  +        final ComponentMetaData component = getMetaData( entry );
           return getLogger().getChildLogger( component.getName() );
       }
   }
  
  
  

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