webwork/src/main/webwork/util/injection DefaultObjectCreator.java,NONE,1.1 ObjectCreator.java,NONE,1.1 ObjectFactory.java,NONE,1.1
[email protected] Sun, 16 Jan 2005 23:28:14 -0800
| Newsgroups | gmane.comp.java.open-symphony.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/opensymphony/webwork/src/main/webwork/util/injection
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18098/src/main/webwork/util/injection
Added Files:
DefaultObjectCreator.java ObjectCreator.java
ObjectFactory.java
Log Message:
Allow instantiation of classes to be pluggable from within webwork.
This allows you to use Pico or Spring to instantiate the webwork classes
that you need.
This is especially useful for instantiating beans in web pages (using
<webwork:bean..>
There is a new property 'webwork.injection.objectcreator' that you can
specify to load a class to instantiate your objects.
Note that other object loaded directly through the webwork.properties
file are not passed through this object creation process.
Fixes WW-723
--- NEW FILE: DefaultObjectCreator.java ---
package webwork.util.injection;
import java.beans.Beans;
import java.io.IOException;
public class DefaultObjectCreator implements ObjectCreator
{
public Object instantiate(Class clazz) throws IllegalAccessException, InstantiationException
{
return clazz.newInstance();
}
public Object instantiateBean(ClassLoader classloader, String className) throws IOException, ClassNotFoundException
{
return Beans.instantiate(classloader, className);
}
}
--- NEW FILE: ObjectCreator.java ---
package webwork.util.injection;
import java.io.IOException;
public interface ObjectCreator
{
public Object instantiate(Class actionClass) throws IllegalAccessException, InstantiationException;
public Object instantiateBean(ClassLoader classloader, String className) throws IOException, ClassNotFoundException;
}
--- NEW FILE: ObjectFactory.java ---
package webwork.util.injection;
import org.apache.commons.logging.LogConfigurationException;
import org.apache.commons.logging.LogFactory;
import webwork.config.Configuration;
import webwork.util.ClassLoaderUtils;
import webwork.util.InjectionUtils;
import java.io.IOException;
public class ObjectFactory
{
private static ObjectCreator impl;
public static final String CLASS_NAME = "webwork.injection.objectcreator";
static
{
impl = new DefaultObjectCreator();
try
{
String classname = (String) Configuration.get(CLASS_NAME);
if (classname != null && classname.length() > 0)
{
try
{
impl = (ObjectCreator) ClassLoaderUtils.loadClass(classname, ObjectCreator.class).newInstance();
}
catch (Exception e)
{
LogFactory.getLog(InjectionUtils.class).error("Could not load class " + classname + " or could not cast it to InjectionUtils. Using default", e);
}
}
}
catch (IllegalArgumentException e)
{
//do nothing - this is just because the property couldn't be found.
}
catch (LogConfigurationException e)
{
//just catching this to be safe.
}
}
public static Object instantiate(Class actionClass) throws IllegalAccessException, InstantiationException
{
return impl.instantiate(actionClass);
}
public static Object instantiateBean(ClassLoader classloader, String className) throws IOException, ClassNotFoundException
{
return impl.instantiateBean(classloader, className);
}
}
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt