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 SimpleResourceProvider.java SimpleServiceKernel.java
Date Tue, 25 Jun 2002 07:43:24 GMT
donaldp     2002/06/25 00:43:24

  Added:       containerkit/src/java/org/apache/excalibur/containerkit/kernel/components
                        Component1.java Component1.xinfo config.xml
                        Main.java Service1.java
               containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        SimpleResourceProvider.java
                        SimpleServiceKernel.java
  Log:
  Add a bunch of stuff used to test architecture
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/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.kernel.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;
  
  public class Component1
      implements Service1, Configurable, Initializable
  {
      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/kernel/components/Component1.xinfo
  
  Index: Component1.xinfo
  ===================================================================
  <?xml version="1.0" encoding="utf-8" ?>
  
  <!DOCTYPE component-info
        PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN" "http://home.osm.net/componentinfo.dtd"
>
  
  <component-info>
      <component>
          <name>component1</name>
          <version>1.2.1</version>
      </component>
  
      <services>
          <service>
              <service-ref type="org.apache.excalibur.containerkit.kernel.components.Service1"/>
          </service>
      </services>
  </component-info>
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/components/config.xml
  
  Index: config.xml
  ===================================================================
  <my-app>
      <component name="s" impl="org.apache.excalibur.containerkit.kernel.components.Component1">
          <config>lalal</config>
      </component>
  </my-app>
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/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.kernel.components;
  
  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.excalibur.containerkit.kernel.SimpleServiceKernel;
  import org.xml.sax.InputSource;
  import java.io.InputStream;
  
  /**
   *
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 07:43:24 $
   */
  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 );
          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 );
          ContainerUtil.initialize( serviceKernel );
          Thread.sleep( 2000 );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/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.kernel.components;
  
  public interface Service1
  {
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/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.kernel;
  
  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;
  
  /**
   *
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 07:43:24 $
   */
  public class SimpleResourceProvider
      extends AbstractResourceProvider
  {
      private final AbstractServiceKernel m_serviceKernel;
  
      public SimpleResourceProvider( final AbstractServiceKernel serviceKernel )
      {
          m_serviceKernel = serviceKernel;
      }
  
      protected ComponentMetaData getMetaData( 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 Object createObject( final Object entry )
          throws Exception
      {
          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();
      }
  
      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/kernel/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.kernel;
  
  import java.io.InputStream;
  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.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;
  
  /**
   *
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/25 07:43:24 $
   */
  public class SimpleServiceKernel
      extends AbstractServiceKernel
      implements Configurable
  {
      private final ComponentInfoBuilder m_infoBuilder = new ComponentInfoBuilder();
  
      private Configuration m_configuration;
      private final HashMap m_infos = new HashMap();
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          m_configuration = configuration;
      }
  
      public void enableLogging( final Logger logger )
      {
          super.enableLogging( logger );
          setupLogger( m_infoBuilder, "infobuilder" );
      }
  
      public void initialize()
          throws Exception
      {
          super.initialize();
  
          final Configuration[] children =
              m_configuration.getChildren( "component" );
          loadComponentDatas( children );
  
          startupAllComponents();
      }
  
      private void loadComponentDatas( final Configuration[] components )
          throws Exception
      {
          for( int i = 0; i < components.length; i++ )
          {
              loadComponentData( components[ i ] );
          }
      }
  
      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 =
              parseDependencies( component.getChildren( "provide" ) );
  
          final ComponentMetaData metaData =
              new ComponentMetaData( name, dependencies, null, config, info );
          addComponent( metaData );
      }
  
      private DependencyMetaData[] parseDependencies( final Configuration[] provides )
          throws ConfigurationException
      {
          final ArrayList dependencies = 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 metaData = new DependencyMetaData( role, provider );
              dependencies.add( metaData );
          }
          return (DependencyMetaData[])dependencies.toArray( new DependencyMetaData[ dependencies.size()
] );
      }
  
      private ComponentInfo getComponentInfo( final String impl )
          throws Exception
      {
          ComponentInfo info = (ComponentInfo)m_infos.get( impl );
          if( null == info )
          {
              info = createComponentInfo( impl );
              m_infos.put( impl, info );
          }
  
          return info;
      }
  
      private ComponentInfo createComponentInfo( final String impl )
          throws Exception
      {
          final Class clazz = Class.forName( impl );
          final String xinfo = "/" + clazz.getName().replace( '.', '/' ) + ".xinfo";
          System.out.println( "xinfo = " + xinfo );
          final InputStream input = clazz.getResourceAsStream( xinfo );
          System.out.println( "input = " + input );
          return m_infoBuilder.build( impl, input );
      }
  
      protected ResourceProvider prepareResourceProvider()
      {
          final SimpleResourceProvider resourceProvider =
              new SimpleResourceProvider( this );
          setupLogger( resourceProvider, "provider" );
          return resourceProvider;
      }
  }
  
  
  

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