donaldp 01/11/16 21:22:07
Modified: src/scratchpad/org/apache/avalon/excalibur/extension
PackageManager.java
Added: src/scratchpad/org/apache/avalon/excalibur/extension
UnsatisfiedExtensionException.java
Log:
Added methods to scan dependencies. However unlike the others these will
return an array of OptionalPackage objects and if a requirement i\s unsatisfied
then an exception will be thrown.
Revision Changes Path
1.4 +75 -40
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/extension/PackageManager.java
Index: PackageManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/extension/PackageManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PackageManager.java 2001/11/17 01:01:40 1.3
+++ PackageManager.java 2001/11/17 05:22:07 1.4
@@ -19,80 +19,115 @@
* directories.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.3 $ $Date: 2001/11/17 01:01:40 $
+ * @version $Revision: 1.4 $ $Date: 2001/11/17 05:22:07 $
* @see PackageRepository
*/
public class PackageManager
{
///Ordered list of repositories to search in
- private PackageRepository[] m_repositorys;
+ private PackageRepository m_repository;
/**
- * Construct a PackageManager for a specific set of repositories.
+ * Construct a PackageManager for a repositories.
*
- * @param repositorys the array of repositories to use in PackageManager
+ * @param repository the repository to use in PackageManager
*/
- public PackageManager( final PackageRepository[] repositorys )
+ public PackageManager( final PackageRepository repository )
{
- m_repositorys = repositorys;
-
- if( null == repositorys )
+ if( null == repository )
{
- throw new NullPointerException( "repositorys property is null" );
+ throw new NullPointerException( "repository property is null" );
}
+
+ m_repository = repository;
}
/**
* Return the <code>OptionalPackage</code> that provides specified
* <code>Extension</code>. If the specified <code>Extension</code>
- * can not be found then <code>null</code> is returned.
+ * can not be found then <code>null</code> is returned. If there is
+ * multiple implementations that satisfy <code>Extension</code>,
+ * then an <code>OptionalPackage</code> returned is based on the
+ * following heristic;
+ *
+ * <p>Return the first Optional Package. (This heuristic will
+ * be replaced in time).</p>
*
- * @param extension Description of the optional package
- * @see #getOptionalPackages()
+ * @param extension Description of the extension that needs to be
provided by
+ * optional package
* @see OptionalPackage
* @see Extension
*/
public OptionalPackage getOptionalPackage( final Extension extension )
{
- final OptionalPackage[] packages = getOptionalPackages( extension );
+ final OptionalPackage[] packages = m_repository.getOptionalPackages(
extension );
- //If theres a candidate package then return it
- //else return null
- if( null != packages || 0 != packages.length )
- {
- return packages[ 0 ];
- }
- else
- {
- return null;
- }
+ if( null == packages || 0 == packages.length ) return null;
+
+ //TODO: Use heurisitic to find which is best package
+
+ return packages[ 0 ];
}
+
/**
- * Return all the <code>OptionalPackage</code>s that satisfy specified
- * <code>Extension</code>.
+ * Build a list of dependencies based on specified
<code>Extension</code>s.
+ * Each specified <code>Extension</code> is expected to be a required
extension
+ * of another "Optional Package".
*
- * @param extension Description of the optional package
- * @see #getOptionalPackage()
- * @see OptionalPackage
+ * <p>If the required <code>Extension</code> can not be found locally
then
+ * an UnsatisfiedPackageException is thrown. if an
<code>OptionalPackage</code>
+ * is found locally that satisfies specified required
<code>Extension</code>
+ * then it is returned in the array of OptionalPackages.
scanDependencies() is then recursively
+ * called on all of the candidates required extensions.</p>
+ *
+ * @param required the array of required Extensions.
+ * @param available the array of Extensions already available to caller.
+ * @return the list of OptionalPackages that satisfy required Extensions
+ * @exception UnsatisfiedPackageException if unable to satisfy all
extensions
+ * @see #scanDependencies
*/
- public synchronized OptionalPackage[] getOptionalPackages( final
Extension extension )
+ public OptionalPackage[] scanDependencies( final Extension required,
+ final Extension[] available )
+ throws UnsatisfiedExtensionException
{
- final ArrayList results = new ArrayList();
+ final Extension[] extensions = new Extension[] { required };
+ return scanDependencies( required, available );
+ }
- for( int i = 0; i < m_repositorys.length; i++ )
- {
- final PackageRepository repository = m_repositorys[ i ];
- final OptionalPackage[] packages =
repository.getOptionalPackages( extension );
+ /**
+ * Build a list of dependencies based on specified
<code>Extension</code>.
+ * The specified <code>Extension</code> is expected to be a required
extension
+ * of another "Optional Package".
+ *
+ * <p>If the required <code>Extension</code> can not be found locally
then
+ * an UnsatisfiedPackageException is thrown. if an
<code>OptionalPackage</code>
+ * is found locally that satisfies specified required
<code>Extension</code>
+ * then it is returned in the array of OptionalPackages.
scanDependencies() is then recursively
+ * called on all of the candidates required extensions.</p>
+ *
+ * @param required the array of required Extensions.
+ * @param available the array of Extensions already available to caller.
+ * @return the list of OptionalPackages that satisfy required Extensions
+ * @exception UnsatisfiedPackageException if unable to satisfy all
extensions
+ * @see #scanDependencies
+ */
+ public OptionalPackage[] scanDependencies( final Extension[] required,
+ final Extension[] available )
+ throws UnsatisfiedExtensionException
+ {
+ final ArrayList dependencies = new ArrayList();
+ final ArrayList unsatisfied = new ArrayList();
- for( int j = 0; j < packages.length; j++ )
- {
- results.add( packages[ j ] );
- }
+ scanDependencies( required, available, dependencies, unsatisfied );
+
+ if( 0 != unsatisfied.size() )
+ {
+ final Extension extension = (Extension)unsatisfied.get( 0 );
+ throw new UnsatisfiedExtensionException( extension );
}
- //TODO: Sort packages based on the degree to which they match
- return (OptionalPackage[])results.toArray( new OptionalPackage[ 0 ]
);
+ return (OptionalPackage[])dependencies.toArray( new OptionalPackage[
0 ] );
}
/**
1.1
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/extension/UnsatisfiedExtensionException.java
Index: UnsatisfiedExtensionException.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.excalibur.extension;
/**
* Exception indicating an extension was not found in Package Repository.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2001/11/17 05:22:07 $
* @see Extension
*/
public class UnsatisfiedExtensionException
extends Exception
{
private Extension m_extension;
/**
* Construct the <code>UnsatisfiedPackageException</code>
* for specified <code>Extension</code>.
*
* @param extension the extension that caused exception
*/
public UnsatisfiedExtensionException( final Extension extension )
{
m_extension = extension;
}
/**
* Return the unsatisfied <code>Extension</code> that
* caused this exception tho be thrown.
*
* @return the unsatisfied Extension
*/
public Extension getUnsatisfiedExtension()
{
return m_extension;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>