geirm       01/04/19 21:28:49

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTMethod.java ASTReference.java
                        ASTSetDirective.java
  Log:
  Added support for the EventCartridge support.  For ASTMethod, it's what
  came to mind - hoping Tim can provide some insight.
  
  None of these are holy - they may not work well in practice.  It think
  that we can reduce nullReferenceRender and referenceInsert into the
  a single interface/method - they really do the same thing
  
  Revision  Changes    Path
  1.15      +49 -20    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
  
  Index: ASTMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ASTMethod.java    2001/04/18 12:25:28     1.14
  +++ ASTMethod.java    2001/04/20 04:28:47     1.15
  @@ -1,4 +1,4 @@
  -/* Generated By:JJTree: Do not edit this line. ASTMethod.java */
  +package org.apache.velocity.runtime.parser.node;
   
   /*
    * The Apache Software License, Version 1.1
  @@ -54,6 +54,22 @@
    * <http://www.apache.org/>.
    */
   
  +import java.lang.reflect.Method;
  +
  +import java.io.*;
  +
  +import org.apache.velocity.context.InternalContextAdapter;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.util.introspection.Introspector;
  +import org.apache.velocity.util.introspection.IntrospectionCacheData;
  +
  +import org.apache.velocity.exception.MethodInvocationException;
  +import java.lang.reflect.InvocationTargetException;
  +
  +import org.apache.velocity.context.EventCartridge;
  +import org.apache.velocity.context.MethodExceptionEventHandler;
  +
   /**
    *  ASTMethod.java
    *
  @@ -68,24 +84,8 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: ASTMethod.java,v 1.14 2001/04/18 12:25:28 geirm Exp $ 
  + * @version $Id: ASTMethod.java,v 1.15 2001/04/20 04:28:47 geirm Exp $ 
    */
  -
  -package org.apache.velocity.runtime.parser.node;
  -
  -import java.lang.reflect.Method;
  -
  -import java.io.*;
  -
  -import org.apache.velocity.context.InternalContextAdapter;
  -import org.apache.velocity.runtime.Runtime;
  -import org.apache.velocity.runtime.parser.*;
  -import org.apache.velocity.util.introspection.Introspector;
  -import org.apache.velocity.util.introspection.IntrospectionCacheData;
  -
  -import org.apache.velocity.exception.MethodInvocationException;
  -import java.lang.reflect.InvocationTargetException;
  -
   public class ASTMethod extends SimpleNode
   {
       private String methodName = "";
  @@ -255,19 +255,48 @@
           catch( InvocationTargetException ite )
           {
               /*
  -             *  In the even that the invocation of the method
  +             *  In the event that the invocation of the method
                *  itself throws an exception, we want to catch that
                *  wrap it, and throw.  We don't log here as we want to figure
                *  out which reference threw the exception, so do that 
                *  above
                */
  +
  +            EventCartridge ec = context.getEventCartridge();
  +
  +            /*
  +             *  if we have an event cartridge, see if it wants to veto
  +             *  also, let non-Exception Throwables go...
  +             */
   
  -            throw  new MethodInvocationException( 
  +            if ( ec != null && ite.getTargetException() instanceof 
java.lang.Exception)
  +            {
  +                try
  +                {
  +                    return ec.methodException( o.getClass(), methodName, 
(Exception)ite.getTargetException() );
  +                }
  +                catch( Exception e )
  +                {
  +                    throw new MethodInvocationException( 
  +                        "Invocation of method '" 
  +                        + methodName + "' in  " + o.getClass() 
  +                        + " threw exception " 
  +                        + e.getClass(), e, methodName );
  +                }
  +            }
  +            else
  +            {
  +                /*
  +                 * no event cartridge to override. Just throw
  +                 */
  +
  +                throw new MethodInvocationException( 
                   "Invocation of method '" 
                   + methodName + "' in  " + o.getClass() 
                   + " threw exception " 
                   + ite.getTargetException().getClass(), 
                   ite.getTargetException(), methodName );
  +            }
           }
           catch( Exception e )
           {
  
  
  
  1.28      +49 -18    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
  
  Index: ASTReference.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ASTReference.java 2001/04/18 21:00:44     1.27
  +++ ASTReference.java 2001/04/20 04:28:47     1.28
  @@ -69,6 +69,10 @@
   
   import org.apache.velocity.exception.MethodInvocationException;
   
  +import org.apache.velocity.context.EventCartridge;
  +import org.apache.velocity.context.ReferenceInsertionEventHandler;
  +import org.apache.velocity.context.NullReferenceEventHandler;
  +
   /**
    * This class is responsible for handling the references in
    * VTL ($foo).
  @@ -80,7 +84,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Christoph Reck</a>
    * @author <a href="mailto:[EMAIL PROTECTED]>Kent Johnson</a>
  - * @version $Id: ASTReference.java,v 1.27 2001/04/18 21:00:44 geirm Exp $ 
  + * @version $Id: ASTReference.java,v 1.28 2001/04/20 04:28:47 geirm Exp $ 
   */
   public class ASTReference extends SimpleNode
   {
  @@ -256,29 +260,56 @@
            *  the normal processing
            */
   
  +        EventCartridge ec = context.getEventCartridge();
  +
           if (value == null)
  -        {
  -            /* 
  -             *  write prefix twice, because it's shmoo, so the \ don't escape each 
other...
  +        { 
  +            /*
  +             *  if we have an event cartridge, get a new value object
                */
  -            
  -            writer.write( firstTokenPrefix );
  -            writer.write( prefix );
  -            writer.write( nullString );
  -
  -            if (referenceType != QUIET_REFERENCE 
  -                 && Runtime.getBoolean( 
  -                     RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID, true) )
  +            if (ec != null)
               {
  -                Runtime.warn(new ReferenceException("reference : template = " + 
context.getCurrentTemplateName(), this));
  +               value = ec.nullReferenceRender( nullString );
               }
  +
  +            /*
  +             *  if still null, then render output.  If we got a value object
  +             *  then fall through to the normal rendering
  +             */
  +            if (value == null)
  +            {
  +                /* 
  +                 *  write prefix twice, because it's shmoo, so the \ don't escape 
each other...
  +                 */
  +                
  +                writer.write( firstTokenPrefix );
  +                writer.write( prefix );
  +                writer.write( nullString );
  +                
  +                if (referenceType != QUIET_REFERENCE 
  +                    && Runtime.getBoolean( 
  +                                          
RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID, true) )
  +                {
  +                    Runtime.warn(new ReferenceException("reference : template = " 
  +                                                        + 
context.getCurrentTemplateName(), this));
  +                }
  +
  +                return true;
  +            }
           }                    
  -        else
  +       
  +        /*
  +         *  now see if user want's to override the value for this
  +         *  insert
  +         */
  +        if (ec != null)
           {
  -            writer.write( firstTokenPrefix );
  -            writer.write( value.toString() );
  -        }                    
  -    
  +            value =  ec.referenceInsert( nullString, value );
  +         }
  +
  +        writer.write( firstTokenPrefix );
  +        writer.write( value.toString() );
  +                            
           return true;
       }
          
  
  
  
  1.16      +27 -6     
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
  
  Index: ASTSetDirective.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ASTSetDirective.java      2001/04/18 20:28:11     1.15
  +++ ASTSetDirective.java      2001/04/20 04:28:47     1.16
  @@ -1,7 +1,5 @@
   package org.apache.velocity.runtime.parser.node;
   
  -/* Generated By:JJTree: Do not edit this line. ASTSetDirective.java */
  -
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -67,12 +65,15 @@
   
   import org.apache.velocity.exception.MethodInvocationException;
   
  +import org.apache.velocity.context.NullSetEventHandler;
  +import org.apache.velocity.context.EventCartridge;
  +
   /**
    * Node for the #set directive
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: ASTSetDirective.java,v 1.15 2001/04/18 20:28:11 geirm Exp $
  + * @version $Id: ASTSetDirective.java,v 1.16 2001/04/20 04:28:47 geirm Exp $
    */
   public class ASTSetDirective extends SimpleNode
   {
  @@ -139,10 +140,30 @@
   
           if ( value  == null)
           {
  +            /*
  +             *  first, are we supposed to say anything anyway?
  +             */
               if(blather)
  -                Runtime.error("RHS of #set statement is null. Context will not be 
modified. " 
  -                          + context.getCurrentTemplateName() + " [line " + 
getLine() 
  -                          + ", column " + getColumn() + "]");
  +            {
  +                EventCartridge ec = context.getEventCartridge();
  +
  +                boolean doit = true;
  +               
  +                /*
  +                 *  if we have an EventCartridge...
  +                 */
  +                if (ec != null)
  +                {
  +                    doit = ec.nullSetLogMessage( left.literal() );
  +                }
  +
  +                if (doit)
  +                {
  +                    Runtime.error("RHS of #set statement is null. Context will not 
be modified. " 
  +                                  + context.getCurrentTemplateName() + " [line " + 
getLine() 
  +                                  + ", column " + getColumn() + "]");
  +                }
  +            }
   
               return false;
           }                
  
  
  

Reply via email to