You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/08/11 20:58:07 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node ASTReference.java PropertyExecutor.java

geirm       01/08/11 11:58:07

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTReference.java PropertyExecutor.java
  Log:
  Changed both to use the Introspector to ensure centralized introspeciton and
  caching.  Also, the Introspector will guarantee an invokable, public
  method if there is one to be found.
  
  Revision  Changes    Path
  1.36      +17 -4     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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- ASTReference.java	2001/08/07 21:56:30	1.35
  +++ ASTReference.java	2001/08/11 18:58:07	1.36
  @@ -67,6 +67,8 @@
   import org.apache.velocity.runtime.exception.ReferenceException;
   import org.apache.velocity.runtime.parser.*;
   
  +import org.apache.velocity.util.introspection.Introspector;
  +
   import org.apache.velocity.exception.MethodInvocationException;
   
   import org.apache.velocity.app.event.EventCartridge;
  @@ -83,7 +85,7 @@
    * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
    * @author <a href="mailto:Christoph.Reck@dlr.de">Christoph Reck</a>
    * @author <a href="mailto:kjohnson@transparent.com>Kent Johnson</a>
  - * @version $Id: ASTReference.java,v 1.35 2001/08/07 21:56:30 geirm Exp $ 
  + * @version $Id: ASTReference.java,v 1.36 2001/08/11 18:58:07 geirm Exp $ 
   */
   public class ASTReference extends SimpleNode
   {
  @@ -397,14 +399,20 @@
               /*
                *  first, we introspect for the set<identifier> setter method
                */
  +
  +            Object[] params = { value };
   
  -            Class[] params = { value.getClass() };
               Class c = result.getClass();
               Method m = null;
   
               try
               {
  -                m = c.getMethod("set" + identifier, params);
  +                m = Introspector.getMethod( c, "set" + identifier, params);
  +
  +                if (m == null)
  +                {
  +                    throw new NoSuchMethodException();
  +                }
               }
               catch( NoSuchMethodException nsme2)
               {
  @@ -419,8 +427,13 @@
                   {
                       sb.setCharAt( 3 ,  Character.toLowerCase( sb.charAt( 3 ) ) );
                   }
  +               
  +                m = Introspector.getMethod( c, sb.toString(), params);
   
  -                m = c.getMethod( sb.toString(), params);
  +                if (m == null)
  +                {
  +                    throw new NoSuchMethodException();
  +                }
               }
   
               /*
  
  
  
  1.10      +25 -3     jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
  
  Index: PropertyExecutor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PropertyExecutor.java	2001/07/18 10:42:22	1.9
  +++ PropertyExecutor.java	2001/08/11 18:58:07	1.10
  @@ -56,6 +56,8 @@
   import java.lang.reflect.Method;
   import java.lang.reflect.InvocationTargetException;
   
  +import org.apache.velocity.util.introspection.Introspector;
  +
   import org.apache.velocity.exception.MethodInvocationException;
   import org.apache.velocity.app.event.EventCartridge;
   import org.apache.velocity.context.InternalContextAdapter;
  @@ -78,8 +80,15 @@
           try
           {
               methodUsed = "get" + property;
  -
  -            method = c.getMethod( methodUsed, null);
  +            
  +            Object[] params = {  };
  +            method = Introspector.getMethod( c, methodUsed, params);
  +           
  +            if (method == null)
  +            {
  +                throw new NoSuchMethodException();
  +            }
  +            
           }
           catch (NoSuchMethodException nsme)
           {
  @@ -113,11 +122,24 @@
               try
               {
                   methodUsed = sb.toString();
  -                method = c.getMethod( methodUsed, null);
  +                               
  +                Object[] params = {  };
  +                method = Introspector.getMethod( c, methodUsed, params);
  +                
  +                if (method == null)
  +                {
  +                    throw new NoSuchMethodException();
  +                }
               }
               catch ( NoSuchMethodException nsme2 )
               {
               }
  +            catch(Exception e )
  +            {
  +            }
  +        }
  +        catch(Exception e )
  +        {
           }
       }