donaldp     01/11/17 03:35:36

  Modified:    src/scratchpad/org/apache/avalon/excalibur/extension
                        DefaultPackageRepository.java
  Log:
  Add setPath method so subclasses can change path.
  
  Update to reflect changes in name of extension static methods.
  
  Use "cache" terminology as it makes it easier to subclass using different 
methodologies.
  
  Revision  Changes    Path
  1.7       +45 -26    
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/extension/DefaultPackageRepository.java
  
  Index: DefaultPackageRepository.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/extension/DefaultPackageRepository.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultPackageRepository.java     2001/11/17 05:21:11     1.6
  +++ DefaultPackageRepository.java     2001/11/17 11:35:36     1.7
  @@ -23,7 +23,7 @@
    * a path to find the Optional Packages.</p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version $Revision: 1.6 $ $Date: 2001/11/17 05:21:11 $
  + * @version $Revision: 1.7 $ $Date: 2001/11/17 11:35:36 $
    * @see OptionalPackage
    * @see PackageRepository
    */
  @@ -40,7 +40,7 @@
       /**
        * The set of directories in which to look for Optional Packages
        */
  -    private final File[]     m_path;
  +    private File[]           m_path;
   
       /**
        * Flag set when it is necessary to scan paths to 
  @@ -55,24 +55,7 @@
        */
       public DefaultPackageRepository( final File[] path )
       {
  -        if( null == path )
  -        {
  -            throw new NullPointerException( "path property is null" );
  -        }
  -
  -        for( int i = 0; i < path.length; i++ )
  -        {
  -            final File directory = path[ i ];
  -            
  -            if( !directory.exists() || !directory.isDirectory() )
  -            {
  -                throw new IllegalArgumentException( "path element " + 
directory + 
  -                                                    " must exist and must be 
a directory" );
  -            }
  -        }
  -
  -        m_path = path;
  -        m_needToScan = true;
  +        setPath( path );
       }
   
       /**
  @@ -120,14 +103,40 @@
       }
   
       /**
  +     * Set the path for the Repository.
  +     *
  +     * @param path the list of directories in which to search
  +     */
  +    protected synchronized void setPath( final File[] path )
  +    {
  +        if( null == path )
  +        {
  +            throw new NullPointerException( "path property is null" );
  +        }
  +
  +        for( int i = 0; i < path.length; i++ )
  +        {
  +            final File directory = path[ i ];
  +            
  +            if( !directory.exists() || !directory.isDirectory() )
  +            {
  +                throw new IllegalArgumentException( "path element " + 
directory + 
  +                                                    " must exist and must be 
a directory" );
  +            }
  +        }
  +
  +        m_path = path;
  +        m_needToScan = true;
  +    }
  +
  +    /**
        * Scan the path for this repository and reload all 
        * the "Optional Packages" found in the path.
        *
        */
       protected final synchronized void scanPath()
       {
  -        m_packages.clear();
  -        m_needToScan = false;
  +        clearCache();
   
           for( int i = 0; i < m_path.length; i++ )
           {
  @@ -164,7 +173,7 @@
               try
               {
                   final OptionalPackage optionalPackage = getOptionalPackage( 
file );
  -                addOptionalPackage( optionalPackage );
  +                cacheOptionalPackage( optionalPackage );
               }
               catch( final IOException ioe )
               {
  @@ -174,13 +183,23 @@
       }
   
       /**
  +     * Clear internal cache of optional packages.
  +     *
  +     */
  +    protected synchronized final void clearCache()
  +    {
  +        m_packages.clear();
  +        m_needToScan = true;
  +    }
  +
  +    /**
        * Add OptionalPackage to internal cache of Optional Packages.
        * Note that this method is only protected so that unit tests can 
sub-class
        * and add entries to PackageRepository by calling this method.
        *
        * @param optionalPackage the OptionalPackage to be added to repository
        */
  -    protected final void addOptionalPackage( final OptionalPackage 
optionalPackage )
  +    protected synchronized final void cacheOptionalPackage( final 
OptionalPackage optionalPackage )
       {
           m_needToScan = false;
           final Extension extension = 
optionalPackage.getAvailableExtensions()[ 0 ];
  @@ -214,8 +233,8 @@
           try
           {
               if( null == manifest ) return null;
  -            final Extension[] available = Extension.getAvailableExtensions( 
manifest );
  -            final Extension[] required = Extension.getRequiredExtensions( 
manifest );
  +            final Extension[] available = Extension.getAvailable( manifest );
  +            final Extension[] required = Extension.getRequired( manifest );
   
               return new OptionalPackage( file, available, required );
           }
  
  
  

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

Reply via email to