webwork/src/main/webwork/action/factory ReloadHelperActionFactoryProxy.java,NONE,1.1 ActionFactory.java,1.18,1.19 ActionFactoryProxy.java,1.8,1.9 AliasingActionFactoryProxy.java,1.13,1.14 DefaultActionFactory.java,1.23,1.24 JavaActionFactory.java,1.12,1.13 PrefixActionFactoryProxy.java,1.16,1.17
[email protected] Sat, 08 Nov 2003 08:27:14 -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-serv30284
Modified Files:
ActionFactory.java ActionFactoryProxy.java
AliasingActionFactoryProxy.java DefaultActionFactory.java
JavaActionFactory.java PrefixActionFactoryProxy.java
Added Files:
ReloadHelperActionFactoryProxy.java
Log Message:
Added proper functional xml file reloading
Added flushCaches method to tell factories to flush stuff so reloading works
default factory creates a ReloadHelper factory in front of everything else that handles checking for out of date files and flushing caches. Feedback appreciated!
--- NEW FILE: ReloadHelperActionFactoryProxy.java ---
package webwork.action.factory;
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
import java.io.File;
import webwork.action.Action;
import webwork.config.Configuration;
import webwork.util.ClassLoaderUtils;
/**
* User: hani
* Date: Nov 7, 2003
* Time: 11:38:42 AM
*/
public class ReloadHelperActionFactoryProxy extends ActionFactoryProxy
{
private File[] files;
private long[] lastModified;
public ReloadHelperActionFactoryProxy(ActionFactory aFactory)
{
super(aFactory);
StringTokenizer configFiles = new StringTokenizer((String)Configuration.get("webwork.configuration.xml"), ",");
List l = new ArrayList(configFiles.countTokens());
while(configFiles.hasMoreTokens())
{
String name = configFiles.nextToken();
URL fileUrl = ClassLoaderUtils.getResource(name+".xml", ReloadHelperActionFactoryProxy.class);
if(fileUrl!=null)
{
File file = new File(fileUrl.getFile());
if(file.exists())
l.add(file);
}
}
files = new File[l.size()];
//lets check when they were all modified
l.toArray(files);
lastModified = new long[files.length];
for(int i = 0; i < files.length; i++)
{
lastModified[i] = files[i].lastModified();
}
}
public Action getActionImpl(String aName) throws Exception
{
for(int i = 0; i < files.length; i++)
{
if(files[i].lastModified() > lastModified[i])
{
lastModified[i] = files[i].lastModified();
flushCaches();
}
}
return getNextFactory().getActionImpl(aName);
}
}
Index: ActionFactory.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/ActionFactory.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- ActionFactory.java 2 Nov 2003 03:30:19 -0000 1.18
+++ ActionFactory.java 8 Nov 2003 16:27:11 -0000 1.19
@@ -95,4 +95,12 @@
*/
public abstract Action getActionImpl(String aName)
throws Exception;
+
+ /**
+ * Called if the configuration has been modified.
+ * If an ActionFactory does any caching of results,
+ * it should override this method and flush its
+ * internal caches in it.
+ */
+ public void flushCaches() {}
}
Index: ActionFactoryProxy.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/ActionFactoryProxy.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ActionFactoryProxy.java 15 Mar 2002 02:17:51 -0000 1.8
+++ ActionFactoryProxy.java 8 Nov 2003 16:27:11 -0000 1.9
@@ -41,4 +41,9 @@
{
return nextFactory;
}
+
+ public void flushCaches()
+ {
+ nextFactory.flushCaches();
+ }
}
Index: AliasingActionFactoryProxy.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/AliasingActionFactoryProxy.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- AliasingActionFactoryProxy.java 9 Sep 2002 21:21:16 -0000 1.13
+++ AliasingActionFactoryProxy.java 8 Nov 2003 16:27:11 -0000 1.14
@@ -95,4 +95,9 @@
return getNextFactory().getActionImpl(actionName);
}
+
+ public void flushCaches() {
+ getNextFactory().flushCaches();
+ actionAliases.clear();
+ }
}
Index: DefaultActionFactory.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/DefaultActionFactory.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- DefaultActionFactory.java 17 Sep 2003 14:38:45 -0000 1.23
+++ DefaultActionFactory.java 8 Nov 2003 16:27:11 -0000 1.24
@@ -7,6 +7,7 @@
package webwork.action.factory;
import webwork.action.Action;
+import webwork.config.Configuration;
/**
* Default implementation of an action factory facade that creates the default
@@ -74,7 +75,14 @@
factory = new PrepareActionFactoryProxy(factory);
factory = new ParametersActionFactoryProxy(factory);
factory = new ChainingActionFactoryProxy(factory);
-
+ try {
+ boolean reloadEnabled = "true".equalsIgnoreCase(Configuration.getString("webwork.configuration.xml.reload"));
+ if(reloadEnabled)
+ factory = new ReloadHelperActionFactoryProxy(factory);
+ } catch(IllegalArgumentException ex)
+ {}
+
+
}
/**
@@ -91,5 +99,5 @@
{
return factory.getActionImpl(name);
}
-
+
}
Index: JavaActionFactory.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/JavaActionFactory.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- JavaActionFactory.java 6 Nov 2003 02:58:10 -0000 1.12
+++ JavaActionFactory.java 8 Nov 2003 16:27:11 -0000 1.13
@@ -52,7 +52,7 @@
try
{
actionClass = actionLoader.loadClass(name);
- } catch (Exception e)
+ } catch (ClassNotFoundException e)
{
try
{
@@ -62,6 +62,16 @@
// Not found or could not be instantiated
throw new IllegalArgumentException("Action '"+name+"' not found or could not be initialized: "+e2);
}
+ } catch (NoClassDefFoundError e)
+ {
+ try
+ {
+ actionClass = ClassLoaderUtils.loadClass(name, JavaActionFactory.class);
+ } catch (Throwable e2)
+ {
+ // Not found or could not be instantiated
+ throw new IllegalArgumentException("Action '"+name+"' not found or could not be initialized: "+e2);
+ }
}
// Put action class in cache
@@ -75,5 +85,9 @@
{
throw new IllegalArgumentException("Action '"+name+"' could not be instantiated:"+e);
}
+ }
+
+ public void flushCaches() {
+ actionMapping.clear();
}
}
Index: PrefixActionFactoryProxy.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/action/factory/PrefixActionFactoryProxy.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- PrefixActionFactoryProxy.java 15 Jan 2003 00:06:45 -0000 1.16
+++ PrefixActionFactoryProxy.java 8 Nov 2003 16:27:11 -0000 1.17
@@ -111,4 +111,9 @@
return getNextFactory().getActionImpl(actionName);
}
}
+
+ public void flushCaches() {
+ getNextFactory().flushCaches();
+ actionNames.clear();
+ }
}
-------------------------------------------------------
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/