Return-Path: Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 27418 invoked by uid 500); 4 Jul 2003 15:24:54 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 27407 invoked by uid 500); 4 Jul 2003 15:24:54 -0000 Received: (qmail 27404 invoked from network); 4 Jul 2003 15:24:54 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 4 Jul 2003 15:24:54 -0000 Received: (qmail 39510 invoked by uid 1438); 4 Jul 2003 15:24:55 -0000 Date: 4 Jul 2003 15:24:55 -0000 Message-ID: <20030704152455.39509.qmail@icarus.apache.org> From: mcconnell@apache.org To: avalon-sandbox-cvs@apache.org Subject: cvs commit: avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/model ClassLoaderModel.java ContainmentModel.java DeploymentModel.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mcconnell 2003/07/04 08:24:55 Modified: merlin/composition/src/java/org/apache/avalon/composition/model/impl DefaultClassLoaderModel.java DefaultCompositionModel.java DefaultCompositionModelFactory.java DefaultContainmentModel.java DefaultDeploymentModel.java Resources.properties merlin/composition-spi/src/java/org/apache/avalon/composition/model ClassLoaderModel.java ContainmentModel.java DeploymentModel.java Log: Updating of the composition model to ensure that a model is built using the classpath declared within the model (i.e. all factory methods have to look ahead into the model, construct the classloader, and supply the classloader as a constructor argument to the model it is creating). This ensures that *any* class referenced within the scope of a particular model is valid providing it is declared with the models classpath. This allows the declaration of model factories within the declaration of the model. Revision Changes Path 1.2 +90 -55 avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java Index: DefaultClassLoaderModel.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultClassLoaderModel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DefaultClassLoaderModel.java 4 Jul 2003 07:27:35 -0000 1.1 +++ DefaultClassLoaderModel.java 4 Jul 2003 15:24:55 -0000 1.2 @@ -57,9 +57,11 @@ import java.util.jar.Manifest; import java.net.JarURLConnection; import java.net.URL; +import java.net.URLClassLoader; import org.apache.avalon.composition.model.ClassLoaderModel; import org.apache.avalon.composition.model.SystemContext; +import org.apache.avalon.composition.model.TypeRepository; import org.apache.avalon.composition.repository.Repository; import org.apache.avalon.extension.Extension; import org.apache.avalon.extension.manager.ExtensionManager; @@ -67,14 +69,13 @@ import org.apache.avalon.extension.manager.PackageManager; import org.apache.avalon.extension.manager.impl.DefaultExtensionManager; import org.apache.avalon.extension.manager.impl.DelegatingExtensionManager; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.meta.data.ClassLoaderDirective; import org.apache.avalon.meta.data.ClasspathDirective; import org.apache.avalon.meta.data.RepositoryDirective; import org.apache.avalon.meta.data.ResourceDirective; -import org.apache.avalon.excalibur.i18n.ResourceManager; -import org.apache.avalon.excalibur.i18n.Resources; - /** *

Implementation of a classloader model within which a @@ -119,25 +120,23 @@ // state //============================================================== - private File m_base; - - private Repository m_repository; + private final ClassLoaderModel m_parent; - private ClassLoaderDirective m_directive; + private final String[] m_classpath; - private ClassLoaderModel m_parent; + private final ExtensionManager m_extension; - private String[] m_classpath; + private final PackageManager m_manager; - private ExtensionManager m_extension; + private final Logger m_logger; - private PackageManager m_manager; + private final OptionalPackage[] m_packages; - private Logger m_logger; + private final URL[] m_urls; - private OptionalPackage[] m_packages; + private final URLClassLoader m_classLoader; - private URL[] m_urls; + private final DefaultTypeRepository m_types; //============================================================== // constructor @@ -156,29 +155,49 @@ * primative classpath entries and resource directives */ protected DefaultClassLoaderModel( - final Logger logger, final SystemContext system, final ClassLoaderDirective directive ) + final Logger logger, final SystemContext system, ClassLoader classLoader, final ClassLoaderDirective directive ) throws Exception { + if( logger == null ) + { + throw new NullPointerException( "logger" ); + } if( system == null ) { throw new NullPointerException( "system" ); } + if( classLoader == null ) + { + throw new NullPointerException( "classLoader" ); + } + if( directive == null ) + { + throw new NullPointerException( "directive" ); + } m_logger = logger; - m_repository = system.getRepository(); - m_base = system.getBaseDirectory(); m_extension = new DefaultExtensionManager( - directive.getLibrary().getOptionalExtensionDirectories( m_base ) ); + directive.getLibrary().getOptionalExtensionDirectories( system.getBaseDirectory() ) ); m_manager = new PackageManager( m_extension ); - m_directive = directive; + m_parent = null; // // generate the primitive classpath // - m_classpath = createClassPath(); + m_classpath = createClassPath( system, directive ); m_packages = buildOptionalPackages( m_classpath ); m_urls = buildQualifiedClassPath(); + m_classLoader = new URLClassLoader( + m_urls, classLoader ); + + // + // create a type repository + // + + m_types = new DefaultTypeRepository( m_classLoader ); + m_types.enableLogging( logger.getChildLogger( "type" ) ); + } /** @@ -186,48 +205,65 @@ * repository, a base directory and a classloader directive * enabling the creation of a fully populated classpath. * - * @param base the base directory from which relative references - * shall be resolved - * @param repository a local cache of jar files addressable - * relative to group/name/version identifiers + * @param logger the assigned logging channel + * @param system the system context + * @param classloader the parent classloader + * @param parent the parent classloader model * @param directive the classloader directive containing the * primative classpath entries and resource directives */ protected DefaultClassLoaderModel( - final Logger logger, final SystemContext system, ClassLoaderModel parent, ClassLoaderDirective directive ) + final Logger logger, final SystemContext system, + ClassLoaderModel parent, ClassLoaderDirective directive ) throws Exception { + if( logger == null ) + { + throw new NullPointerException( "logger" ); + } + if( system == null ) + { + throw new NullPointerException( "system" ); + } if( parent == null ) { throw new NullPointerException( "parent" ); } - if( directive == null ) { throw new NullPointerException( "directive" ); } m_logger = logger; - m_repository = system.getRepository(); - m_base = system.getBaseDirectory(); m_parent = parent; DefaultExtensionManager local = new DefaultExtensionManager( - directive.getLibrary().getOptionalExtensionDirectories( m_base ) ); + directive.getLibrary().getOptionalExtensionDirectories( system.getBaseDirectory() ) ); m_extension = new DelegatingExtensionManager( new ExtensionManager[]{ parent.getExtensionManager(), local } ); m_manager = new PackageManager( m_extension ); - m_directive = directive; // // generate the primitive classpath // - m_classpath = createClassPath(); + m_classpath = createClassPath( system, directive ); m_packages = buildOptionalPackages( m_classpath, parent.getOptionalPackages( true ) ); m_urls = buildQualifiedClassPath(); + m_classLoader = new URLClassLoader( + m_urls, parent.getClassLoader() ); + + // + // create a type repository + // + + m_types = + new DefaultTypeRepository( + m_classLoader, parent.getTypeRepository() ); + m_types.enableLogging( logger.getChildLogger( "type" ) ); + } //============================================================== @@ -235,15 +271,14 @@ //============================================================== /** - * Return the fully qualified classpath including extension jar files - * resolved relative to the classpath directives in the meta-data - * and any parent classloader models. + * Return the type repository managed by this containment + * context. * - * @return an array of URL representing the complete classpath + * @return the repository */ - public URL[] getQualifiedClassPath() + public TypeRepository getTypeRepository() { - return m_urls; + return m_types; } /** @@ -297,27 +332,25 @@ return (OptionalPackage[]) list.toArray( new OptionalPackage[0] ); } - //============================================================== - // protected implementation - //============================================================== - /** - * Return the base directory from which any relative file references - * shall be resolved. - * @return the base directory + * Return the fully qualified classpath including extension jar files + * resolved relative to the classpath directives in the meta-data + * and any parent classloader models. + * + * @return an array of URL representing the complete classpath */ - protected File getBaseDirectory() + public URL[] getQualifiedClassPath() { - return m_base; + return m_urls; } /** - * Return the system wide jar file repository. - * @return the repository + * Return the classloader established by this classloader model. + * @return the classloader */ - protected Repository getRepository() + public ClassLoader getClassLoader() { - return m_repository; + return m_classLoader; } //============================================================== @@ -352,15 +385,17 @@ return m_classpath; } - private String[] createClassPath() + private String[] createClassPath( SystemContext system, ClassLoaderDirective directive ) throws Exception { ArrayList classpath = new ArrayList(); addToClassPath( - classpath, m_directive.getClasspathDirective().expandFileSetDirectives( m_base ) ); + classpath, + directive.getClasspathDirective().expandFileSetDirectives( + system.getBaseDirectory() ) ); RepositoryDirective[] repositories = - m_directive.getClasspathDirective().getRepositoryDirectives(); + directive.getClasspathDirective().getRepositoryDirectives(); for( int i=0; i