You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/04/20 04:08:59 UTC

cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot AbstractContainer.java AbstractDeployer.java CamelotUtil.java Container.java ContainerException.java DefaultFactory.java DefaultLoader.java DefaultLocator.java DefaultRegistry.java Deployer.java DeployerUtil.java DeploymentException.java Descriptor.java Entry.java Factory.java FactoryException.java Info.java Loader.java Locator.java Registry.java RegistryException.java SimpleFactory.java State.java

donaldp     01/04/19 19:08:59

  Modified:    .        build.xml
               lib      avalonapi.jar
  Added:       src/java/org/apache/avalon/atlantis AbstractKernel.java
                        Application.java ApplicationException.java
                        Embeddor.java Facility.java Kernel.java
               src/java/org/apache/avalon/camelot AbstractContainer.java
                        AbstractDeployer.java CamelotUtil.java
                        Container.java ContainerException.java
                        DefaultFactory.java DefaultLoader.java
                        DefaultLocator.java DefaultRegistry.java
                        Deployer.java DeployerUtil.java
                        DeploymentException.java Descriptor.java Entry.java
                        Factory.java FactoryException.java Info.java
                        Loader.java Locator.java Registry.java
                        RegistryException.java SimpleFactory.java
                        State.java
  Log:
  Move camelot+atlantis to phoenix
  
  Revision  Changes    Path
  1.16      +4 -0      jakarta-avalon-phoenix/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/build.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- build.xml	2001/04/02 06:47:12	1.15
  +++ build.xml	2001/04/20 02:08:55	1.16
  @@ -338,6 +338,10 @@
       <jar jarfile="${build.lib}/phoenix-engine.jar"
            basedir="${build.classes}"
            manifest="${manifest.dir}/engine-Manifest.mf" >
  +
  +      <!-- temporary hack until camelot stabilizes -->
  +      <include name="org/apache/avalon/**"/>
  +
         <include name="org/apache/phoenix/metainfo/**"/>
         <include name="org/apache/phoenix/engine/**"/>
         <exclude name="org/apache/phoenix/engine/loader/**"/>
  
  
  
  1.17      +300 -371  jakarta-avalon-phoenix/lib/avalonapi.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/AbstractKernel.java
  
  Index: AbstractKernel.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.atlantis;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Iterator;
  import org.apache.avalon.camelot.AbstractContainer;
  import org.apache.avalon.camelot.Container;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.FactoryException;
  import org.apache.avalon.camelot.Locator;
  import org.apache.avalon.component.Component;
  import org.apache.avalon.component.ComponentManager;
  import org.apache.avalon.component.DefaultComponentManager;
  import org.apache.avalon.context.Context;
  import org.apache.avalon.context.DefaultContext;
  import org.apache.avalon.logger.AbstractLoggable;
  
  /**
   * This is the basic Kernel that supports functionality most kernels need.
   * It builds a DAG of blocks, can load/unload/reload blocks, can
   * configure/reconfigure blocks, can start/stop/initialize blocks, provide
   * contexts for blocks etc.
   *
   * When extending this the developer must set the value of m_entryClass and m_applicationClass.
   * ie.
   * m_entryClass = ServerApplicationEntry.class;
   * m_applicationClass = ServerApplication.class;
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public abstract class AbstractKernel
      extends AbstractContainer
      implements Kernel
  {
      protected boolean             m_initialised;
  
      public void init()
          throws Exception
      {
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              initializeEntry( name, entry );
          }
      }
  
      public void start()
          throws Exception
      {
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              startEntry( name, entry );
          }
      }
  
      public void stop()
          throws Exception
      {
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              stopEntry( name, entry );
          }
      }
  
      public void dispose()
          throws Exception
      {
          m_initialised = false;
  
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              disposeEntry( name, entry );
          }
      }
  
      /**
       * Retrieve Application from container.
       * The Application that is returned must be initialized
       * and prepared for manipulation.
       *
       * @param name the name of application
       * @return the application
       * @exception ContainerException if an error occurs
       */
      public Application getApplication( String name )
          throws ContainerException
      {
          final Entry entry = getEntry( name );
  
          initializeEntry( name, entry );
  
          return (Application)entry.getInstance();
      }
  
      /**
       * Create and initialize the application instance if it is not already initialized.
       *
       * @param name the name of application
       * @param entry the entry for application
       * @exception ContainerException if an error occurs
       */
      private void initializeEntry( final String name, final Entry entry )
          throws ContainerException
      {
          Application application = (Application)entry.getInstance();
  
          if( null == application )
          {
              //Give sub-class chance to do some validation
              //by overiding preInitialize
              preInitializeEntry( name, entry );
  
              application = createApplicationFor( name, entry );
  
              try
              {
                  entry.setInstance( application );
  
                  //Give sub-class chance to prepare entry
                  //This performs process required before the application
                  //is ready to be initialized
                  prepareApplication( name, entry );
  
                  application.init();
              }
              catch( final Throwable t )
              {
                  //Initialization failed so clean entry
                  //so invalid instance is not used
                  entry.setInstance( null );
  
                  throw new ContainerException( "Failed to initialize application", t );
              }
  
              //Give sub-class chance to do something post
              //initialisation
              postInitializeEntry( name, entry );
          }
      }
  
      private void startEntry( final String name, final Entry entry )
          throws Exception
      {
          final Application application = (Application)entry.getInstance();
          if( null != application )
          {
              application.start();
          }
          else
          {
              getLogger().warn( "Failed to start application " + name +
                                " as it is not initialized" );
          }
      }
  
      private void stopEntry( final String name, final Entry entry )
          throws Exception
      {
          final Application application = (Application)entry.getInstance();
          if( null != application )
          {
              application.stop();
          }
          else
          {
              getLogger().warn( "Failed to stop application " + name +
                                " as it is not initialized/started" );
          }
      }
  
      private void disposeEntry( final String name, final Entry entry )
          throws ContainerException
      {
          final Application application = (Application)entry.getInstance();
  
          if( null != application )
          {
              preDisposeEntry( name, entry );
              entry.setInstance( null );
  
              try { application.dispose(); }
              catch( final Exception e )
              {
                  throw new ContainerException( "Failed to dispose application " + name,
                                                e );
              }
  
              postDisposeEntry( name, entry );
          }
      }
  
      /**
       * This method is called before an entry is initialized.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception ContainerException if an error occurs
       */
      protected void preInitializeEntry( final String name, final Entry entry )
          throws ContainerException
      {
      }
  
      /**
       * This method is called after an entry is initialized.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       */
      protected void postInitializeEntry( final String name, final Entry entry )
      {
      }
  
      /**
       * This method is called before an entry is disposed.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception ContainerException if an error occurs
       */
      protected void preDisposeEntry( final String name, final Entry entry )
          throws ContainerException
      {
      }
  
      /**
       * This method is called after an entry is disposed.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       */
      protected void postDisposeEntry( final String name, final Entry entry )
      {
      }
  
      /**
       * 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
       * @exception ContainerException if an error occurs
       */
      protected void prepareApplication( final String name, final Entry entry )
          throws ContainerException
      {
      }
  
      /**
       * Create a new application for kernel.
       *
       * @param name the name of application
       * @param entry the entry corresponding to application
       * @return the new Application
       * @exception ContainerException if an error occurs
       */
      protected abstract Application createApplicationFor( String name, Entry entry )
          throws ContainerException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/Application.java
  
  Index: Application.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.atlantis;
  
  import org.apache.avalon.Disposable;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.Startable;
  import org.apache.avalon.Stoppable;
  import org.apache.avalon.camelot.Container;
  
  /**
   * The Application is a self-contained component that performs a specific
   * function. 
   *
   * Example ServerApplications may be a Mail Server, File Server, Directory Server etc.
   * Example JesktopApplications may be a Spreadsheet program, browser, mail client
   * Example WebApplications may be a particular website or application within a website
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Application 
      extends Container, Initializable, Startable, Stoppable, Disposable
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/ApplicationException.java
  
  Index: ApplicationException.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.atlantis;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * The ApplicationException used to indicate problems with applications.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class ApplicationException
      extends CascadingException
  {
      public ApplicationException( final String message )
      {
          this( message, null );
      }
  
      public ApplicationException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/Embeddor.java
  
  Index: Embeddor.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.atlantis;
  
  import org.apache.avalon.Disposable;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.parameters.Parametizable;
  
  /**
   * This is the object that is interacted with to create, manage and
   * dispose of the kernel and related resources.
   *
   * @author <a href="mail@leosimons.com">Leo Simons</a>
   * @author <a href="donaldp@apache.org">Peter Donald</a>
   */
  public interface Embeddor
      extends Parametizable, Initializable, Disposable
  {
      /**
       * After the Embeddor is initialized, this method is called to actually
       * do the work. It will return when the embeddor is ready to be disposed.
       *
       * @exception Exception if an error occurs
       */
      void execute()
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/Facility.java
  
  Index: Facility.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.atlantis;
  
  import org.apache.avalon.component.Component;
  
  /**
   * A Facility is a horizontal cut through the kernel. 
   * Unlike Components which offer a Service/Content interface, Facilitys 
   * are used to facilitate the non-Service/Form interface or life-cycle orientated
   * methods of Components. See documentation for a clearer explanation.
   *
   * Example Facilities would be 
   * <ul>
   *   <li>ConfigurationRepository that stores configuration data for components</li>
   *   <li>ThreadFacility that allows components to run in threads</li>
   *   <li>ContextUtility that builds context information for components</li>
   *   <li>ExportFacility that exports components to external users (perhaps via RMI)</li>
   *   <li>NamingFacility that binds compoents to a name in a directory</li>
   *   <li>ManagementFacility that manages components via JMX</li>
   * </ul>
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Facility 
      extends Component
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/atlantis/Kernel.java
  
  Index: Kernel.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.atlantis;
  
  import org.apache.avalon.camelot.ContainerException;
  
  /**
   * The Kernel is the core of any system.
   * The kernel is responsible for orchestrating low level services 
   * such as loading, configuring and destroying applications. It also 
   * gives access to basic facilities specific to that particular kernel.
   * A ServerKernel may offer scheduling, naming, security, classloading etc.
   * A JesktopKernel may offer inter-application drag-n-drop support.
   * A VEKernel may offer inter-VE transport for Avatars.
   *
   * Note that no facilities are available until after the Kernel has been initialized.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Kernel 
      extends Application
  {
      /**
       * Retrieve Application from container. 
       * The Application that is returned must be initialized 
       * and prepared for manipulation.
       *
       * @param name the name of application
       * @return the application
       * @exception ContainerException if an error occurs 
       */
      Application getApplication( String name )
          throws ContainerException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/AbstractContainer.java
  
  Index: AbstractContainer.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.camelot;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import org.apache.avalon.component.Component;
  import org.apache.avalon.logger.AbstractLoggable;
  
  /**
   * This contains it during execution and may provide certain
   * facilities (like a thread per EJB etc).
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public abstract class AbstractContainer
      extends AbstractLoggable
      implements Container
  {
      protected final HashMap          m_entries      = new HashMap();
      protected Class                  m_entryClass;
  
      /**
       * Add a component instance to container.
       *
       * @param entry the component entry
       */
      public void add( final String name, final Entry entry )
          throws ContainerException
      {
          checkEntry( name, entry );
          preAdd( name, entry );
          m_entries.put( name, entry );
          postAdd( name, entry );
      }
  
      /**
       * Remove a component instance from container.
       *
       * @param name the name of component
       */
      public void remove( final String name )
          throws ContainerException
      {
          final Entry entry = (Entry)m_entries.get( name );
  
          if( null == entry )
          {
              throw new ContainerException( "Component named " + name + " not contained" );
          }
  
          preRemove( name, entry );
          m_entries.remove( name );
          postRemove( name, entry );
      }
  
      /**
       * Retrieve Entry from container
       *
       * @param name the name of entry
       * @return the entry
       */
      public Entry getEntry( final String name )
          throws ContainerException
      {
          final Entry entry = (Entry)m_entries.get( name );
  
          if( null == entry )
          {
              throw new ContainerException( "Name " + name + " not contained" );
          }
          else
          {
              return entry;
          }
      }
  
      /**
       * List all names of entries in container.
       *
       * @return the list of all entries
       */
      public Iterator list()
      {
          return m_entries.keySet().iterator();
      }
  
      /**
       * This method is called before entry is added to give chance for
       * sub-class to veto removal.
       *
       * @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
      {
      }
  
      /**
       * This method is called after entry is added to give chance for
       * sub-class to do some cleanup.
       *
       * @param name the name of entry
       * @param entry the entry
       */
      protected void postAdd( final String name, final Entry entry )
      {
      }
  
      /**
       * This method is called before entry is removed to give chance for
       * sub-class to veto removal.
       *
       * @param name the name of entry
       * @param entry the entry
       * @exception ContainerException to stop removal of entry
       */
      protected void preRemove( final String name, final Entry entry )
          throws ContainerException
      {
      }
  
      /**
       * This method is called after entry is removed to give chance for
       * sub-class to do some cleanup.
       *
       * @param name the name of entry
       * @param entry the entry
       */
      protected void postRemove( final String name, final Entry entry )
      {
      }
  
      /**
       * List all entries in container.
       *
       * @return the list of all entries
       */
      protected Iterator listEntries()
      {
          return m_entries.values().iterator();
      }
  
      protected void checkEntry( final String name, final Entry entry )
          throws ContainerException
      {
          if( null != m_entries.get( name ) )
          {
              throw new ContainerException( "Can not add component to container because " +
                                            "entry already exists with name " + name );
          }
  
          if( !isValidName( name ) )
          {
              throw new ContainerException( "Can not add component to container because " +
                                            "invalid name " + name );
          }
  
          if( !isValidEntry( entry ) )
          {
              throw new ContainerException( "Can not add component to container because " +
                                            "invalid entry for " + name );
          }
  
          if( !m_entryClass.isAssignableFrom( entry.getClass() ) )
          {
              throw new ContainerException( "Only Entries of type " + m_entryClass.getName() +
                                            " may be placed in container." );
          }
      }
  
      protected boolean isValidName( final String name )
          throws ContainerException
      {
          return true;
      }
  
      protected boolean isValidEntry( final Entry entry )
          throws ContainerException
      {
          return true;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/AbstractDeployer.java
  
  Index: AbstractDeployer.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.camelot;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.URL;
  import java.util.HashMap;
  import org.apache.avalon.logger.AbstractLoggable;
  import org.apache.avalon.component.Component;
  import org.apache.avalon.component.ComponentException;
  import org.apache.excalibur.io.FileUtil;
  import org.apache.log.Logger;
  
  /**
   * A Deployer is responsible for taking a URL (ie a jar/war/ear) and deploying
   * it to a particular "location". "location" means different things for
   * different containers. For a servlet container it may mean the place to
   * mount servlet (ie /myapp --> /myapp/Cocoon.xml is mapping cocoon servlet to
   * /myapp context).
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public abstract class AbstractDeployer
      extends AbstractLoggable
      implements Deployer
  {
      protected final HashMap                m_deployments  = new HashMap();
      protected boolean                      m_autoUndeploy;
      protected String                       m_type;
  
      public void deploy( final String location, final URL url )
          throws DeploymentException
      {
          checkDeployment( location, url );
          final File file = getFileFor( url );
  
          getLogger().info( "Deploying " + m_type + " file (" + file + ") as " + location );
          deployFromFile( location, file );
      }
  
      protected void checkDeployment( final String location, final URL url )
          throws DeploymentException
      {
          if( null != m_deployments.get( location ) )
          {
              throw new DeploymentException( m_type + " already exists at " + location );
          }
          
          if( !isValidLocation( location ) )
          {
              throw new DeploymentException( "Invalid location (" + location + 
                                             ") for " + m_type );
          }
      }
  
      public void undeploy( final String location )
          throws DeploymentException
      {
          final Component component = (Component)m_deployments.get( location );
  
          if( null == component )
          {
              throw new DeploymentException( m_type + " does not exist at " + location );
          }
  
          final boolean canUndeploy = canUndeploy( component );
  
          if( !canUndeploy )
          {
              if( !m_autoUndeploy )
              {
                  //we are midstream but not allowed to automagically undeploy .. therefore
                  throw new DeploymentException( m_type + " not ready to undeploy at " + 
                                                 location );
              }
              else
              {
                  shutdownDeployment( component );
              }
          }
  
          //if everything has gone successful then remove application
          m_deployments.remove( location );
      }
  
      protected File getCacheLocationFor( final URL url )
          throws DeploymentException
      {
          throw new DeploymentException( "Unable to deploy non-local resources" );
      }
  
      protected File getFileFor( final URL url )
          throws DeploymentException
      {
          File file = null;
  
          if( url.getProtocol().equals( "file" ) )
          {
              file = new File( url.getFile() );
          }
          else
          {
              file = getCacheLocationFor( url );
              try { FileUtil.copyURLToFile( url, file ); }
              catch( final IOException ioe )
              {
                  throw new DeploymentException( "Failed attempting to copy from  " + url +
                                                 " to local file cache " + file, ioe );
              }
          }
  
          file = file.getAbsoluteFile();
  
          if( !file.exists() )
          {
              throw new DeploymentException( "Could not find application archive at " + 
                                             file );
          }
  
          if( file.isDirectory() )
          {
              throw new DeploymentException( "Could not find application archive at " + 
                                             file + " as it is a directory." );
          }
  
          return file;
      }
  
      protected boolean isValidLocation( String location )
      {
          return true;
      }
  
      protected boolean canUndeploy( Component component )
          throws DeploymentException
      {
          return true;
      }
  
      protected void shutdownDeployment( Component component )
          throws DeploymentException
      {
      }
  
      protected abstract void deployFromFile( String location, File file )
          throws DeploymentException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/CamelotUtil.java
  
  Index: CamelotUtil.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.camelot;
  
  import java.io.File;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.util.Iterator;
  import org.apache.avalon.component.Component;
  import org.apache.excalibur.io.DirectoryFileFilter;
  import org.apache.excalibur.io.ExtensionFileFilter;
  
  /**
   * Utility methods for Camelot related facilities.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class CamelotUtil
  {
      /**
       * Private constructor so impossible to instantiate.
       */
      private CamelotUtil()
      {
      }
  
      public static void deployFromDirectory( final Deployer deployer, 
                                              final File directory,
                                              final String extention )
          throws DeploymentException
      {
          deployFromDirectory( deployer, directory, new String[] { extention } );
      }
  
      public static void deployFromDirectory( final Deployer deployer, 
                                              final File directory,
                                              final String[] extentions )
          throws DeploymentException
                                            
      {
          final ExtensionFileFilter filter = new ExtensionFileFilter( extentions );
          deployFromDirectory( deployer, directory, filter );
      }
  
      public static void deployFromDirectory( final Deployer deployer, 
                                              final File directory,
                                              final FilenameFilter filter )
          throws DeploymentException
                                            
      {
          final File[] files = directory.listFiles( filter );
  
          if( null != files )
          {
              deployFiles( deployer, files );
          }
      }
  
      public static void deployFiles( final Deployer deployer, final File[] files )
          throws DeploymentException
      {
          for( int i = 0; i < files.length; i++ )
          {
              final String filename = files[ i ].getName();
  
              int index = filename.lastIndexOf( '.' );
              if( -1 == index ) index = filename.length();
  
              final String name = filename.substring( 0, index );
  
              try
              {
                  final File file = files[ i ].getCanonicalFile();
                  deployer.deploy( name, file.toURL() );
              }
              catch( final MalformedURLException mue )
              {
                  throw new DeploymentException( "Malformed URL for " + files[ i ], mue );
              }
              catch( final IOException ioe )
              {
                  throw new DeploymentException( "Unable to get canonical representation " +
                                                 "for file " + files[ i ], ioe );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Container.java
  
  Index: Container.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.camelot;
  
  import java.util.Iterator;
  import org.apache.avalon.component.Component;
  
  /**
   * This contains it during execution and may provide certain
   * facilities (like a thread per EJB etc).
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Container
      extends Component
  {
      /**
       * Add a component instance to container.
       *
       * @param entry the component entry
       */
      void add( String name, Entry entry )
          throws ContainerException;
  
     /**
      * Remove a component instance from container.
      *
      * @param name the name of component
      */
      void remove( String name )
          throws ContainerException;
  
      /**
       * Retrieve Entry from container
       *
       * @param name the name of entry
       * @return the entry
       */
      Entry getEntry( String name )
          throws ContainerException;
  
      /**
       * List all names of entries in container.
       *
       * @return the list of all entries
       */
      Iterator list();
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/ContainerException.java
  
  Index: ContainerException.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.camelot;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * Exception to indicate error manipulating container.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class ContainerException
      extends CascadingException
  {
      /**
       * Construct a new <code>ContainerException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public ContainerException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>ContainerException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public ContainerException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DefaultFactory.java
  
  Index: DefaultFactory.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.camelot;
  
  import java.net.URL;
  import java.util.HashMap;
  import org.apache.avalon.component.Component;
  import org.apache.avalon.logger.AbstractLoggable;
  
  /**
   * This is the component that creates the components.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultFactory
      extends AbstractLoggable
      implements Factory
  {
      protected static class LoaderEntry
      {
          Loader      m_loader;
          long        m_lastModified;
      }
  
      protected final HashMap        m_loaders      = new HashMap();
  
      /**
       * Create a component whos position is indicated by locator.
       *
       * @param locator the locator indicating the component location
       * @return the component
       * @exception FactoryException if an error occurs
       */
      public Object create( final Locator locator )
          throws FactoryException
      {
          final Loader loader = getLoaderFor( locator.getLocation() );
  
          try { return loader.load( locator.getName() ); }
          catch( final Exception e )
          {
              throw new FactoryException( "Unable to create " + locator.getName() +
                                          " from " + locator.getLocation(), e );
          }
      }
  
      public Object create( final Locator locator, final Class clazz )
          throws FactoryException
      {
          final Object object = create( locator );
  
          if( !clazz.isInstance( object ) )
          {
              throw new FactoryException( "Created object of type " + object.getClass().getName() +
                                          " not compatable with type " + clazz.getName() );
          }
  
          return object;
      }
  
      protected Loader getLoaderFor( final URL url )
      {
          final String location = url.toString();
          LoaderEntry loader = (LoaderEntry)m_loaders.get( location );
  
          if( null == loader )
          {
              getLogger().info( "Creating ClassLoader for " + location );
              loader = new LoaderEntry();
  
              loader.m_loader = setupLoader( url );
              loader.m_lastModified = System.currentTimeMillis();
  
              m_loaders.put( location, loader );
          }
          else
          {
              //TODO: Check it up to date and reload if necessary
          }
  
          return loader.m_loader;
      }
  
      protected Loader setupLoader( final URL url )
      {
          final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          final Loader loader = createLoader( url, classLoader );
          setupLogger( loader );
  
          return loader;
      }
  
      /**
       * Create a new loader.
       * Put in another method so that it can be overridden.
       *
       * @param location the location the Loader will load from
       * @return the loader
       */
      protected Loader createLoader( final URL url, final ClassLoader classLoader )
      {
          return new DefaultLoader( url, classLoader );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DefaultLoader.java
  
  Index: DefaultLoader.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.camelot;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import org.apache.avalon.ExceptionUtil;
  
  /**
   * Class used to load resources from a source.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultLoader
      implements Loader
  {
      protected ClassLoader         m_classLoader;
  
      public DefaultLoader( final ClassLoader classLoader )
      {
          m_classLoader = classLoader;
      }
  
      public DefaultLoader( final URL location, final ClassLoader classLoader )
      {
          m_classLoader = new URLClassLoader( new URL[] { location }, classLoader );
      }
  
      public DefaultLoader( final URL location )
      {
          this( location, Thread.currentThread().getContextClassLoader() );
      }
  
      public DefaultLoader()
      {
          final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          m_classLoader = new URLClassLoader( new URL[0], classLoader );
      }
  
      /**
       * Retrieve classloader associated with source.
       *
       * @return the ClassLoader
       */
      public ClassLoader getClassLoader()
      {
          return m_classLoader;
      }
  
      public Object load( final String classname, final Class clazz )
          throws FactoryException
      {
          final Object object = load( classname );
  
          if( !clazz.isInstance( object ) )
          {
              throw new FactoryException( "Created object of type " + object.getClass().getName() +
                                          " not compatable with type " + clazz.getName() );
          }
  
          return object;
      }
  
      /**
       * Load an object from source.
       *
       * @param classname the name of object
       * @return the Object
       * @exception FactoryException if an error occurs
       */
      public Object load( final String classname )
          throws FactoryException
      {
          try
          {
              return m_classLoader.loadClass( classname ).newInstance();
          }
          catch( final ClassNotFoundException cnfe )
          {
              throw new FactoryException( "Failed to locate class " + classname, cnfe );
          }
          catch( final InstantiationException ie )
          {
              throw new FactoryException( "Failed to instantiate class " + classname, ie );
          }
          catch( final IllegalAccessException iae )
          {
              throw new FactoryException( "Failed to instantiate class " + classname +
                                          " as it does not have a publicly accesable " +
                                          "default constructor", iae );
          }
          catch( final Throwable t )
          {
              throw new FactoryException( "Failed to get class " + classname +
                                          " due to " + ExceptionUtil.printStackTrace( t, 5, true ),
                                          t );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DefaultLocator.java
  
  Index: DefaultLocator.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.camelot;
  
  import java.net.URL;
  import org.apache.avalon.component.Component;
  
  /**
   * This contains information required to locate a component.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultLocator
      implements Locator
  {
      protected final String     m_name;
      protected final URL        m_location;
  
      public DefaultLocator( final String name, final URL location )
      {
          m_name = name;
          m_location = location;
      }
  
      /**
       * Retrieve "name" of component type.
       * The "name" usually indicates the classname.
       *
       * @return the name
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Retrieve location of component.
       * Usually references the archive (zip/jar/war/ear)
       * which contains the name (ie classname)
       *
       * @return the URL of location
       */
      public URL getLocation()
      {
          return m_location;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DefaultRegistry.java
  
  Index: DefaultRegistry.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.camelot;
  
  import java.util.HashMap;
  import java.util.Iterator;
  
  /**
   * Represents a Registry of names to types.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultRegistry
      implements Registry
  {
      protected final HashMap        m_infos       = new HashMap();
      protected final Class          m_infoClass;
  
      public DefaultRegistry( final Class clazz )
      {
          m_infoClass = clazz;
      }
  
      public void register( final String name, final Info info )
          throws RegistryException
      {
          if( null != m_infos.get( name ) )
          {
              throw new RegistryException( "Name " + name + " already registered" );
          }
          else
          {
              checkInfo( name, info );
              m_infos.put( name, info );
          }
      }
  
      public void unregister( final String name )
          throws RegistryException
      {
          if( null == m_infos.remove( name ) )
          {
              throw new RegistryException( "Name " + name + " not registered" );
          }
      }
  
      public Info getInfo( final String name, final Class clazz )
          throws RegistryException
      {
          final Info info = (Info)m_infos.get( name );
  
          if( null == info )
          {
              throw new RegistryException( "Name " + name + " not registered" );
          }
          else if( !clazz.isInstance( info ) )
          {
              throw new RegistryException( "Info of type " + info.getClass().getName() +
                                           " not compatable with expected type " + clazz.getName() );
          }
          else
          {
              return info;
          }
      }
  
      public Iterator getInfoNames()
      {
          return m_infos.keySet().iterator();
      }
  
      protected void checkInfo( final String name, final Info info )
          throws RegistryException
      {
          if( !m_infoClass.isAssignableFrom( info.getClass() ) )
          {
              throw new RegistryException( "Only Infos of type " + m_infoClass.getName() +
                                           " may be placed in registry." );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Deployer.java
  
  Index: Deployer.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.camelot;
  
  import java.net.URL;
  import org.apache.avalon.component.Component;
  
  /**
   * A Deployer is responsible for taking a URL (ie a jar/war/ear) and deploying
   * it to a particular "location". "location" means different things for
   * different containers. For a servlet container it may mean the place to
   * mount servlet (ie /myapp --> /myapp/Cocoon.xml is mapping cocoon servlet to
   * /myapp context).
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Deployer
      extends Component
  {
      /**
       * Deploy a resource indicate by url to location.
       *
       * @param location the location to deploy to
       * @param url the url of deployment
       * @exception DeploymentException if an error occurs
       */
      void deploy( String location, URL url )
          throws DeploymentException;
  
      /**
       * undeploy a resource from a location.
       *
       * @param location the location
       * @exception DeploymentException if an error occurs
       */
      void undeploy( String location )
          throws DeploymentException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DeployerUtil.java
  
  Index: DeployerUtil.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.camelot;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URL;
  import java.util.Properties;
  import java.util.jar.Manifest;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipException;
  import java.util.zip.ZipFile;
  import org.apache.avalon.component.ComponentManager;
  import org.apache.avalon.component.ComponentException;
  import org.apache.avalon.component.Composable;
  import org.apache.avalon.configuration.Configuration;
  import org.apache.avalon.configuration.ConfigurationException;
  import org.apache.avalon.configuration.DefaultConfigurationBuilder;
  import org.xml.sax.SAXException;
  
  /**
   * This class deploys resources from camelot based system.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class DeployerUtil
  {
      protected static DefaultConfigurationBuilder  c_configurationBuilder;
  
      /**
       * Private constructor to block instantiation.
       */
      private DeployerUtil()
      {
      }
  
      protected static DefaultConfigurationBuilder getBuilder()
      {
          if( null == c_configurationBuilder )
          {
              c_configurationBuilder = new DefaultConfigurationBuilder();
          }
  
          return c_configurationBuilder;
      }
  
      /**
       * Get zipFile represented by URL.
       *
       * @param url the URL
       * @return the ZipFile
       * @exception DeploymentException if an error occurs
       */
  /*
    public final static ZipFile getZipFileFor( final URL url )
    throws DeploymentException
    {
    final File file = getFileFor( url );
    return getZipFileFor( file );
    }
  */
      /**
       * Retrieve zip file for file.
       *
       * @param file the file
       * @return the zipFile
       * @exception DeploymentException if an error occurs
       */
      public final static ZipFile getZipFileFor( final File file )
          throws DeploymentException
      {
          try { return new ZipFile( file ); }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error opening " + file +
                                             " due to " + ioe.getMessage(),
                                             ioe );
          }
      }
  
      /**
       * Utility method to load configuration from zip.
       *
       * @param zipFile the zip file
       * @param filename the property filename
       * @return the Configuration
       * @exception DeploymentException if an error occurs
       */
      public final static Configuration loadConfiguration( final ZipFile zipFile,
                                                           final String filename )
          throws DeploymentException
      {
          return buildConfiguration( loadResourceStream( zipFile, filename ) );
      }
  
      /**
       * Build a configuration tree based on input stream.
       *
       * @param input the InputStream
       * @return the Configuration tree
       * @exception DeploymentException if an error occurs
       */
      public final static Configuration buildConfiguration( final InputStream input )
          throws DeploymentException
      {
          try { return getBuilder().build( input ); }
          catch( final SAXException se )
          {
              throw new DeploymentException( "Malformed configuration data", se );
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Error building configuration", ce );
          }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error reading configuration", ioe );
          }
      }
  
      /**
       * Utility method to load a manifest from a zip file.
       *
       * @param zipFile the zip file
       * @return the Manifest
       */
      public final static Manifest loadManifest( final ZipFile zipFile )
          throws DeploymentException
      {
          final InputStream input = loadResourceStream( zipFile, "META-INF/MANIFEST.MF" );
  
          try { return new Manifest( input ); }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error reading manifest", ioe );
          }
          finally
          {
              try { input.close(); }
              catch( final IOException ioe ) {}
          }
      }
  
      /**
       * Utility method to load properties from zip.
       *
       * @param zipFile the zip file
       * @param filename the property filename
       * @return the Properties
       * @exception DeploymentException if an error occurs
       */
      public final static Properties loadProperties( final ZipFile zipFile,
                                                     final String filename )
          throws DeploymentException
      {
          final Properties properties = new Properties();
  
          try { properties.load( loadResourceStream( zipFile, filename ) ); }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error reading " + filename +
                                             " from " + zipFile.getName(),
                                             ioe );
          }
  
          return properties;
      }
  
      /**
       * Load a resource from a zip file.
       *
       * @param zipFile the ZipFile
       * @param filename the filename
       * @return the InputStream
       * @exception DeploymentException if an error occurs
       */
      public final static InputStream loadResourceStream( final ZipFile zipFile,
                                                          final String filename )
          throws DeploymentException
      {
          final ZipEntry entry = zipFile.getEntry( filename );
  
          if( null == entry )
          {
              throw new DeploymentException( "Unable to locate " + filename +
                                             " in " + zipFile.getName() );
          }
  
          try { return zipFile.getInputStream( entry ); }
          catch( final IOException ioe )
          {
              throw new DeploymentException( "Error reading " + filename +
                                             " from " + zipFile.getName(),
                                             ioe );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/DeploymentException.java
  
  Index: DeploymentException.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.camelot;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * Exception to indicate error deploying.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class DeploymentException
      extends CascadingException
  {
      /**
       * Construct a new <code>DeploymentException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public DeploymentException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>DeploymentException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public DeploymentException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/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.avalon.camelot;
  
  /**
   * 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 Info
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Entry.java
  
  Index: Entry.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.camelot;
  
  import org.apache.avalon.component.Component;
  
  /**
   * Contains information about a particular instance of contained component. 
   * This would contain name, configuration data, parameters, log entries etc. 
   * Basically instance data.
  *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class Entry
      implements Component
  {
      private Info          m_info;
      private Object        m_instance;
      private State         m_state;
      private Locator       m_locator;
  
      public Entry()
      {
      }
  
      public Entry( final Info info, final Object instance, final State state )
      {
          m_info = info;
          m_instance = instance;
          m_state = state;
      }
  
      /**
       * Retrieve Info describing instance.
       *
       * @return the info
       */
      public Info getInfo()
      {
          return m_info;
      }
  
      /**
       * Mutator for info property.
       *
       * @param info the Info
       */
      public void setInfo( final Info info )
      {
          m_info = info;
      }
  
      /**
       * Retrieve Locator describing access path for instance.
       *
       * @return the locator
       */
      public Locator getLocator()
      {
          return m_locator;
      }
  
      /**
       * Mutator for locator property.
       *
       * @param locator the Locator
       */
      public void setLocator( final Locator locator )
      {
          m_locator = locator;
      }
  
      /**
       * Retrieve instance of component.
       *
       * @return the component instance
       */
      public Object getInstance()
      {
          return m_instance;
      }
      
      /**
       * Set instance of component.
       *
       * @return the component instance
       */
      public void setInstance( final Object instance )
      {
          m_instance = instance;
      }
      
      /**
       * Retrieve state of a component.
       *
       * @return the components state
       */
      public State getState()
      {
          return m_state;
      }
      
      /**
       * set state of a component.
       *
       * @param state  the components state
       */
      public void setState( final State state )
      {
          m_state = state;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Factory.java
  
  Index: Factory.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.camelot;
  
  import org.apache.avalon.component.Component;
  
  /**
   * This is the component that creates the components.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Factory
      extends Component
  {
      /**
       * Create a component whos position is indicated by locator.
       *
       * @param locator the locator indicating the component location
       * @return the component
       * @exception FactoryException if an error occurs
       */
      Object create( Locator locator )
          throws FactoryException;
  
      /**
       * Create a component whos position is indicated by locator.
       * Make sure it is of the correct type.
       *
       * @param locator the locator indicating the component location
       * @param clazz the expected type of component
       * @return the component
       * @exception FactoryException if an error occurs
       */
      Object create( Locator locator, Class clazz )
          throws FactoryException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/FactoryException.java
  
  Index: FactoryException.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.camelot;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * Exception to indicate error creating entries in factory.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class FactoryException
      extends CascadingException
  {
      /**
       * Construct a new <code>FactoryException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public FactoryException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>FactoryException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public FactoryException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Info.java
  
  Index: Info.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.camelot;
  
  import org.apache.avalon.component.Component;
  
  /**
   * This contains information relating to a component.
   * (ie BlockInfo, BeanInfo, MailetInfo etc).
   *
   * There is currently also two different sub-interfaces - Descriptor and Locator.
   * Descriptor describes static meta information about component while Locator
   * locates it in the system.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Info
      extends Component
  {
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Loader.java
  
  Index: Loader.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.camelot;
  
  import org.apache.avalon.component.Component;
  
  /**
   * Class used to load resources from a source.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Loader
      extends Component
  {
      /**
       * Retrieve classloader associated with source.
       *
       * @return the ClassLoader
       */
      ClassLoader getClassLoader();
  
      /**
       * Load an object from source.
       *
       * @param component the name of object
       * @return the Object
       * @exception FactoryException if an error occurs
       */
      Object load( String component )
          throws FactoryException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Locator.java
  
  Index: Locator.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.camelot;
  
  import java.net.URL;
  import org.apache.avalon.component.Component;
  
  /**
   * This contains information required to locate a component.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Locator
      extends Info
  {
      /**
       * Retrieve "name" of component type.
       * The "name" usually indicates the classname.
       *
       * @return the name
       */
      String getName();
  
      /**
       * Retrieve location of component.
       * Usually references the archive (zip/jar/war/ear)
       * which contains the name (ie classname)
       *
       * @return the URL of location
       */
      URL getLocation();
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/Registry.java
  
  Index: Registry.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.camelot;
  
  import java.util.Iterator;
  import org.apache.avalon.component.Component;
  
  /**
   * Represents a database of Infos.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface Registry
      extends Component
  {
      /**
       * register an info under a particular name.
       *
       * @param name the name
       * @param info the info
       * @exception RegistryException if info is invalid or name already contains info under name
       */
      void register( String name, Info info )
          throws RegistryException;
  
      /**
       * unregister an info.
       *
       * @param name the name of info
       * @exception RegistryException if no such info exists
       */
      void unregister( String name )
          throws RegistryException;
  
      /**
       * Retrieve an Info by name.
       *
       * @param name the name
       * @param clazz the expected class type of info
       * @return the Info
       * @exception RegistryException if an error occurs
       */
      Info getInfo( String name, Class clazz )
          throws RegistryException;
  
      /**
       * Return an iterator of all names of infos registered.
       *
       * @return the info names
       */
      Iterator getInfoNames();
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/RegistryException.java
  
  Index: RegistryException.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.camelot;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * Exception to indicate registry error.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class RegistryException
      extends CascadingException
  {
      /**
       * Construct a new <code>RegistryException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public RegistryException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>RegistryException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public RegistryException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/SimpleFactory.java
  
  Index: SimpleFactory.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.camelot;
  
  import java.net.URL;
  
  /**
   * This is the component that creates the components. 
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class SimpleFactory
      implements Factory
  {
      private final ClassLoader    m_classLoader;
  
      public SimpleFactory( final ClassLoader classLoader )
      {
          m_classLoader = classLoader;
      }
  
      /**
       * Create a component whos position is indicated by locator.
       *
       * @param locator the locator indicating the component location
       * @return the component
       * @exception FactoryException if an error occurs
       */
      public Object create( final Locator locator )
          throws FactoryException
      {
          try
          {
              final Class clazz = m_classLoader.loadClass( locator.getName() );
              return clazz.newInstance();
          }
          catch( final Exception e )
          {
              throw new FactoryException( "Unable to create " + locator.getName() +
                                          " from " + locator.getLocation(), e );
          }
      }
  
      public Object create( final Locator locator, final Class clazz )
          throws FactoryException
      {
          final Object object = create( locator );
  
          if( !clazz.isInstance( object ) )
          {
              throw new FactoryException( "Created object of type " + object.getClass().getName() +
                                          " not compatable with type " + clazz.getName() );
          }
  
          return object;
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/camelot/State.java
  
  Index: State.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.camelot;
  
  import org.apache.avalon.util.ValuedEnum;
  
  /**
   * Defines possible states for contained components.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class State
      extends ValuedEnum
  {
      public State( final String name, final int value )
      {
          super( name, value );
      }
  }
  
  
  

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