You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/08/02 07:47:21 UTC
cvs commit: jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/factory DefaultComponentFactory.java ComponentFactory.java
donaldp 2002/08/01 22:47:21
Added: containerkit/src/java/org/apache/excalibur/containerkit/factory
DefaultComponentFactory.java ComponentFactory.java
Log:
Moved componentFactory to a separate package
and added a default implementation that loads
from ClassLoader
Revision Changes Path
1.1 jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/factory/DefaultComponentFactory.java
Index: DefaultComponentFactory.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.excalibur.containerkit.factory;
import org.apache.excalibur.containerkit.infobuilder.ComponentInfoBuilder;
import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
/**
* The default implementation of {@link ComponentFactory}
* that simply creates components from a {@link java.lang.ClassLoader}.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/08/02 05:47:21 $
*/
public class DefaultComponentFactory
implements ComponentFactory
{
/**
* The utility class that is used when building info
* objects for Components.
*/
private final ComponentInfoBuilder m_infoBuilder = new ComponentInfoBuilder();
/**
* The classloader from which all resources are loaded.
*/
private final ClassLoader m_classLoader;
/**
* Create a Factory that loads from specified ClassLoader.
*
* @param classLoader the classLoader to use in factory, must not be null
*/
public DefaultComponentFactory( final ClassLoader classLoader )
{
if( null == classLoader )
{
throw new NullPointerException( "classLoader" );
}
m_classLoader = classLoader;
}
/**
* Create a component by creating info for class
* with specified name and loaded from factorys ClassLoader.
*
* @see ComponentFactory#createInfo
*/
public ComponentInfo createInfo( final String implementationKey )
throws Exception
{
return m_infoBuilder.build( implementationKey, m_classLoader );
}
/**
* Create a component by creating instance of class
* with specified name and loaded from factorys ClassLoader.
*
* @see ComponentFactory#createComponent
*/
public Object createComponent( final String implementationKey )
throws Exception
{
final Class clazz = m_classLoader.loadClass( implementationKey );
return clazz.newInstance();
}
}
1.1 jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/factory/ComponentFactory.java
Index: ComponentFactory.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.excalibur.containerkit.factory;
import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
/**
* This interface defines the mechanism via which a
* component or its associated {@link org.apache.excalibur.containerkit.metainfo.ComponentInfo} can
* be created.
*
* <p>Usually the component or componentInfo will just be loaded
* from a particular ClassLoader. However if a developer wanted
* to dynamically assemble applications they could implement
* a custom factory that created components via non-standard
* mechanisms (say by wrapping remote, CORBA, or other style
* objects).</p>
*
* <p>The methods take a <code>implementationKey</code> parameter
* and usually this represents the class name of the component.
* However in alternative component systems this may designate
* objects via different mechanisms.</p>
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/08/02 05:47:21 $
*/
public interface ComponentFactory
{
/**
* Create a {@link org.apache.excalibur.containerkit.metainfo.ComponentInfo} for component
* specified by implementationKey.
*
* @param implementationKey the key indicating type of component (usually classname)
* @return the ComponentInfo for component
* @throws java.lang.Exception if unable to create Info object
*/
ComponentInfo createInfo( String implementationKey )
throws Exception;
/**
* Create an instance of component with specified
* implementationKey.
*
* @param implementationKey the key indicating type of component (usually classname)
* @return an instance of component
* @throws java.lang.Exception if unable to create component
*/
Object createComponent( String implementationKey )
throws Exception;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>