You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2002/06/22 18:49:30 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine/modules/actions TemplateAction.java

jmcnally    2002/06/22 09:49:30

  Modified:    src/java/org/apache/turbine/modules/actions
                        TemplateAction.java
  Log:
  patch by Stephen Haberman <st...@chase3000.com>
  
  The Turbine 3 TemplateAction copies most of the code from the abstract
  ActionEvent, however, it's missing a crucial exception handling
  condition that didn't get copied from ActionEvent to TemplateAction that
  causes errors in doXxx methods to not show up in the log. I submitted a
  patch awhile ago that merely copied the extra exception handling from
  ActionEvent to TemplateAction.
  
  After looking at the code again, I refactored perform() out of
  TemplateAction, thereby relying on ActionEvent's good exception
  handling.
  
  Instead of TemplateAction.perform() just being copied
  ActionEvent.perform() code with the TemplateContext attribute added in,
  I overrode the ActionEvent.doPerform(data) and
  ActionEvent.executeEvents(data) in TemplateContext that then later get
  the TemplateContext via getTemplateContext(data).
  
  Overall, I think this is a lot cleaner, reduces the duplicated code, and
  most importantly, fixes the original error I was having of not seeing
  action exceptions in the logs.
  
  Revision  Changes    Path
  1.3       +20 -29    jakarta-turbine-3/src/java/org/apache/turbine/modules/actions/TemplateAction.java
  
  Index: TemplateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/modules/actions/TemplateAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TemplateAction.java	20 Mar 2002 01:55:28 -0000	1.2
  +++ TemplateAction.java	22 Jun 2002 16:49:30 -0000	1.3
  @@ -57,8 +57,10 @@
   import org.apache.turbine.RunData;
   import org.apache.turbine.TemplateContext;
   import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
   import java.util.Enumeration;
   import org.apache.turbine.ParameterParser;
  +import org.apache.turbine.TurbineException;
   import org.apache.turbine.modules.ActionEvent;
   
   /**
  @@ -81,52 +83,41 @@
   public abstract class TemplateAction
       extends ActionEvent
   {
  +    
       /**
        * You need to implement this in your classes that extend this
        * class.
  -     *
  +     * 
        * @param data A Turbine RunData object.
  -     * @exception Exception a generic exception.
  +     * @throws Exception a generic exception.
        */
  -    public void doPerform(RunData data)
  +    public void doPerform( RunData data )
           throws Exception
       {
  +        doPerform(data, getTemplateContext(data));
       }
  -
  -    public void doPerform(RunData data, TemplateContext context)
  -        throws Exception
  -    {
  -    }
  -
  +    
       /**
  -     * This overrides the default Action.perform() to execute the
  -     * doEvent() method.  If that fails, then it will execute the
  -     * doPerform() method instead.
  -     *
  +     * You can also implement this method instead to easily
  +     * get the TemplateContext object.
  +     * 
        * @param data A Turbine RunData object.
  -     * @exception Exception a generic exception.
  +     * @param context A Turbine TemplateContext object.
  +     * @throws Exception a generic exception.
        */
  -    protected void perform( RunData data )
  +    public void doPerform( RunData data, TemplateContext context )
           throws Exception
       {
  -        try
  -        {
  -            executeEvents(data, getTemplateContext(data));
  -        }
  -        catch (NoSuchMethodException e)
  -        {
  -            doPerform( data, getTemplateContext(data) );
  -        }
       }
   
       /**
  -     * This method should be called to execute the event based system.
  +     * This method is called by the parent ActionEvent
  +     * to try and execute an event for this request.
        *
        * @param data A Turbine RunData object.
  -     * @param context Velocity context information.
        * @exception Exception a generic exception.
        */
  -    public void executeEvents(RunData data, TemplateContext context)
  +    public void executeEvents(RunData data)
           throws Exception
       {
           // Name of the button.
  @@ -166,8 +157,8 @@
   
               Method method = getClass().getMethod(theButton, classes);
               args[0] = data;
  -            args[1] = context;
  -            method.invoke(this, args );
  +            args[1] = getTemplateContext(data);
  +            method.invoke(this, args);
           }
           catch (NoSuchMethodException nsme)
           {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>