You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by le...@apache.org on 2001/04/22 12:07:24 UTC

cvs commit: jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/loader PhoenixLoader.java

leosimons    01/04/22 03:07:24

  Modified:    proposal/4.0/src/java/org/apache/phoenix Start.java
               proposal/4.0/src/java/org/apache/phoenix/engine
                        PhoenixEmbeddor.java PhoenixKernel.java
               proposal/4.0/src/java/org/apache/phoenix/engine/applications
                        DefaultServerApplication.java
               proposal/4.0/src/java/org/apache/phoenix/engine/facilities
                        ThreadManagerImpl.java
  Added:       proposal/4.0/src/java/org/apache/phoenix/engine/applications
                        ServerApplicationEntry.java
               proposal/4.0/src/java/org/apache/phoenix/engine/blocks
                        AbstractBlock.java Block.java BlockContext.java
                        BlockDAG.java BlockEntry.java BlockVisitor.java
                        DefaultBlockContext.java DefaultBlockDeployer.java
                        RoleEntry.java
               proposal/4.0/src/java/org/apache/phoenix/engine/deployer
                        DefaultSarDeployer.java SarContextResources.java
               proposal/4.0/src/java/org/apache/phoenix/engine/loader
                        PhoenixLoader.java
               proposal/4.0/src/java/org/apache/phoenix/engine/metainfo
                        BlockDescriptor.java BlockInfo.java
                        BlockInfoBuilder.java BlockUtil.java
                        Contributor.java DefaultBlockDescriptor.java
                        DefaultBlockInfo.java DefaultContributor.java
                        DefaultDependencyDescriptor.java
                        DefaultServiceDescriptor.java
                        DependencyDescriptor.java Descriptor.java
                        ServiceDescriptor.java
  Removed:     proposal/4.0/src/java/org/apache/phoenix/engine/applications
                        DefaultServerApplicationFactory.java
               proposal/4.0/src/java/org/apache/phoenix/engine/deployer
                        DefaultDeployer.java
               proposal/4.0/src/java/org/apache/phoenix/loader
                        PhoenixLoader.java
  Log:
  - moving loader into engine
  - adding blocks and metainfo packages
  - replacing defaultdeployer with defaultsardeployer
  - more fixes
  
  Revision  Changes    Path
  1.6       +1 -1      jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/Start.java
  
  Index: Start.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/Start.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Start.java	2001/04/19 14:18:24	1.5
  +++ Start.java	2001/04/22 10:07:09	1.6
  @@ -57,7 +57,7 @@
                                                       "org.apache.phoenix.engine.PhoenixEmbeddor";
           private static String deployerClass;
           private static final String DEFAULT_DEPLOYER_CLASS =
  -                                                    "org.apache.phoenix.engine.deployer.DefaultDeployer";
  +                                                    "org.apache.phoenix.engine.deployer.DefaultSarDeployer";
           private static String mBeanServerClass;
           private static final String DEFAULT_MBEANSERVER_CLASS =
                                                       "org.apache.jmx.MBeanServerImpl";
  
  
  
  1.7       +9 -1      jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/PhoenixEmbeddor.java
  
  Index: PhoenixEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/PhoenixEmbeddor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PhoenixEmbeddor.java	2001/04/19 14:18:28	1.6
  +++ PhoenixEmbeddor.java	2001/04/22 10:07:12	1.7
  @@ -16,6 +16,7 @@
   import org.apache.framework.parameters.ParameterException;
   
   import org.apache.framework.context.Context;
  +import org.apache.framework.context.Contextualizable;
   import org.apache.framework.context.DefaultContext;
   import org.apache.framework.context.ContextualizationException;
   
  @@ -43,6 +44,7 @@
   import org.apache.avalon.atlantis.core.Kernel;
   import org.apache.avalon.atlantis.core.Embeddor;
   import org.apache.phoenix.engine.facilities.ManagerImpl;
  +import org.apache.phoenix.engine.facilities.ThreadManagerImpl;
   
   import org.apache.avalon.aut.log.AvalonLogFormatter;
   import org.apache.log.output.FileOutputLogTarget;
  @@ -417,7 +419,7 @@
                   ((Configurable)this.kernel).configure( configuration );
               }
               catch( Exception e ) { throw new StartException(
  -                        "Unable to configuration kernel from "+kernelConfigLocation, e ); }
  +                        "Unable to configure kernel from "+kernelConfigLocation, e ); }
           }
           if( this.kernel instanceof Contextualizable )
           {
  @@ -425,7 +427,12 @@
               // create them here and put them in the kernel's Context.
               this.createKernelContext();
               final Contextualizable contextualizable = (Contextualizable)this.kernel;
  +            try
  +            {
               contextualizable.contextualize( this.kernelContext );
  +            }
  +            catch( Exception e ) { throw new StartException(
  +                        "Unable to contextualize kernel", e ); }
           }
   
           try
  @@ -442,6 +449,7 @@
           this.kernelContext = new DefaultContext();
   
           kernelContext.put( "facilities.manager", this.manager );
  +        kernelContext.put( "facilities.threadManager", new ThreadManagerImpl() );
       }
   
       /**
  
  
  
  1.6       +72 -20    jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/PhoenixKernel.java
  
  Index: PhoenixKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/PhoenixKernel.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PhoenixKernel.java	2001/04/19 14:18:29	1.5
  +++ PhoenixKernel.java	2001/04/22 10:07:13	1.6
  @@ -13,9 +13,15 @@
   import javax.management.ObjectName;
   
   import org.apache.framework.context.Context;
  +import org.apache.framework.context.Contextualizable;
   import org.apache.framework.context.ContextException;
  +import org.apache.framework.component.Composer;
   import org.apache.framework.configuration.Configuration;
  -import org.apache.framework.lifecycle.Interruptable;
  +import org.apache.framework.configuration.Configurable;
  +import org.apache.framework.configuration.ConfigurationException;
  +import org.apache.framework.lifecycle.InitializationException;
  +import org.apache.framework.lifecycle.StartException;
  +import org.apache.framework.lifecycle.StopException;
   
   import org.apache.avalon.camelot.Container;
   import org.apache.avalon.camelot.ContainerException;
  @@ -23,28 +29,36 @@
   
   import org.apache.avalon.atlantis.applications.Application;
   import org.apache.avalon.atlantis.core.ServerKernel;
  +import org.apache.avalon.atlantis.core.AbstractKernel;
   import org.apache.avalon.atlantis.facilities.Manager;
   
  +import org.apache.phoenix.engine.applications.DefaultServerApplication;
  +import org.apache.phoenix.engine.applications.ServerApplicationEntry;
  +
   import org.apache.log.Logger;
  +import org.apache.log.LogKit;
   
   import org.apache.jmx.introspector.DynamicMBeanFactory;
   
   /**
  - * This is the default Kernel for Phoenix. It uses Camelot for container/
  - * deployer stuff.
  + * This is the default ServerKernel for Phoenix. It uses Camelot for
  + * container/deployer stuff.
    *
  + * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
    */
  -public class PhoenixKernel implements ServerKernel, Interruptable
  +public class PhoenixKernel extends AbstractKernel implements ServerKernel
       // and thus implements Application, Runnable, Initializable, Startable,
       // Stoppable, Disposable, Container, Component, Loggable, Kernel,
       // Contextualizable and ServerApplication
  +    // and thus extends AbstractContainer and AbstractLoggable
   {
       private Logger logger = null;
       private Manager manager = null;
   
       public PhoenixKernel()
       {
  +        m_entryClass = ServerApplicationEntry.class;
       }
       /////////////////////////
       /// LIFECYCLE METHODS ///
  @@ -66,37 +80,32 @@
       {
           try { this.manager = (Manager)context.get( "facilities.manager" ); }
           catch( Exception e ) { throw new ContextException( "Invalid context - no Manager Facility supplied!" ); }
  -    }
  -    public void configure( Configuration configuration )
  -    {
       }
  -    public void init()
  +    public void configure( Configuration configuration ) throws ConfigurationException
       {
       }
  -    public void start()
  +    public void init() throws InitializationException
       {
  +        super.init();
       }
  -    public void run()
  +    public void start() throws StartException
       {
  +        super.start();
       }
  -    public void suspend()
  +    public void stop() throws StopException
       {
  +        super.stop();
       }
  -    public void resume()
  -    {
  -    }
  -    public void stop()
  -    {
  -    }
       public void dispose()
       {
  +        super.dispose();
       }
       /////////////////////////
       /// CONTAINER METHODS ///
       /////////////////////////
       public Application getApplication( String name ) throws ContainerException
       {
  -        return null;
  +        return super.getApplication( name );
       }
       public void add( String name, Entry entry ) throws ContainerException
       {
  @@ -112,6 +121,8 @@
               this.logger.error( "There was an error adding "+name+" to the JMX Manager", e );
           }
   
  +        super.add( name, entry );
  +
       }
       public void remove( String name ) throws ContainerException
       {
  @@ -124,13 +135,54 @@
           {
               this.logger.error( "There was an error removing "+name+" from the JMX Manager", e );
           }
  +
  +        super.remove( name );
       }
       public Entry getEntry( String name ) throws ContainerException
       {
  -        return null;
  +        return super.getEntry( name );
       }
       public Iterator list()
       {
  -        return null;
  +        return super.list();
  +    }
  +
  +    //////////////////////
  +    /// KERNEL METHODS ///
  +    //////////////////////
  +    protected Application createApplicationFor( String name, Entry entry )
  +        throws ContainerException
  +    {
  +        //It is here where you could return new EASServerApplication()
  +        //if you wanted to host multiple different types of apps
  +        return new DefaultServerApplication();
  +    }
  +    protected void prepareApplication( final String name, final Entry entry )
  +        throws ContainerException
  +    {
  +        final Application application = (Application)entry.getInstance();
  +        final ServerApplicationEntry saEntry = (ServerApplicationEntry)entry;
  +
  +        setupLogger( application, LogKit.getLoggerFor( name ) );
  +
  +        try
  +        {
  +            if( application instanceof Contextualizable )
  +            {
  +                ((Contextualizable)application).contextualize( saEntry.getContext() );
  +            }
  +            if( application instanceof Composer )
  +            {
  +                ((Composer)application).compose( saEntry.getComponentManager() );
  +            }
  +            if( application instanceof Configurable )
  +            {
  +                ((Configurable)application).configure( saEntry.getConfiguration() );
  +            }
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new ContainerException( "Error preparing Application", e );
  +        }
       }
   }
  
  
  
  1.5       +1 -1      jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/applications/DefaultServerApplication.java
  
  Index: DefaultServerApplication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/applications/DefaultServerApplication.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultServerApplication.java	2001/04/17 11:31:50	1.4
  +++ DefaultServerApplication.java	2001/04/22 10:07:14	1.5
  @@ -24,7 +24,7 @@
    *
    * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
    */
  -class DefaultServerApplication implements ServerApplication
  +public class DefaultServerApplication implements ServerApplication
       // and thus implements Application, Contextualizable, Configurable,
       // Initializable, Startable, Stoppable, Disposable and Container
   {
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/applications/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.applications;
  
  import org.apache.framework.component.ComponentManager;
  import org.apache.framework.context.Context;
  import org.apache.avalon.camelot.Entry;
  import org.apache.framework.configuration.Configuration;
  import org.apache.log.Logger;
  
  /**
   * This is the structure describing each server application before it is loaded.
   *
   * @author <a href="mailto:donaldp@apache.org">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/proposal/4.0/src/java/org/apache/phoenix/engine/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.phoenix.engine.blocks;
  
  import org.apache.framework.logger.AbstractLoggable;
  import org.apache.framework.component.ComponentManager;
  import org.apache.framework.component.ComponentException;
  import org.apache.framework.component.Composer;
  import org.apache.framework.configuration.Configurable;
  import org.apache.framework.configuration.Configuration;
  import org.apache.framework.configuration.ConfigurationException;
  import org.apache.framework.context.Context;
  import org.apache.framework.context.Contextualizable;
  import org.apache.framework.lifecycle.Disposable;
  import org.apache.framework.lifecycle.Initializable;
  
  /**
   * This is an <code>AbstractBlock</code> that makes deployment a bit
   * easier.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/04/22 10:07:17 $
   */
  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 ComponentException
      {
          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/proposal/4.0/src/java/org/apache/phoenix/engine/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.phoenix.engine.blocks;
  
  import org.apache.framework.component.Component;
  
  /**
   * The main interface to implement for building servers using Avalon patterns.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   */
  public interface Block
      extends Component
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/blocks/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.engine.blocks;
  
  import java.io.File;
  import org.apache.framework.context.Context;
  import org.apache.framework.context.ContextException;
  import org.apache.avalon.thread.ThreadPool;
  import org.apache.log.Logger;
  
  /**
   * Context via which Blocks communicate with container.
   *
   * @author <a href="mailto:donaldp@apache.org">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() throws ContextException;
  
      /**
       * Retrieve name of block.
       *
       * @return the name of block
       */
      String getName() throws ContextException;
  
      /**
       * Retrieve thread pool by category.
       * ThreadPools 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 );
  
      /**
       * Retrieve default thread pool.
       * Equivelent to getThreadPool( "default" );
       *
       * @return the default ThreadPool
       */
      ThreadPool getDefaultThreadPool();
  
      /**
       * Retrieve logger coresponding to named category.
       *
       * @return the logger
       */
      Logger getLogger( String name );
  
      /**
       * Retrieve logger coresponding to root category of application.
       *
       * @return the base logger
       * @deprecated Use the getLogger(String) version
       */
      Logger getBaseLogger();
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/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.ArrayList;
  import java.util.Iterator;
  import org.apache.framework.logger.AbstractLoggable;
  import org.apache.framework.component.ComponentManager;
  import org.apache.framework.component.ComponentException;
  import org.apache.framework.component.Composer;
  import org.apache.avalon.camelot.Container;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.phoenix.engine.metainfo.DependencyDescriptor;
  import org.apache.phoenix.engine.metainfo.ServiceDescriptor;
  import org.apache.avalon.aut.Enum;
  
  /**
   * This is the dependency graph for blocks.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class BlockDAG
      extends AbstractLoggable
      implements Composer
  {
      public final static Traversal  FORWARD     = new Traversal( "FORWARD" );
      public final static Traversal  REVERSE     = new Traversal( "REVERSE" );
      public final static Traversal  LINEAR      = new Traversal( "LINEAR" );
  
      public final static class Traversal
          extends Enum
      {
          private Traversal( final String name )
          {
              super( name );
          }
      }
  
      private Container       m_container;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          m_container = (Container)componentManager.lookup( "org.apache.avalon.camelot.Container" );
      }
  
      public void walkGraph( final BlockVisitor visitor, final Traversal traversal )
          throws Exception
      {
          //temporary storage to record those
          //that are already traversed
          final ArrayList completed = new ArrayList();
  
          final Iterator entries = m_container.list();
          while( entries.hasNext() )
          {
              final String name = (String)entries.next();
              final BlockEntry entry = getBlockEntry( name );
              visitBlock( name, entry, visitor, traversal, completed );
          }
      }
  
      private BlockEntry getBlockEntry( final String name )
          throws Exception
      {
          return (BlockEntry)m_container.getEntry( name );
      }
  
      /**
       * Traverse dependencies of specified entry.
       *
       * @param name name of BlockEntry
       * @param entry the BlockEntry
       */
      private void visitDependencies( final String name,
                                      final BlockEntry entry,
                                      final BlockVisitor visitor,
                                      final ArrayList completed )
          throws Exception
      {
          getLogger().debug( "Traversing dependencies for " + name );
  
          final DependencyDescriptor[] descriptors = entry.getBlockInfo().getDependencies();
          for( int i = 0; i < descriptors.length; i++ )
          {
              final ServiceDescriptor serviceDescriptor = descriptors[ i ].getService();
              final String role = descriptors[ i ].getRole();
  
              getLogger().debug( "Traversing dependency of " + name + " with role " + role +
                                 " to provide service " + serviceDescriptor.getName() );
  
              //roleEntry should NEVER be null as it is checked when
              //entry is added to container
              final RoleEntry roleEntry = entry.getRoleEntry( role );
              final String dependencyName = roleEntry.getName();
              final BlockEntry dependency = getBlockEntry( dependencyName );
              visitBlock( dependencyName, dependency, visitor, FORWARD, completed );
          }
      }
  
      /**
       * 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
       */
      private void visitReverseDependencies( final String name,
                                             final BlockVisitor visitor,
                                             final ArrayList completed )
          throws Exception
      {
          getLogger().debug( "Traversing reverse dependencies for " + name );
  
          final Iterator entries = m_container.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, REVERSE, completed );
                  }
              }
          }
      }
  
      private void visitBlock( final String name,
                               final BlockEntry entry,
                               final BlockVisitor visitor,
                               final Traversal traversal,
                               final ArrayList completed )
          throws Exception
      {
          //If already visited this block then bug out early
          if( completed.contains( name ) ) return;
          completed.add( name );
  
          if( FORWARD == traversal )
          {
              visitDependencies( name, entry, visitor, completed );
          }
          else if( REVERSE == traversal )
          {
              visitReverseDependencies( name, visitor, completed );
          }
  
          visitor.visitBlock( name, entry );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/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.Entry;
  import org.apache.avalon.camelot.Locator;
  import org.apache.framework.configuration.Configuration;
  import org.apache.phoenix.engine.metainfo.BlockInfo;
  
  /**
   * This is the structure describing each block before it is loaded.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class BlockEntry
      extends Entry
  {
      protected final RoleEntry[]           m_roleEntrys;
  
      //UGLY HACK should be stored in another server Facility (ie ConfigurationRepository)
      protected Configuration               m_configuration;
  
      public BlockEntry( final RoleEntry[] roleEntrys )
      {
          m_roleEntrys = roleEntrys;
      }
  
      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;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/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.applications.ApplicationException;
  import org.apache.framework.component.Component;
  
  /**
   * Visitor interface that objects implement to walk the DAG.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface BlockVisitor
      extends Component
  {
      /**
       * 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/proposal/4.0/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.framework.context.Context;
  import org.apache.framework.context.DefaultContext;
  import org.apache.framework.context.ContextException;
  import org.apache.avalon.thread.ThreadPool;
  import org.apache.log.Logger;
  import org.apache.avalon.atlantis.facilities.ThreadManager;
  
  /**
   * Context via which Blocks communicate with container.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultBlockContext
      extends DefaultContext
      implements BlockContext
  {
      protected ThreadManager  m_threadManager;
      protected Logger         m_baseLogger;
  
      public DefaultBlockContext( final Logger logger, final ThreadManager threadManager )
      {
          this( logger, threadManager, null );
      }
  
      public DefaultBlockContext( final Logger logger,
                                  final ThreadManager threadManager,
                                  final Context context )
      {
          super( context );
          m_baseLogger = logger;
          m_threadManager = threadManager;
      }
  
      /**
       * Base directory of .sar application.
       *
       * @return the base directory
       */
      public File getBaseDirectory() throws ContextException
      {
          return (File)get( APP_HOME_DIR );
      }
  
      /**
       * Retrieve name of block.
       *
       * @return the name of block
       */
      public String getName() throws ContextException
      {
          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 the default thread pool.
       * Equivelent to getThreadPool( "default" );
       * @return the ThreadPool
       */
      public ThreadPool getDefaultThreadPool()
      {
          return getThreadPool( "default" );
      }
  
  
      /**
       * Retrieve logger coresponding to named category.
       *
       * @return the logger
       */
      public Logger getLogger( final String name )
      {
          return m_baseLogger.getChildLogger( name );
      }
  
      /**
       * Retrieve logger coresponding to root category of application.
       *
       * @return the base logger
       * @deprecated Use the getLogger(String) version
       */
      public Logger getBaseLogger()
      {
          return m_baseLogger;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/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.File;
  import java.io.InputStream;
  import java.net.URL;
  import java.net.MalformedURLException;
  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.AbstractDeployer;
  import org.apache.avalon.camelot.DeployerUtil;
  import org.apache.avalon.camelot.DeploymentException;
  import org.apache.avalon.camelot.DefaultLocator;
  import org.apache.avalon.camelot.Registry;
  import org.apache.avalon.camelot.RegistryException;
  import org.apache.avalon.aut.io.IOUtil;
  import org.apache.phoenix.engine.metainfo.BlockInfo;
  import org.apache.phoenix.engine.metainfo.BlockInfoBuilder;
  import org.apache.framework.component.ComponentManager;
  import org.apache.framework.component.ComponentException;
  import org.apache.framework.component.Composer;
  
  /**
   * This class deploys a .bar file into a registry.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class DefaultBlockDeployer
      extends AbstractDeployer
      implements Composer
  {
      private Registry            m_registry;
      private BlockInfoBuilder    m_builder;
  
  
      /**
       * Default constructor.
       */
      public DefaultBlockDeployer()
      {
          m_builder = new BlockInfoBuilder();
          m_autoUndeploy = true;
          m_type = "Block";
      }
  
      /**
       * Retrieve relevent services needed to deploy.
       *
       * @param componentManager the ComponentManager
       * @exception ComponentManagerException if an error occurs
       */
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          m_registry = (Registry)componentManager.
              lookup( "org.apache.avalon.camelot.Registry" );
      }
  
      /**
       * Deploy a file.
       * Eventually this should be cached for performance reasons.
       *
       * @param location the location
       * @param file the file
       * @exception DeploymentException if an error occurs
       */
      protected void deployFromFile( final String location, final File file )
          throws DeploymentException
      {
          final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
  
          URL url = null;
  
          try
          {
              try { url = file.toURL(); }
              catch( final MalformedURLException mue )
              {
                  throw new DeploymentException( "Unable to form url", mue );
              }
  
              handleBlocks( zipFile, DeployerUtil.loadManifest( zipFile ), url );
          }
          finally
          {
              try { zipFile.close(); }
              catch( final IOException ioe ) {}
          }
      }
  
      /**
       * 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 );
          }
      }
  
  
      protected void addLocator( final String name, final String classname, final URL url )
          throws DeploymentException
      {
          final DefaultLocator locator = new DefaultLocator( classname, url );
  
          try { m_registry.register( name + "/Locator", locator ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering " + name + " due to " + re,
                                             re );
          }
  
          getLogger().debug( "Registered Locator for " + m_type + " " + name + " as " + classname );
      }
  
      protected void addInfo( final String name, final BlockInfo info )
          throws DeploymentException
      {
          try { m_registry.register( name, info ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering " + name + " due to " + re,
                                             re );
          }
  
          getLogger().debug( "Registered Info " + m_type + " " + name );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/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:donaldp@apache.org">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.3       +85 -54    jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/deployer/DefaultSarDeployer.java
  
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/deployer/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.deployer;
  
  /**
   * This represents the names of the various resources in sars context.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface SarContextResources
  {
      String    APP_ARCHIVE       = "app.archive";
      String    APP_NAME          = "app.name";
      String    APP_HOME_DIR      = "app.home";
  }
  
  
  
  1.3       +66 -3     jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/facilities/ThreadManagerImpl.java
  
  Index: ThreadManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/facilities/ThreadManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ThreadManagerImpl.java	2001/04/17 11:32:08	1.2
  +++ ThreadManagerImpl.java	2001/04/22 10:07:19	1.3
  @@ -7,12 +7,75 @@
    */
   package org.apache.phoenix.engine.facilities;
   
  +import java.util.Hashtable;
  +import java.util.Iterator;
  +import org.apache.framework.logger.AbstractLoggable;
   import org.apache.avalon.atlantis.facilities.ThreadManager;
  +import org.apache.framework.configuration.Configurable;
  +import org.apache.framework.configuration.Configuration;
  +import org.apache.framework.configuration.ConfigurationException;
  +import org.apache.avalon.thread.DefaultThreadPool;
  +import org.apache.avalon.thread.ThreadPool;
   
   /**
    *
  - * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
  + *
  + * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
  + * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
  -public class ThreadManagerImpl implements ThreadManager
  +public class ThreadManagerImpl
  +    extends AbstractLoggable
  +    implements ThreadManager, Configurable
   {
  -}
  \ No newline at end of file
  +    protected final Hashtable       m_pools = new Hashtable();
  +
  +    public void configure( final Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        final Configuration[] groups = configuration.getChildren( "thread-group" );
  +        for( int i = 0; i < groups.length; i++ )
  +        {
  +            final Configuration group = groups[ i ];
  +
  +            final String name = group.getChild( "name" ).getValue();
  +            final int priority = group.getChild( "priority" ).getValueAsInt( 5 );
  +            final boolean isDaemon = group.getChild( "is-daemon" ).getValueAsBoolean( false );
  +
  +            final int minThreads = group.getChild( "min-threads" ).getValueAsInt( 5 );
  +            final int maxThreads = group.getChild( "max-threads" ).getValueAsInt( 10 );
  +            final int minSpareThreads = group.getChild( "min-spare-threads" ).
  +                getValueAsInt( maxThreads - minThreads );
  +
  +            try
  +            {
  +                final DefaultThreadPool threadPool = new DefaultThreadPool( name, maxThreads );
  +                threadPool.setDaemon( isDaemon );
  +                setupLogger( threadPool );
  +                m_pools.put( name, threadPool );
  +            }
  +            catch( final Exception e )
  +            {
  +                throw new ConfigurationException( "Error creating thread pool " + name,
  +                                                  e );
  +            }
  +        }
  +    }
  +
  +    public ThreadPool getDefaultThreadPool()
  +    {
  +        return getThreadPool( "default" );
  +    }
  +
  +    public ThreadPool getThreadPool( final String name )
  +    {
  +        final ThreadPool threadPool = (ThreadPool)m_pools.get( name );
  +
  +        if( null == threadPool )
  +        {
  +            //Should this be a ComponentNotFoundException ????
  +            throw new IllegalArgumentException( "No such thread group " + name );
  +        }
  +
  +        return threadPool;
  +    }
  +}
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/loader/PhoenixLoader.java
  
  Index: PhoenixLoader.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.io.FilenameFilter;
  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;
  
  /**
   * PhoenixLoader 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:donaldp@apache.org">Peter Donald</a>
   */
  public final class PhoenixLoader
  {
      protected final static boolean         ENABLE_SECURITY_MANAGER =
          !Boolean.getBoolean("phoenix.insecure");
  
      protected final static String          RESTRICTED_PACKAGES =
          System.getProperty( "phoenix.restricted.packages",
                              Security.getProperty("package.access") );
  
      protected final static String          MAIN_JAR =
          System.getProperty( "phoenix.mainJar", "phoenix-engine.jar" );
  
      protected final static String          LIB_DIR =
          System.getProperty( "phoenix.libDir", "../lib" );
  
      protected final static String          MAIN_CLASS =
          System.getProperty( "phoenix.mainClass", "org.apache.phoenix.Start" );
  
      public final static void main( final String args[] )
          throws Exception
      {
          //setup restricted packages
          Security.setProperty( "phoenix.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( "phoenix.home", avalonHome );
  
          final ArrayList urls = new ArrayList();
  
          // add main jar
          final File mainJar = new File( loaderDir, MAIN_JAR );
          final URL mainJarURL = mainJar.toURL();
          urls.add( mainJarURL );
  
          // add library jars
          final File libDir = new File( LIB_DIR );
          final File[] libFiles = libDir.listFiles();
          for( int i = 0; i < libFiles.length; i++ )
          {
              if( libFiles[i].getName().endsWith( ".jar" ) )
              {
                  final URL libFile = libFiles[i].toURL();
                  urls.add( libFile );
              }
          }
          final URL[] urlArr = new URL[0];
          final URL[] jars = (URL[])urls.toArray( urlArr );
  
          final URLClassLoader classLoader = new URLClassLoader( jars );
  
  
          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 Method setCl = clazz.getMethod( "setClassLoader", new Class[] { ClassLoader.class } );
  
              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
                      {
                          setCl.invoke( instance, new Object[] { classLoader }  );
                          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( "phoenix-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/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/BlockDescriptor.java
  
  Index: BlockDescriptor.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.metainfo;
  
  import java.net.URL;
  import javax.swing.Icon;
  import org.apache.avalon.aut.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:donaldp@apache.org">Peter Donald</a>
   */
  public interface BlockDescriptor
      extends Descriptor
  {
      /**
       * 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/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  import org.apache.avalon.camelot.MetaInfo;
  
  /**
   * This descrbes information about the block that is used by administration tools and kernel.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface BlockInfo
      extends 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 BlockDescriptor
       */
      BlockDescriptor getBlockDescriptor();
  
      /**
       * This returns a list of Services that this block exports.
       *
       * @return an array of Services (can be null)
       */
      ServiceDescriptor[] getServices();
  
      /**
       * Return an array of Service dependencies that this Block depends upon.
       *
       * @return an array of Service dependencies (may be null)
       */
      DependencyDescriptor[] getDependencies();
  
      /**
       * Retrieve a dependency with a particular role.
       *
       * @param role the role
       * @return the dependency or null if it does not exist
       */
      DependencyDescriptor getDependency( String role );
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import org.apache.framework.configuration.Configuration;
  import org.apache.framework.configuration.ConfigurationException;
  import org.apache.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.aut.Version;
  
  /**
   * A BlockInfoBuilder builds configurations via SAX2 compliant parser.
   *
   * @author <a href="mailto:donaldp@apache.org">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 ServiceDescriptor services[] = buildServices( configuration );
  
          configuration = info.getChild( "dependencies" );
          final DependencyDescriptor dependencies[] = buildDependencies( configuration );
  
          configuration = info.getChild( "meta" );
          final BlockDescriptor descriptor = buildBlockDescriptor( configuration );
  
          return new DefaultBlockInfo( descriptor, services, dependencies );
      }
  
      protected DependencyDescriptor[] buildDependencies( final Configuration configuration )
          throws ConfigurationException
      {
          if( null == configuration ) return new DependencyDescriptor[0];
  
          final Configuration[] elements = configuration.getChildren( "dependency" );
          final ArrayList descriptors = new ArrayList();
  
          for( int i = 0; i < elements.length; i++ )
          {
              final DependencyDescriptor descriptor = buildDependency( elements[ i ] );
              descriptors.add( descriptor );
          }
  
          return (DependencyDescriptor[]) descriptors.toArray( new DependencyDescriptor[0] );
      }
  
      protected DependencyDescriptor buildDependency( final Configuration dependency )
          throws ConfigurationException
      {
          final String role = dependency.getChild( "role" ).getValue();
          final ServiceDescriptor serviceDescriptor = buildService( dependency.getChild( "service" ) );
  
          return new DefaultDependencyDescriptor( role, serviceDescriptor );
      }
  
      protected ServiceDescriptor[] buildServices( final Configuration servicesSet )
          throws ConfigurationException
      {
          if( null == servicesSet ) return new ServiceDescriptor[0];
  
          final Configuration[] elements = servicesSet.getChildren( "service" );
          final ArrayList descriptors = new ArrayList();
  
          for( int i = 0; i < elements.length; i++ )
          {
              final ServiceDescriptor descriptor = buildService( elements[ i ] );
              descriptors.add( descriptor );
          }
  
          return (ServiceDescriptor[])descriptors.toArray( new ServiceDescriptor[0] );
      }
  
      protected ServiceDescriptor buildService( final Configuration service )
          throws ConfigurationException
      {
          final String name = service.getAttribute( "name" );
          final Version version =  buildVersion( service.getAttribute( "version" ) );
          return new DefaultServiceDescriptor( 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 BlockDescriptor buildBlockDescriptor( final Configuration meta )
      {
          if( null == meta ) return null;
  
          return null;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  import org.apache.phoenix.engine.blocks.Block;
  
  /**
   * Class containing utility methods for blocks.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class BlockUtil
  {
      /**
       * Private constructor to block instantiation.
       */
      private BlockUtil()
      {
      }
  
      public static boolean implementsService( final Block block,  final ServiceDescriptor 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 ServiceDescriptor[] candidates,
                                                final ServiceDescriptor service )
      {
          for( int i = 0; i < candidates.length; i++ )
          {
              if( service.matches( candidates[ i ] ) )
              {
                  return true;
              }
          }
  
          return false;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  /**
   * This describes some one who contributed to creating Block.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Contributor
  {
      /**
       * 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/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/DefaultBlockDescriptor.java
  
  Index: DefaultBlockDescriptor.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.metainfo;
  
  import javax.swing.Icon;
  import java.net.URL;
  import java.util.Locale;
  import org.apache.avalon.aut.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:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultBlockDescriptor
      implements BlockDescriptor
  {
      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 DefaultBlockDescriptor( 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/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  /**
   * This is implementaion of BlockInfo.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultBlockInfo
      implements BlockInfo
  {
      protected final BlockDescriptor          m_descriptor;
      protected final ServiceDescriptor[]      m_services;
      protected final DependencyDescriptor[]   m_dependencies;
  
      /**
       * Basic constructor that takes as parameters all parts.
       */
      public DefaultBlockInfo( final BlockDescriptor descriptor,
                               final ServiceDescriptor[] services,
                               final DependencyDescriptor[] dependencies )
      {
          m_descriptor = descriptor;
          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 BlockDescriptor
       */
      public BlockDescriptor getBlockDescriptor()
      {
          return m_descriptor;
      }
  
      /**
       * This returns a list of Services that this block exports.
       *
       * @return an array of Services (can be null)
       */
      public ServiceDescriptor[] 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 DependencyDescriptor[] 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 DependencyDescriptor 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/proposal/4.0/src/java/org/apache/phoenix/engine/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.engine.metainfo;
  
  /**
   * This describes some one who contributed to creating Block.
   *
   * @author <a href="mailto:donaldp@apache.org">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/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/DefaultDependencyDescriptor.java
  
  Index: DefaultDependencyDescriptor.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.metainfo;
  
  import org.apache.avalon.aut.Version;
  
  /**
   * This is implementation of DependencyDescriptor.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultDependencyDescriptor
      implements DependencyDescriptor
  {
      protected final String              m_role;
      protected final ServiceDescriptor   m_service;
  
      /**
       * Constructor that has all parts as parameters.
       */
      public DefaultDependencyDescriptor( final String role, final ServiceDescriptor 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 ServiceDescriptor getService()
      {
          return m_service;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/DefaultServiceDescriptor.java
  
  Index: DefaultServiceDescriptor.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.metainfo;
  
  import org.apache.avalon.aut.Version;
  
  /**
   * This is default implementaion of ServiceInfo interface.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class DefaultServiceDescriptor
      implements ServiceDescriptor
  {
      protected final Version                    m_version;
      protected final String                     m_name;
  
      public DefaultServiceDescriptor( 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( final ServiceDescriptor 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/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/DependencyDescriptor.java
  
  Index: DependencyDescriptor.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.metainfo;
  
  /**
   * This interface describes a dependency of Block.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface DependencyDescriptor
      extends Descriptor
  {
      /**
       * 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
       */
      ServiceDescriptor getService();
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/Descriptor.java
  
  Index: Descriptor.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.metainfo;
  
  import org.apache.avalon.camelot.MetaInfo;
  
  /**
   * This contains information about the component.
   * (ie would be a BlockDescriptor, an EJBDescriptor, a MailetDescriptor etc)
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Descriptor
      extends MetaInfo
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/proposal/4.0/src/java/org/apache/phoenix/engine/metainfo/ServiceDescriptor.java
  
  Index: ServiceDescriptor.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.metainfo;
  
  import org.apache.avalon.aut.Version;
  
  /**
   * This interface describes a particular service that a component offers.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface ServiceDescriptor
      extends Descriptor
  {
      /**
       * 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 ServiceDescriptor
       * @return true if matches, false otherwise
       */
      boolean matches( ServiceDescriptor other );
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org