commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell JellyInterpreter.java BeanShellTagLibrary.java BeanShellExpressionFactory.java BeanShellExpression.java
Date Tue, 01 Oct 2002 16:11:24 GMT
jstrachan    2002/10/01 09:11:24

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/beanshell
                        JellyInterpreter.java BeanShellTagLibrary.java
                        BeanShellExpressionFactory.java
                        BeanShellExpression.java
  Log:
  Applied Jason Horman's patches to add support in BeanShell for modifying Jelly's context
as well as adding a new <script> tag
  
  <script>
  	System.out.println("hello there" + foo):
  </script>
  
  Also refactored a little bit the use of the JellyInterpreter for BeanShell so that one is
associated with the JellyContext rather than having an evil static.
  
  Revision  Changes    Path
  1.6       +3 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java
  
  Index: JellyInterpreter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JellyInterpreter.java	12 Jun 2002 16:25:59 -0000	1.5
  +++ JellyInterpreter.java	1 Oct 2002 16:11:24 -0000	1.6
  @@ -93,6 +93,9 @@
               Object value = context.getVariable(name);
               set( name, value );
           }
  +        
  +        // lets pass in the Jelly context 
  +        set( "jellyContext", context );
       }
   
   /*
  
  
  
  1.5       +5 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java
  
  Index: BeanShellTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BeanShellTagLibrary.java	12 Jun 2002 16:25:59 -0000	1.4
  +++ BeanShellTagLibrary.java	1 Oct 2002 16:11:24 -0000	1.5
  @@ -73,8 +73,12 @@
   public class BeanShellTagLibrary extends CoreTagLibrary {
   
       private ExpressionFactory expressionFactory = new BeanShellExpressionFactory();
  +
  +    public BeanShellTagLibrary() {
  +        registerTag("script", ScriptTag.class);
  +    }
       
  -        /** Allows derived tag libraries to use their own factory */
  +    /** Allows derived tag libraries to use their own factory */
       protected ExpressionFactory getExpressionFactory() {
           return expressionFactory;
       }
  
  
  
  1.5       +18 -3     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java
  
  Index: BeanShellExpressionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BeanShellExpressionFactory.java	12 Jun 2002 16:25:59 -0000	1.4
  +++ BeanShellExpressionFactory.java	1 Oct 2002 16:11:24 -0000	1.5
  @@ -61,6 +61,9 @@
    */
   package org.apache.commons.jelly.tags.beanshell;
   
  +import bsh.EvalError;
  +
  +import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.jelly.expression.ExpressionFactory;
   
  @@ -71,12 +74,24 @@
     */
   public class BeanShellExpressionFactory implements ExpressionFactory {
   
  -    /** The interpreter */
  -    private JellyInterpreter interpreter = new JellyInterpreter();
  +    /**
  +     * A helper method to return the JellyInterpreter for the given JellyContext
  +     */
  +    public static JellyInterpreter getInterpreter(JellyContext context) throws EvalError
{
  +        JellyInterpreter interpreter 
  +            = (JellyInterpreter) context.getVariable( "org.apache.commons.jelly.beanshell.JellyInterpreter"
);
  +        if ( interpreter == null ) {
  +            interpreter = new JellyInterpreter();
  +            interpreter.setJellyContext(context);
  +            context.setVariable( "org.apache.commons.jelly.beanshell.JellyInterpreter",
interpreter );
  +        }            
  +        return interpreter;
  +    }
  +    
       
       // ExpressionFactory interface
       //------------------------------------------------------------------------- 
       public Expression createExpression(String text) throws Exception {
  -        return new BeanShellExpression(text, interpreter);
  +        return new BeanShellExpression(text);
       }
   }
  
  
  
  1.6       +2 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java
  
  Index: BeanShellExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BeanShellExpression.java	12 Jun 2002 16:25:59 -0000	1.5
  +++ BeanShellExpression.java	1 Oct 2002 16:11:24 -0000	1.6
  @@ -81,19 +81,15 @@
       /** The expression */
       private String text;
       
  -    /** The interpreter */
  -    private JellyInterpreter interpreter = new JellyInterpreter();
  -    
  -    public BeanShellExpression(String text, JellyInterpreter interpreter) {
  +    public BeanShellExpression(String text) {
           this.text = text;
  -        this.interpreter = interpreter;
       }
   
       // Expression interface
       //------------------------------------------------------------------------- 
       public Object evaluate(JellyContext context) {
           try {
  -            interpreter.setJellyContext(context);
  +            JellyInterpreter interpreter = BeanShellExpressionFactory.getInterpreter(context);
               if ( log.isDebugEnabled() ) {            
                   log.debug( "Evaluating EL: " + text );
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message