webwork/src/main/webwork/action/factory ReloadingJavaActionFactory.java,NONE,1.1 DefaultActionFactory.java,1.24,1.25
[email protected] Sun, 09 Nov 2003 13:03:53 -0800
| Newsgroups | gmane.comp.java.open-symphony.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/opensymphony/webwork/src/main/webwork/action/factory
In directory sc8-pr-cvs1:/tmp/cvs-serv27996/src/main/webwork/action/factory
Modified Files:
DefaultActionFactory.java
Added Files:
ReloadingJavaActionFactory.java
Log Message:
If webwork.action.java.reload is defined, then we use our own classloader and reload actions. If it isn't defined, then we use the standard JavaActionFactory
--- NEW FILE: ReloadingJavaActionFactory.java ---
package webwork.action.factory;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import webwork.util.classloader.WebworkClassLoader;
import webwork.util.ClassLoaderUtils;
import webwork.action.Action;
import webwork.config.Configuration;
public class ReloadingJavaActionFactory extends JavaActionFactory
{
private static final Log log = LogFactory.getLog(ReloadingJavaActionFactory.class);
//we store this here as well as the parent field to avoid having to cast to call methods on the classloader
private WebworkClassLoader reloadingClassLoader;
private URL source;
public ReloadingJavaActionFactory()
{
URL url = getClass().getResource("/webwork.properties");
System.out.println(this + " " + url);
if (url == null)
{
log.warn("Cannot find CodeSource for webwork, unable to creare reloading action factory");
}
else
{
try
{
String urlVal = url.toString();
source = new URL(urlVal.substring(0, urlVal.lastIndexOf("webwork.properties")));
log.debug("Creating classloader for url " + source);
WebworkClassLoader actionLoader = WebworkClassLoader.getInstance(source, Thread.currentThread().getContextClassLoader());
StringTokenizer tok = new StringTokenizer(Configuration.getString("webwork.action.packages").trim(), ", ");
String[] packages = new String[tok.countTokens()];
int counter = 0;
while(tok.hasMoreTokens())
{
packages[counter++] = tok.nextToken();
}
actionLoader.setPackages(packages);
this.actionLoader = actionLoader;
this.reloadingClassLoader = actionLoader;
}
catch(MalformedURLException ex)
{
log.error("Grr", ex);
}
}
}
/**
* Returns a loaded and instantiated action class instance using a fully
* qualified classname.
*
* @param name classname of the action to be created
* @return the action corresponding to the given Java class name
*/
public Action getActionImpl(String name) throws Exception
{
if(reloadingClassLoader!=null && reloadingClassLoader.isStale())
{
synchronized(this)
{
log.debug("Classes modified, reloading...");
reloadingClassLoader = (WebworkClassLoader)reloadingClassLoader.clone();
actionLoader = reloadingClassLoader;
}
}
Class actionClass = null;
try
{
actionClass = reloadingClassLoader.loadClass(name);
}
catch (Exception e)
{
try
{
actionClass = ClassLoaderUtils.loadClass(name, getClass());
}
catch (Exception e2)
{
// Not found
throw new IllegalArgumentException("Action '" + name + "' not found");
}
}
try
{
Action action = (Action)actionClass.newInstance();
return action;
}
catch (Exception e)
{
throw new IllegalArgumentException("Action '" + name + "' could not be instantiated:" + e);
}
}
}
Index: DefaultActionFactory.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/DefaultActionFactory.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- DefaultActionFactory.java 8 Nov 2003 16:27:11 -0000 1.24
+++ DefaultActionFactory.java 9 Nov 2003 21:03:51 -0000 1.25
@@ -16,6 +16,8 @@
*
* <p>The order in which factory proxies are executed is as follows:</p>
* <ol>
+ * <li>{@link ChainingActionFactoryProxy} -
+ * Copies properties from one action to the next in a chain.</li>
* <li>{@link ParametersActionFactoryProxy} -
* Sets parameters on the action.</li>
* <li>{@link PrepareActionFactoryProxy} -
@@ -63,7 +65,14 @@
// Default series of factory proxies
// RO: There is a purpose for the duplicated
// command proxy. DON'T REMOVE THE SECOND ONE!
- factory = new JavaActionFactory();
+ try {
+ boolean reloadEnabled = "true".equalsIgnoreCase(Configuration.getString("webwork.action.java.reload"));
+ if(reloadEnabled)
+ factory = new ReloadingJavaActionFactory();
+ } catch(IllegalArgumentException ex)
+ {}
+ if(factory==null)
+ factory = new JavaActionFactory();
factory = new ScriptActionFactoryProxy(factory);
factory = new XMLActionFactoryProxy(factory);
factory = new PrefixActionFactoryProxy(factory);
@@ -81,8 +90,6 @@
factory = new ReloadHelperActionFactoryProxy(factory);
} catch(IllegalArgumentException ex)
{}
-
-
}
/**
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/