mcconnell    2004/03/03 19:26:42

  Modified:    repository/api/src/java/org/apache/avalon/repository
                        Repository.java
               repository/impl/src/java/org/apache/avalon/repository/impl
                        DefaultFactory.java DefaultRepository.java
                        DefaultRepositoryCriteria.java
               repository/main/src/java/org/apache/avalon/repository/main
                        DefaultInitialContext.java
                        DefaultInitialContextFactory.java
               repository/spi/src/java/org/apache/avalon/repository/provider
                        InitialContext.java InitialContextFactory.java
                        RepositoryCriteria.java
               repository/test/src/test/org/apache/avalon/repository/main
                        DefaultInitialContextFactoryTestCase.java
               repository/util/src/java/org/apache/avalon/repository/util
                        LoaderUtils.java
  Removed:     repository/main/src/java/org/apache/avalon/repository/main
                        DefaultRegistry.java
               repository/spi/src/java/org/apache/avalon/repository/provider
                        Registry.java
  Log:
  Move recent addition of factory discovery via service class from the initial context 
to the repository interface.  This will enable future enhanvements to the plug-in 
repository implementation without impacing the initial context interfaces (which are 
somewhat critical to the ability to support switching between alternative 
implementations).
  
  Revision  Changes    Path
  1.4       +9 -1      
