Author: markt
Date: Wed Jan 13 18:02:36 2010
New Revision: 898864

URL: http://svn.apache.org/viewvc?rev=898864&view=rev
Log:
Implement method invocation with parameters

Added:
    tomcat/trunk/java/org/apache/el/parser/Suffix.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/el/parser/AstBracketSuffix.java
    tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java
    tomcat/trunk/java/org/apache/el/parser/AstValue.java
    tomcat/trunk/java/org/apache/el/parser/ELParser.jjt

Modified: tomcat/trunk/java/org/apache/el/parser/AstBracketSuffix.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstBracketSuffix.java?rev=898864&r1=898863&r2=898864&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstBracketSuffix.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstBracketSuffix.java Wed Jan 13 
18:02:36 2010
@@ -27,7 +27,7 @@
  * @author Jacob Hookom [ja...@hookom.net]
  * @version $Change: 181177 $$Date$$Author$
  */
-public final class AstBracketSuffix extends SimpleNode {
+public final class AstBracketSuffix extends SimpleNode implements Suffix {
     public AstBracketSuffix(int id) {
         super(id);
     }

Modified: tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java?rev=898864&r1=898863&r2=898864&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstDotSuffix.java Wed Jan 13 
18:02:36 2010
@@ -27,7 +27,7 @@
  * @author Jacob Hookom [ja...@hookom.net]
  * @version $Change: 181177 $$Date$$Author$
  */
-public final class AstDotSuffix extends SimpleNode {
+public final class AstDotSuffix extends SimpleNode implements Suffix {
     public AstDotSuffix(int id) {
         super(id);
     }

Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstValue.java?rev=898864&r1=898863&r2=898864&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Wed Jan 13 18:02:36 
2010
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 
 import javax.el.ELException;
 import javax.el.ELResolver;
@@ -109,17 +110,34 @@
         Object base = this.children[0].getValue(ctx);
         int propCount = this.jjtGetNumChildren();
         int i = 1;
-        Object property = null;
+        Object suffix = null;
         ELResolver resolver = ctx.getELResolver();
         while (base != null && i < propCount) {
-            property = this.children[i].getValue(ctx);
-            if (property == null) {
-                return null;
+            suffix = this.children[i].getValue(ctx);
+            if (i + 1 < propCount && !(this.children[i+1] instanceof Suffix)) {
+                // Looking for a method
+                ArrayList<Object> params = new ArrayList<Object>();
+                ArrayList<Class<?>> paramTypes = new ArrayList<Class<?>>();
+                while (i + 1 < propCount &&
+                        !(this.children[i+1] instanceof Suffix)) {
+                    params.add(this.children[i+1].getValue(ctx));
+                    paramTypes.add(this.children[i+1].getType(ctx));
+                    i++;
+                }
+                base = resolver.invoke(ctx, base, suffix,
+                        paramTypes.toArray(new Class<?>[paramTypes.size()]),
+                        params.toArray(new Object[params.size()]));
+                i++;
             } else {
-                ctx.setPropertyResolved(false);
-                base = resolver.getValue(ctx, base, property);
+                // Looking for a property
+                if (suffix == null) {
+                    return null;
+                } else {
+                    ctx.setPropertyResolved(false);
+                    base = resolver.getValue(ctx, base, suffix);
+                }
+                i++;
             }
-            i++;
         }
         return base;
     }

Modified: tomcat/trunk/java/org/apache/el/parser/ELParser.jjt
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/ELParser.jjt?rev=898864&r1=898863&r2=898864&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/ELParser.jjt (original)
+++ tomcat/trunk/java/org/apache/el/parser/ELParser.jjt Wed Jan 13 18:02:36 2010
@@ -227,7 +227,7 @@
  */
 void ValueSuffix() : {}
 {
-    DotSuffix() | BracketSuffix()
+    ( DotSuffix() | BracketSuffix() ) ( MethodParameters())?
 }
 
 /*
@@ -249,6 +249,14 @@
 }
 
 /*
+ * MethodParameters
+ */
+void MethodParameters() : {}
+{
+    <LPAREN> ( Expression() ( <COMMA> Expression())* )? <RPAREN>
+}
+
+/*
  * NonLiteral
  * For Grouped Operations, Identifiers, and Functions
  */

Added: tomcat/trunk/java/org/apache/el/parser/Suffix.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/Suffix.java?rev=898864&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/Suffix.java (added)
+++ tomcat/trunk/java/org/apache/el/parser/Suffix.java Wed Jan 13 18:02:36 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.el.parser;
+
+/**
+ * Marker interface used to simplfy the implementation of
+ * {...@link AstValue#getValue(org.apache.el.lang.EvaluationContext). 
+ */
+public interface Suffix {
+    // Marker interface - defines no methods
+}

Propchange: tomcat/trunk/java/org/apache/el/parser/Suffix.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/java/org/apache/el/parser/Suffix.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision



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

Reply via email to