donaldp     01/02/23 20:31:02

  Added:       src/java/org/apache/avalon/blocks AbstractBlock.java
                        Block.java
               src/java/org/apache/avalon/services Service.java
               src/java/org/apache/phoenix AbstractBlock.java Block.java
                        BlockContext.java Service.java
               src/java/org/apache/phoenix/engine AbstractServerKernel.java
                        Constants.java DefaultSarDeployer.java
                        DefaultServerApplication.java
                        DefaultServerKernel.java Main.java
                        SarBlockFactory.java SarClassLoader.java
                        SarContextResources.java ServerApplication.java
                        ServerApplicationEntry.java ServerKernel.java
               src/java/org/apache/phoenix/engine/blocks BlockDAG.java
                        BlockEntry.java BlockVisitor.java
                        DefaultBlockContext.java DefaultBlockDeployer.java
                        RoleEntry.java
               src/java/org/apache/phoenix/engine/facilitys
                        DefaultComponentBuilder.java
                        DefaultComponentManagerBuilder.java
                        DefaultConfigurationRepository.java
                        DefaultContextBuilder.java
                        DefaultLoggerBuilder.java
               src/java/org/apache/phoenix/engine/loader AvalonLoader.java
               src/java/org/apache/phoenix/engine/phases DefaultPhase.java
                        Phase.java PipelineRunner.java
               src/java/org/apache/phoenix/metainfo BlockInfo.java
                        BlockInfoBuilder.java BlockUtil.java
                        Contributor.java DefaultBlockInfo.java
                        DefaultContributor.java DefaultDependencyInfo.java
                        DefaultMetaInfo.java DefaultServiceInfo.java
                        DependencyInfo.java MetaInfo.java ServiceInfo.java
  Log:
  Initial check in of phoenix source
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/avalon/blocks/AbstractBlock.java
  
  Index: AbstractBlock.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 file.
   */
  package org.apache.avalon.blocks;
  
  /**
   * This is an <code>AbstractBlock</code> that makes deployment a bit
   * easier.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/02/24 04:30:58 $
   * @deprecated This is deprecated in favour of directly extending the class 
in atlantis package
   */
  public abstract class AbstractBlock 
      extends org.apache.phoenix.AbstractBlock
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/avalon/blocks/Block.java
  
  Index: Block.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 file.
   */
  package org.apache.avalon.blocks;
  
  /**
   * The main interface to implement for building servers using Avalon patterns.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
   * @deprecated This is deprecated in favour of directly extending the 
interface in atlantis package
   */
  public interface Block 
      extends org.apache.phoenix.Block
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/avalon/services/Service.java
  
  Index: Service.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 file.
   */
  package org.apache.avalon.services;
  
  /**
   * This is a marker interface that all Services must implement.
   * A Service is a behavioural contract that an object implements.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @deprecated This is deprecated in favour of directly extending the 
interface in phoenix package
   */
  public interface Service 
      extends org.apache.phoenix.Service
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/AbstractBlock.java
  
  Index: AbstractBlock.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 file.
   */
  package org.apache.phoenix;
  
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.configuration.Configurable;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.Context;
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.Disposable;
  import org.apache.avalon.Initializable;
  
  /**
   * This is an <code>AbstractBlock</code> that makes deployment a bit
   * easier.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/02/24 04:30:59 $
   */
  public abstract class AbstractBlock
      extends AbstractLoggable
      implements Block, Contextualizable, Composer, Configurable
  {
      protected BlockContext           m_context;
      protected Configuration          m_configuration;
      protected ComponentManager       m_componentManager;
  
      public void contextualize( final Context context )
      {
          m_context = (BlockContext)context;
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          m_configuration = configuration;
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_componentManager = componentManager;
      }
  
      protected final BlockContext getBlockContext()
      {
          return m_context;
      }
  
      protected final ComponentManager getComponentManager()
      {
          return m_componentManager;
      }
  
      protected final Configuration getConfiguration()
      {
          return m_configuration;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/Block.java
  
  Index: Block.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 file.
   */
  package org.apache.phoenix;
  
  import org.apache.avalon.Component;
  
  /**
   * The main interface to implement for building servers using Avalon patterns.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
   */
  public interface Block 
      extends Component
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/BlockContext.java
  
  Index: BlockContext.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 file. 
   */
  package org.apache.phoenix;
  
  import java.io.File;
  import org.apache.avalon.Context;
  import org.apache.avalon.util.thread.ThreadPool;
  import org.apache.log.Logger;
  
  /**
   * Context via which Blocks communicate with container.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface BlockContext
      extends Context
  {
      String    APP_NAME          = "app.name";
      String    APP_HOME_DIR      = "app.home";
      String    NAME              = "block.name";
  
      /**
       * Base directory of .sar application.
       *
       * @return the base directory
       */
      File getBaseDirectory();
  
      /**
       * Retrieve name of block.
       *
       * @return the name of block
       */
      String getName();
  
      /**
       * Retrieve thread manager by category.
       * ThreadManagers are given names so that you can manage different thread 
       * count to different components.
       *
       * @param category the category
       * @return the ThreadManager
       */
      ThreadPool getThreadPool( String category );
  
      ThreadPool getDefaultThreadPool();
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/Service.java
  
  Index: Service.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 file.
   */
  package org.apache.phoenix;
  
  /**
   * This is a marker interface that all Services must implement.
   * A Service is a behavioural contract that an object implements.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Service 
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/AbstractServerKernel.java
  
  Index: AbstractServerKernel.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 file.
   */
  package org.apache.phoenix.engine;
  
  import org.apache.avalon.Composer;
  import org.apache.avalon.atlantis.AbstractKernel;
  import org.apache.avalon.atlantis.Application;
  import org.apache.avalon.camelot.Entry;
  import org.apache.log.LogKit;
  
  /**
   * This is the base abstract ServerKernel which other implementations should 
extend.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public abstract class AbstractServerKernel 
      extends AbstractKernel
      implements ServerKernel
  {
      public AbstractServerKernel()
      {
          m_entryClass = ServerApplicationEntry.class;
          m_applicationClass = ServerApplication.class;
      }
  
      /**
       * Prepare an application before it is initialized.
       * Overide to provide functionality. 
       * Usually used to setLogger(), contextualize, compose, configure.
       *
       * @param name the name of application
       * @param entry the application entry 
       * @param application the application instance
       * @exception Exception if an error occurs
       */
      protected void prepareApplication( final String name, 
                                         final Entry entry, 
                                         final Application application )
          throws Exception
      {
          final ServerApplicationEntry saEntry = (ServerApplicationEntry)entry;
          final ServerApplication saApplication = 
(ServerApplication)application;
  
          setupLogger( saApplication, LogKit.getLoggerFor( name ) );
          saApplication.contextualize( saEntry.getContext() );
          
          if( saApplication instanceof Composer )
          { 
              ((Composer)saApplication).compose( saEntry.getComponentManager() 
);
          }
  
          saApplication.configure( saEntry.getConfiguration() );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/Constants.java
  
  Index: Constants.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 file.
   */
  package org.apache.phoenix.engine;
  
  /**
   * Package access to kernel constants.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  interface Constants
  {
      String SOFTWARE  = "@@NAME@@";
      String VERSION   = "@@VERSION@@";
      String DATE      = "@@DATE@@"; 
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultSarDeployer.java
  
  Index: DefaultSarDeployer.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 file.
   */
  package org.apache.phoenix.engine;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipFile;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.DefaultComponentManager;
  import org.apache.avalon.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.DefaultContext;
  import org.apache.avalon.camelot.AbstractCamelotDeployer;
  import org.apache.avalon.camelot.CamelotUtil;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.avalon.camelot.DefaultLocatorRegistry;
  import org.apache.avalon.camelot.DefaultRegistry;
  import org.apache.avalon.camelot.Deployer;
  import org.apache.avalon.camelot.DeployerUtil;
  import org.apache.avalon.camelot.DeploymentException;
  import org.apache.avalon.camelot.Locator;
  import org.apache.avalon.camelot.LocatorRegistry;
  import org.apache.avalon.camelot.Registry;
  import org.apache.avalon.camelot.RegistryException;
  import org.apache.avalon.util.io.FileUtil;
  import org.apache.avalon.util.io.IOUtil;
  import org.apache.phoenix.BlockContext;
  import org.apache.phoenix.metainfo.BlockInfo;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  import org.apache.phoenix.engine.blocks.RoleEntry;
  import org.apache.phoenix.engine.blocks.DefaultBlockDeployer;
  
  /**
   * This class deploys a .sar file.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultSarDeployer
      extends AbstractCamelotDeployer
  {
      protected File            m_deployDirectory;
  
      /**
       * Default constructor.
       */
      public DefaultSarDeployer()
      {
          m_deployToContainer = true;
          m_autoUndeploy = true;
          m_type = "Sar";
      }
  
      protected void deployFromFile( final String location, final File file )
          throws DeploymentException
      {
          if( file.isDirectory() )
          {
              deployFromDirectory( location, file );
          }
          else
          {
              final File destination = getDestinationFor( location, file );
              expandTo( file, destination );
              deployFromDirectory( location, destination );
          }
      }
  
      protected void expandTo( final File file, final File directory )
          throws DeploymentException
      {
          final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
  
          if( !needsExpanding( zipFile, directory ) ) 
          {
              return;
          }
  
          directory.mkdirs();
  
          final Enumeration entries = zipFile.entries();
          while( entries.hasMoreElements() )
          {
              final ZipEntry entry = (ZipEntry)entries.nextElement();
              if( entry.isDirectory() ) continue;
  
              final String name = entry.getName().replace( '/', 
File.separatorChar );
              if( name.startsWith( "META-INF" ) ) continue;
  
              final File destination = new File( directory, name );
  
              InputStream input = null;
              OutputStream output = null;
  
              try
              {
                  destination.getParentFile().mkdirs();
                  output = new FileOutputStream( destination );
                  input = zipFile.getInputStream( entry );
                  IOUtil.copy( input, output );
              }
              catch( final IOException ioe )
              {
                  throw new DeploymentException( "Error extracting " + name, 
ioe );
              }
              finally
              {
                  IOUtil.shutdownStream( input );
                  IOUtil.shutdownStream( output );
              }
          }
      }
  
      protected boolean needsExpanding( final ZipFile zipFile, final File 
directory )
      {
          return !directory.exists();
      }
  
      protected File getDestinationFor( final String location, final File file )
      {
          final String name =
              FileUtil.removeExtention( FileUtil.removePath( file.getName() ) );
  
          if( null != m_deployDirectory )
          {
              return (new File( m_deployDirectory, name )).getAbsoluteFile();
          }
          else
          {
              return (new File( file.getParentFile(), name )).getAbsoluteFile();
          }
      }
  
      protected ServerKernel getKernel()
          throws DeploymentException
      {
          if( !(m_container instanceof ServerKernel) )
          {
              throw new DeploymentException( "Can only deploy to a kernel 
container" );
          }
          else
          {
              return (ServerKernel)m_container;
          }
      }
  
      protected void buildEntry( final String name, 
                                 final ServerApplicationEntry entry, 
                                 final File directory )
          throws DeploymentException
      {
          /*
            final File file = new File( directory, "SAR-INF" + File.separator + 
"sar-inf.xml" );
            if( file.exists() )
            {
            final Configuration configuration = getConfigurationFor( file );
            libDirectory = 
            configuration.getChild( "lib-directory" ).getValue( libDirectory );
            blocksDirectory =
            configuration.getChild( "blocks-directory" ).getValue( 
blocksDirectory );
            confDirectory = 
            configuration.getChild( "conf-directory" ).getValue( confDirectory 
);
            }
          */
  
          //setup the ServerApplications context
          final DefaultContext context = new DefaultContext();
          context.put( SarContextResources.APP_HOME_DIR, directory );
          context.put( SarContextResources.APP_BLOCKS_DIR, "blocks" );
          context.put( SarContextResources.APP_CONF_DIR, "conf" );
          context.put( SarContextResources.APP_LIB_DIR, "lib" );
          context.put( SarContextResources.APP_NAME, name );
          entry.setContext( context );
  
          //setup the ServerApplications component manager
          final DefaultComponentManager componentManager = new 
DefaultComponentManager();
          componentManager.put( "org.apache.avalon.camelot.Registry",
                                new DefaultRegistry( BlockInfo.class ) );
          componentManager.put( "org.apache.avalon.camelot.LocatorRegistry",
                                new DefaultLocatorRegistry() );
          entry.setComponentManager( componentManager );
  
          //setup the ServerApplications configuration manager
          final File file = new File( directory, "conf" + File.separator + 
"server.xml" );
          final Configuration configuration = getConfigurationFor( file );
          entry.setConfiguration( configuration );
      }
  
      protected void deployFromDirectory( final String name, final File 
directory )
          throws DeploymentException
      {
          getLogger().info( "deploying from expanded directory " + directory );
  
          final ServerApplicationEntry entry = new ServerApplicationEntry();
          buildEntry( name, entry, directory );
          addEntry( name, entry );
  
          final ServerKernel kernel = getKernel();
          ServerApplication serverApplication = null;
          try 
          { 
              serverApplication = (ServerApplication)kernel.getApplication( 
name ); 
          }
          catch( final ContainerException ce ) 
          {
              throw new DeploymentException( "Error preparingserver 
application", ce );
          }
   
          final Deployer deployer = getBlockDeployer( entry );
          final String blockDirectory = 
              (String)entry.getContext().get( 
SarContextResources.APP_BLOCKS_DIR );
          final File blocksDirectory = new File( directory, blockDirectory );   
 
          CamelotUtil.deployFromDirectory( deployer, blocksDirectory, ".bar" );
  
          final String confDirectory = 
              (String)entry.getContext().get( SarContextResources.APP_CONF_DIR 
);
  
          final File file = 
              new File( directory, confDirectory + File.separator + 
"assembly.xml" );
  
          try
          {
              final Configuration configuration = getConfigurationFor( file );
              final Configuration[] blocks = configuration.getChildren( "block" 
);
              handleBlocks( serverApplication, entry, blocks );
          }
          catch( final ComponentManagerException cme )
          {
              throw new DeploymentException( "Error setting up registries", cme 
);
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Error in assembly.xml", ce );
          }
      }
  
      protected Configuration getConfigurationFor( final File file )
          throws DeploymentException
      {
          try
          {
              final FileInputStream input = new FileInputStream( file );
              return DeployerUtil.buildConfiguration( input );
          }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error reading " + file, ioe );
          }
      }
  
      protected Deployer getBlockDeployer( final ServerApplicationEntry entry )
          throws DeploymentException
      {
          final Deployer deployer = new DefaultBlockDeployer();
          setupLogger( deployer );
  
          if( deployer instanceof Composer )
          {
              try { ((Composer)deployer).compose( entry.getComponentManager() 
); }
              catch( final Exception e )
              {
                  throw new DeploymentException( "Error composing block 
deployer", e );
              }
          }
  
          return deployer;
      }
  
      protected void handleBlocks( final ServerApplication serverApplication,
                                   final ServerApplicationEntry saEntry,
                                   final Configuration[] blocks )
          throws ComponentManagerException, ConfigurationException, 
DeploymentException
      {
          final ComponentManager componentManager = 
saEntry.getComponentManager();
  
          final Registry infoRegistry = 
              (Registry)componentManager.lookup( 
"org.apache.avalon.camelot.Registry" );
  
          final LocatorRegistry locatorRegistry = 
(LocatorRegistry)componentManager.
              lookup( "org.apache.avalon.camelot.LocatorRegistry" );
  
          for( int i = 0; i < blocks.length; i++ )
          {
              final Configuration block = blocks[ i ];
              final String name = block.getAttribute("name");
              final String className = block.getAttribute("class");
  
              BlockInfo info = null;
  
              try { info = (BlockInfo)infoRegistry.getInfo( className ); }
              catch( final RegistryException re ) 
              {
                  throw new DeploymentException( "Failed to aquire BlockInfo 
for " + className, 
                                                 re );
              }
  
              Locator locator = null;
              try { locator = locatorRegistry.getLocator( className ); }
              catch( final RegistryException re ) 
              {
                  throw new DeploymentException( "Failed to aquire Locator for 
" + className, 
                                                 re );
              }
             
              final Configuration[] provides = block.getChildren( "provide" );
              final ArrayList roleList = new ArrayList();
              for( int j = 0; j < provides.length; j++ )
              {
                  final Configuration provide = provides[ j ];
                  final String requiredName = provide.getAttribute("name");
                  final String role = provide.getAttribute("role");
                  
                  roleList.add( new RoleEntry( requiredName, role ) );
              } 
  
              final RoleEntry[] roles = (RoleEntry[]) roleList.toArray( new 
RoleEntry[ 0 ] );
              final BlockEntry entry = new BlockEntry( locator, roles );
  
              entry.setBlockInfo( info );
              entry.setConfiguration( block.getChild( "configuration" ) );
  
              try { serverApplication.add( name, entry ); }
              catch( final ContainerException ce )
              {
                  throw new DeploymentException( "Error adding component to 
container", ce );
              }
              
              getLogger().debug( "Adding " + m_type + "Entry " + name + " as " 
+ entry );
          }  
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultServerApplication.java
  
  Index: DefaultServerApplication.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 file.
   */
  package org.apache.phoenix.engine;
  
  import java.security.Policy;
  import java.util.HashMap;
  import java.util.Iterator;
  import org.apache.avalon.Component;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Context;
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.DefaultComponentManager;
  import org.apache.avalon.DefaultContext;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.atlantis.ApplicationException;
  import org.apache.avalon.camelot.AbstractContainer;
  import org.apache.avalon.camelot.AvalonState;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.Factory;
  import org.apache.avalon.camelot.pipeline.ComponentBuilder;
  import org.apache.avalon.camelot.pipeline.ComponentManagerBuilder;
  import org.apache.avalon.camelot.pipeline.ConfigurationRepository;
  import org.apache.avalon.camelot.pipeline.ContextBuilder;
  import org.apache.avalon.camelot.pipeline.LoggerBuilder;
  import org.apache.avalon.camelot.pipeline.ShutdownPipeline;
  import org.apache.avalon.camelot.pipeline.StartupPipeline;
  import org.apache.avalon.configuration.Configurable;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.util.log.DefaultLogManager;
  import org.apache.avalon.util.security.DefaultPolicy;
  import org.apache.avalon.util.thread.DefaultThreadManager;
  import org.apache.avalon.util.thread.ThreadManager;
  import org.apache.phoenix.engine.blocks.BlockDAG;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  import org.apache.phoenix.engine.blocks.RoleEntry;
  import org.apache.phoenix.engine.facilitys.DefaultComponentBuilder;
  import org.apache.phoenix.engine.facilitys.DefaultComponentManagerBuilder;
  import org.apache.phoenix.engine.facilitys.DefaultConfigurationRepository;
  import org.apache.phoenix.engine.facilitys.DefaultContextBuilder;
  import org.apache.phoenix.engine.facilitys.DefaultLoggerBuilder;
  import org.apache.phoenix.engine.phases.DefaultPhase;
  import org.apache.phoenix.engine.phases.Phase;
  import org.apache.phoenix.metainfo.DependencyInfo;
  
  /**
   * This is the basic container of blocks. A server application 
   * represents an aggregation of blocks that act together to form
   * an application.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
   */
  public class DefaultServerApplication
      extends AbstractContainer
      implements ServerApplication
  {
      protected HashMap                  m_phases           = new HashMap();
      protected BlockDAG                 m_dag              = new BlockDAG();
  
      //the following are used for setting up facilities
      protected Context                  m_context;
      protected Configuration            m_configuration;
      protected ComponentManager         m_componentManager;
  
      protected DefaultLogManager        m_logManager;
      protected ThreadManager            m_threadManager;
      protected DefaultPolicy            m_policy;
      protected SarClassLoader           m_classLoader;
  
      //these are the facilities (internal components) of ServerApplication
      protected ComponentBuilder         m_componentBuilder;
      protected LoggerBuilder            m_loggerBuilder;
      protected ContextBuilder           m_contextBuilder;
      protected ComponentManagerBuilder  m_componentManagerBuilder;
      protected ConfigurationRepository  m_configurationRepository;
  
      public DefaultServerApplication()
      {
          m_entryClass = BlockEntry.class;
      }
  
      public void contextualize( final Context context )
      {
          //save it to contextualize policy/logManager/etc
          final DefaultContext newContext = new DefaultContext( context );
          newContext.put( "name", context.get( SarContextResources.APP_NAME ) );
          newContext.put( "directory", context.get( 
SarContextResources.APP_HOME_DIR ) );
          m_context = newContext;
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          m_configuration = configuration;
      }    
  
      public void init() 
          throws Exception 
      {        
          createComponents();
  
          //setup the component manager
          m_componentManager = createComponentManager();
  
          setupComponents();
  
          initPhases();
          setupPhases();
      }
  
      protected void initPhases()
          throws ApplicationException
      {
          Phase phase = null;
  
          phase = new DefaultPhase( Phase.FORWARD, 
                                    new StartupPipeline(),
                                    AvalonState.BASE,
                                    AvalonState.RUNNING );
          m_phases.put( "startup", phase );
  
          phase = new DefaultPhase( Phase.REVERSE, 
                                    new ShutdownPipeline(),
                                    AvalonState.RUNNING,
                                    AvalonState.DISPOSED );
          m_phases.put( "shutdown", phase );
      }
  
      protected void setupPhases()
          throws Exception
      {
          final Iterator phases = m_phases.values().iterator();
          while( phases.hasNext() )
          {
              final Phase phase = (Phase)phases.next();
              setupComponent( phase );
          }
      }
  
      public void start()
          throws Exception
      {
          // load blocks 
          try { loadBlocks(); }
          catch( final ApplicationException ae )
          {
              getLogger().warn( "Error loading blocks: " + ae.getMessage(), ae 
);
              throw ae;
          }
      }
  
      public void stop()
          throws Exception
      {
      }    
  
      public void dispose() 
          throws Exception
      {
          getLogger().info( "Number of blocks to unload: " + m_entries.size() );
  
          final Phase phase = (Phase)m_phases.get( "shutdown" );
          runPhase( phase );
  
          m_entries.clear();
      }
  
      /**
       * Create all required components.
       *
       * @exception Exception if an error occurs
       */
      protected void createComponents()
          throws Exception
      {
          //TODO: Refactor logManager so it does more useful managing
          // possibly including setting up rolling etc
          m_logManager = new DefaultLogManager();
  
          m_contextBuilder = new DefaultContextBuilder();
          m_componentManagerBuilder = new DefaultComponentManagerBuilder();
          m_configurationRepository = new DefaultConfigurationRepository();
          m_loggerBuilder = new DefaultLoggerBuilder();
          m_componentBuilder = new DefaultComponentBuilder();
  
          m_classLoader = new SarClassLoader();
          m_threadManager = new DefaultThreadManager();
          m_policy = new DefaultPolicy();
      }
  
      /**
       * Setup all the components. (ir run all required lifecycle methods).
       *
       * @exception Exception if an error occurs
       */
      protected void setupComponents()
          throws Exception
      {
          Configuration configuration = null;
  
          configuration = m_configuration.getChild( "logs" );
          setupComponent( m_logManager, "<core>.logs", configuration );
  
          configuration = m_configuration.getChild( "threads" );
          setupComponent( m_threadManager, "<core>.threads", configuration );
  
          configuration = m_configuration.getChild( "policy" );
          setupComponent( (Component)m_policy, "<policy>", configuration );
  
          setupComponent( m_classLoader );
  
          setupComponent( m_componentBuilder );
          setupComponent( m_loggerBuilder );
          setupComponent( m_contextBuilder );
          setupComponent( m_componentManagerBuilder );
          setupComponent( m_configurationRepository );
  
          setupComponent( m_dag, "<core>.dag", null );
      }
  
      protected void setupComponent( final Component object )
          throws Exception
      {
          setupComponent( object, null, null );
      }
  
      protected void setupComponent( final Component object, 
                                     final String logName, 
                                     final Configuration configuration )
          throws Exception
      {
          setupLogger( object, logName );
  
          if( object instanceof Contextualizable )
          {
              ((Contextualizable)object).contextualize( m_context );
          }
  
          if( object instanceof Composer )
          {
              ((Composer)object).compose( m_componentManager );
          }
  
          if( object instanceof Configurable )
          {
              ((Configurable)object).configure( configuration );
          }
  
          if( object instanceof Initializable )
          {
              ((Initializable)object).init();
          }
      }
  
      protected void runPhase( final Phase phase )
          throws Exception
      {
  
          if( Phase.FORWARD == phase.getTraversal() )
          {
              final Iterator entries = list();
              while( entries.hasNext() ) 
              {
                  final String name = (String)entries.next();
                  m_dag.walkGraph( name, phase );
              }
          }
          else if( Phase.REVERSE == phase.getTraversal() )
          {
              //TODO: 
              final Iterator entries = list();
              while( entries.hasNext() ) 
              {
                  final String name = (String)entries.next();
                  //m_dag.reverseWalkGraph( name, phase );
              }
          }
          else
          {
              //TODO: Does this make sense ????
              final Iterator entries = list();
              while( entries.hasNext() ) 
              {
                  final String name = (String)entries.next();
                  final BlockEntry entry = (BlockEntry)getEntry( name );
                  phase.visitBlock( name, entry );
              }
          }
      }
  
      /**
       * This method is called before entry is added to give chance for
       * sub-class to veto addition.
       *
       * @param name the name of entry
       * @param entry the entry
       * @exception ContainerException to stop removal of entry
       */
      protected void preAdd( final String name, final Entry entry )
          throws ContainerException
      {
          final BlockEntry blockEntry = (BlockEntry)entry;
          verifyDependenciesMap( name, blockEntry );
      }
  
      /**
       * Retrieve a list of RoleEntry objects that were specified 
       * in configuration file and verify they were expected based 
       * on BlockInfo file. Also verify that all entries specified 
       * in BlockInfo file have been provided.
       *
       * @param entry the BlockEntry describing block
       * @return the list of RoleEntry objects
       */
      protected void verifyDependenciesMap( final String name, final BlockEntry 
entry )
          throws ContainerException
      {
          //Make sure all role entries specified in config file are valid
          final RoleEntry[] roleEntrys = entry.getRoleEntrys();
          for( int i = 0; i < roleEntrys.length; i++ )
          {
              final String role = roleEntrys[ i ].getRole();
              final DependencyInfo info = entry.getBlockInfo().getDependency( 
role );
              
              if( null == info )
              {
                  final String message = "Unknown dependency " + roleEntrys[ i 
].getName() + 
                      " with role " + role + " declared for Block " + name;
  
                  getLogger().warn( message );
                  throw new ContainerException( message );
              }
          }
  
          //Make sure all dependencies in BlockInfo file are satisfied
          final DependencyInfo[] dependencies = 
entry.getBlockInfo().getDependencies();
          for( int i = 0; i < dependencies.length; i++ )
          {
              final RoleEntry roleEntry = 
                  entry.getRoleEntry( dependencies[ i ].getRole() );
              
              if( null == roleEntry )
              {
                  final String message = "Dependency " + dependencies[ i 
].getRole() +
                      " not provided in configuration for Block " + name;
  
                  getLogger().warn( message );
                  throw new ContainerException( message );
              }
          }
      }
  
      protected void loadBlocks() 
          throws Exception
      {
          getLogger().info( "Number of blocks to load: " + m_entries.size() );
          final Phase phase = (Phase)m_phases.get( "startup" );
          runPhase( phase );
      }
  
      /**
       * Create a ComponentManager containing all components in engine.
       *
       * @return the ComponentManager
       */
      protected ComponentManager createComponentManager()
      {
          final DefaultComponentManager componentManager = new 
DefaultComponentManager();
          componentManager.put( "org.apache.phoenix.engine.ServerApplication", 
this );
          componentManager.put( "java.security.Policy", m_policy );
          componentManager.put( "java.lang.ClassLoader", m_classLoader );
          componentManager.put( "NOT_DONE_YET", m_logManager );
          componentManager.put( "org.apache.avalon.util.thread.ThreadManager", 
m_threadManager );
          componentManager.put( 
"org.apache.avalon.camelot.pipeline.ContextBuilder", m_contextBuilder );
          componentManager.put( 
"org.apache.avalon.camelot.pipeline.LoggerBuilder", m_loggerBuilder );
          componentManager.put( 
"org.apache.avalon.camelot.pipeline.ComponentBuilder",
                                m_componentBuilder );
          componentManager.put( 
"org.apache.avalon.camelot.pipeline.ComponentManagerBuilder",
                                m_componentManagerBuilder );
          componentManager.put( 
"org.apache.avalon.camelot.pipeline.ConfigurationRepository", 
                                m_configurationRepository );
  
          return componentManager;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultServerKernel.java
  
  Index: DefaultServerKernel.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 file.
   */
  package org.apache.phoenix.engine;
  
  import org.apache.avalon.atlantis.Application;
  import org.apache.avalon.camelot.Entry;
  
  /**
   * This is the DefaultServerKernel for phoenix.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultServerKernel 
      extends AbstractServerKernel
  {
      public final static String BANNER = Constants.SOFTWARE + " " + 
Constants.VERSION;
  
      public void init() 
          throws Exception 
      {
          System.out.println();
          System.out.println( BANNER );
  
          super.init();
      }
  
      protected Application newApplication( final String name, final Entry 
entry )
          throws Exception
      {
          //It is here where you could return new EASServerApplication()
          //if you wanted to host multiple different types of apps
          return new DefaultServerApplication();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/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 file.
   */
  package org.apache.phoenix.engine;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.net.URL;
  import java.security.AccessController;
  import java.security.PrivilegedActionException;
  import java.security.PrivilegedExceptionAction;
  import java.util.List;
  import org.apache.avalon.Composer;
  import org.apache.avalon.DefaultComponentManager;
  import org.apache.avalon.Loggable;
  import org.apache.avalon.camelot.CamelotUtil;
  import org.apache.avalon.camelot.Deployer;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.util.ObjectUtil;
  import org.apache.avalon.util.StringUtil;
  import org.apache.avalon.util.cli.AbstractMain;
  import org.apache.avalon.util.cli.CLArgsParser;
  import org.apache.avalon.util.cli.CLOption;
  import org.apache.avalon.util.cli.CLOptionDescriptor;
  import org.apache.avalon.util.cli.CLUtil;
  import org.apache.avalon.util.log.AvalonLogFormatter;
  import org.apache.log.LogKit;
  import org.apache.log.LogTarget;
  import org.apache.log.Logger;
  import org.apache.log.Priority;
  import org.apache.log.output.FileOutputLogTarget;
  
  /**
   * The class to load the kernel and start it running.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class Main
      extends AbstractMain
  {
      private static final String    AVALON_HOME          = 
          System.getProperty( "avalon.home", ".." );
  
      private static final String    DEFAULT_LOG_FILE     = AVALON_HOME + 
"/logs/avalon.log";
      private static final String    DEFAULT_APPS_PATH    = AVALON_HOME + 
"/apps";
  
      private static final String    DEFAULT_KERNEL_CLASS =
          "org.apache.phoenix.engine.DefaultServerKernel";
  
      private static final int       DEBUG_LOG_OPT        = 'd';
      private static final int       HELP_OPT             = 'h';
      private static final int       KERNEL_CLASS_OPT     = 'k';
      private static final int       LOG_FILE_OPT         = 'l';
      private static final int       APPS_PATH_OPT        = 'a';
  
      //HACK: force resolution of .jar libraries before security manager is 
installed.
      //TODO: Is this still needed ????
      private static final Class     AWARE_DEPEND         = 
          org.apache.avalon.Component.class;
      private static final Class     PARSER_DEPEND        = 
          org.xml.sax.SAXException.class;
  
      protected String               m_kernelClass        = 
DEFAULT_KERNEL_CLASS;
      protected String               m_appsPath           = DEFAULT_APPS_PATH;
      protected String               m_logFile            = DEFAULT_LOG_FILE;
      protected Logger               m_logger;
  
      /**
       * Initialise the options for command line parser.
       *
       */
      protected CLOptionDescriptor[] createCLOptions()
      {
          //TODO: localise
          final CLOptionDescriptor options[] = new CLOptionDescriptor[ 5 ];
          options[0] =
              new CLOptionDescriptor( "help",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      HELP_OPT,
                                      "display this help" );
  
          options[1] =
              new CLOptionDescriptor( "kernel-class",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      KERNEL_CLASS_OPT,
                                      "the classname of the kernel." );
  
          options[2] =
              new CLOptionDescriptor( "log-file",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      LOG_FILE_OPT,
                                      "the name of log file." );
  
          options[3] =
              new CLOptionDescriptor( "apps-path",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      APPS_PATH_OPT,
                                      "the path to apps/ directory that 
contains .sars" );
  
          options[4] =
              new CLOptionDescriptor( "debug-init",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      DEBUG_LOG_OPT,
                                      "use this option to specify enable debug 
" + 
                                      "initialisation logs." );
          return options;
      }
  
      /**
       * Main entry point.
       *
       * @param args[] the command line arguments
       * @exception Exception if an error occurs
       */
      public void main( final String args[] )
      { 
          final Main main = new Main();
  
          try { main.execute( args ); }
          catch( final Throwable throwable )
          {
              if( null != main.m_logger )
              {
                  main.m_logger.error( "Unhandled exception", throwable );
              }
  
              System.err.println( "Error: " + 
                                  StringUtil.printStackTrace( throwable, 8, 
true ) );
              System.exit( 1 );
          }
      }
  
      /**
       * Setup properties, classloader, policy, logger etc.
       *
       * @param clOptions the command line options
       * @exception Exception if an error occurs
       */
      protected void execute( final List clOptions )
          throws Exception
      {
          final int size = clOptions.size();
          boolean debugLog = false;
  
          for( int i = 0; i < size; i++ ) 
          {
              final CLOption option = (CLOption)clOptions.get( i );
              
              switch( option.getId() )
              {
              case 0: 
                  System.err.println( "Error: Unknown argument" + 
option.getArgument() );
                  //fall threw
              case HELP_OPT: 
                  usage(); 
                  return;
  
              case KERNEL_CLASS_OPT: m_kernelClass = option.getArgument(); 
break;
              case DEBUG_LOG_OPT: debugLog = true; break;
              case LOG_FILE_OPT: m_logFile = option.getArgument(); break;
              case APPS_PATH_OPT: m_appsPath = option.getArgument(); break;
              }
          }
          
          if( !debugLog ) LogKit.setGlobalPriority( Priority.DEBUG );
  
          try
          {
              final PrivilegedExceptionAction action = new 
PrivilegedExceptionAction() 
              {
                  public Object run() throws Exception
                  {        
                      execute();
                      return null;
                  }
              };
  
              AccessController.doPrivileged( action );
          } 
          catch( final PrivilegedActionException pae )
          {
              // only "checked" exceptions will be "wrapped" in a 
PrivilegedActionException.
              throw pae.getException();
          }
      }
      
      /**
       * Actually create and execute the main component of kernel.
       *
       * @exception Exception if an error occurs
       */
      protected void execute()
          throws Exception
      {
          //temporary logging hack ....
          
          // create a log channel for the loader.
          final FileOutputLogTarget logTarget = new FileOutputLogTarget( 
m_logFile );
          final AvalonLogFormatter formatter = new AvalonLogFormatter();
          formatter.setFormat( "%{time} [%7.7{priority}] <<%{category}>> " +
                               "(%{context}): %{message}\\n%{throwable}" );
          logTarget.setFormatter( formatter );
          
          LogKit.addLogTarget( m_logFile, logTarget );
          m_logger = LogKit.createLogger( LogKit.createCategory( "Avalon", 
Priority.DEBUG ), 
                                          new LogTarget[] { logTarget } );
          m_logger.info( "Loader started" );
          
          ServerKernel kernel = null;
          try
          {
              Thread.currentThread().setContextClassLoader( 
getClass().getClassLoader() );
              kernel = (ServerKernel)ObjectUtil.createObject( m_kernelClass );
          }
          catch( final Exception e )
          {
              throw new ConfigurationException( "Failed to create kernel", e );
          }
  
          kernel.setLogger( m_logger );
          kernel.init();//ialize();
  
          final File directory = new File( m_appsPath );
          final Deployer deployer = createDeployer();
          setupDeployer( kernel, deployer );
  
          CamelotUtil.deployFromDirectory( deployer, directory, ".sar" );
  
          //run kernel lifecycle
          kernel.start();
          kernel.run();  
          kernel.stop();      
          kernel.dispose();
          
          System.exit(0);
      }
  
      /**
       * Setup deployer including Logging/componentManager.
       *
       * @param kernel the kernel deploying to
       * @param deployer the deployer
       * @exception Exception if an error occurs
       */
      protected void setupDeployer( final ServerKernel kernel, final Deployer 
deployer )
          throws Exception
      {
          if( deployer instanceof Loggable )
          {
              ((Loggable)deployer).setLogger( m_logger );
          }     
  
          if( deployer instanceof Composer )
          {
              final DefaultComponentManager componentManager = new 
DefaultComponentManager();
              componentManager.put( "org.apache.avalon.camelot.Container", 
kernel );
              ((Composer)deployer).compose( componentManager );
          }
      }
  
      /**
       * Create a deployer for Sar objects.
       * Overide this in sub-classes if necessary.
       *
       * @return the created deployer
       */
      protected Deployer createDeployer()
      {
          return new DefaultSarDeployer();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/SarBlockFactory.java
  
  Index: SarBlockFactory.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 file. 
   */
  package org.apache.phoenix.engine;
  
  import java.net.URL;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.camelot.DefaultFactory;
  import org.apache.avalon.camelot.DefaultLoader;
  import org.apache.avalon.camelot.Loader;
  
  /**
   * This component creates blocks and blockInfos.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class SarBlockFactory
      extends DefaultFactory
      implements Composer, Initializable
  {
      protected Loader            m_loader;
      protected ClassLoader       m_classLoader;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_classLoader = (ClassLoader)componentManager.lookup( 
"java.lang.ClassLoader" );
      }
  
      public void init()
          throws Exception
      {
          m_loader = new DefaultLoader( m_classLoader );
      }
  
      /**
       * Overidden so that there is only one Loader per Application rather than 
one per archive.
       *
       * @param url the url to archive that contains code (ignored)
       * @return the Loader
       */
      protected Loader getLoaderFor( final URL url )
      {
          return m_loader;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/SarClassLoader.java
  
  Index: SarClassLoader.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 file. 
   */
  package org.apache.phoenix.engine;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.security.Policy;
  import org.apache.avalon.Component;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Context;
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.util.io.ExtensionFileFilter;
  import org.apache.avalon.util.security.PolicyClassLoader;
  
  /**
   * This component creates blocks and blockInfos.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class SarClassLoader
      extends PolicyClassLoader
      implements Component, Contextualizable, Composer, Initializable
  {
      protected File              m_baseDirectory;
      protected String            m_blocksDirectory;
      protected String            m_libDirectory;
  
      public SarClassLoader()
      {
          super( new URL[ 0 ], Thread.currentThread().getContextClassLoader(), 
null );
      }
  
      public void contextualize( final Context context )
      {
          m_baseDirectory = (File)context.get( SarContextResources.APP_HOME_DIR 
);
          m_blocksDirectory = (String)context.get( 
SarContextResources.APP_BLOCKS_DIR );
          m_libDirectory = (String)context.get( SarContextResources.APP_LIB_DIR 
);
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_policy = (Policy)componentManager.lookup( "java.security.Policy" );
      }
  
      public void init()
          throws Exception
      {
          final File blockDir = 
              (new File( m_baseDirectory, m_blocksDirectory 
)).getAbsoluteFile();
          final File libDir = 
              (new File( m_baseDirectory, m_libDirectory )).getAbsoluteFile();
          
          addURLs( blockDir, new String[] { ".bar" } );
          addURLs( libDir, new String[] { ".jar", ".zip" } );
      }
  
      protected void addURLs( final File directory, final String[] extentions )
          throws MalformedURLException
      {
          final ExtensionFileFilter filter = new ExtensionFileFilter( 
extentions );
          final File[] files = directory.listFiles( filter );
          if( null == files ) return;
          addURLs( files );
      }
  
      protected void addURLs( final File[] files )
          throws MalformedURLException
      {     
          for( int i = 0; i < files.length; i++ )
          {
              addURL( files[ i ].toURL() );
          }
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/SarContextResources.java
  
  Index: SarContextResources.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 file.
   */
  package org.apache.phoenix.engine;
  
  /**
   * This represents the names of the various resources in sars context.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface SarContextResources 
  {
      String    APP_NAME          = "app.name";
      String    APP_HOME_DIR      = "app.home";
  
      String    APP_BLOCKS_DIR    = "app.blocks";
      String    APP_LIB_DIR       = "app.lib";
      String    APP_CONF_DIR      = "app.conf";
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/ServerApplication.java
  
  Index: ServerApplication.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 file.
   */
  package org.apache.phoenix.engine;
  
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.Loggable;
  import org.apache.avalon.atlantis.Application;
  import org.apache.avalon.configuration.Configurable;
  
  /**
   * The ServerApplication is a self-contained server component that performs a 
specific
   * user function. 
   *
   * Example ServerApplications may be a Mail Server, File Server, Directory 
Server etc.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface ServerApplication 
      extends Application, Contextualizable, Configurable
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/ServerApplicationEntry.java
  
  Index: ServerApplicationEntry.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 file.
   */
  package org.apache.phoenix.engine;
  
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.Context;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.log.Logger;
  
  /**
   * This is the structure describing each server application before it is 
loaded.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class ServerApplicationEntry
      extends Entry
  {
      protected Logger            m_logger;
      protected Context           m_context;
      protected ComponentManager  m_componentManager;
      protected Configuration     m_configuration;
  
      public Logger getLogger()
      {
          return m_logger;
      }
  
      public void setLogger( final Logger logger )
      {
          m_logger = logger;
      }
  
      public Context getContext()
      {
          return m_context;
      }
  
      public void setContext( final Context context )
      {
          m_context = context;;
      }
  
      public ComponentManager getComponentManager()
      {
          return m_componentManager;
      }
      
      public void setComponentManager( final ComponentManager componentManager )
      {
          m_componentManager = componentManager;
      }
      
      public Configuration getConfiguration()
      {
          return m_configuration;
      }
  
      public void setConfiguration( final Configuration configuration )
      {
          m_configuration = configuration;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/ServerKernel.java
  
  Index: ServerKernel.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 file.
   */
  package org.apache.phoenix.engine;
  
  import org.apache.avalon.Loggable;
  import org.apache.avalon.atlantis.Kernel;
  
  /**
   * The ServerKernel is the core of the Phoenix system.
   * The kernel is responsible for orchestrating low level services 
   * such as loading, configuring and destroying blocks. It also 
   * gives access to basic facilities such as scheduling sub-systems,
   * protected execution contexts, naming and directory services etc.
   *
   * Note that no facilities are available until after the Kernel has been 
   * configured and initialized.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface ServerKernel 
      extends Loggable, Kernel
  {
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/BlockDAG.java
  
  Index: BlockDAG.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 file.
   */
  package org.apache.phoenix.engine.blocks;
  
  import java.util.Iterator;
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.phoenix.Block;
  import org.apache.phoenix.engine.ServerApplication;
  import org.apache.phoenix.metainfo.BlockUtil;
  import org.apache.phoenix.metainfo.DependencyInfo;
  import org.apache.phoenix.metainfo.ServiceInfo;
  
  /**
   * This is the dependency graph for blocks.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class BlockDAG
      extends AbstractLoggable
      implements Composer
  {
      protected ServerApplication       m_serverApplication;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_serverApplication = (ServerApplication)componentManager.
              lookup( "org.apache.phoenix.engine.ServerApplication" );
      }
  
      public void walkGraph( final String root, final BlockVisitor visitor )
          throws Exception
      {
          visitBlock( root, getBlockEntry( root ), visitor, true );
      }
  
      public void reverseWalkGraph( final String root, final BlockVisitor 
visitor )
          throws Exception
      {
          visitBlock( root, getBlockEntry( root ), visitor, false );
      }
  
      protected BlockEntry getBlockEntry( final String name )
          throws Exception
      {
          return (BlockEntry)m_serverApplication.getEntry( name );
          //catch( final ContainerException ce )
      }
  
      /**
       * Traverse dependencies of specified entry.
       *
       * @param name name of BlockEntry
       * @param entry the BlockEntry
       */
      protected void visitDependencies( final String name, 
                                        final BlockEntry entry, 
                                        final BlockVisitor visitor )
          throws Exception
      {
          getLogger().debug( "Traversing dependencies for " + name );
  
          final DependencyInfo[] infos = entry.getBlockInfo().getDependencies();
          for( int i = 0; i < infos.length; i++ )
          {
              final ServiceInfo serviceInfo = infos[ i ].getService();
              final String role = infos[ i ].getRole();
  
              getLogger().debug( "Traversing dependency of " + name + " with 
role " + role + 
                                 " to provide service " + serviceInfo.getName() 
);
  
              //roleEntry should NEVER be null as it is checked when 
              //entry is added to container
              final RoleEntry roleEntry = entry.getRoleEntry( role );
              visitDependency( roleEntry.getName(), serviceInfo, visitor );
          }
      }
  
      /**
       * Traverse all reverse dependencies of specified entry.
       * A reverse dependency are those that dependend on entry.
       *
       * @param name name of BlockEntry
       * @param entry the BlockEntry
       */
      protected void visitReverseDependencies( final String name, final 
BlockVisitor visitor )
          throws Exception
      {
          getLogger().debug( "Traversing reverse dependencies for " + name );
          
          final Iterator entries = m_serverApplication.list();
          while( entries.hasNext() ) 
          {
              final String blockName = (String)entries.next();
              final BlockEntry entry = getBlockEntry( blockName );           
              final RoleEntry[] roles = entry.getRoleEntrys();
  
              for( int i = 0; i < roles.length; i++ )
              {
                  final String depends = roles[ i ].getName();
                  
                  if( depends.equals( name ) )
                  {
                      getLogger().debug( "Attempting to unload block " + 
blockName +
                                         " as it depends on " + depends );
  
                      //finally try to traverse block
                      visitBlock( blockName, entry, visitor, false );
                  }
              }
          }
      }
  
      /**
       * Load a single dependency. 
       * Make sure dependency has service that it is supposed to be providing.
       *
       * @param name the name of dependency
       * @param serviceInfo the description of service dependency should provide
       * @return false on unrecoverable failure
       */
      protected void visitDependency( final String name, 
                                      final ServiceInfo serviceInfo,
                                      final BlockVisitor visitor )
          throws Exception
      {
          final BlockEntry entry = getBlockEntry( name );
  
          //make sure that the block offers service it supposed to be providing
          final ServiceInfo[] services = entry.getBlockInfo().getServices();
          if( !BlockUtil.hasMatchingService( services, serviceInfo ) )
          {
              throw new Exception( "Dependency " + name + " does not offer " +
                                   "service required: " + serviceInfo );
          }
          
          //finally try to traverse block
          visitBlock( name, entry, visitor, true );
      }
  
      protected void visitBlock( final String name, 
                                 final BlockEntry entry,
                                 final BlockVisitor visitor,
                                 final boolean forward )
          throws Exception
      {
          if( forward ) 
          {
              visitDependencies( name, entry, visitor );
          }
          else
          {
              visitReverseDependencies( name, visitor );
          }
  
          visitor.visitBlock( name, entry );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/BlockEntry.java
  
  Index: BlockEntry.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 file.
   */
  package org.apache.phoenix.engine.blocks;
  
  import org.apache.avalon.camelot.AvalonState;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.Locator;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.phoenix.Block;
  import org.apache.phoenix.metainfo.BlockInfo;
  
  /**
   * This is the structure describing each block before it is loaded.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class BlockEntry
      extends Entry
  {
      protected final Locator               m_locator;  
      protected final RoleEntry[]           m_roleEntrys;
  
      //UGLY HACK should be stored in another server Facility (ie 
ConfigurationRepository)
      protected Configuration               m_configuration;
  
      public BlockEntry( final Locator locator, final RoleEntry[] roleEntrys ) 
      {
          setState( AvalonState.BASE );
          m_locator = locator;
          m_roleEntrys = roleEntrys;
      }
  
      public Locator getLocator()
      {
          return m_locator;
      }
  
      public BlockInfo getBlockInfo()
      {
          return (BlockInfo)getInfo();
      }
  
      public void setBlockInfo( final BlockInfo blockInfo )
      {
          setInfo(  blockInfo );
      }
  
      /**
       * Get a RoleEntry from entry with a particular role.
       *
       * @param role the role of RoleEntry to look for
       * @return the matching deendency else null
       */
      public RoleEntry getRoleEntry( final String role )
      {
          for( int i = 0; i < m_roleEntrys.length; i++ )
          {
              if( m_roleEntrys[ i ].getRole().equals( role ) )
              {
                  return m_roleEntrys[ i ];
              }
          }
          
          return null;
      }
  
      public RoleEntry[] getRoleEntrys()
      {
          return m_roleEntrys;
      }
   
      public Configuration getConfiguration()
      {
          return m_configuration;
      }
  
      public void setConfiguration( final Configuration configuration )
      {
          m_configuration = configuration;
      }
  
      public Block getBlock()
      {
          return (Block)getInstance();
      }
  
      public void setBlock( final Block block )
      {
          setInstance( block );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/BlockVisitor.java
  
  Index: BlockVisitor.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 file.
   */
  package org.apache.phoenix.engine.blocks;
  
  import org.apache.avalon.atlantis.ApplicationException;
  
  /**
   * Visitor interface that objects implement to walk the DAG.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface BlockVisitor
  {
      /**
       * This is called when a block is reached whilst walking the tree.
       *
       * @param name the name of block
       * @param entry the BlockEntry
       * @exception ApplicationException if walking is to be stopped
       */
      void visitBlock( String name, BlockEntry entry )
          throws ApplicationException;
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/DefaultBlockContext.java
  
  Index: DefaultBlockContext.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 file. 
   */
  package org.apache.phoenix.engine.blocks;
  
  import java.io.File;
  import org.apache.avalon.Context;
  import org.apache.avalon.DefaultContext;
  import org.apache.avalon.util.thread.ThreadManager;
  import org.apache.avalon.util.thread.ThreadPool;
  import org.apache.log.Logger;
  import org.apache.phoenix.BlockContext;
  
  /**
   * Context via which Blocks communicate with container.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultBlockContext
      extends DefaultContext
      implements BlockContext
  {
      protected ThreadManager  m_threadManager;
  
      public DefaultBlockContext( final ThreadManager threadManager )
      {
          m_threadManager = threadManager;
      }
  
      public DefaultBlockContext( final ThreadManager threadManager, final 
Context context )
      {
          super( context );
          m_threadManager = threadManager;
      }
  
      /**
       * Base directory of .sar application.
       *
       * @return the base directory
       */
      public File getBaseDirectory()
      {
          return (File)get( APP_HOME_DIR );
      }
  
      /**
       * Retrieve name of block.
       *
       * @return the name of block
       */
      public String getName()
      {
          return (String)get( NAME );
      }
  
      /**
       * Retrieve thread manager by category.
       * ThreadManagers are given names so that you can manage different thread 
       * count to different components.
       *
       * @param category the category
       * @return the ThreadManager
       */
      public ThreadPool getThreadPool( final String category )
      {
          return m_threadManager.getThreadPool( category );
      }
  
      /**
       * Retrieve thread manager by category.
       * ThreadManagers are given names so that you can manage different thread 
       * count to different components.
       *
       * @param category the category
       * @return the ThreadManager
       */
      public ThreadPool getDefaultThreadPool()
      {
          return m_threadManager.getThreadPool( "default" );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/DefaultBlockDeployer.java
  
  Index: DefaultBlockDeployer.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 file.
   */
  package org.apache.phoenix.engine.blocks;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.jar.Attributes;
  import java.util.jar.Manifest;
  import java.util.zip.ZipFile;
  import org.apache.avalon.camelot.AbstractZipDeployer;
  import org.apache.avalon.camelot.DeployerUtil;
  import org.apache.avalon.camelot.DeploymentException;
  import org.apache.avalon.camelot.LocatorRegistry;
  import org.apache.avalon.camelot.Registry;
  import org.apache.avalon.camelot.RegistryException;
  import org.apache.avalon.util.io.IOUtil;
  import org.apache.phoenix.metainfo.BlockInfo;
  import org.apache.phoenix.metainfo.BlockInfoBuilder;
  
  /**
   * This class deploys a .bar file into a registry.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultBlockDeployer
      extends AbstractZipDeployer
  {
      protected BlockInfoBuilder    m_builder;
  
      /**
       * Default constructor.
       */
      public DefaultBlockDeployer()
      {
          m_builder = new BlockInfoBuilder();
  
          //Indicate that this deployer should deploy to respective types
          m_deployToLocatorRegistry = true;
          m_deployToInfoRegistry = true;
  
          m_autoUndeploy = true;
          m_type = "Block";
      }
  
      /**
       * Load resources from jar required to deploy file.
       *
       * @param zipFile the zipFile
       * @param location the location deploying to
       * @param url the URL
       * @exception DeploymentException if an error occurs
       */
      protected void loadResources( final ZipFile zipFile, final String 
location, final URL url )
          throws DeploymentException
      {
          handleBlocks( zipFile, DeployerUtil.loadManifest( zipFile ), url );
      }
      
      /**
       * Create and register Infos for all blocks stored in deployment.
       *
       * @param properties the properties
       * @param url the url of deployment
       * @exception DeploymentException if an error occurs
       */     
      protected void handleBlocks( final ZipFile zipFile, final Manifest 
manifest, final URL url )
          throws DeploymentException
      {
          final Map entries = manifest.getEntries();
          final Iterator sections = entries.keySet().iterator();
  
          //for every section (aka resource)
          // check to see if the attribute "Avalon-Block" is set to true
          while( sections.hasNext() )
          {
              final String section = (String)sections.next();
              final Attributes attributes = manifest.getAttributes( section );
              final String blockValue = attributes.getValue( "Avalon-Block" );
              final boolean isBlock = Boolean.valueOf( blockValue 
).booleanValue();
              
              if( isBlock )
              {
                  handleBlock( zipFile, section, url );
              }
          }
      }
  
      /**
       * Handle the addition of a block from .bar file.
       *
       * @param zipFile the .bar zip
       * @param block the block filename
       * @param url the url of .bar file
       * @exception DeploymentException if an error occurs
       */
      protected void handleBlock( final ZipFile zipFile, final String block, 
final URL url )
          throws DeploymentException
      {
          final String classname = block.substring( 0, block.length() - 6 
).replace('/','.');
          addLocator( classname, classname, url );
  
          final BlockInfo info = loadBlockInfo( zipFile, classname, url );
          addInfo( classname, info );
      }
  
      /**
       * Create a blockinfo object by loading a .xinfo file.
       *
       * @param zipFile the zipFile to load it from
       * @param classname the name of the block class
       * @param url the url for zip
       * @return the created block info
       * @exception DeploymentException if an error occurs
       */
      protected BlockInfo loadBlockInfo( final ZipFile zipFile, 
                                         final String classname, 
                                         final URL url )
          throws DeploymentException
      {
          final String resource = classname.replace( '.', '/' ) + ".xinfo";
          final InputStream inputStream = DeployerUtil.loadResourceStream( 
zipFile, resource );
  
          try { return m_builder.build( inputStream ); }
          catch( final Exception e )
          {
              throw new DeploymentException( "Failed to build BlockInfo for " + 
classname +
                                             " in location " + url, e );
          }
          finally
          {
              IOUtil.shutdownStream( inputStream );
          }
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/RoleEntry.java
  
  Index: RoleEntry.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 file.
   */
  package org.apache.phoenix.engine.blocks;
  
  /**
   * This is the structure describing the instances of roles provided to each 
block.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class RoleEntry
  {
      protected final String        m_name;
      protected final String        m_role;
  
      public RoleEntry( final String name, final String role )
      {
          m_name = name;
          m_role = role;
      }
  
      public String getRole()
      {
          return m_role;
      }
      
      public String getName()
      {
          return m_name;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys/DefaultComponentBuilder.java
  
  Index: DefaultComponentBuilder.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 file.
   */
  package org.apache.phoenix.engine.facilitys;
  
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.Component;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.atlantis.ApplicationException;
  import org.apache.avalon.atlantis.Facility;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.Factory;
  import org.apache.avalon.camelot.FactoryException;
  import org.apache.avalon.camelot.pipeline.ComponentBuilder;
  import org.apache.log.Logger;
  import org.apache.phoenix.Block;
  import org.apache.phoenix.engine.SarBlockFactory;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  import org.apache.phoenix.metainfo.BlockUtil;
  import org.apache.phoenix.metainfo.ServiceInfo;
  
  /**
   * Component responsible for building componentManager information for entry.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultComponentBuilder
      extends AbstractLoggable
      implements Facility, ComponentBuilder, Composer, Initializable
  {
      protected SarBlockFactory      m_factory = new SarBlockFactory();
  
      public void setLogger( final Logger logger )
      {
          super.setLogger( logger );
          setupLogger( m_factory, "<core>.factory" );
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_factory.compose( componentManager );
      }
  
      public void init()
          throws Exception
      {
          m_factory.init();
      }
  
      public Object createComponent( final String name, final Entry entry )
          throws Exception
      {
          getLogger().info( "Creating block " + name );
  
          final BlockEntry blockEntry = (BlockEntry)entry;
  
          Block block = null;
          
          try { block = (Block)m_factory.create( blockEntry.getLocator(), 
Block.class ); }
          catch( final FactoryException fe )
          {
              throw new ApplicationException( "Failed to create block " + name, 
fe );
          }
          
          getLogger().debug( "Created block " + block );
          verifyBlockServices( name, blockEntry, block );
  
          return block;
      }
  
      /**
       * Verify that all the services that a block 
       * declares it provides are actually provided.
       *
       * @param name the name of block
       * @param blockEntry the blockEntry
       * @param block the Block
       * @exception ApplicationException if verification fails
       */
      protected void verifyBlockServices( final String name, 
                                          final BlockEntry blockEntry,  
                                          final Block block )
          throws ApplicationException
      {
          final ServiceInfo[] services = 
blockEntry.getBlockInfo().getServices();
          for( int i = 0; i < services.length; i++ )
          {
              if( false == BlockUtil.implementsService( block, services[ i ] ) )
              {
                  final String message = "Block " + name + " fails to implement 
" + 
                      "advertised service " + services[ i ];
                  getLogger().warn( message );
                  throw new ApplicationException( message );
              }
          }        
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys/DefaultComponentManagerBuilder.java
  
  Index: DefaultComponentManagerBuilder.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 file.
   */
  package org.apache.phoenix.engine.facilitys;
  
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.DefaultComponentManager;
  import org.apache.avalon.atlantis.Facility;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.pipeline.ComponentManagerBuilder;
  import org.apache.phoenix.engine.ServerApplication;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  import org.apache.phoenix.engine.blocks.RoleEntry;
  
  /**
   * Component responsible for building componentManager information for entry.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultComponentManagerBuilder
      implements Facility, ComponentManagerBuilder, Composer
  {
      //container to get dependencies from
      protected ServerApplication        m_serverApplication;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_serverApplication = (ServerApplication)componentManager.
              lookup( "org.apache.phoenix.engine.ServerApplication" );
      }
  
      /**
       * Build a ComponentManager for a specific Block.
       *
       * @param name the name of the block
       * @param entry the BlockEntry
       * @return the created ComponentManager
       */
      public ComponentManager createComponentManager( String name, Entry entry )
          throws ComponentManagerException
      {
          final DefaultComponentManager componentManager = new 
DefaultComponentManager();       
          final RoleEntry[] roleEntrys = ((BlockEntry)entry).getRoleEntrys();
          
          for( int i = 0; i < roleEntrys.length; i++ )
          {
              final String dependencyName = roleEntrys[ i ].getName();
  
              try
              {
                  //dependency should NEVER be null here as it 
                  //is validated at entry time
                  final BlockEntry dependency = 
                      (BlockEntry)m_serverApplication.getEntry( dependencyName 
);
                  componentManager.put( roleEntrys[ i ].getRole(), 
dependency.getBlock() );
              }
              catch( final ContainerException ce ) {}
          }
          
          return componentManager;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys/DefaultConfigurationRepository.java
  
  Index: DefaultConfigurationRepository.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 file.
   */
  package org.apache.phoenix.engine.facilitys;
  
  import org.apache.avalon.atlantis.Facility;
  import org.apache.avalon.camelot.pipeline.ConfigurationRepository;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  
  /**
   * Repository from which all configuration data is retrieved.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultConfigurationRepository
      implements Facility, ConfigurationRepository
  {
      public Configuration getConfiguration( String name, Entry entry ) 
          throws ConfigurationException
      {
          final BlockEntry blockEntry = (BlockEntry)entry;
          return blockEntry.getConfiguration();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys/DefaultContextBuilder.java
  
  Index: DefaultContextBuilder.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 file.
   */
  package org.apache.phoenix.engine.facilitys;
  
  import java.io.File;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Context;
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.DefaultContext;
  import org.apache.avalon.atlantis.Facility;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.pipeline.ContextBuilder;
  import org.apache.avalon.util.thread.ThreadManager;
  import org.apache.phoenix.BlockContext;
  import org.apache.phoenix.engine.SarContextResources;
  import org.apache.phoenix.engine.blocks.DefaultBlockContext;
  
  /**
   * Component responsible for building context information for block.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultContextBuilder
      implements Facility, ContextBuilder, Contextualizable, Composer
  {
      //context used to setup hosted blocks
      protected DefaultContext           m_baseBlockContext;
  
      //thread manager used to build contexts with
      protected ThreadManager            m_threadManager;
  
      public void contextualize( final Context context )
      {
          final File baseDirectory = (File)context.get( 
SarContextResources.APP_HOME_DIR );
          final String name = (String)context.get( SarContextResources.APP_NAME 
);
          
          //base contxt that all block contexts inherit from 
          final DefaultContext blockContext = new DefaultContext();
          blockContext.put( BlockContext.APP_NAME, name );
          blockContext.put( BlockContext.APP_HOME_DIR, baseDirectory );
          m_baseBlockContext = blockContext;
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_threadManager = (ThreadManager)componentManager.
              lookup( "org.apache.avalon.util.thread.ThreadManager" );
      }
  
      public Context createContext( String name, Entry entry )
      {
          final DefaultBlockContext context =
              new DefaultBlockContext( m_threadManager, m_baseBlockContext );
          context.put( BlockContext.NAME, name );
          return context;        
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys/DefaultLoggerBuilder.java
  
  Index: DefaultLoggerBuilder.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 file.
   */
  package org.apache.phoenix.engine.facilitys;
  
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.atlantis.Facility;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.pipeline.LoggerBuilder;
  import org.apache.log.Logger;
  
  /**
   * Component responsible for building logger for entry.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultLoggerBuilder
      extends AbstractLoggable
      implements LoggerBuilder, Facility
  {
      public Logger createLogger( final String name, final Entry entry )
      {
          return  getLogger().getChildLogger( name );
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/loader/AvalonLoader.java
  
  Index: AvalonLoader.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 file.
   */
  package org.apache.phoenix.engine.loader;
  
  import java.io.File;
  import java.lang.reflect.Method;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.security.AccessControlContext;
  import java.security.AccessController;
  import java.security.CodeSource;
  import java.security.PermissionCollection;
  import java.security.Permissions;
  import java.security.Policy;
  import java.security.PrivilegedActionException;
  import java.security.PrivilegedExceptionAction;
  import java.security.ProtectionDomain;
  import java.security.Security;
  import java.util.ArrayList;
  import java.util.Enumeration;
  import java.util.StringTokenizer;
  
  /**
   * AvalonLoader is the class that bootstraps and installs the security 
manager.
   * It also a default policy that gives all code all permssions.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public final class AvalonLoader
  {
      protected final static boolean         ENABLE_SECURITY_MANAGER =
          !Boolean.getBoolean("avalon.insecure");
  
      protected final static String          RESTRICTED_PACKAGES = 
          System.getProperty( "avalon.restricted.packages", 
                              Security.getProperty("package.access") );
  
      protected final static String          MAIN_JAR =
          System.getProperty( "avalon.mainJar", "avalon-engine.jar" );
  
      protected final static String          MAIN_CLASS =
          System.getProperty( "avalon.mainClass", 
"org.apache.phoenix.engine.Main" );
  
      public final static void main( final String args[] )
          throws Exception
      {
          //setup restricted packages
          Security.setProperty( "package.access", RESTRICTED_PACKAGES );
  
          //setup new Policy manager
          Policy.setPolicy( new FreeNEasyPolicy() );
  
          final File loaderDir = findLoaderDir();
          final String avalonHome = 
              loaderDir.getAbsoluteFile().getParentFile() + File.separator;
          System.setProperty( "avalon.home", avalonHome );
  
          final File mainJar = new File( loaderDir, MAIN_JAR );
  
          //load main jar
          final URL archive = mainJar.toURL();
          final URLClassLoader classLoader = new URLClassLoader( new URL[] { 
archive } );
  
          runSystem( classLoader, args );
      }
  
      /**
       * load class and retrieve appropriate main method.
       */
      protected static void runSystem( final ClassLoader classLoader, final 
String[] args )
      {
          try
          {
              final Class clazz = classLoader.loadClass( MAIN_CLASS );
              final Method method = clazz.getMethod( "main", new Class[] { 
args.getClass() } );
  
              final Object instance = clazz.newInstance();
  
              // Set security manager unless it has been disabled by system 
property
              if( ENABLE_SECURITY_MANAGER )
              {
                  System.setSecurityManager( new SecurityManager() );
              }
  
              //kick the tires and light the fires....
              try
              {
                  final PrivilegedExceptionAction action = new 
PrivilegedExceptionAction() 
                  {
                      public Object run() throws Exception
                      {        
                          method.invoke( instance, new Object[] { args } );
                          return null;
                      }
                  };
                  
                  AccessController.doPrivileged( action );
              } 
              catch( final PrivilegedActionException pae )
              {
                  // only "checked" exceptions will be "wrapped" in a 
PrivilegedActionException.
                  throw pae.getException();
              }
          }
          catch( final Exception throwable ) 
          {
              throwable.printStackTrace( System.err );
          }
      }
  
      /**
       *  Finds the avalon-loader.jar file in the classpath.
       */
      protected final static File findLoaderDir() 
          throws Exception
      {
          final String classpath = System.getProperty( "java.class.path" );
          final String pathSeparator = System.getProperty( "path.separator" );
          final StringTokenizer tokenizer = new StringTokenizer( classpath, 
pathSeparator );
          
          while( tokenizer.hasMoreTokens() )
          {
              final String element = tokenizer.nextToken();
              
              if( element.endsWith( "avalon-loader.jar" ) )
              {
                  File file = (new File( element )).getCanonicalFile();
                  file = file.getParentFile();
                  return file;                
              }
          }
          
          throw new Exception( "Unable to locate avalon-loader.jar in 
classpath" );
      }
  
      /**
       * Default polic class to give every code base all permssions. 
       * Will be replaced once the kernel loads.
       */
      private static class FreeNEasyPolicy
          extends Policy
      {
          public PermissionCollection getPermissions( final CodeSource 
codeSource )
          {
              final Permissions permissions = new Permissions();
              permissions.add( new java.security.AllPermission() );
              return permissions;
          }
  
          public void refresh() {}
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/phases/DefaultPhase.java
  
  Index: DefaultPhase.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 file.
   */
  package org.apache.phoenix.engine.phases;
  
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.ComponentManagerException;
  import org.apache.avalon.Composer;
  import org.apache.avalon.Context;
  import org.apache.avalon.Contextualizable;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.atlantis.ApplicationException;
  import org.apache.avalon.camelot.pipeline.LifeCycleStage;
  import org.apache.avalon.util.Enum;
  import org.apache.log.LogKit;
  import org.apache.log.Logger;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  import org.apache.avalon.camelot.AvalonState;
  import org.apache.avalon.util.thread.ThreadManager;
  
  /**
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultPhase
      extends AbstractLoggable
      implements Phase, Contextualizable, Composer, Initializable
  {  
      protected final AvalonState           m_startState;
      protected final AvalonState           m_endState;
      protected final Traversal             m_traversal;
      protected final LifeCycleStage        m_pipeline;
      protected ThreadManager               m_threadManager;
      protected ClassLoader                 m_classLoader;
  
      public DefaultPhase( final Traversal traversal, 
                           final LifeCycleStage pipeline,
                           final AvalonState startState,
                           final AvalonState endState )
      {
          m_traversal = traversal;
          m_pipeline = pipeline;
          m_startState = startState;
          m_endState = endState;
      }
  
      public void setLogger( final Logger logger )
      {
          super.setLogger( logger );
          setupLogger( m_pipeline );
      }
  
      public void contextualize( final Context context )
      {
          if( m_pipeline instanceof Contextualizable )
          {
              ((Contextualizable)m_pipeline).contextualize( context );
          }
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentManagerException
      {
          m_classLoader = (ClassLoader)componentManager.lookup( 
"java.lang.ClassLoader" );
  
          m_threadManager = (ThreadManager)componentManager.
              lookup( "org.apache.avalon.util.thread.ThreadManager" );
  
          if( m_pipeline instanceof Composer )
          {
              ((Composer)m_pipeline).compose( componentManager );
          }
      }
  
      public void init()
          throws Exception
      {
          if( m_pipeline instanceof Initializable )
          {
              ((Initializable)m_pipeline).init();
          }  
      }
  
      /**
       * Retrieve traversal that should be taken.
       *
       * @return the Traversal
       */
      public Traversal getTraversal()
      {
          return m_traversal;
      }
  
      /**
       * This is called when a block is reached whilst walking the tree.
       *
       * @param name the name of block
       * @param entry the BlockEntry
       * @exception ApplicationException if walking is to be stopped
       */
      public void visitBlock( final String name, final BlockEntry entry )
          throws ApplicationException
      {
          if( entry.getState() == m_endState ) return;
          else if( entry.getState() != m_startState ) 
          {
              final String message = "Block (" + name + ") not prepared for 
phase";
              getLogger().warn( message );
              throw new ApplicationException( message );
          }
  
          LogKit.getCurrentContext().push( name );
  
          final PipelineRunner runner =
              new PipelineRunner( name, entry, m_pipeline, m_classLoader );
          Exception exception = null;
          try
          {
              try
              {
                  m_threadManager.getDefaultThreadPool().executeAndWait( runner 
);
                  exception = runner.getException();
              }
              catch( final Exception e )
              {
                  exception = e;
              }
              
              if( null != exception )
              {
                  throw new ApplicationException( "Failed to load block " + 
name, exception );
              }
              else
              {
                  getLogger().info( "Ran Phase " + name );
              }
          }
          finally
          {
              LogKit.getCurrentContext().pop();
          }
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/phases/Phase.java
  
  Index: Phase.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 file.
   */
  package org.apache.phoenix.engine.phases;
  
  import org.apache.avalon.Component;
  import org.apache.avalon.util.Enum;
  import org.apache.phoenix.engine.blocks.BlockVisitor;
  
  /**
   * This represents a phase in applications lifecycle. 
   * Each phase is made up of a number of stages.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Phase
      extends BlockVisitor, Component
  {  
      public class Traversal
          extends Enum
      {
          Traversal( final String name )
          {
              super( name );
          }
      }
  
      Traversal   FORWARD      = new Traversal( "FORWARD" );
      Traversal   REVERSE      = new Traversal( "REVERSE" );
      Traversal   LINEAR       = new Traversal( "LINEAR" );
  
      /**
       * Retrieve traversal that should be taken.
       *
       * @return the Traversal
       */
      Traversal getTraversal();
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/phases/PipelineRunner.java
  
  Index: PipelineRunner.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 file.
   */
  package org.apache.phoenix.engine.phases;
  
  import org.apache.avalon.camelot.pipeline.LifeCycleStage;
  import org.apache.phoenix.Block;
  import org.apache.phoenix.engine.blocks.BlockEntry;
  
  class PipelineRunner
      implements Runnable
  {
      protected final ClassLoader     m_classLoader;
      protected final LifeCycleStage  m_pipeline;
      protected final String          m_name;
      protected final BlockEntry      m_entry;
  
      protected Exception             m_exception;
  
      public PipelineRunner( final String name, 
                             final BlockEntry entry, 
                             final LifeCycleStage pipeline,
                             final ClassLoader classLoader )
      {
          m_name = name;
          m_entry = entry;
          m_pipeline = pipeline;
          m_classLoader = classLoader;
      }
  
      public void run()
      {
          m_exception = null;
  
          try
          {
              Thread.currentThread().setContextClassLoader( m_classLoader );
              m_pipeline.process( m_name, m_entry );
          }
          catch( final Exception e )
          {
              m_exception = e;
          }
      }
  
      public Exception getException()
      {
          return m_exception;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/BlockInfo.java
  
  Index: BlockInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  /**
   * This descrbes information about the block that is used by administration 
tools and kernel.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface BlockInfo 
      extends org.apache.avalon.camelot.MetaInfo
  {
      /**
       * Return meta information that is generallly only required by 
administration tools.
       *
       * It should be loaded on demand and not always present in memory.
       *
       * @return the MetaInfo
       */
      MetaInfo getMetaInfo();
      
      /**
       * This returns a list of Services that this block exports.
       *
       * @return an array of Services (can be null)
       */
      ServiceInfo[] getServices();
  
      /**
       * Return an array of Service dependencies that this Block depends upon.
       *
       * @return an array of Service dependencies (may be null) 
       */
      DependencyInfo[] getDependencies();
  
      /**
       * Retrieve a dependency with a particular role.
       *
       * @param role the role
       * @return the dependency or null if it does not exist
       */
      DependencyInfo getDependency( String role );
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/BlockInfoBuilder.java
  
  Index: BlockInfoBuilder.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.util.Version;
  
  /**
   * A BlockInfoBuilder builds configurations via SAX2 compliant parser.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public final class BlockInfoBuilder
  {
      protected DefaultConfigurationBuilder     m_builder = new 
DefaultConfigurationBuilder();
  
      public BlockInfo build( final InputStream inputStream )
          throws Exception
      {
          final Configuration info = m_builder.build( inputStream );
  
          Configuration configuration  = null;
  
          configuration = info.getChild( "services" );
          final ServiceInfo services[] = buildServices( configuration );
  
          configuration = info.getChild( "dependencies" );
          final DependencyInfo dependencies[] = buildDependencies( 
configuration );
  
          configuration = info.getChild( "meta" );
          final MetaInfo metaInfo = buildMetaInfo( configuration );
  
          return new DefaultBlockInfo( metaInfo, services, dependencies );
      }
  
      protected DependencyInfo[] buildDependencies( final Configuration 
configuration )
          throws ConfigurationException
      {
          if( null == configuration ) return new DependencyInfo[0];
  
          final Configuration[] elements = configuration.getChildren( 
"dependency" );
          final ArrayList infos = new ArrayList();
  
          for( int i = 0; i < elements.length; i++ )
          {
              final DependencyInfo info = buildDependency( elements[ i ] );
              infos.add( info );
          }
  
          return (DependencyInfo[]) infos.toArray( new DependencyInfo[0] );
      }
  
      protected DependencyInfo buildDependency( final Configuration dependency )
          throws ConfigurationException
      {
          final String role = dependency.getChild( "role" ).getValue();
          final ServiceInfo serviceInfo = buildService( dependency.getChild( 
"service" ) );
  
          return new DefaultDependencyInfo( role, serviceInfo );
      }
  
      protected ServiceInfo[] buildServices( final Configuration servicesSet )
          throws ConfigurationException
      {
          if( null == servicesSet ) return new ServiceInfo[0];
  
          final Configuration[] elements = servicesSet.getChildren( "service" );
          final ArrayList infos = new ArrayList();
  
          for( int i = 0; i < elements.length; i++ )
          {
              final ServiceInfo info = buildService( elements[ i ] );
              infos.add( info );
          }
  
          return (ServiceInfo[])infos.toArray( new ServiceInfo[0] );
      }
  
      protected ServiceInfo buildService( final Configuration service )
          throws ConfigurationException
      {
          final String name = service.getAttribute( "name" );
          final Version version =  buildVersion( service.getAttribute( 
"version" ) );
          return new DefaultServiceInfo( name, version );
      }
  
      protected Version buildVersion( final String version )
      {
          final int length = version.length();
          int start = 0;
          int end = version.indexOf('.');
          int major = 1;
          int minor = 0;
          int revision = 0;
  
          try { major = Integer.parseInt( version.substring( start, end ) ); }
          catch( final NumberFormatException nfe ) { }
  
          start = end + 1;
          end = version.indexOf( '.', start );
  
          if( -1 == end ) end = version.length();
  
          try { minor = Integer.parseInt( version.substring( start, end ) ); }
          catch( final NumberFormatException nfe ) { }
  
          if( end != length )
          {
              start = end + 1;
              end = length;
  
              try { revision = Integer.parseInt( version.substring( start, end 
) ); }
              catch( final NumberFormatException nfe ) { }
          }
  
          return new Version( major, minor, revision );
      }
  
      protected MetaInfo buildMetaInfo( final Configuration meta )
      {
          if( null == meta ) return null;
  
          return null;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/BlockUtil.java
  
  Index: BlockUtil.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import org.apache.phoenix.Block;
  
  /**
   * Class containing utility methods for blocks.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public final class BlockUtil 
  {
      /**
       * Private constructor to block instantiation.
       */
      private BlockUtil()
      {
      }
  
      public static boolean implementsService( final Block block,  final 
ServiceInfo service )
      {
          try
          {
              final Class clazz = 
                  block.getClass().getClassLoader().loadClass( 
service.getName() );
  
              return clazz.isAssignableFrom( block.getClass() );
          }
          catch( final Throwable throwable ) {}
          
          return false;
      }
  
      public static boolean hasMatchingService( final ServiceInfo[] candidates, 
                                                final ServiceInfo service )
      {
          for( int i = 0; i < candidates.length; i++ )
          {
              if( service.matches( candidates[ i ] ) )
              {
                  return true;
              }
          }
          
          return false;
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/Contributor.java
  
  Index: Contributor.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  /**
   * This describes some one who contributed to creating Block.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Contributor
      extends org.apache.avalon.camelot.MetaInfo
  {
      /**
       * Retrieve name of identity/person.
       *
       * @return the name of identity/person
       */
      String getName();
      
      /**
       * Return their contact details. (Usually an email address).
       *
       * @return the contact details
       */
      String getContactDetails();
      
      /**
       * Retrieve what role the contributor played in creating block.
       *
       * Valid values are "author" and "patcher".
       *
       * @return the role of contributor
       */
      String getRole();
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DefaultBlockInfo.java
  
  Index: DefaultBlockInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  /**
   * This is implementaion of BlockInfo.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultBlockInfo
      implements BlockInfo
  {
      protected final MetaInfo                 m_meta;
      protected final ServiceInfo              m_services[];
      protected final DependencyInfo           m_dependencies[];
  
      /**
       * Basic constructor that takes as parameters all parts.
       */
      public DefaultBlockInfo( final MetaInfo meta, 
                               final ServiceInfo services[], 
                               final DependencyInfo dependencies[] )
      {
          m_meta = meta;
          m_services = services;
          m_dependencies = dependencies;
      }
  
      /**
       * Return meta information that is generallly only required by 
administration tools.
       *
       * It should be loaded on demand and not always present in memory.
       *
       * @return the MetaInfo
       */
      public MetaInfo getMetaInfo()
      {
          return m_meta;
      }
      
      /**
       * This returns a list of Services that this block exports.
       *
       * @return an array of Services (can be null)
       */
      public ServiceInfo[] getServices()
      {
          return m_services;
      }
  
      /**
       * Return an array of Service dependencies that this Block depends upon.
       *
       * @return an array of Service dependencies (may be null) 
       */
      public DependencyInfo[] getDependencies()
      {
          return m_dependencies;
      }
  
      /**
       * Retrieve a dependency with a particular role.
       *
       * @param role the role
       * @return the dependency or null if it does not exist
       */
      public DependencyInfo getDependency( final String role )
      {
          for( int i = 0; i < m_dependencies.length; i++ )
          {
              if( m_dependencies[ i ].getRole().equals( role ) )
              {
                  return m_dependencies[ i ];
              }
          }
          
          return null;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DefaultContributor.java
  
  Index: DefaultContributor.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  /**
   * This describes some one who contributed to creating Block.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultContributor
      implements Contributor
  {
      protected final String              m_name;
      protected final String              m_contactDetails;
      protected final String              m_role;
  
      /**
       * Default constructor that takes components as parts.
       */
      public DefaultContributor( final String name, 
                                 final String contactDetails, 
                                 final String role )
      {
          m_name = name;
          m_contactDetails = contactDetails;
          m_role = role;
      }
      
      /**
       * Retrieve name of identity/person.
       *
       * @return the name of identity/person
       */
      public String getName()
      {
          return m_name;
      }
          
      /**
       * Return their contact details. (Usually an email address).
       *
       * @return the contact details
       */
      public String getContactDetails()
      {
          return m_contactDetails;
      }
  
      /**
       * Retrieve what role the contributor played in creating block.
       *
       * Valid values are "author" and "patcher".
       *
       * @return the role of contributor
       */
      public String getRole()
      {
          return m_role;        
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DefaultDependencyInfo.java
  
  Index: DefaultDependencyInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import org.apache.avalon.util.Version;
  
  /**
   * This is implementation of DependencyInfo.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultDependencyInfo 
      implements DependencyInfo
  {
      protected final String                      m_role;
      protected final ServiceInfo                 m_service;
  
      /**
       * Constructor that has all parts as parameters.
       */
      public DefaultDependencyInfo( final String role, final ServiceInfo 
service )
      {
          m_role = role;
          m_service = service;
      }
  
      /**
       * Return role of dependency.
       *
       * The role is what is used by block implementor to 
       * aquire dependency in ComponentManager.
       *
       * @return the name of the dependency
       */
      public String getRole()
      {
          return m_role;
      }
  
      /**
       * Return Service dependency provides.
       *
       * @return the service dependency provides
       */
      public ServiceInfo getService()
      {
          return m_service;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DefaultMetaInfo.java
  
  Index: DefaultMetaInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import javax.swing.Icon;
  import java.net.URL;
  import java.util.Locale;
  import org.apache.avalon.util.Version;
  
  /**
   * This descrbes information about the block that is used by administration 
   * tools during configuration and upgrade but is not neccesary for running.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class DefaultMetaInfo 
      implements MetaInfo
  {
      protected Contributor[]   m_contributors;
      protected Version         m_version;
      protected Icon            m_icon;
      protected Icon            m_largeIcon;
      protected URL             m_documentationLocation;
      protected URL             m_licenseLocation;
      protected URL             m_updateLocation;
  
      public DefaultMetaInfo( final Version version )
      {
          m_version = version;
      }
  
      /**
       * Get a list of contributors who helped create block.
       *
       * @return an array of Contributors
       */
      public Contributor[] getContributors()
      {
          return m_contributors;
      }
  
      public void setContributors(  final Contributor contributors[] )
      {
          m_contributors = contributors;
      }
  
      /**
       * Get a 16x16 Color Icon for block.
       *
       * @return a 16x16 Color Icon for block
       */
      public Icon getIcon()
      {
          return m_icon;
      }
  
      public void setIcon( final Icon icon )
      {
          m_icon = icon;
      }
  
      /**
       * Get a 32x32 Color Icon for block.
       *
       * @return a 32x32 Color Icon for block
       */
      public Icon getLargeIcon()
      {
          return m_largeIcon;
      }
  
      public void setLargeIcon( final Icon largeIcon )
      {
          m_largeIcon = largeIcon;
      }
  
      /**
       * Get URL of documentation.
       *
       * @return URL to documentation (if any)
       */
      public URL getDocumentationLocation()
      {
          return m_documentationLocation;
      }
  
      public void setDocumentationLocation( final URL documentationLocation )
      {
          m_documentationLocation = documentationLocation;
      }
  
      /**
       * Get URL of License.
       *
       * @return URL to License (if any)
       */
      public URL getLicenseLocation()
      {
          return m_licenseLocation;
      }
  
      public void setLicenseLocation( final URL licenseLocation )
      {
          m_licenseLocation = licenseLocation;
      }
  
      /**
       * Get URL of Update. Allows a block to be automatically updated from a 
URL.
       *
       * @return URL to Update (if any)
       */
      public URL getUpdateLocation()
      {
          return m_updateLocation;
      }
  
      public void setUpdateLocation( final URL updateLocation )
      {
          m_updateLocation = updateLocation;
      }
  
      /**
       * Retrieve Version of current Block.
       *
       * @return the version of block
       */
      public Version getVersion()
      {
          return m_version;
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DefaultServiceInfo.java
  
  Index: DefaultServiceInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import org.apache.avalon.util.Version;
  
  /**
   * This is default implementaion of ServiceInfo interface.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public final class DefaultServiceInfo 
      implements ServiceInfo
  {
      protected final Version                    m_version;
      protected final String                     m_name;
  
      public DefaultServiceInfo( final String name, final Version version )
      {
          m_name = name;
          m_version = version;
      }
  
      /**
       * Return version of interface
       *
       * @return the version of interface
       */
      public Version getVersion()
      {
          return m_version;
      }
  
      /**
       * Return name of Service (which coresponds to the interface 
       * name eg org.apache.block.Logger)
       *
       * @return the name of the Service
       */
      public String getName()
      {
          return m_name;
      }
  
      
      /**
       * Determine if other service will match this service.
       * To match a service has to have same name and must comply with version.
       *
       * @param other the other ServiceInfo
       * @return true if matches, false otherwise
       */
      public boolean matches( ServiceInfo other )
      {
          return 
              other.getName().equals( m_name ) &&
              other.getVersion().complies( m_version );
      }
  
      /**
       * Convert to a string of format name/version
       *
       * @return string describing service
       */
      public String toString()
      {
          return m_name + "/" + m_version;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/DependencyInfo.java
  
  Index: DependencyInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  /**
   * This interface describes a dependency of Block.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface DependencyInfo 
      extends org.apache.avalon.camelot.MetaInfo
  {
      /**
       * Return name of dependency.
       *
       * The name is what is used by block implementor to aquire dependency in 
ComponentManager.
       *
       * @return the name of the dependency
       */
      String getRole();
  
      /**
       * Return Service dependency provides.
       *
       * @return the service dependency provides
       */
      ServiceInfo getService();
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/MetaInfo.java
  
  Index: MetaInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import java.net.URL;
  import javax.swing.Icon;
  import org.apache.avalon.util.Version;
  
  /**
   * This descrbes information about the block that is used by administration 
   * tools during configuration and upgrade but is not neccesary for running.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface MetaInfo 
      extends org.apache.avalon.camelot.MetaInfo
  {
      /**
       * Get a list of contributors who helped create block.
       *
       * @return an array of Contributors
       */
      Contributor[] getContributors();
  
      /**
       * Get a 16x16 Color Icon for block.
       *
       * @return a 16x16 Color Icon for block
       */
      Icon getIcon();
  
      /**
       * Get a 32x32 Color Icon for block.
       *
       * @return a 32x32 Color Icon for block
       */
      Icon getLargeIcon();
  
      /**
       * Get URL of documentation.
       *
       * @return URL to documentation (if any)
       */
      URL getDocumentationLocation();
  
      /**
       * Get URL of License.
       *
       * @return URL to License (if any)
       */
      URL getLicenseLocation();
  
      /**
       * Get URL of Update. Allows a block to be automatically updated from a 
URL.
       *
       * @return URL to Update (if any)
       */
      URL getUpdateLocation();
  
  
      /**
       * Retrieve Version of current Block.
       *
       * @return the version of block
       */
      Version getVersion();
  }
  
  
  
  1.1                  
jakarta-avalon-phoenix/src/java/org/apache/phoenix/metainfo/ServiceInfo.java
  
  Index: ServiceInfo.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 file.
   */
  package org.apache.phoenix.metainfo;
  
  import org.apache.avalon.util.Version;
  
  /**
   * This interface describes a particular service that a component offers.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface ServiceInfo
      extends org.apache.avalon.camelot.MetaInfo
  {
      /**
       * Return version of interface
       *
       * @return the version of interface
       */
      Version getVersion();
  
      /**
       * Return name of Service (which coresponds to the interface name 
       * eg org.apache.block.Logger).
       *
       * @return the name of the Service
       */
      String getName();
  
      /**
       * Determine if other service will match this service.
       * To match a service has to have same name and must comply with version.
       *
       * @param other the other ServiceInfo
       * @return true if matches, false otherwise
       */
      boolean matches( ServiceInfo other );
  }
  
  
  

Reply via email to