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/demo/components Component1-info.xml Component1.java Main.java Service1.java config.xml package.html
Date Fri, 23 Aug 2002 08:51:16 GMT
donaldp     2002/08/23 01:51:15

  Modified:    containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        Resources.properties
  Added:       containerkit/src/java/org/apache/excalibur/containerkit/demo
                        Resources.properties SimpleMetaDataBuilder.java
                        SimpleResourceProvider.java
                        SimpleServiceKernel.java
               containerkit/src/java/org/apache/excalibur/containerkit/demo/components
                        Component1-info.xml Component1.java Main.java
                        Service1.java config.xml package.html
  Removed:     containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        SimpleMetaDataBuilder.java
                        SimpleResourceProvider.java
                        SimpleServiceKernel.java
               containerkit/src/java/org/apache/excalibur/containerkit/kernel/components
                        Component1-info.xml Component1.java Main.java
                        Service1.java config.xml package.html
  Log:
  Move demo stuff to a separate hierarchy.
  
  Revision  Changes    Path
  1.6       +0 -1      jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/Resources.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Resources.properties	2 Aug 2002 03:52:07 -0000	1.5
  +++ Resources.properties	23 Aug 2002 08:51:15 -0000	1.6
  @@ -1,5 +1,4 @@
   processed-component=Processed component {0}.
   components-processing=Processing component {0} in phase {1} from {2}.
   process-component=Processing component {0}, named "{1}".
  -provider-shutdown.error=Error shutting down ResourceProvider.
   lifecycle-shutdown.error=Error shutting down LifecycleHelper.
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  provider-shutdown.error=Error shutting down ResourceProvider.
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/SimpleMetaDataBuilder.java
  
  Index: SimpleMetaDataBuilder.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.demo;
  
  import java.util.ArrayList;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  import org.apache.excalibur.containerkit.metadata.DependencyMetaData;
  import org.apache.excalibur.containerkit.metadata.MetaDataBuilder;
  import org.xml.sax.InputSource;
  
  /**
   * Load metadata from some source. The source is usually
   * one or more xml config files.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/23 08:51:15 $
   */
  public class SimpleMetaDataBuilder
      implements MetaDataBuilder
  {
      public ComponentMetaData[] loadMetaData( final String location )
          throws Exception
      {
          final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
          final InputSource input = new InputSource( location );
  
          final Configuration configuration = builder.build( input );
          final Configuration[] children =
              configuration.getChildren( "component" );
          return loadComponentDatas( children );
      }
  
      private ComponentMetaData[] loadComponentDatas( final Configuration[] components )
          throws Exception
      {
          final ArrayList profiles = new ArrayList();
  
          for( int i = 0; i < components.length; i++ )
          {
              final ComponentMetaData component =
                  loadComponentData( components[ i ] );
              profiles.add( component );
          }
  
          return (ComponentMetaData[])profiles.toArray( new ComponentMetaData[ profiles.size()
] );
      }
  
      private ComponentMetaData 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 DependencyMetaData[] dependencies =
              parseAssociations( component.getChildren( "provide" ) );
  
          return new ComponentMetaData( name, impl, dependencies, null, config );
      }
  
      private DependencyMetaData[] parseAssociations( final Configuration[] provides )
          throws ConfigurationException
      {
          final ArrayList associations = new ArrayList();
          for( int i = 0; i < provides.length; i++ )
          {
              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 );
          }
          return (DependencyMetaData[])associations.toArray( new DependencyMetaData[ associations.size()
] );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/SimpleResourceProvider.java
  
  Index: SimpleResourceProvider.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.demo;
  
  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.kernel.AbstractServiceKernel;
  import org.apache.excalibur.containerkit.kernel.ComponentEntry;
  
  /**
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/23 08:51:15 $
   */
  public class SimpleResourceProvider
      extends AbstractResourceProvider
  {
      private final AbstractServiceKernel m_serviceKernel;
  
      public SimpleResourceProvider( final AbstractServiceKernel serviceKernel,
                                     final ComponentFactory factory )
      {
          super( factory );
          m_serviceKernel = serviceKernel;
      }
  
      protected ComponentMetaData getMetaData( final Object entry )
      {
          return ((ComponentEntry)entry).getMetaData();
      }
  
      protected Object getService( final String name,
                                   final Object entry )
      {
          return m_serviceKernel.getComponent( name );
      }
  
      protected Object getContextValue( final String name,
                                        final Object entry )
      {
          //Should return classloaders that are available
          return null;
      }
  
      public Logger createLogger( final Object entry )
          throws Exception
      {
          final ComponentMetaData component = getMetaData( entry );
          return getLogger().getChildLogger( component.getName() );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/SimpleServiceKernel.java
  
  Index: SimpleServiceKernel.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.demo;
  
  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.MetaDataBuilder;
  import org.apache.excalibur.containerkit.demo.SimpleMetaDataBuilder;
  import org.apache.excalibur.containerkit.demo.SimpleResourceProvider;
  import org.apache.excalibur.containerkit.kernel.AbstractServiceKernel;
  
  /**
   * This is a simple ServiceKernel.
   *
   * <p>It loads components from the current ClassLoader.
   * The Assembly information is passed in via Configuration object
   * in a format similar to merged assembly.xml/config.xml from Phoenix.</p>
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/23 08:51:15 $
   */
  public class SimpleServiceKernel
      extends AbstractServiceKernel
      implements Parameterizable
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( SimpleServiceKernel.class );
  
      private MetaDataBuilder m_metaDataBuilder;
      private String m_configURL;
  
      public void parameterize( final Parameters parameters )
          throws ParameterException
      {
          m_configURL = parameters.getParameter( "config-url" );
      }
  
      public void initialize()
          throws Exception
      {
          super.initialize();
  
          m_metaDataBuilder = new SimpleMetaDataBuilder();
          setupLogger( getFactory(), "builder" );
  
          final ComponentMetaData[] components = m_metaDataBuilder.loadMetaData( m_configURL
);
          for( int i = 0; i < components.length; i++ )
          {
              final ComponentMetaData component = components[ i ];
              addComponent( component );
          }
  
          startupAllComponents();
      }
  
      public void dispose()
      {
          try
          {
              shutdownAllComponents();
          }
          catch( final Exception e )
          {
              final String message =
                  REZ.getString( "provider-shutdown.error" );
              getLogger().warn( message, e );
          }
          super.dispose();
      }
  
      protected ComponentFactory prepareFactory()
      {
          final DefaultComponentFactory factory =
              new DefaultComponentFactory( getClass().getClassLoader() );
          setupLogger( factory, "factory" );
          return factory;
      }
  
      protected ResourceProvider prepareResourceProvider()
      {
          final SimpleResourceProvider resourceProvider =
              new SimpleResourceProvider( this, getFactory() );
          setupLogger( resourceProvider, "provider" );
          return resourceProvider;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Component1-info.xml
  
  Index: Component1-info.xml
  ===================================================================
  <?xml version="1.0" encoding="utf-8" ?>
  
  <!DOCTYPE component-info
        PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN"
               "http://jakarta.apache.org/avalon/componentinfo_1_0.dtd" >
  
  <component-info>
      <component>
          <name>component1</name>
          <version>1.2.1</version>
      </component>
  
      <loggers>
          <logger/>
          <logger name="meep"/>
      </loggers>
  
      <services>
          <service>
              <service-ref type="org.apache.excalibur.containerkit.demo.components.Service1"/>
          </service>
      </services>
  </component-info>
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Component1.java
  
  Index: Component1.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.demo.components;
  
  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.activity.Initializable;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import java.lang.ClassLoader;
  
  /**
   * @avalon.component lifestyle="alternative" version="1.4"
   * @avalon.service interface="Service1" shareable="true"
   */
  public class Component1
      implements Service1, Contextualizable, Serviceable, Configurable, Initializable
  {
      /**
       * @avalon.context type="Context" anAttribute="f"
       * @avalon.entry key="foo" type="ClassLoader"
       * @avalon.entry key="bar" type="java.lang.Integer" attribute1="meep meep!" isOptional="false"
       */
      public void contextualize( final Context context )
          throws ContextException
      {
          try
          {
              context.get( ClassLoader.class.getName() );
          }
          catch( ContextException e )
          {
          }
      }
  
      /**
       * @avalon.dependency role="fred" interface="Service1" optional="true" shareable="true"
       */
      public void service( final ServiceManager manager )
          throws ServiceException
      {
          System.out.println( "Component1.service" );
      }
  
      public void configure( Configuration configuration )
          throws ConfigurationException
      {
          System.out.println( "Component1.configure" );
      }
  
      public void initialize()
          throws Exception
      {
          System.out.println( "Component1.initialize" );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Main.java
  
  Index: Main.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.demo.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.parameters.Parameters;
  import org.apache.excalibur.containerkit.demo.SimpleServiceKernel;
  
  /**
   *
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/23 08:51:15 $
   */
  public class Main
  {
      public static void main( String[] args )
          throws Exception
      {
          SimpleServiceKernel serviceKernel = new SimpleServiceKernel();
          final Logger logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
          ContainerUtil.enableLogging( serviceKernel, logger );
          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.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Service1.java
  
  Index: Service1.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.demo.components;
  
  public interface Service1
  {
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/config.xml
  
  Index: config.xml
  ===================================================================
  <my-app>
      <component name="s" impl="org.apache.excalibur.containerkit.demo.components.Component1">
          <config>lalal</config>
      </component>
  </my-app>
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/package.html
  
  Index: package.html
  ===================================================================
  <html><body>
  <p>Experimentatal resource including a test kernel application main class and related
components.</P>
  </body></html>
  
  
  

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