this patch should be applied against CVS HEAD.
All tests pass on my machine !
I did a bigger/better refactoring on another patch, but that didn't pass
the tests :-(
--
Leandro Rodrigo Saad Cruz
InterBusiness Tecnologia e Servi�os
IB - www.ibnetwork.com.br
DB - www.digitalbrand.com.br
OJB - db.apache.org/ojb
XINGU - xingu.sf.net
Index: src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java,v
retrieving revision 1.19
diff -u -b -B -r1.19 VelocityActionEvent.java
--- src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java 28 Sep 2003 17:35:45 -0000 1.19
+++ src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java 4 Feb 2004 16:58:56 -0000
@@ -90,6 +90,8 @@
private static final Class [] methodParams
= new Class [] { RunData.class, Context.class };
+ protected boolean initialized = false;
+
/**
* You need to implement this in your classes that extend this
* class.
@@ -100,6 +102,9 @@
public abstract void doPerform(RunData data)
throws Exception;
+ protected abstract void initialize()
+ throws Exception;
+
/**
* This overrides the default Action.perform() to execute the
* doEvent() method. If that fails, then it will execute the
@@ -113,6 +118,10 @@
{
try
{
+ if(!initialized)
+ {
+ initialize();
+ }
executeEvents(data, TurbineVelocity.getContext(data));
}
catch (NoSuchMethodException e)
Index: src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java,v
retrieving revision 1.22
diff -u -b -B -r1.22 VelocityActionEvent.java
--- src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java 2 Aug 2004 08:57:36 -0000 1.22
+++ src/java/org/apache/turbine/util/velocity/VelocityActionEvent.java 15 Oct 2004 20:38:21 -0000
@@ -187,54 +187,17 @@
public void executeEvents(RunData data, Context context)
throws Exception
{
- // Name of the button.
- String theButton = null;
-
- // ParameterParser.
- ParameterParser pp = data.getParameters();
-
- String button = pp.convert(BUTTON);
- String key = null;
-
- // Loop through and find the button.
- for (Iterator it = pp.keySet().iterator(); it.hasNext();)
- {
- key = (String) it.next();
- if (key.startsWith(button))
- {
- if (considerKey(key, pp))
- {
- theButton = formatString(key);
- break;
- }
- }
- }
-
- if (theButton == null)
- {
- throw new NoSuchMethodException(
- "ActionEvent: The button was null");
- }
-
- Method method = null;
+ String methodName = findMethodName(data);
try
{
- method = getClass().getMethod(theButton, methodParams);
- Object[] methodArgs = new Object[] { data, context };
-
- if (log.isDebugEnabled())
- {
- log.debug("Invoking " + method);
- }
-
- method.invoke(this, methodArgs);
+ executeEvent(methodName,new Object[]{data, context});
}
catch (NoSuchMethodException nsme)
{
// Attempt to execute things the old way..
if (log.isDebugEnabled())
{
- log.debug("Couldn't locate the Event ( " + theButton
+ log.debug("Couldn't locate the Event ( " + methodName
+ "), running executeEvents() in "
+ super.getClass().getName());
}
@@ -244,13 +207,9 @@
catch (InvocationTargetException ite)
{
Throwable t = ite.getTargetException();
- log.error("Invokation of " + method , t);
+ log.error("Invokation of " + methodName , t);
throw ite;
}
- finally
- {
- pp.remove(key);
- }
}
/**
@@ -264,6 +223,46 @@
throws Exception
{
RunData data = (RunData) getRunData(pipelineData);
+ String methodName = findMethodName(data);
+ try
+ {
+ executeEvent(methodName,new Object[]{pipelineData, context});
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // Attempt to execute things the old way..
+ if (log.isDebugEnabled())
+ {
+ log.debug("Couldn't locate the Event ( " + methodName
+ + "), running executeEvents() in "
+ + super.getClass().getName());
+ }
+
+ super.executeEvents(pipelineData);
+ }
+ catch (InvocationTargetException ite)
+ {
+ Throwable t = ite.getTargetException();
+ log.error("Invokation of " + methodName , t);
+ throw ite;
+ }
+ }
+
+ protected void executeEvent(String methodName, Object[] params)
+ throws Exception
+ {
+ Method method = getClass().getMethod(methodName, methodParams);
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("Invoking " + method);
+ }
+ method.invoke(this, params);
+ }
+
+ protected String findMethodName(RunData data)
+ throws NoSuchMethodException
+ {
// Name of the button.
String theButton = null;
@@ -292,42 +291,8 @@
throw new NoSuchMethodException(
"ActionEvent: The button was null");
}
-
- Method method = null;
- try
- {
- method = getClass().getMethod(theButton, methodParams);
- Object[] methodArgs = new Object[] { pipelineData, context };
-
- if (log.isDebugEnabled())
- {
- log.debug("Invoking " + method);
- }
-
- method.invoke(this, methodArgs);
- }
- catch (NoSuchMethodException nsme)
- {
- // Attempt to execute things the old way..
- if (log.isDebugEnabled())
- {
- log.debug("Couldn't locate the Event ( " + theButton
- + "), running executeEvents() in "
- + super.getClass().getName());
- }
-
- super.executeEvents(pipelineData);
- }
- catch (InvocationTargetException ite)
- {
- Throwable t = ite.getTargetException();
- log.error("Invokation of " + method , t);
- throw ite;
- }
- finally
- {
pp.remove(key);
- }
+ return theButton;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]