On Sun, 27 Oct 2002 08:16, you wrote:
> Peter,
>
> I have need of the Excalibur ClassLoader Component from within Phoenix. 

Okay - I will try to have a bash at it real soon. If you want to have a go at 
integrating it into phoenix instead then that would be fine with me.

Currently a film crew have disassembled half my house and I don't have a 
decent dev machine to dev/test on and may not for a couple more days until 
the shoot stops :)

> What is the current status of this component...(unit tested?)? 

From memory everything is unit tested except for one class. Namely 
org.apache.excalibur.loader.builder.LoaderBuilder. To unit test this you need 
to write an implementation of LoaderResolver. Assuming no changes are made 
then the kit should be good to go.

> Does
> Phoenix support this component within the environment.xml?  What steps
> might I need to take to utilize this component?

Well you first need to modify 
phoenix.components.classloader.DefaulClassLoaderManager to use the 
configuration. It should check if a <classloader/> element does not exist 
then we should do what is already done. 

If it does exist then we should turn Configuration into DOM tree (using 
org.apache.avalon.phoenix.components.util.ConfigurationUtil). Build 
ClassloaderMetaData, validate it and then using to build a set of 
ClassLoaders. We should then return the "default" classloader (specified in 
metadata).

We should then add a new method to ApplicationContext and BlockContext that 
looks like

ClassLoader getClassLoader( String name ) 
  throws Exception;

The only hard bit about this is implementing LoaderResolver. I have started to 
do this a few weeks ago and then got distracted by other things. I have 
attached the start of that code which may (or may not) compile, and may or 
may not work (the Filesets are currently an unimplemented feature).

Anyways I will push that to the top of my list of things to do if you want ;) 
If you want things done quicker than I can do it then feel free to do it 
yourself - and send the changes along! ;)

-- 
Cheers,

Peter Donald
*------------------------------------------------------*
| Despite your efforts to be a romantic hero, you will |
| gradually evolve into a postmodern plot device.      |
*------------------------------------------------------* 
/*
 * 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.excalibur.loader.builder;

import java.net.URL;
import java.net.URLClassLoader;
import java.io.File;
import org.apache.avalon.excalibur.extension.Extension;
import org.apache.avalon.excalibur.packagemanager.PackageManager;
import org.apache.avalon.excalibur.packagemanager.OptionalPackage;
import org.apache.excalibur.loader.runtime.JoinClassLoader;

/**
 *
 * @author <a href="mailto:peter at apache.org">Peter Donald</a>
 * @version $Revision: 1.1 $ $Date: 2002/09/15 21:22:39 $
 */
public class SimpleLoaderResolver
    implements LoaderResolver
{
    /**
     * The base directory relative to which to aquire files.
     */
    private File m_baseDirectory;

    /**
     * The PackageManager to use to resolve Extensions.
     */
    private PackageManager m_manager;

    /**
     * Create a resolver that resolves all files according to specied
     * baseDirectory and using specified {@link PackageManager} to aquire
     * {@link Extension} objects.
     *
     * @param baseDirectory the base directory
     * @param manager the {@link PackageManager}
     */
    public SimpleLoaderResolver( final File baseDirectory,
                                 final PackageManager manager )
    {
        setBaseDirectory( baseDirectory );
        setManager( manager );
    }

    public URL resolveExtension( final Extension extension )
        throws Exception
    {
        if( null == getManager() )
        {
            final String message =
                "Unable to resolve Extension as no PackageManager " +
                "has been specified";
            throw new IllegalStateException( message );
        }
        final OptionalPackage optionalPackage =
            getManager().getOptionalPackage( extension );
        return optionalPackage.getFile().toURL();
    }

    public URL resolveURL( final String location )
        throws Exception
    {
        return getFileFor( location ).toURL();
    }

    public URL[] resolveFileSet( String baseDirectory,
                                 String[] includes,
                                 String[] excludes )
        throws Exception
    {
        return new URL[ 0 ];
    }

    /**
     * Create a Join ClassLoader for specified ClassLoaders.
     * Use {@link JoinClassLoader} to implement functionality.
     *
     * @param classLoaders the ClassLoaders to "join"
     * @return the joined ClassLoader
     * @throws Exception if unable to create classloader
     */
    public ClassLoader createJoinClassLoader( final ClassLoader[] classLoaders )
        throws Exception
    {
        return new JoinClassLoader( classLoaders,
                                    ClassLoader.getSystemClassLoader() );
    }

    /**
     * Create a ClassLoader with specified parent and
     * containing specified URLs. This implementation just creates
     * it using the default URLClassLoader.
     *
     * @param parent the parent classloader
     * @param urls the URLs that the ClassLoader should contain
     * @return the newly created ClassLoader
     * @throws Exception if unable to create classloader
     */
    public ClassLoader createClassLoader( final ClassLoader parent,
                                          final URL[] urls )
        throws Exception
    {
        return new URLClassLoader( urls, parent );
    }

    /**
     * Utility class to retrieve a file object for specified location.
     *
     * @param location which to get file for.
     * @return the file for specified location
     */
    protected File getFileFor( final String location )
    {
        File base = getBaseDirectory();
        if( null == base )
        {
            base = new File( "." );
        }
        return new File( base, location );
    }

    /**
     * Return the base directory against which to resolve relative files.
     *
     * @return the base directory against which to resolve relative files.
     */
    protected File getBaseDirectory()
    {
        return m_baseDirectory;
    }

    /**
     * Set the base directory.
     *
     * @param baseDirectory the base directory.
     */
    protected void setBaseDirectory( File baseDirectory )
    {
        m_baseDirectory = baseDirectory;
    }

    /**
     * Return the PackageManager for resolver.
     *
     * @return the PackageManager for resolver.
     */
    protected PackageManager getManager()
    {
        return m_manager;
    }

    /**
     * Set the PackageManager for resolver.
     *
     * @param manager the PackageManager for resolver.
     */
    protected void setManager( final PackageManager manager )
    {
        m_manager = manager;
    }
}

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

Reply via email to