avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/extension/src/java/org/apache/avalon/excalibur/extension DelegatingPackageRepository.java
Date Sun, 14 Jul 2002 05:08:26 GMT
donaldp     2002/07/13 22:08:26

  Added:       extension/src/java/org/apache/avalon/excalibur/extension
                        DelegatingPackageRepository.java
  Log:
  Add in a simple delegating package repository
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/extension/src/java/org/apache/avalon/excalibur/extension/DelegatingPackageRepository.java
  
  Index: DelegatingPackageRepository.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.txt file.
   */
  package org.apache.avalon.excalibur.extension;
  
  import java.util.ArrayList;
  
  /**
   * A {@link PackageRepository} that can delegate to multiple
   * different package repositories.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/14 05:08:25 $
   */
  public class DelegatingPackageRepository
      implements PackageRepository
  {
      /**
       * The list containing the package repositories.
       */
      private final ArrayList m_repositories = new ArrayList();
  
      /**
       * Default constructor that does not add any repositories.
       */
      public DelegatingPackageRepository()
      {
      }
  
      /**
       * Default constructor that delegates to specified repositories.
       */
      public DelegatingPackageRepository( final PackageRepository[] repositories )
      {
          for( int i = 0; i < repositories.length; i++ )
          {
              addPackageRepository( repositories[ i ] );
          }
      }
  
      /**
       * Add a repository to list of repositories delegated to
       * to find Optional Packages.
       *
       * @param repository the repository to add
       */
      protected synchronized void addPackageRepository( final PackageRepository repository
)
      {
          if( !m_repositories.contains( repository ) )
          {
              m_repositories.add( repository );
          }
      }
  
      /**
       * Remove a repository from list of repositories delegated to
       * to find Optional Packages.
       *
       * @param repository the repository to remove
       */
      protected synchronized void removePackageRepository( final PackageRepository repository
)
      {
          m_repositories.remove( repository );
      }
  
      /**
       * Scan through list of respositories and return all the matching {@link OptionalPackage}
       * objects that match in any repository.
       *
       * @param extension the extension to search for
       * @return the matching {@link OptionalPackage} objects.
       */
      public synchronized OptionalPackage[] getOptionalPackages( final Extension extension
)
      {
          final ArrayList resultPackages = new ArrayList();
  
          final int size = m_repositories.size();
          for( int i = 0; i < size; i++ )
          {
              final PackageRepository repository =
                  (PackageRepository)m_repositories.get( i );
              final OptionalPackage[] packages =
                  repository.getOptionalPackages( extension );
              if( null == packages || 0 == packages.length )
              {
                  continue;
              }
  
              for( int j = 0; j < packages.length; j++ )
              {
                  resultPackages.add( packages[ j ] );
              }
          }
  
          final OptionalPackage[] resultData =
              new OptionalPackage[ resultPackages.size() ];
          return (OptionalPackage[])resultPackages.toArray( resultData );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message