avalon/repository/api/src/java/org/apache/avalon/repository/Repository.java
  
  Index: Repository.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/api/src/java/org/apache/avalon/repository/Repository.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Repository.java   24 Feb 2004 22:18:23 -0000      1.3
  +++ Repository.java   4 Mar 2004 03:26:41 -0000       1.4
  @@ -56,6 +56,14 @@
        */
       URL getResource( Artifact artifact ) throws RepositoryException;
   
  +   /**
  +    * Return the set of available artifacts capable of providing the  
  +    * supplied service class.
  +    *
  +    * @return the set of candidate factory artifacts
  +    */
  +    Artifact[] getCandidates( Class service );
  +
       /**
        * Creates a ClassLoader chain returning the lowest ClassLoader containing 
        * the jar artifact in the loader's path.  The dependencies of the argument 
  
  
  
  1.8       +10 -2     
avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultFactory.java       24 Feb 2004 22:18:23 -0000      1.7
  +++ DefaultFactory.java       4 Mar 2004 03:26:41 -0000       1.8
  @@ -34,6 +34,7 @@
   import org.apache.avalon.util.defaults.SimpleDefaultsFinder;
   import org.apache.avalon.util.defaults.SystemDefaultsFinder;
   
  +import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.Repository;
   import org.apache.avalon.repository.RepositoryException;
   import org.apache.avalon.repository.RepositoryRuntimeException;
  @@ -134,7 +135,8 @@
           File root = getCache( map );
           String[] hosts = getHosts( map );
           boolean online = getOnlineMode( map );
  -        return new DefaultRepository( root, hosts, online );
  +        Artifact[] candidates = getFactoryArtifacts( map );
  +        return new DefaultRepository( root, hosts, online, candidates );
       }
   
       private boolean getOnlineMode( Map map )
  @@ -155,5 +157,11 @@
       {
           return (String[]) map.get( 
               RepositoryCriteria.REPOSITORY_REMOTE_HOSTS );
  +    }
  +
  +    private Artifact[] getFactoryArtifacts( Map map )
  +    {
  +        return (Artifact[]) map.get( 
  +            RepositoryCriteria.REPOSITORY_FACTORY_ARTIFACTS );
       }
   }
  
  
  
  1.9       +70 -2     
avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepository.java
  
  Index: DefaultRepository.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepository.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultRepository.java    23 Feb 2004 01:29:05 -0000      1.8
  +++ DefaultRepository.java    4 Mar 2004 03:26:41 -0000       1.9
  @@ -24,6 +24,7 @@
   import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.Enumeration;
  +import java.util.List;
   import java.util.jar.JarFile;
   import java.util.zip.ZipEntry;
   
  @@ -64,6 +65,11 @@
   
       private final LoaderUtils m_loader;
   
  +   /**
  +    * A list of registered factory descriptors.
  +    */
  +    private final List m_descriptors = new ArrayList();
  +
       //------------------------------------------------------------------
       // mutable state 
       //------------------------------------------------------------------
  @@ -94,16 +100,22 @@
       * @exception NullPointerException if the cache or hosts argument
       * is null
       */
  -    DefaultRepository( File cache, String[] hosts, boolean online )
  +    DefaultRepository( 
  +      File cache, String[] hosts, boolean online, Artifact[] candidates )
  +      throws RepositoryException
       {
           if( cache == null ) throw new NullPointerException( "cache" );
           if( hosts == null ) throw new NullPointerException( "hosts" );
  +        if( candidates == null ) throw new NullPointerException( "candidates" );
   
           m_cache = cache;
           m_roots = RepositoryUtils.getCleanPaths( hosts );
           m_hosts = getHosts( m_roots );
           m_online = online;
           m_loader = new LoaderUtils( online );
  +
  +        setupRegistry( candidates );
  +
       }
   
       //------------------------------------------------------------------
  @@ -140,6 +152,29 @@
           }
       }
   
  +   /**
  +    * Return the set of available artifacts capable of providing the  
  +    * supplied service class.
  +    *
  +    * @return the set of candidate factory artifacts
  +    */
  +    public Artifact[] getCandidates( Class service )
  +    {
  +        ArrayList list = new ArrayList();
  +        String classname = service.getName();
  +        FactoryDescriptor[] descriptors = getFactoryDescriptors();
  +        for( int i=0; i<descriptors.length; i++ )
  +        {
  +            FactoryDescriptor descriptor = descriptors[i];
  +            final String key = descriptor.getInterface();
  +            if( classname.equals( key ) )
  +            {
  +                list.add( descriptor.getArtifact() );
  +            }
  +        }
  +        return (Artifact[]) list.toArray( new Artifact[0] );
  +    }
  +
       /**
        * Get a resource url relative to the supplied artifact.
        * 
  @@ -302,4 +337,37 @@
           urls[ artifacts.length ] = getResource( primary );
           return urls;
       }
  +
  +    private void setupRegistry( Artifact[] artifacts ) throws RepositoryException
  +    {
  +        for( int i=0; i<artifacts.length; i++ )
  +        {
  +            Artifact artifact = artifacts[i];
  +            registerArtifact( artifact );
  +        }
  +    }
  +
  +    private void registerArtifact( Artifact artifact ) throws RepositoryException
  +    {
  +        Attributes attributes = getAttributes( artifact );
  +        FactoryDescriptor descriptor = new FactoryDescriptor( attributes );
  +        final String key = descriptor.getInterface();
  +        if( null == key ) 
  +        {
  +            final String error = 
  +              "Artifact [" + artifact + "] does not declare a exported interface.";
  +            throw new RepositoryException( error );
  +        }
  +        else if( !m_descriptors.contains( descriptor ) )
  +        {
  +            m_descriptors.add( descriptor );
  +        }
  +    }
  +
  +    private FactoryDescriptor[] getFactoryDescriptors()
  +    {
  +        return (FactoryDescriptor[]) 
  +          m_descriptors.toArray( new FactoryDescriptor[0] );
  +    }
  +
   }
  
  
  
  1.9       +16 -2     
avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepositoryCriteria.java
  
  Index: DefaultRepositoryCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepositoryCriteria.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultRepositoryCriteria.java    24 Feb 2004 22:18:23 -0000      1.8
  +++ DefaultRepositoryCriteria.java    4 Mar 2004 03:26:41 -0000       1.9
  @@ -26,6 +26,7 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   
  +import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.RepositoryException;
   import org.apache.avalon.repository.provider.InitialContext;
   import org.apache.avalon.repository.provider.RepositoryCriteria;
  @@ -70,7 +71,11 @@
             new PackedParameter( 
               REPOSITORY_REMOTE_HOSTS,
               ",",
  -            context.getInitialHosts() ) };
  +            context.getInitialHosts() ),
  +          new ArtifactSequenceParameter( 
  +            REPOSITORY_FACTORY_ARTIFACTS,
  +            ",",
  +            new Artifact[0] ) };
       }
   
       //--------------------------------------------------------------
  @@ -142,6 +147,15 @@
       {
           put( REPOSITORY_REMOTE_HOSTS, hosts );
       }
  +
  +    public void setFactoryArtifacts( Artifact[] artifacts )
  +    {
  +        put( REPOSITORY_FACTORY_ARTIFACTS, artifacts );
  +    }
  +
  +    //--------------------------------------------------------------
  +    // Object
  +    //--------------------------------------------------------------
   
       public String toString()
       {
  
  
  
  1.25      +3 -18     
avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java
  
  Index: DefaultInitialContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultInitialContext.java        27 Feb 2004 22:39:37 -0000      1.24
  +++ DefaultInitialContext.java        4 Mar 2004 03:26:41 -0000       1.25
  @@ -57,7 +57,6 @@
   import org.apache.avalon.repository.provider.FactoryNotFoundException;
   import org.apache.avalon.repository.provider.InitialContext;
   import org.apache.avalon.repository.provider.RepositoryCriteria;
  -import org.apache.avalon.repository.provider.Registry;
   import org.apache.avalon.repository.provider.Builder;
   import org.apache.avalon.repository.util.LoaderUtils;
   import org.apache.avalon.repository.util.RepositoryUtils;
  @@ -117,8 +116,6 @@
   
       private final LoaderUtils m_loader;
   
  -    private final Registry m_registry;
  -
       // ------------------------------------------------------------------------
       // mutable state
       // ------------------------------------------------------------------------
  @@ -221,6 +218,7 @@
               criteria.setCacheDirectory( m_cache );
               criteria.setHosts( m_hosts );
               criteria.setOnlineMode( online );
  +            criteria.setFactoryArtifacts( candidates );
               m_repository = (Repository) m_factory.create( criteria );
           }
           catch( Throwable e )
  @@ -235,10 +233,7 @@
                 + clazz.getProtectionDomain().getCodeSource().getLocation() );
               buffer.append( "\n cache: " + m_cache );
               throw new RepositoryException( buffer.toString(), e );
  -        }
  -
  -        m_registry = new DefaultRegistry( m_repository, candidates );
  -        
  +        }        
       }
   
       private void setupProxy( 
  @@ -260,16 +255,6 @@
       // ------------------------------------------------------------------------
       // InitialContext
       // ------------------------------------------------------------------------
  -
  -   /**
  -    * Return the factory registry.
  -    *
  -    * @return the registry
  -    */
  -    public Registry getRegistry()
  -    {
  -        return m_registry;
  -    }
   
      /**
       * Return the inital repository.
  
  
  
  1.9       +10 -10    
avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContextFactory.java
  
  Index: DefaultInitialContextFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContextFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultInitialContextFactory.java 27 Feb 2004 22:39:37 -0000      1.8
  +++ DefaultInitialContextFactory.java 4 Mar 2004 03:26:41 -0000       1.9
  @@ -108,8 +108,6 @@
   
       private final Properties m_properties;
   
  -    private final List m_registry = new ArrayList();
  -
       //------------------------------------------------------------------
       // mutable state 
       //------------------------------------------------------------------
  @@ -132,6 +130,8 @@
   
       private boolean m_online;
   
  +    private Artifact[] m_registry;
  +
       // ------------------------------------------------------------------------
       // constructor
       // ------------------------------------------------------------------------
  @@ -208,8 +208,7 @@
   
           m_properties = 
             m_defaults.getConsolidatedProperties(
  -            getDefaultProperties(), 
  -            KEYS );
  +            getDefaultProperties(), KEYS );
           Defaults.macroExpand( 
               m_properties, 
               new Properties[]{ m_properties } );
  @@ -240,12 +239,12 @@
       // ------------------------------------------------------------------------
   
      /**
  -    * Register a factory artifict.
  -    * @param artifact the artifact reference
  +    * Register a set of factory artifacts.
  +    * @param artifacts the artifact references
       */
  -    public void addFactoryArtifact( Artifact artifact )
  +    public void setFactoryArtifacts( Artifact[] artifacts )
       {
  -        m_registry.add( artifact );
  +        m_registry = artifacts;
       }
   
      /**
  @@ -391,7 +390,8 @@
       */
       public Artifact[] getRegisteredArtifacts()
       {
  -        return (Artifact[]) m_registry.toArray( new Artifact[0] );
  +        if( null != m_registry ) return m_registry;
  +        return new Artifact[0];
       }
   
      /**
  
  
  
  1.14      +7 -8      
avalon/repository/spi/src/java/org/apache/avalon/repository/provider/InitialContext.java
  
  Index: InitialContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/spi/src/java/org/apache/avalon/repository/provider/InitialContext.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- InitialContext.java       27 Feb 2004 22:39:37 -0000      1.13
  +++ InitialContext.java       4 Mar 2004 03:26:41 -0000       1.14
  @@ -46,6 +46,12 @@
       String ONLINE_KEY = "avalon.repository.online";
   
      /**
  +    * The property key used when resolving a sequence of factory
  +    * artifact references.
  +    */
  +    String FACTORY_ARTIFACTS_KEY = "avalon.repository.artifacts";
  +
  +   /**
       * The property key used when resolving the default cache directory.
       */
       String CACHE_KEY = "avalon.repository.cache";
  @@ -111,13 +117,6 @@
       * @return the repository
       */
       Repository getRepository();
  -
  -   /**
  -    * Return the factory registry.
  -    *
  -    * @return the registry
  -    */
  -    Registry getRegistry();
   
      /**
       * Create a factory builder using a supplied artifact.
  
  
  
  1.7       +8 -5      
avalon/repository/spi/src/java/org/apache/avalon/repository/provider/InitialContextFactory.java
  
  Index: InitialContextFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/spi/src/java/org/apache/avalon/repository/provider/InitialContextFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- InitialContextFactory.java        28 Feb 2004 16:41:07 -0000      1.6
  +++ InitialContextFactory.java        4 Mar 2004 03:26:41 -0000       1.7
  @@ -40,19 +40,22 @@
       * @see InitialContext#IMPLEMENTATION_KEY
       * @see InitialContext#CACHE_KEY
       * @see InitialContext#HOSTS_KEY
  +    * @see InitialContext#ONLINE_KEY
  +    * @see InitialContext#FACTORY_ARTIFACTS_KEY
       */
       String[] KEYS = 
         new String[]{
           InitialContext.ONLINE_KEY,
           InitialContext.IMPLEMENTATION_KEY,
           InitialContext.CACHE_KEY,
  -        InitialContext.HOSTS_KEY };
  +        InitialContext.HOSTS_KEY,
  +        InitialContext.FACTORY_ARTIFACTS_KEY };
   
      /**
  -    * Register a factory artifict.
  -    * @param artifact the artifact reference
  +    * Register a set of factory artifacts.
  +    * @param artifacts the factory artifact references
       */
  -    void addFactoryArtifact( Artifact artifact );
  +    void setFactoryArtifacts( Artifact[] artifacts );
   
      /**
       * Set the online mode of the repository. The default policy is to 
  
  
  
  1.5       +21 -2     
avalon/repository/spi/src/java/org/apache/avalon/repository/provider/RepositoryCriteria.java
  
  Index: RepositoryCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/spi/src/java/org/apache/avalon/repository/provider/RepositoryCriteria.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RepositoryCriteria.java   24 Feb 2004 22:18:23 -0000      1.4
  +++ RepositoryCriteria.java   4 Mar 2004 03:26:41 -0000       1.5
  @@ -20,6 +20,8 @@
   import java.io.File;
   import java.util.Map;
   
  +import org.apache.avalon.repository.Artifact;
  +
   /**
    * Interface defining the operations available to manipulate repository
    * factory criteria.
  @@ -45,6 +47,12 @@
       String REPOSITORY_REMOTE_HOSTS = InitialContext.HOSTS_KEY;
   
      /**
  +    * Repository proxy password parameter descriptor.
  +    */
  +    String REPOSITORY_FACTORY_ARTIFACTS = 
  +      InitialContext.FACTORY_ARTIFACTS_KEY;
  +
  +   /**
       * An array of property keys that are used to locate default
       * values.
       */
  @@ -52,7 +60,8 @@
         new String[]{
           REPOSITORY_ONLINE_MODE,
           REPOSITORY_CACHE_DIR,
  -        REPOSITORY_REMOTE_HOSTS };
  +        REPOSITORY_REMOTE_HOSTS,
  +        REPOSITORY_FACTORY_ARTIFACTS };
   
      /**
       * Set the online mode of the repository. The default policy is to 
  @@ -81,4 +90,14 @@
       * @param hosts a sequence of remote host urls
       */
       void setHosts( String[] hosts );
  +
  +   /**
  +    * Set the available factory artifacts.  Each artifact represents a 
  +    * resolvable factory artifiact (artifact with an associate meta 
  +    * descriptor) than can be used as the basis for classloader creation
  +    * and instance establishment.
  +    *
  +    * @param artifacts a sequence of artifact identifiers
  +    */
  +    void setFactoryArtifacts( Artifact[] artifacts );
   }
  
  
  
  1.6       +4 -7      
