You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/08/02 11:39:04 UTC

cvs commit: jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel MetaDataBuilder.java SimpleMetaDataBuilder.java

donaldp     2002/08/02 02:39:04

  Added:       containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        MetaDataBuilder.java SimpleMetaDataBuilder.java
  Log:
  Add simple abstraction to deal with loading of assembly/configuraiton data.
  
  Needs to be reworked and info removed from it possibly
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/MetaDataBuilder.java
  
  Index: MetaDataBuilder.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.metadata.ComponentMetaData;
  import org.apache.excalibur.containerkit.factory.ComponentFactory;
  
  /**
   * Load metadata from some source. The source is usually
   * one or more xml config files.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/02 09:39:03 $
   */
  public interface MetaDataBuilder
  {
      /**
       * Load metadata from a particular source
       * defined by location string. The format of
       * location string and format of source loaded
       * from is left unspecified.
       *
       * @param location the location of meta data source
       * @return the set of components in metadata
       * @throws Exception if unable to load or resolve meta
       *         data for any reason
       */
      ComponentMetaData[] loadMetaData( String location,
                                        ComponentFactory factory )
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/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.kernel;
  
  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.factory.ComponentFactory;
  import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  import org.apache.excalibur.containerkit.metadata.DependencyMetaData;
  import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
  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@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/02 09:39:03 $
   */
  public class SimpleMetaDataBuilder
      implements MetaDataBuilder
  {
      public ComponentMetaData[] loadMetaData( final String location,
                                               final ComponentFactory factory )
          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, factory );
      }
  
      private ComponentMetaData[] loadComponentDatas( final Configuration[] components,
                                                      final ComponentFactory factory )
          throws Exception
      {
          final ArrayList profiles = new ArrayList();
  
          for( int i = 0; i < components.length; i++ )
          {
              final ComponentMetaData component =
                  loadComponentData( components[ i ],factory );
              profiles.add( component );
          }
  
          return (ComponentMetaData[])profiles.toArray( new ComponentMetaData[ profiles.size() ] );
      }
  
      private ComponentMetaData loadComponentData( final Configuration component,
                                                   final ComponentFactory factory )
          throws Exception
      {
          final String name = component.getAttribute( "name" );
          final String impl = component.getAttribute( "impl" );
          final Configuration config = component.getChild( "config" );
          final ComponentInfo info = factory.createInfo( impl );
          final DependencyMetaData[] dependencies =
              parseAssociations( component.getChildren( "provide" ) );
  
          return new ComponentMetaData( name, dependencies, null, config, info );
      }
  
      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() ] );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>