You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2003/03/24 02:06:01 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets PortletActionEvent.java
weaver 2003/03/23 17:06:00
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
PortletActionEvent.java
Log:
- Now correctly recognizes the do* method parameters passed by legacy JspActions
which included the Portlet as a argument in place of Context.
- reduced reflection lookups by caching Method objects. Previous implementation
would lookup the method every time. Now methods are pulled from a HashMap
if they have ever been called in the past.
Revision Changes Path
1.2 +69 -20 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PortletActionEvent.java
Index: PortletActionEvent.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PortletActionEvent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PortletActionEvent.java 20 Mar 2003 18:09:39 -0000 1.1
+++ PortletActionEvent.java 24 Mar 2003 01:06:00 -0000 1.2
@@ -58,10 +58,15 @@
*/
package org.apache.jetspeed.modules.actions.portlets;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
+import java.util.HashMap;
+import org.apache.jetspeed.portal.Portlet;
+import org.apache.jetspeed.portal.portlets.GenericMVCPortlet;
+import org.apache.jetspeed.util.PortletSessionState;
import org.apache.turbine.modules.ActionEvent;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.util.ParameterParser;
@@ -76,12 +81,19 @@
* this convienent functionality to all GenericMVCPortlets
*
* @author tkuebler
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
* @version $Id$
* @stereotype moment-interval
*/
public abstract class PortletActionEvent
extends ActionEvent
{
+
+ /**
+ * Cache ActionEvent methods to avoid repeated replection
+ * method lookups.
+ */
+ private static final HashMap eventMethods = new HashMap();
/**
* You need to implement this in your classes that extend this
@@ -128,6 +140,9 @@
// Name of the button.
String theButton = null;
+
+ // Portlet whom this action is a target of
+ Portlet portlet = (Portlet) context.get(GenericMVCPortlet.PORTLET);
// ParameterParser.
ParameterParser pp = data.getParameters();
@@ -147,31 +162,65 @@
}
}
- if (theButton == null)
+ if (theButton == null )
{
throw new NoSuchMethodException("ActionEvent: The button was null");
}
- try
- {
+
- // The arguments to the method to find.
- Class[] classes = new Class[2];
- classes[0] = RunData.class;
- classes[1] = Context.class;
-
- // The arguments to pass to the method to execute.
- Object[] args = new Object[2];
- Method method = getClass().getMethod(theButton, classes);
- args[0] = data;
- args[1] = context;
- method.invoke(this, args);
- }
- catch (NoSuchMethodException nsme)
- {
+ if (!fireEvent(data, Context.class, context, theButton) && PortletSessionState.isMyRequest(data, portlet))
+ {
+ // Old JSP actions use Portlet instead of Context
+ // as their event method's 2nd parameter
+ if (!fireEvent(data, Portlet.class,
+ portlet,
+ theButton))
+ {
+ // Attempt to execut things the old way..
+ super.executeEvents(data);
+ }
+ }
- // Attempt to execut things the old way..
- super.executeEvents(data);
- }
}
+
+ /**
+ * Convenience method for firing portlet events.
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
+ */
+ protected boolean fireEvent(RunData data, Class deltaClass, Object deltaValue, String theButton)
+ {
+ try
+ {
+ // The arguments to the method to find.
+ Class[] classes = new Class[2];
+ classes[0] = RunData.class;
+ classes[1] = deltaClass;
+
+ // The arguments to pass to the method to execute.
+ Object[] args = new Object[2];
+
+ String methodKey = getClass().getName()+":"
+ +theButton+":"+classes[0].getName()
+ +":"+classes[1].getName();
+
+ Method method = (Method)eventMethods.get(methodKey);
+ if(method == null)
+ {
+ method = getClass().getMethod(theButton, classes);
+ eventMethods.put(methodKey, method);
+ }
+ args[0] = data;
+ args[1] = deltaValue;
+ method.invoke(this, args);
+ return true;
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org