tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1230711 - in /tomcat/trunk: java/org/apache/el/parser/AstIdentifier.java test/org/apache/el/TestValueExpressionImpl.java
Date Thu, 12 Jan 2012 19:33:17 GMT
Author: markt
Date: Thu Jan 12 19:33:17 2012
New Revision: 1230711

URL: http://svn.apache.org/viewvc?rev=1230711&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=52440
Need to resolve EL variables when returning ValueReferences
Includes a new test case.

Modified:
    tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java
    tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java

Modified: tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java?rev=1230711&r1=1230710&r2=1230711&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstIdentifier.java Thu Jan 12 19:33:17 2012
@@ -24,6 +24,7 @@ import javax.el.MethodInfo;
 import javax.el.MethodNotFoundException;
 import javax.el.PropertyNotFoundException;
 import javax.el.ValueExpression;
+import javax.el.ValueReference;
 import javax.el.VariableMapper;
 
 import org.apache.el.lang.EvaluationContext;
@@ -135,6 +136,25 @@ public final class AstIdentifier extends
         this.image = image;
     }
 
+
+    @Override
+    public ValueReference getValueReference(EvaluationContext ctx) {
+        VariableMapper varMapper = ctx.getVariableMapper();
+
+        if (varMapper == null) {
+            return null;
+        }
+
+        ValueExpression expr = varMapper.resolveVariable(this.image);
+
+        if (expr == null) {
+            return null;
+        }
+
+        return expr.getValueReference(ctx);
+    }
+
+
     private final MethodExpression getMethodExpression(EvaluationContext ctx)
             throws ELException {
         Object obj = null;

Modified: tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java?rev=1230711&r1=1230710&r2=1230711&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java (original)
+++ tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java Thu Jan 12 19:33:17 2012
@@ -64,6 +64,34 @@ public class TestValueExpressionImpl {
     }
 
     @Test
+    public void testGetValueReferenceVariable() {
+        ExpressionFactory factory = ExpressionFactory.newInstance();
+        ELContext context = new ELContextImpl();
+
+        TesterBeanB beanB = new TesterBeanB();
+        beanB.setName("Tomcat");
+        ValueExpression var =
+            factory.createValueExpression(beanB, TesterBeanB.class);
+        context.getVariableMapper().setVariable("beanB", var);
+
+        ValueExpression var2 = factory.createValueExpression(
+                context, "${beanB.name}", String.class);
+
+        context.getVariableMapper().setVariable("foo", var2);
+
+        ValueExpression ve = factory.createValueExpression(
+                context, "${foo}", ValueExpression.class);
+
+
+        // Now check the value reference
+        ValueReference vr = ve.getValueReference(context);
+        assertNotNull(vr);
+
+        assertEquals(beanB, vr.getBase());
+        assertEquals("name", vr.getProperty());
+    }
+
+    @Test
     public void testBug49345() {
         ExpressionFactory factory = ExpressionFactory.newInstance();
         ELContext context = new ELContextImpl();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message