mcconnell    2003/11/26 13:45:38

  Modified:    repository/impl/src/java/org/apache/avalon/repository/impl
                        DefaultFactory.java
               repository/main/src/java/org/apache/avalon/repository/main
                        InitialRepositoryFactory.java
               repository/spi/src/java/org/apache/avalon/repository/criteria
                        Factory.java
  Log:
  Add support for target factories that take a Factory as a constructor argument.  
This is option but needed for application like Merlin that want to construct 
supplimentary repositories.
  
  Revision  Changes    Path
  1.13      +4 -4      
avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DefaultFactory.java       26 Nov 2003 14:11:39 -0000      1.12
  +++ DefaultFactory.java       26 Nov 2003 21:45:38 -0000      1.13
  @@ -120,7 +120,7 @@
       * Create a new instance of an application.
       * @return the application instance
       */
  -    public Object create()
  +    public Object create( ) throws Exception
       {
           return create( createDefaultCriteria() );
       }
  @@ -128,10 +128,10 @@
      /**
       * Create a new instance of the repository using the supplied 
       * parameters.
  -    * @param map a map of repsotory parameters
  +    * @param criteria a map of repsotory parameters
       * @return the repository
       */
  -    public Object create( Map map )
  +    public Object create( Map map ) throws Exception
       {
           if( null == map ) 
             throw new NullPointerException( "map" );
  
  
  
  1.8       +40 -5     
avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java
  
  Index: InitialRepositoryFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InitialRepositoryFactory.java     26 Nov 2003 17:05:47 -0000      1.7
  +++ InitialRepositoryFactory.java     26 Nov 2003 21:45:38 -0000      1.8
  @@ -56,6 +56,9 @@
   import java.io.InputStream;
   import java.io.FileOutputStream;
   
  +import java.lang.reflect.Constructor;
  +import java.lang.NoSuchMethodException;
  +
   import java.util.ArrayList;
   import java.util.Map;
   import java.util.Properties;
  @@ -136,14 +139,32 @@
        * implementation factory's class name.  This factory delegates 
        * calls to the implementation factory once it is created.
        * 
  -     * @throws RepositoryException
  +     * @param repositories a set of initial remote repository addresses 
  +     * @throws RepositoryException if an error occurs during establishment
        */
       public InitialRepositoryFactory( String[] repositories ) 
           throws RepositoryException
       {
  -         this( STANDARD_REF, repositories );
  +         this( repositories, CACHE );
  +    }
  +
  +    /**
  +     * Creates a repository which in turn instantiates a Repository 
  +     * factory implementation specified by an artifact descriptor and the 
  +     * implementation factory's class name.  This factory delegates 
  +     * calls to the implementation factory once it is created.
  +     * 
  +     * @param repositories a set of initial remote repository addresses 
  +     * @param cache the cache directory
  +     * @throws RepositoryException if an error occurs during establishment
  +     */
  +    public InitialRepositoryFactory( String[] repositories, File cache ) 
  +        throws RepositoryException
  +    {
  +         this( STANDARD_REF, repositories, cache );
       }
   
  +
       /**
        * Creates a repository which in turn instantiates a Repository 
        * factory implementation specified by an artifact descriptor and the 
  @@ -169,7 +190,8 @@
        *
        * @param reference an artifact that references a file with an associated
        *     meta target descriptor
  -     * @param repositories a set of initial remote repository addresses  
  +     * @param repositories a set of initial remote repository addresses 
  +     * @param cache the cache directory
        * @throws RepositoryException if an error occurs during establishment
        */
       public InitialRepositoryFactory( Artifact reference, String[] repositories, 
File cache ) 
  @@ -243,7 +265,7 @@
           try
           {
               Class l_clazz = classloader.loadClass( factory );
  -            m_delegate = ( Factory ) l_clazz.newInstance();
  +            m_delegate = createDelegate( l_clazz );
           }
           catch( IllegalAccessException e )
           {
  @@ -270,6 +292,19 @@
               final String error = 
                 "Unable to establish factory: " + factory;
               throw new RepositoryException( error, e );
  +        }
  +    }
  +
  +    private Factory createDelegate( Class clazz ) throws Exception
  +    {
  +        try
  +        {
  +            Constructor constructor = clazz.getConstructor( new Class[]{ 
Factory.class } );
  +            return ( Factory ) constructor.newInstance( new Object[]{ this } );
  +        }
  +        catch( NoSuchMethodException e )
  +        {
  +            return ( Factory ) clazz.newInstance();
           }
       }
   
  
  
  
  1.5       +1 -2      
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Factory.java
  
  Index: Factory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Factory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Factory.java      26 Nov 2003 14:11:40 -0000      1.4
  +++ Factory.java      26 Nov 2003 21:45:38 -0000      1.5
  @@ -60,7 +60,6 @@
    */
   public interface Factory
   {
  -
      /**
       * Return a new instance of default criteria for the factory.
       * @return a new criteria instance
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to