avalon/repository/test/src/test/org/apache/avalon/repository/main/DefaultInitialContextFactoryTestCase.java
  
  Index: DefaultInitialContextFactoryTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/test/src/test/org/apache/avalon/repository/main/DefaultInitialContextFactoryTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultInitialContextFactoryTestCase.java 27 Feb 2004 22:39:37 -0000      1.5
  +++ DefaultInitialContextFactoryTestCase.java 4 Mar 2004 03:26:41 -0000       1.6
  @@ -100,12 +100,9 @@
   
           Artifact[] artifacts = 
             getArtifactsToRegister( "src/test/conf/system.xml" );
  -        for( int i=0; i<artifacts.length; i++ )
  -        {
  -            Artifact artifact = artifacts[i];
  -            factory.addFactoryArtifact( artifact );
  -        }
  +        factory.setFactoryArtifacts( artifacts );
   
  +        //
           // Once customized we can proceed with the instantiation
           // of the initial context. The following method invocation
           // will trigger the population of the system cache with the  
  @@ -144,7 +141,7 @@
           String key = Repository.class.getName();
           System.out.println( "  key: " + key );
           Artifact[] candidates = 
  -          context.getRegistry().getCandidates( Repository.class );
  +          context.getRepository().getCandidates( Repository.class );
           for( int i=0; i<candidates.length; i++ )
           {
               System.out.println( "  artifact: " + candidates[i] );
  
  
  
  1.6       +6 -4      
avalon/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
  
  Index: LoaderUtils.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LoaderUtils.java  24 Feb 2004 22:18:24 -0000      1.5
  +++ LoaderUtils.java  4 Mar 2004 03:26:42 -0000       1.6
  @@ -88,7 +88,8 @@
               else
               {
                   final String error = 
  -                  "Artifact [" + artifact + "] does not exist in local cache 
(repository offline).";
  +                  "Artifact [" + artifact 
  +                  + "] does not exist in local cache.";
                   throw new RepositoryException( error );
               }
           }
  @@ -155,7 +156,8 @@
   
           Exception cause = null;
   
  -        File destination = new File( root, artifact.getPath() + "." + mime );
  +        File destination = 
  +          new File( root, artifact.getPath() + "." + mime );
           
           if( !m_online )
           {
  @@ -168,7 +170,7 @@
                   final String error = 
                     "Artifact ["
                     + artifact.getPath() + "." + mime 
  -                  + "] does not exist in local cache (repository offline).";
  +                  + "] does not exist in local cache.";
                   throw new RepositoryException( error );
               }
           }
  
  
  

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

Reply via email to