You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/09/30 21:50:34 UTC

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

jvanzyl     00/09/30 12:50:33

  Modified:    src/java/org/apache/velocity/runtime/parser
                        ASTReference.java
  Log:
  - cleaned up the ASTReference node so that the set directive could
    use it's features instead of duplicating the code itself.
  
  Revision  Changes    Path
  1.2       +27 -4     jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ASTReference.java
  
  Index: ASTReference.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ASTReference.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTReference.java	2000/09/30 17:04:23	1.1
  +++ ASTReference.java	2000/09/30 19:50:33	1.2
  @@ -82,11 +82,34 @@
           int children = jjtGetNumChildren();
           
           for (int i = 0; i < children; i++)
  -        {
  -            Node n = jjtGetChild(i);
  -            result = n.invoke(result, context);
  -        }
  +            result = jjtGetChild(i).invoke(result, context);
  +
           return result;
  +    }
  +
  +    public void setValue(Context context, Object value)
  +    {
  +        // The rootOfIntrospection is the object we will
  +        // retrieve from the Context. This is the base
  +        // object we will apply reflection to.
  +        String root = getRoot();
  +        Object result = getVariableValue(context, root);
  +        
  +        if (result == null)
  +        {
  +            Runtime.error("Reference error: " + root + " " +
  +                          "not defined in the context.");
  +        }                          
  +        
  +        // How many child nodes do we have?
  +        int children = jjtGetNumChildren();
  +        
  +        for (int i = 0; i < children - 1; i++)
  +            result = jjtGetChild(i).invoke(result, context);
  +
  +        Object[] args = { value };
  +        ClassUtils.invoke(result, "set" + jjtGetChild(children - 1)
  +            .getFirstToken().image, args);
       }
   
       private String getRoot()