JBossWeb SVN: r1885 - trunk/java/org/apache/coyote/http11.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2011-12-07 11:23:56 -0500 (Wed, 07 Dec 2011)
New Revision: 1885
Modified:
trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
trunk/java/org/apache/coyote/http11/Http11Protocol.java
Log:
Default to unlimited timeouts, for now.
Modified: trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2011-12-07 16:23:26 UTC (rev 1884)
+++ trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2011-12-07 16:23:56 UTC (rev 1885)
@@ -379,7 +379,7 @@
* Maximum number of requests which can be performed over a keepalive
* connection. The default is the same as for Apache HTTP Server.
*/
- protected int maxKeepAliveRequests = Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_KEEP_ALIVE_REQUESTS", "100")).intValue();
+ protected int maxKeepAliveRequests = Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_KEEP_ALIVE_REQUESTS", "-1")).intValue();
public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
Modified: trunk/java/org/apache/coyote/http11/Http11Protocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11Protocol.java 2011-12-07 16:23:26 UTC (rev 1884)
+++ trunk/java/org/apache/coyote/http11/Http11Protocol.java 2011-12-07 16:23:56 UTC (rev 1885)
@@ -336,7 +336,7 @@
* connection. The default is the same as for Apache HTTP Server.
*/
protected int maxKeepAliveRequests = (org.apache.tomcat.util.Constants.LOW_MEMORY) ? 1 :
- Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_KEEP_ALIVE_REQUESTS", "100")).intValue();
+ Integer.valueOf(System.getProperty("org.apache.coyote.http11.Http11Protocol.MAX_KEEP_ALIVE_REQUESTS", "-1")).intValue();
public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
13 years
JBossWeb SVN: r1884 - trunk/test/java/org/apache/el.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2011-12-07 11:23:26 -0500 (Wed, 07 Dec 2011)
New Revision: 1884
Modified:
trunk/test/java/org/apache/el/TestMethodExpressionImpl.java
Log:
Add test case.
Modified: trunk/test/java/org/apache/el/TestMethodExpressionImpl.java
===================================================================
--- trunk/test/java/org/apache/el/TestMethodExpressionImpl.java 2011-12-06 15:29:27 UTC (rev 1883)
+++ trunk/test/java/org/apache/el/TestMethodExpressionImpl.java 2011-12-07 16:23:26 UTC (rev 1884)
@@ -125,6 +125,37 @@
}
@Test
+ public void testInvoke2825() {
+ TesterBeanB beanB = new TesterBeanB();
+ beanB.setName("B");
+
+ context.getVariableMapper().setVariable("method",
+ factory.createValueExpression("sayHello", String.class));
+ context.getVariableMapper().setVariable("arg",
+ factory.createValueExpression("JUnit", String.class));
+
+ MethodExpression me1 = factory.createMethodExpression(
+ context, "${beanB.getName()}", String.class, new Class<?>[] {});
+ MethodExpression me2 = factory.createMethodExpression(
+ context, "${beanB[method](arg)}", String.class,
+ new Class<?>[] { String.class });
+ MethodExpression me3 = factory.createMethodExpression(
+ context, "${beanB.sayHello}", String.class,
+ new Class<?>[] { String.class });
+
+ assertEquals("B", me1.invoke(context, null));
+ assertEquals("Hello JUnit from B", me2.invoke(context, null));
+ assertEquals("Hello JUnit from B",
+ me2.invoke(context, new Object[] { "JUnit2" }));
+ assertEquals("Hello JUnit2 from B",
+ me3.invoke(context, new Object[] { "JUnit2" }));
+ assertEquals("Hello JUnit from B",
+ me2.invoke(context, new Object[] { null }));
+ assertEquals("Hello null from B",
+ me3.invoke(context, new Object[] { null }));
+ }
+
+ @Test
public void testInvokeWithSuper() {
MethodExpression me = factory.createMethodExpression(context,
"${beanA.setBean(beanBB)}", null ,
13 years
JBossWeb SVN: r1883 - in trunk: test/java/org/apache and 5 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2011-12-06 10:29:27 -0500 (Tue, 06 Dec 2011)
New Revision: 1883
Added:
trunk/test/java/org/apache/el/
trunk/test/java/org/apache/el/TestELEvaluation.java
trunk/test/java/org/apache/el/TestMethodExpressionImpl.java
trunk/test/java/org/apache/el/TestValueExpressionImpl.java
trunk/test/java/org/apache/el/TesterBeanA.java
trunk/test/java/org/apache/el/TesterBeanAA.java
trunk/test/java/org/apache/el/TesterBeanAAA.java
trunk/test/java/org/apache/el/TesterBeanB.java
trunk/test/java/org/apache/el/TesterBeanBB.java
trunk/test/java/org/apache/el/TesterBeanBBB.java
trunk/test/java/org/apache/el/TesterBeanC.java
trunk/test/java/org/apache/el/TesterEnum.java
trunk/test/java/org/apache/el/TesterFunctions.java
trunk/test/java/org/apache/el/lang/
trunk/test/java/org/apache/el/lang/TestELArithmetic.java
trunk/test/java/org/apache/el/lang/TestELSupport.java
trunk/test/java/org/apache/el/parser/
trunk/test/java/org/apache/el/parser/TestELParser.java
trunk/test/java/org/apache/el/parser/TesterBeanA.java
Removed:
trunk/test/java/org/apache/catalina/startup/TestTomcatSSL.java
trunk/test/java/org/apache/catalina/startup/TomcatBaseTest.java
trunk/test/java/org/apache/catalina/startup/test.keystore
Modified:
trunk/test/build.properties.default
trunk/test/build.xml
trunk/webapps/docs/changelog.xml
Log:
Add EL tests from Tomcat, which cover things well. Two failures due to the BeanELResolver which
could use more tweaks.
Modified: trunk/test/build.properties.default
===================================================================
--- trunk/test/build.properties.default 2011-12-06 15:27:15 UTC (rev 1882)
+++ trunk/test/build.properties.default 2011-12-06 15:29:27 UTC (rev 1883)
@@ -1,5 +1,5 @@
# junit stuff
-junit.version=4.5
+junit.version=4.10
junit.jar.loc=http://kent.dl.sourceforge.net/sourceforge/junit/junit-${ju...
junit.jar=${base.path}/junit-${junit.version}/junit-${junit.version}.jar
base-junit.home=${base.path}/junit-${junit.version}
Modified: trunk/test/build.xml
===================================================================
--- trunk/test/build.xml 2011-12-06 15:27:15 UTC (rev 1882)
+++ trunk/test/build.xml 2011-12-06 15:29:27 UTC (rev 1883)
@@ -77,11 +77,42 @@
<!-- Run the tests -->
<target name="all" depends="compile">
+ <!--
<java dir="${test.classes}" classname="${test.runner}" fork="yes">
<arg value="org.jboss.web.cookies.CookiesTestCase"/>
<jvmarg line="-Dcluster=${cluster}"/>
<classpath refid="jbossweb.test.classpath"/>
- </java>
+ </java>-->
+ <mkdir dir="${basedir}/output/logs" />
+ <junit printsummary="yes" fork="yes" dir="." showoutput="yes"
+ errorproperty="test.result.error"
+ failureproperty="test.result.failure"
+ haltonfailure="false" >
+
+ <classpath refid="jbossweb.test.classpath" />
+
+ <formatter type="plain"/>
+
+ <!-- If test.entry is defined, run a single test, otherwise run all valid tests -->
+ <test todir="${basedir}/output/logs" />
+ <batchtest todir="${basedir}/output/logs">
+ <fileset dir="java" >
+ <!-- Include all by default -->
+ <include name="**/Test*.java" />
+ <!-- Exclude helper classes -->
+ <exclude name="**/Tester*.java" />
+ </fileset>
+ </batchtest>
+ </junit>
+
+ <java dir="${test.classes}" classname="${test.runner}" fork="yes">
+ <arg value="org.apache.el.TestValueExpressionImpl"/>
+ <classpath refid="jbossweb.test.classpath"/>
+ </java>
+ <java dir="${test.classes}" classname="${test.runner}" fork="yes">
+ <arg value="org.apache.el.TestMethodExpressionImpl"/>
+ <classpath refid="jbossweb.test.classpath"/>
+ </java>
</target>
<target name="ssl" depends="compile">
Deleted: trunk/test/java/org/apache/catalina/startup/TestTomcatSSL.java
===================================================================
--- trunk/test/java/org/apache/catalina/startup/TestTomcatSSL.java 2011-12-06 15:27:15 UTC (rev 1882)
+++ trunk/test/java/org/apache/catalina/startup/TestTomcatSSL.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -1,251 +0,0 @@
-/*
- * 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.catalina.startup;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.HandshakeCompletedEvent;
-import javax.net.ssl.HandshakeCompletedListener;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.apache.catalina.connector.Connector;
-import org.apache.tomcat.util.buf.ByteChunk;
-
-/**
- * Requires test.keystore (checked in), generated with:
- * keytool -genkey -alias tomcat -keyalg RSA
- * pass: changeit
- * CN: localhost ( for hostname validation )
- */
-public class TestTomcatSSL extends TomcatBaseTest {
- static TrustManager[] trustAllCerts = new TrustManager[] {
- new X509TrustManager() {
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- public void checkClientTrusted(X509Certificate[] certs,
- String authType) {
- // NOOP - Trust everything
- }
- public void checkServerTrusted(X509Certificate[] certs,
- String authType) {
- // NOOP - Trust everything
- }
- }
- };
-
- private void initSsl(Tomcat tomcat, boolean nio) throws Exception {
- if (nio) {
- Connector connector =
- new Connector("org.apache.coyote.http11.Http11NioProtocol");
- connector.setPort(getPort());
- tomcat.getService().addConnector(connector);
- tomcat.setConnector(connector);
- tomcat.getConnector().setSecure(true);
- } else {
- tomcat.getConnector().setSecure(true);
- }
- tomcat.getConnector().setProperty("SSLEnabled", "true");
- tomcat.getConnector().setProperty("sslProtocol",
- "tls");
- // test runs in output/tmp
- tomcat.getConnector().setAttribute("keystore",
- "../test.keystore");
- }
-
- public void testSimpleSsl() throws Exception {
- simpleSsl(false);
- }
-
- // No Nio in jbossweb
- // public void testSimpleSslNio() throws Exception {
- // simpleSsl(true);
- // }
-
- public void simpleSsl(boolean nio) throws Exception {
- // Install the all-trusting trust manager so https:// works
- // with unsigned certs.
-
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(
- sc.getSocketFactory());
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- Tomcat tomcat = getTomcatInstance();
-
- File appDir =
- new File("output/build/webapps/examples");
- tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
-
- initSsl(tomcat, nio);
-
- tomcat.start();
- ByteChunk res = getUrl("https://localhost:" + getPort() +
- "/examples/");
- assertTrue(res.toString().indexOf("Hello World!") > 0);
- }
-
- boolean handshakeDone = false;
-
- public void testRenegotiateFail() throws Exception {
- renegotiateFail(false);
- }
-
- public void renegotiateFail(boolean nio) throws Exception {
- Tomcat tomcat = getTomcatInstance();
-
- File appDir =
- new File("output/build/webapps/examples");
- // app dir is relative to server home
- tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
-
- initSsl(tomcat, nio);
- // Default - MITM not enabled
-
- tomcat.start();
- SSLContext sslCtx = SSLContext.getInstance("TLS");
- sslCtx.init(null, trustAllCerts, new java.security.SecureRandom());
- SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
- SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
-
- socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
- @Override
- public void handshakeCompleted(HandshakeCompletedEvent event) {
- handshakeDone = true;
- }
- });
-
- OutputStream os = socket.getOutputStream();
- os.write("GET /examples/ HTTP/1.1\n".getBytes());
- os.flush();
-
- InputStream is = socket.getInputStream();
-
- socket.startHandshake();
- handshakeDone = false;
- byte[] b = new byte[0];
- int maxTries = 5; // 5 sec should be enough - in NIO we'll timeout
- socket.setSoTimeout(1000);
- for (int i = 0; i < maxTries; i++) {
- try {
- is.read(b);
- } catch (IOException e) {
- // timeout
- }
- if (handshakeDone) {
- break;
- }
- }
- os = socket.getOutputStream();
- if (!handshakeDone) {
- // success - we timedout without handshake
- return;
- }
- try {
- os.write("Host: localhost\n\n".getBytes());
- } catch (IOException ex) {
- // success - connection closed
- return;
- }
-
- fail("Re-negotiation worked");
-
- }
-
- public void testRenegotiateWorks() throws Exception {
- renegotiateWorks(false);
- }
-
-
- // Re-negotiation not implemented in NIO
- // public void testRenegotiateWorksNio() throws Exception {
- // renegotiateWorks(true);
- // }
-
- // public void testRenegotiateFailNio() throws Exception {
- // renegotiateFail(true);
- // }
-
-
- public void renegotiateWorks(boolean nio) throws Exception {
- Tomcat tomcat = getTomcatInstance();
-
- File appDir =
- new File("output/build/webapps/examples");
- // app dir is relative to server home
- tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
-
- initSsl(tomcat, nio);
- // Enable MITM attack
- tomcat.getConnector().setAttribute("allowUnsafeLegacyRenegotiation", "true");
-
- tomcat.start();
- SSLContext sslCtx = SSLContext.getInstance("TLS");
- sslCtx.init(null, trustAllCerts, new java.security.SecureRandom());
- SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
- SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
-
- socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
- @Override
- public void handshakeCompleted(HandshakeCompletedEvent event) {
- handshakeDone = true;
- }
- });
-
- OutputStream os = socket.getOutputStream();
- os.write("GET /examples/ HTTP/1.1\n".getBytes());
- os.flush();
-
- InputStream is = socket.getInputStream();
-
- socket.startHandshake();
- handshakeDone = false;
- byte[] b = new byte[0];
- int maxTries = 5;
- socket.setSoTimeout(1000);
- for (int i = 0; i < maxTries; i++) {
- try {
- is.read(b);
- } catch (IOException e) {
- // timeout
- }
- if (handshakeDone) {
- break;
- }
- }
- os = socket.getOutputStream();
-
- try {
- os.write("Host: localhost\n\n".getBytes());
- } catch (IOException ex) {
- fail("Re-negotiation failed");
- }
-
- }
-}
Deleted: trunk/test/java/org/apache/catalina/startup/TomcatBaseTest.java
===================================================================
--- trunk/test/java/org/apache/catalina/startup/TomcatBaseTest.java 2011-12-06 15:27:15 UTC (rev 1882)
+++ trunk/test/java/org/apache/catalina/startup/TomcatBaseTest.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -1,137 +0,0 @@
-/*
- * 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.catalina.startup;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.tomcat.util.buf.ByteChunk;
-
-import junit.framework.TestCase;
-
-/**
- * Base test case that provides a Tomcat instance for each test - mainly so we
- * don't have to keep writing the cleanup code.
- */
-public abstract class TomcatBaseTest extends TestCase {
- private Tomcat tomcat;
- private File tempDir;
- private static int port = 8001;
-
- /**
- * Make Tomcat instance accessible to sub-classes.
- */
- public Tomcat getTomcatInstance() {
- return tomcat;
- }
-
- /**
- * Sub-classes need to know port so they can connect
- */
- public int getPort() {
- return port;
- }
-
- /**
- * Sub-classes may want to add connectors on a new port
- */
- public int getNextPort() {
- port++;
- return getPort();
- }
-
- @Override
- public void setUp() throws Exception {
- tempDir = new File("output/tmp");
- tempDir.mkdir();
-
- tomcat = new Tomcat();
- tomcat.setBaseDir(tempDir.getAbsolutePath());
- tomcat.getHost().setAppBase(tempDir.getAbsolutePath() + "/webapps");
-
- // If each test is running on same port - they
- // may interfere with each other (on unix at least)
- port++;
- tomcat.setPort(port);
- }
-
- @Override
- public void tearDown() throws Exception {
- tomcat.stop();
- ExpandWar.delete(tempDir);
- }
-
- /**
- * Simple Hello World servlet for use by test cases
- */
- public static final class HelloWorldServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- PrintWriter out = resp.getWriter();
- out.print("<html><body><p>Hello World</p></body></html>");
- }
- }
-
-
- /**
- * Wrapper for getting the response.
- */
- public static ByteChunk getUrl(String path) throws IOException {
- ByteChunk out = new ByteChunk();
- getUrl(path, out, null);
- return out;
- }
-
- public static int getUrl(String path,
- ByteChunk out,
- Map<String, List<String>> resHead) throws IOException {
- URL url = new URL(path);
- HttpURLConnection connection =
- (HttpURLConnection) url.openConnection();
- connection.setReadTimeout(100000);
- connection.connect();
- int rc = connection.getResponseCode();
- if (resHead != null) {
- Map<String, List<String>> head = connection.getHeaderFields();
- resHead.putAll(head);
- }
- InputStream is = connection.getInputStream();
- BufferedInputStream bis = new BufferedInputStream(is);
- byte[] buf = new byte[2048];
- int rd = 0;
- while((rd = bis.read(buf)) > 0) {
- out.append(buf, 0, rd);
- }
- return rc;
- }
-}
Deleted: trunk/test/java/org/apache/catalina/startup/test.keystore
===================================================================
(Binary files differ)
Added: trunk/test/java/org/apache/el/TestELEvaluation.java
===================================================================
--- trunk/test/java/org/apache/el/TestELEvaluation.java (rev 0)
+++ trunk/test/java/org/apache/el/TestELEvaluation.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,228 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Date;
+
+import javax.el.ELException;
+import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import org.apache.el.lang.ELSupport;
+import org.apache.jasper.el.ELContextImpl;
+
+/**
+ * Tests the EL engine directly. Similar tests may be found in
+ * {@link org.apache.jasper.compiler.TestAttributeParser} and
+ * {@link TestELInJsp}.
+ */
+public class TestELEvaluation {
+
+ /**
+ * Test use of spaces in ternary expressions. This was primarily an EL
+ * parser bug.
+ */
+ @Test
+ public void testBug42565() {
+ assertEquals("false", evaluateExpression("${false?true:false}"));
+ assertEquals("false", evaluateExpression("${false?true: false}"));
+ assertEquals("false", evaluateExpression("${false?true :false}"));
+ assertEquals("false", evaluateExpression("${false?true : false}"));
+ assertEquals("false", evaluateExpression("${false? true:false}"));
+ assertEquals("false", evaluateExpression("${false? true: false}"));
+ assertEquals("false", evaluateExpression("${false? true :false}"));
+ assertEquals("false", evaluateExpression("${false? true : false}"));
+ assertEquals("false", evaluateExpression("${false ?true:false}"));
+ assertEquals("false", evaluateExpression("${false ?true: false}"));
+ assertEquals("false", evaluateExpression("${false ?true :false}"));
+ assertEquals("false", evaluateExpression("${false ?true : false}"));
+ assertEquals("false", evaluateExpression("${false ? true:false}"));
+ assertEquals("false", evaluateExpression("${false ? true: false}"));
+ assertEquals("false", evaluateExpression("${false ? true :false}"));
+ assertEquals("false", evaluateExpression("${false ? true : false}"));
+ }
+
+
+ /**
+ * Test use nested ternary expressions. This was primarily an EL parser bug.
+ */
+ @Test
+ public void testBug44994() {
+ assertEquals("none", evaluateExpression(
+ "${0 lt 0 ? 1 lt 0 ? 'many': 'one': 'none'}"));
+ assertEquals("one", evaluateExpression(
+ "${0 lt 1 ? 1 lt 1 ? 'many': 'one': 'none'}"));
+ assertEquals("many", evaluateExpression(
+ "${0 lt 2 ? 1 lt 2 ? 'many': 'one': 'none'}"));
+ }
+
+ @Test
+ public void testParserBug45511() {
+ // Test cases provided by OP
+ assertEquals("true", evaluateExpression("${empty ('')}"));
+ assertEquals("true", evaluateExpression("${empty('')}"));
+ assertEquals("false", evaluateExpression("${(true) and (false)}"));
+ assertEquals("false", evaluateExpression("${(true)and(false)}"));
+ }
+
+ @Test
+ public void testBug48112() {
+ // bug 48112
+ assertEquals("{world}", evaluateExpression("${fn:trim('{world}')}"));
+ }
+
+ @Test
+ public void testParserLiteralExpression() {
+ // Inspired by work on bug 45451, comments from kkolinko on the dev
+ // list and looking at the spec to find some edge cases
+
+ // '\' is only an escape character inside a StringLiteral
+ assertEquals("\\\\", evaluateExpression("\\\\"));
+
+ /*
+ * LiteralExpresions can only contain ${ or #{ if escaped with \
+ * \ is not an escape character in any other circumstances including \\
+ */
+ assertEquals("\\", evaluateExpression("\\"));
+ assertEquals("$", evaluateExpression("$"));
+ assertEquals("#", evaluateExpression("#"));
+ assertEquals("\\$", evaluateExpression("\\$"));
+ assertEquals("\\#", evaluateExpression("\\#"));
+ assertEquals("\\\\$", evaluateExpression("\\\\$"));
+ assertEquals("\\\\#", evaluateExpression("\\\\#"));
+ assertEquals("${", evaluateExpression("\\${"));
+ assertEquals("#{", evaluateExpression("\\#{"));
+ assertEquals("\\${", evaluateExpression("\\\\${"));
+ assertEquals("\\#{", evaluateExpression("\\\\#{"));
+ }
+
+ @Test
+ public void testParserStringLiteral() {
+ // Inspired by work on bug 45451, comments from kkolinko on the dev
+ // list and looking at the spec to find some edge cases
+
+ // The only characters that can be escaped inside a String literal
+ // are \ " and '. # and $ are not escaped inside a String literal.
+ assertEquals("\\", evaluateExpression("${'\\\\'}"));
+ assertEquals("\\", evaluateExpression("${\"\\\\\"}"));
+ assertEquals("\\\"'$#", evaluateExpression("${'\\\\\\\"\\'$#'}"));
+ assertEquals("\\\"'$#", evaluateExpression("${\"\\\\\\\"\\'$#\"}"));
+
+ // Trying to quote # or $ should throw an error
+ Exception e = null;
+ try {
+ evaluateExpression("${'\\$'}");
+ } catch (ELException el) {
+ e = el;
+ }
+ assertNotNull(e);
+
+ assertEquals("\\$", evaluateExpression("${'\\\\$'}"));
+ assertEquals("\\\\$", evaluateExpression("${'\\\\\\\\$'}"));
+
+
+ // Can use ''' inside '"' when quoting with '"' and vice versa without
+ // escaping
+ assertEquals("\\\"", evaluateExpression("${'\\\\\"'}"));
+ assertEquals("\"\\", evaluateExpression("${'\"\\\\'}"));
+ assertEquals("\\'", evaluateExpression("${'\\\\\\''}"));
+ assertEquals("'\\", evaluateExpression("${'\\'\\\\'}"));
+ assertEquals("\\'", evaluateExpression("${\"\\\\'\"}"));
+ assertEquals("'\\", evaluateExpression("${\"'\\\\\"}"));
+ assertEquals("\\\"", evaluateExpression("${\"\\\\\\\"\"}"));
+ assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}"));
+ }
+
+ private void compareBoth(String msg, int expected, Object o1, Object o2){
+ int i1 = ELSupport.compare(o1, o2);
+ int i2 = ELSupport.compare(o2, o1);
+ assertEquals(msg,expected, i1);
+ assertEquals(msg,expected, -i2);
+ }
+
+ @Test
+ public void testElSupportCompare(){
+ compareBoth("Nulls should compare equal", 0, null, null);
+ compareBoth("Null should compare equal to \"\"", 0, "", null);
+ compareBoth("Null should be less than File()",-1, null, new File(""));
+ compareBoth("Null should be less than Date()",-1, null, new Date());
+ compareBoth("Date(0) should be less than Date(1)",-1, new Date(0), new Date(1));
+ try {
+ compareBoth("Should not compare",0, new Date(), new File(""));
+ fail("Expecting ClassCastException");
+ } catch (ClassCastException expected) {
+ // Expected
+ }
+ assertTrue(null == null);
+ }
+
+ /**
+ * Test mixing ${...} and #{...} in the same expression.
+ */
+ @Test
+ public void testMixedTypes() {
+ // Mixing types should throw an error
+ Exception e = null;
+ try {
+ evaluateExpression("${1+1}#{1+1}");
+ } catch (ELException el) {
+ e = el;
+ }
+ assertNotNull(e);
+ }
+
+
+ // ************************************************************************
+
+ private String evaluateExpression(String expression) {
+ ELContextImpl ctx = new ELContextImpl();
+ ctx.setFunctionMapper(new FMapper());
+ ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
+ ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
+ String.class);
+ return (String) ve.getValue(ctx);
+ }
+
+ public static class FMapper extends FunctionMapper {
+
+ @Override
+ public Method resolveFunction(String prefix, String localName) {
+ if ("trim".equals(localName)) {
+ Method m;
+ try {
+ m = TesterFunctions.class.getMethod("trim", String.class);
+ return m;
+ } catch (SecurityException e) {
+ // Ignore
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+ }
+ return null;
+ }
+ }
+}
Added: trunk/test/java/org/apache/el/TestMethodExpressionImpl.java
===================================================================
--- trunk/test/java/org/apache/el/TestMethodExpressionImpl.java (rev 0)
+++ trunk/test/java/org/apache/el/TestMethodExpressionImpl.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,402 @@
+/*
+ * 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;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.jasper.el.ELContextImpl;
+
+public class TestMethodExpressionImpl {
+
+ private ExpressionFactory factory;
+ private ELContext context;
+
+ @Before
+ public void setUp() {
+ factory = ExpressionFactory.newInstance();
+ context = new ELContextImpl();
+
+ TesterBeanA beanA = new TesterBeanA();
+ beanA.setName("A");
+ context.getVariableMapper().setVariable("beanA",
+ factory.createValueExpression(beanA, TesterBeanA.class));
+
+ TesterBeanAA beanAA = new TesterBeanAA();
+ beanAA.setName("AA");
+ context.getVariableMapper().setVariable("beanAA",
+ factory.createValueExpression(beanAA, TesterBeanAA.class));
+
+ TesterBeanAAA beanAAA = new TesterBeanAAA();
+ beanAAA.setName("AAA");
+ context.getVariableMapper().setVariable("beanAAA",
+ factory.createValueExpression(beanAAA, TesterBeanAAA.class));
+
+ TesterBeanB beanB = new TesterBeanB();
+ beanB.setName("B");
+ context.getVariableMapper().setVariable("beanB",
+ factory.createValueExpression(beanB, TesterBeanB.class));
+
+ TesterBeanBB beanBB = new TesterBeanBB();
+ beanBB.setName("BB");
+ context.getVariableMapper().setVariable("beanBB",
+ factory.createValueExpression(beanBB, TesterBeanBB.class));
+
+ TesterBeanBBB beanBBB = new TesterBeanBBB();
+ beanBBB.setName("BBB");
+ context.getVariableMapper().setVariable("beanBBB",
+ factory.createValueExpression(beanBBB, TesterBeanBBB.class));
+
+ TesterBeanC beanC = new TesterBeanC();
+ context.getVariableMapper().setVariable("beanC",
+ factory.createValueExpression(beanC, TesterBeanC.class));
+ }
+
+ @Test
+ public void testIsParametersProvided() {
+ TesterBeanB beanB = new TesterBeanB();
+ beanB.setName("Tomcat");
+ ValueExpression var =
+ factory.createValueExpression(beanB, TesterBeanB.class);
+ context.getVariableMapper().setVariable("beanB", var);
+
+ MethodExpression me1 = factory.createMethodExpression(
+ context, "${beanB.getName}", String.class, new Class<?>[] {});
+ MethodExpression me2 = factory.createMethodExpression(
+ context, "${beanB.sayHello('JUnit')}", String.class,
+ new Class<?>[] { String.class });
+
+ assertFalse(me1.isParmetersProvided());
+ assertTrue(me2.isParmetersProvided());
+ }
+
+ @Test
+ public void testInvoke() {
+ TesterBeanB beanB = new TesterBeanB();
+ beanB.setName("B");
+
+ context.getVariableMapper().setVariable("beanB",
+ factory.createValueExpression(beanB, TesterBeanB.class));
+
+ MethodExpression me1 = factory.createMethodExpression(
+ context, "${beanB.getName()}", String.class, new Class<?>[] {});
+ MethodExpression me2 = factory.createMethodExpression(
+ context, "${beanB.sayHello('JUnit')}", String.class,
+ new Class<?>[] { String.class });
+ MethodExpression me3 = factory.createMethodExpression(
+ context, "${beanB.sayHello}", String.class,
+ new Class<?>[] { String.class });
+
+ assertEquals("B", me1.invoke(context, null));
+ assertEquals("Hello JUnit from B", me2.invoke(context, null));
+ assertEquals("Hello JUnit from B",
+ me2.invoke(context, new Object[] { "JUnit2" }));
+ assertEquals("Hello JUnit2 from B",
+ me3.invoke(context, new Object[] { "JUnit2" }));
+ assertEquals("Hello JUnit from B",
+ me2.invoke(context, new Object[] { null }));
+ assertEquals("Hello null from B",
+ me3.invoke(context, new Object[] { null }));
+ }
+
+ @Test
+ public void testInvokeWithSuper() {
+ MethodExpression me = factory.createMethodExpression(context,
+ "${beanA.setBean(beanBB)}", null ,
+ new Class<?>[] { TesterBeanB.class });
+ me.invoke(context, null);
+ ValueExpression ve = factory.createValueExpression(context,
+ "${beanA.bean.name}", String.class);
+ Object r = ve.getValue(context);
+ assertEquals("BB", r);
+ }
+
+ @Test
+ public void testInvokeWithSuperABNoReturnTypeNoParamTypes() {
+ MethodExpression me2 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanB)}", null , null);
+ Object r2 = me2.invoke(context, null);
+ assertEquals("AB: Hello A from B", r2.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperABReturnTypeNoParamTypes() {
+ MethodExpression me3 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanB)}", String.class , null);
+ Object r3 = me3.invoke(context, null);
+ assertEquals("AB: Hello A from B", r3.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperABNoReturnTypeParamTypes() {
+ MethodExpression me4 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanB)}", null ,
+ new Class<?>[] {TesterBeanA.class, TesterBeanB.class});
+ Object r4 = me4.invoke(context, null);
+ assertEquals("AB: Hello A from B", r4.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperABReturnTypeParamTypes() {
+ MethodExpression me5 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanB)}", String.class ,
+ new Class<?>[] {TesterBeanA.class, TesterBeanB.class});
+ Object r5 = me5.invoke(context, null);
+ assertEquals("AB: Hello A from B", r5.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperABB() {
+ MethodExpression me6 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanBB)}", null , null);
+ Object r6 = me6.invoke(context, null);
+ assertEquals("ABB: Hello A from BB", r6.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperABBB() {
+ MethodExpression me7 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanBBB)}", null , null);
+ Object r7 = me7.invoke(context, null);
+ assertEquals("ABB: Hello A from BBB", r7.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperAAB() {
+ MethodExpression me8 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanB)}", null , null);
+ Object r8 = me8.invoke(context, null);
+ assertEquals("AAB: Hello AA from B", r8.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperAABB() {
+ MethodExpression me9 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanBB)}", null , null);
+ Exception e = null;
+ try {
+ me9.invoke(context, null);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ // Expected to fail
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testInvokeWithSuperAABBB() {
+ // The Java compiler reports this as ambiguous. Using the parameter that
+ // matches exactly seems reasonable to limit the scope of the method
+ // search so the EL will find a match.
+ MethodExpression me10 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanBBB)}", null , null);
+ Object r10 = me10.invoke(context, null);
+ assertEquals("AAB: Hello AA from BBB", r10.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperAAAB() {
+ MethodExpression me11 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanB)}", null , null);
+ Object r11 = me11.invoke(context, null);
+ assertEquals("AAB: Hello AAA from B", r11.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperAAABB() {
+ // The Java compiler reports this as ambiguous. Using the parameter that
+ // matches exactly seems reasonable to limit the scope of the method
+ // search so the EL will find a match.
+ MethodExpression me12 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanBB)}", null , null);
+ Object r12 = me12.invoke(context, null);
+ assertEquals("ABB: Hello AAA from BB", r12.toString());
+ }
+
+ @Test
+ public void testInvokeWithSuperAAABBB() {
+ MethodExpression me13 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanBBB)}", null , null);
+ Exception e = null;
+ try {
+ me13.invoke(context, null);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ // Expected to fail
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAB() throws Exception {
+ MethodExpression me1 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanB,beanB)}", null , null);
+ Exception e = null;
+ try {
+ me1.invoke(context, null);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ // Expected to fail
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testInvokeWithVarArgsABB() throws Exception {
+ MethodExpression me2 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanBB,beanBB)}", null , null);
+ Object r2 = me2.invoke(context, null);
+ assertEquals("ABB[]: Hello A from BB, BB", r2.toString());
+ }
+
+ @Test
+ public void testInvokeWithVarArgsABBB() throws Exception {
+ MethodExpression me3 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanA,beanBBB,beanBBB)}", null , null);
+ Object r3 = me3.invoke(context, null);
+ assertEquals("ABB[]: Hello A from BBB, BBB", r3.toString());
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAAB() throws Exception {
+ MethodExpression me4 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanB,beanB)}", null , null);
+ Exception e = null;
+ try {
+ me4.invoke(context, null);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ // Expected to fail
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAABB() throws Exception {
+ MethodExpression me5 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanBB,beanBB)}", null , null);
+ Object r5 = me5.invoke(context, null);
+ assertEquals("ABB[]: Hello AA from BB, BB", r5.toString());
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAABBB() throws Exception {
+ MethodExpression me6 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAA,beanBBB,beanBBB)}", null , null);
+ Object r6 = me6.invoke(context, null);
+ assertEquals("ABB[]: Hello AA from BBB, BBB", r6.toString());
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAAAB() throws Exception {
+ MethodExpression me7 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanB,beanB)}", null , null);
+ Exception e = null;
+ try {
+ me7.invoke(context, null);
+ } catch (Exception e1) {
+ e = e1;
+ }
+ // Expected to fail
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAAABB() throws Exception {
+ MethodExpression me8 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanBB,beanBB)}", null , null);
+ Object r8 = me8.invoke(context, null);
+ assertEquals("ABB[]: Hello AAA from BB, BB", r8.toString());
+ }
+
+ @Test
+ public void testInvokeWithVarArgsAAABBB() throws Exception {
+ MethodExpression me9 = factory.createMethodExpression(context,
+ "${beanC.sayHello(beanAAA,beanBBB,beanBBB)}", null , null);
+ Object r9 = me9.invoke(context, null);
+ assertEquals("ABB[]: Hello AAA from BBB, BBB", r9.toString());
+ }
+
+ /*
+ * This is also tested implicitly in numerous places elsewhere in this
+ * class.
+ */
+ @Test
+ public void testBug49655() throws Exception {
+ // This is the call the failed
+ MethodExpression me = factory.createMethodExpression(context,
+ "#{beanA.setName('New value')}", null, null);
+ // The rest is to check it worked correctly
+ me.invoke(context, null);
+ ValueExpression ve = factory.createValueExpression(context,
+ "#{beanA.name}", java.lang.String.class);
+ assertEquals("New value", ve.getValue(context));
+ }
+
+ @Test
+ public void testBugPrimitives() throws Exception {
+ MethodExpression me = factory.createMethodExpression(context,
+ "${beanA.setValLong(5)}", null, null);
+ me.invoke(context, null);
+ ValueExpression ve = factory.createValueExpression(context,
+ "#{beanA.valLong}", java.lang.String.class);
+ assertEquals("5", ve.getValue(context));
+ }
+
+ @Test
+ public void testBug50449a() throws Exception {
+ MethodExpression me1 = factory.createMethodExpression(context,
+ "${beanB.sayHello()}", null, null);
+ String actual = (String) me1.invoke(context, null);
+ assertEquals("Hello from B", actual);
+ }
+
+ @Test
+ public void testBug50449b() throws Exception {
+ MethodExpression me1 = factory.createMethodExpression(context,
+ "${beanB.sayHello('Tomcat')}", null, null);
+ String actual = (String) me1.invoke(context, null);
+ assertEquals("Hello Tomcat from B", actual);
+ }
+
+ @Test
+ public void testBug50790a() throws Exception {
+ ValueExpression ve = factory.createValueExpression(context,
+ "#{beanAA.name.contains(beanA.name)}", java.lang.Boolean.class);
+ Boolean actual = (Boolean) ve.getValue(context);
+ assertEquals(Boolean.TRUE, actual);
+ }
+
+ @Test
+ public void testBug50790b() throws Exception {
+ ValueExpression ve = factory.createValueExpression(context,
+ "#{beanA.name.contains(beanAA.name)}", java.lang.Boolean.class);
+ Boolean actual = (Boolean) ve.getValue(context);
+ assertEquals(Boolean.FALSE, actual);
+ }
+}
Added: trunk/test/java/org/apache/el/TestValueExpressionImpl.java
===================================================================
--- trunk/test/java/org/apache/el/TestValueExpressionImpl.java (rev 0)
+++ trunk/test/java/org/apache/el/TestValueExpressionImpl.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,216 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.el.ValueReference;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import org.apache.jasper.el.ELContextImpl;
+
+public class TestValueExpressionImpl {
+
+ @Test
+ public void testGetValueReference() {
+ 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 ve = factory.createValueExpression(
+ context, "${beanB.name}", String.class);
+
+ // First check the basics work
+ String result = (String) ve.getValue(context);
+ assertEquals("Tomcat", result);
+
+ // 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();
+
+ TesterBeanA beanA = new TesterBeanA();
+ TesterBeanB beanB = new TesterBeanB();
+ beanB.setName("Tomcat");
+ beanA.setBean(beanB);
+
+ ValueExpression var =
+ factory.createValueExpression(beanA, TesterBeanA.class);
+ context.getVariableMapper().setVariable("beanA", var);
+
+ ValueExpression ve = factory.createValueExpression(
+ context, "${beanA.bean.name}", String.class);
+
+ // First check the basics work
+ String result = (String) ve.getValue(context);
+ assertEquals("Tomcat", result);
+
+ // Now check the value reference
+ ValueReference vr = ve.getValueReference(context);
+ assertNotNull(vr);
+
+ assertEquals(beanB, vr.getBase());
+ assertEquals("name", vr.getProperty());
+ }
+
+ @Test
+ public void testBug50105() {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ TesterEnum testEnum = TesterEnum.APPLE;
+
+ ValueExpression var =
+ factory.createValueExpression(testEnum, TesterEnum.class);
+ context.getVariableMapper().setVariable("testEnum", var);
+
+ // When coercing an Enum to a String, name() should always be used.
+ ValueExpression ve1 = factory.createValueExpression(
+ context, "${testEnum}", String.class);
+ String result1 = (String) ve1.getValue(context);
+ assertEquals("APPLE", result1);
+
+ ValueExpression ve2 = factory.createValueExpression(
+ context, "foo${testEnum}bar", String.class);
+ String result2 = (String) ve2.getValue(context);
+ assertEquals("fooAPPLEbar", result2);
+ }
+
+ @Test
+ public void testBug51177ObjectMap() {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ Object o1 = "String value";
+ Object o2 = Integer.valueOf(32);
+
+ Map<Object,Object> map = new HashMap<Object,Object>();
+ map.put("key1", o1);
+ map.put("key2", o2);
+
+ ValueExpression var =
+ factory.createValueExpression(map, Map.class);
+ context.getVariableMapper().setVariable("map", var);
+
+ ValueExpression ve1 = factory.createValueExpression(
+ context, "${map.key1}", Object.class);
+ ve1.setValue(context, o2);
+ assertEquals(o2, ve1.getValue(context));
+
+ ValueExpression ve2 = factory.createValueExpression(
+ context, "${map.key2}", Object.class);
+ ve2.setValue(context, o1);
+ assertEquals(o1, ve2.getValue(context));
+ }
+
+ @Test
+ public void testBug51177ObjectList() {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ Object o1 = "String value";
+ Object o2 = Integer.valueOf(32);
+
+ List<Object> list = new ArrayList<Object>();
+ list.add(0, o1);
+ list.add(1, o2);
+
+ ValueExpression var =
+ factory.createValueExpression(list, List.class);
+ context.getVariableMapper().setVariable("list", var);
+
+ ValueExpression ve1 = factory.createValueExpression(
+ context, "${list[0]}", Object.class);
+ ve1.setValue(context, o2);
+ assertEquals(o2, ve1.getValue(context));
+
+ ValueExpression ve2 = factory.createValueExpression(
+ context, "${list[1]}", Object.class);
+ ve2.setValue(context, o1);
+ assertEquals(o1, ve2.getValue(context));
+ }
+
+
+ /**
+ * Test returning an empty list as a bean property.
+ */
+ @Test
+ public void testBug51544Bean() throws Exception {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ TesterBeanA beanA = new TesterBeanA();
+ beanA.setValList(Collections.emptyList());
+
+ ValueExpression var =
+ factory.createValueExpression(beanA, TesterBeanA.class);
+ context.getVariableMapper().setVariable("beanA", var);
+
+ ValueExpression ve = factory.createValueExpression(
+ context, "${beanA.valList.size()}", Integer.class);
+
+ Integer result = (Integer) ve.getValue(context);
+ assertEquals(Integer.valueOf(0), result);
+ }
+
+
+ /**
+ * Test using list directly as variable.
+ */
+ @Test
+ public void testBug51544Direct() throws Exception {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ List<?> list = Collections.emptyList();
+
+ ValueExpression var =
+ factory.createValueExpression(list, List.class);
+ context.getVariableMapper().setVariable("list", var);
+
+ ValueExpression ve = factory.createValueExpression(
+ context, "${list.size()}", Integer.class);
+
+ Integer result = (Integer) ve.getValue(context);
+ assertEquals(Integer.valueOf(0), result);
+ }
+}
Added: trunk/test/java/org/apache/el/TesterBeanA.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanA.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanA.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import java.util.List;
+
+public class TesterBeanA {
+ private TesterBeanB bean;
+ private String name;
+ private long valLong;
+ private List<?> valList;
+
+ public TesterBeanB getBean() {
+ return bean;
+ }
+
+ public void setBean(TesterBeanB bean) {
+ this.bean = bean;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getValLong() {
+ return valLong;
+ }
+
+ public void setValLong(long valLong) {
+ this.valLong = valLong;
+ }
+
+ public List<?> getValList() {
+ return valList;
+ }
+
+ public void setValList(List<?> valList) {
+ this.valList = valList;
+ }
+}
Added: trunk/test/java/org/apache/el/TesterBeanAA.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanAA.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanAA.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public class TesterBeanAA extends TesterBeanA {
+ // No additional implementation - just need a class that extends A for
+ // testing EL methods calls
+}
Added: trunk/test/java/org/apache/el/TesterBeanAAA.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanAAA.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanAAA.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public class TesterBeanAAA extends TesterBeanAA {
+ // No additional implementation - just need a class that extends AA for
+ // testing EL methods calls
+}
Added: trunk/test/java/org/apache/el/TesterBeanB.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanB.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanB.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+public class TesterBeanB {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String sayHello() {
+ return "Hello from " + name;
+ }
+
+ public String sayHello(String to) {
+ return "Hello " + to + " from " + name;
+ }
+}
Added: trunk/test/java/org/apache/el/TesterBeanBB.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanBB.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanBB.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+public class TesterBeanBB extends TesterBeanB {
+
+ private String extra;
+
+ public String getExtra() {
+ return extra;
+ }
+
+ public void setExtra(String extra) {
+ this.extra = extra;
+ }
+}
Added: trunk/test/java/org/apache/el/TesterBeanBBB.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanBBB.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanBBB.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public class TesterBeanBBB extends TesterBeanBB {
+ // No additional implementation - just need a class that extends BB for
+ // testing EL methods calls
+}
Added: trunk/test/java/org/apache/el/TesterBeanC.java
===================================================================
--- trunk/test/java/org/apache/el/TesterBeanC.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterBeanC.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+public class TesterBeanC {
+ public String sayHello(TesterBeanA a, TesterBeanB b) {
+ return "AB: Hello " + a.getName() + " from " + b.getName();
+ }
+ public String sayHello(TesterBeanAA a, TesterBeanB b) {
+ return "AAB: Hello " + a.getName() + " from " + b.getName();
+ }
+ public String sayHello(TesterBeanA a, TesterBeanBB b) {
+ return "ABB: Hello " + a.getName() + " from " + b.getName();
+ }
+ public String sayHello(TesterBeanA a, TesterBeanBB... b) {
+ StringBuilder result =
+ new StringBuilder("ABB[]: Hello " + a.getName() + " from ");
+ for (int i = 0; i < b.length; i++) {
+ if (i > 0) {
+ result.append(", ");
+ }
+ result.append(b[i].getName());
+ }
+ return result.toString();
+ }
+}
Added: trunk/test/java/org/apache/el/TesterEnum.java
===================================================================
--- trunk/test/java/org/apache/el/TesterEnum.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterEnum.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -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;
+
+public enum TesterEnum {
+ APPLE, ORANGE;
+
+ @Override
+ public String toString() {
+ return "This is a " + this.name();
+ }
+}
Added: trunk/test/java/org/apache/el/TesterFunctions.java
===================================================================
--- trunk/test/java/org/apache/el/TesterFunctions.java (rev 0)
+++ trunk/test/java/org/apache/el/TesterFunctions.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+public class TesterFunctions {
+ public static String trim(String input) {
+ return input.trim();
+ }
+
+ public static class Inner$Class {
+
+ public static final String RETVAL = "Return from bug49555";
+ public static String bug49555() {
+ return RETVAL;
+ }
+ }
+}
Added: trunk/test/java/org/apache/el/lang/TestELArithmetic.java
===================================================================
--- trunk/test/java/org/apache/el/lang/TestELArithmetic.java (rev 0)
+++ trunk/test/java/org/apache/el/lang/TestELArithmetic.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,98 @@
+/*
+ * 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.lang;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class TestELArithmetic {
+ private static final String a = "1.1";
+ private static final BigInteger b =
+ new BigInteger("1000000000000000000000");
+
+ @Test
+ public void testAdd() throws Exception {
+ assertEquals("1000000000000000000001.1",
+ String.valueOf(ELArithmetic.add(a, b)));
+ }
+
+ @Test
+ public void testSubtract() throws Exception {
+ assertEquals("-999999999999999999998.9",
+ String.valueOf(ELArithmetic.subtract(a, b)));
+ }
+
+ @Test
+ public void testMultiply() throws Exception {
+ assertEquals("1100000000000000000000.0",
+ String.valueOf(ELArithmetic.multiply(a, b)));
+ }
+
+ @Test
+ public void testDivide() throws Exception {
+ assertEquals("0.0",
+ String.valueOf(ELArithmetic.divide(a, b)));
+ }
+
+ @Test
+ public void testMod() throws Exception {
+ assertEquals("1.1",
+ String.valueOf(ELArithmetic.mod(a, b)));
+ }
+
+ @Test
+ public void testBug47371bigDecimal() throws Exception {
+ assertEquals(BigDecimal.valueOf(1),
+ ELArithmetic.add("", BigDecimal.valueOf(1)));
+ }
+
+ @Test
+ public void testBug47371double() throws Exception {
+ assertEquals(Double.valueOf(7), ELArithmetic.add("", Double.valueOf(7)));
+ }
+
+ @Test
+ public void testBug47371doubleString() throws Exception {
+ assertEquals(Double.valueOf(2), ELArithmetic.add("", "2."));
+ }
+
+ @Test
+ public void testBug47371bigInteger() throws Exception {
+ assertEquals(BigInteger.valueOf(0),
+ ELArithmetic.multiply("", BigInteger.valueOf(1)));
+ }
+
+ @Test
+ public void testBug47371long() throws Exception {
+ assertEquals(Long.valueOf(1), ELArithmetic.add("", Integer.valueOf(1)));
+ }
+
+ @Test
+ public void testBug47371long2() throws Exception {
+ assertEquals(Long.valueOf(-3), ELArithmetic.subtract("1", "4"));
+ }
+
+ @Test
+ public void testBug47371doubleString2() throws Exception {
+ assertEquals(Double.valueOf(2), ELArithmetic.add("1.", "1"));
+ }
+
+}
Added: trunk/test/java/org/apache/el/lang/TestELSupport.java
===================================================================
--- trunk/test/java/org/apache/el/lang/TestELSupport.java (rev 0)
+++ trunk/test/java/org/apache/el/lang/TestELSupport.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,135 @@
+/*
+ * 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.lang;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.el.ELException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class TestELSupport {
+ @Test
+ public void testBigDecimal() {
+ testIsSame(new BigDecimal(
+ "0.123456789012345678901234567890123456789012345678901234567890123456789"));
+ }
+
+ @Test
+ public void testBigInteger() {
+ testIsSame(new BigInteger(
+ "1234567890123456789012345678901234567890123456789012345678901234567890"));
+ }
+
+ @Test
+ public void testLong() {
+ testIsSame(Long.valueOf(0x0102030405060708L));
+ }
+
+ @Test
+ public void testInteger() {
+ testIsSame(Integer.valueOf(0x01020304));
+ }
+
+ @Test
+ public void testShort() {
+ testIsSame(Short.valueOf((short) 0x0102));
+ }
+
+ @Test
+ public void testByte() {
+ testIsSame(Byte.valueOf((byte) 0xEF));
+ }
+
+ @Test
+ public void testDouble() {
+ testIsSame(Double.valueOf(0.123456789012345678901234));
+ }
+
+ @Test
+ public void testFloat() {
+ testIsSame(Float.valueOf(0.123456F));
+ }
+
+ @Test
+ public void testCoerceIntegerToNumber() {
+ Integer input = Integer.valueOf(4390241);
+ Object output = ELSupport.coerceToType(input, Number.class);
+ assertEquals(input, output);
+ }
+
+ @Test
+ public void testCoerceNullToNumber() {
+ Object output = ELSupport.coerceToType(null, Number.class);
+ assertEquals(Long.valueOf(0), output);
+ }
+
+ @Test
+ public void testCoerceEnumAToEnumA() {
+ Object output = null;
+ try {
+ output = ELSupport.coerceToEnum(TestEnumA.VALA1, TestEnumA.class);
+ } finally {
+ assertEquals(TestEnumA.VALA1, output);
+ }
+ }
+
+ @Test
+ public void testCoerceEnumAToEnumB() {
+ Object output = null;
+ try {
+ output = ELSupport.coerceToEnum(TestEnumA.VALA1, TestEnumB.class);
+ } catch (ELException ele) {
+ // Ignore
+ }
+ assertNull(output);
+ }
+
+ @Test
+ public void testCoerceEnumAToEnumC() {
+ Object output = null;
+ try {
+ output = ELSupport.coerceToEnum(TestEnumA.VALA1, TestEnumC.class);
+ } catch (ELException ele) {
+ // Ignore
+ }
+ assertNull(output);
+ }
+
+ private static void testIsSame(Object value) {
+ assertEquals(value, ELSupport.coerceToNumber(value, value.getClass()));
+ }
+
+ private static enum TestEnumA {
+ VALA1,
+ VALA2
+ }
+ private static enum TestEnumB {
+ VALB1,
+ VALB2
+ }
+ private static enum TestEnumC {
+ VALA1,
+ VALA2,
+ VALB1,
+ VALB2
+ }
+}
Added: trunk/test/java/org/apache/el/parser/TestELParser.java
===================================================================
--- trunk/test/java/org/apache/el/parser/TestELParser.java (rev 0)
+++ trunk/test/java/org/apache/el/parser/TestELParser.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,117 @@
+/*
+ * 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;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import org.apache.jasper.el.ELContextImpl;
+
+public class TestELParser {
+
+ @Test
+ public void testBug49081() {
+ // OP's report
+ testExpression("#${1+1}", "#2");
+
+ // Variations on a theme
+ testExpression("#", "#");
+ testExpression("##", "##");
+ testExpression("###", "###");
+ testExpression("$", "$");
+ testExpression("$$", "$$");
+ testExpression("$$$", "$$$");
+ testExpression("#$", "#$");
+ testExpression("#$#", "#$#");
+ testExpression("$#", "$#");
+ testExpression("$#$", "$#$");
+
+ testExpression("#{1+1}", "2");
+ testExpression("##{1+1}", "#2");
+ testExpression("###{1+1}", "##2");
+ testExpression("${1+1}", "2");
+ testExpression("$${1+1}", "$2");
+ testExpression("$$${1+1}", "$$2");
+ testExpression("#${1+1}", "#2");
+ testExpression("#$#{1+1}", "#$2");
+ testExpression("$#{1+1}", "$2");
+ testExpression("$#${1+1}", "$#2");
+ }
+
+ @Test
+ public void testJavaKeyWordSuffix() {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ TesterBeanA beanA = new TesterBeanA();
+ beanA.setInt("five");
+ ValueExpression var =
+ factory.createValueExpression(beanA, TesterBeanA.class);
+ context.getVariableMapper().setVariable("beanA", var);
+
+ // Should fail
+ Exception e = null;
+ try {
+ factory.createValueExpression(context, "${beanA.int}",
+ String.class);
+ } catch (ELException ele) {
+ e = ele;
+ }
+ assertNotNull(e);
+ }
+
+ @Test
+ public void testJavaKeyWordIdentifier() {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ TesterBeanA beanA = new TesterBeanA();
+ beanA.setInt("five");
+ ValueExpression var =
+ factory.createValueExpression(beanA, TesterBeanA.class);
+ context.getVariableMapper().setVariable("this", var);
+
+ // Should fail
+ Exception e = null;
+ try {
+ factory.createValueExpression(context, "${this}", String.class);
+ } catch (ELException ele) {
+ e = ele;
+ }
+ assertNotNull(e);
+ }
+
+
+ private void testExpression(String expression, String expected) {
+ ExpressionFactory factory = ExpressionFactory.newInstance();
+ ELContext context = new ELContextImpl();
+
+ ValueExpression ve = factory.createValueExpression(
+ context, expression, String.class);
+
+ String result = (String) ve.getValue(context);
+ assertEquals(expected, result);
+ }
+}
Added: trunk/test/java/org/apache/el/parser/TesterBeanA.java
===================================================================
--- trunk/test/java/org/apache/el/parser/TesterBeanA.java (rev 0)
+++ trunk/test/java/org/apache/el/parser/TesterBeanA.java 2011-12-06 15:29:27 UTC (rev 1883)
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+public class TesterBeanA {
+ private String keywordInt;
+
+ public String getInt() {
+ return keywordInt;
+ }
+
+ public void setInt(String keywordInt) {
+ this.keywordInt = keywordInt;
+ }
+}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2011-12-06 15:27:15 UTC (rev 1882)
+++ trunk/webapps/docs/changelog.xml 2011-12-06 15:29:27 UTC (rev 1883)
@@ -16,6 +16,24 @@
<body>
+<section name="JBoss Web 7.0.5.Final (remm)">
+ <subsection name="Catalina">
+ <changelog>
+ <update>
+ <jira>AS7-2844</jira>: Error pages are suppose to complete or dispatch an async operation,
+ but the check was not in the right location. (remm)
+ </update>
+ </changelog>
+ </subsection>
+ <subsection name="Jasper">
+ <changelog>
+ <fix>
+ Rebase on Tomcat EL. (remm)
+ </fix>
+ </changelog>
+ </subsection>
+</section>
+
<section name="JBoss Web 7.0.4.Final (remm)">
<subsection name="Catalina">
<changelog>
13 years
JBossWeb SVN: r1882 - in trunk/java/org/apache: el/lang and 3 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2011-12-06 10:27:15 -0500 (Tue, 06 Dec 2011)
New Revision: 1882
Added:
trunk/java/org/apache/el/parser/AstMethodParameters.java
trunk/java/org/apache/el/util/Validation.java
Modified:
trunk/java/org/apache/el/ExpressionFactoryImpl.java
trunk/java/org/apache/el/Messages.properties
trunk/java/org/apache/el/Messages_es.properties
trunk/java/org/apache/el/MethodExpressionImpl.java
trunk/java/org/apache/el/MethodExpressionLiteral.java
trunk/java/org/apache/el/ValueExpressionImpl.java
trunk/java/org/apache/el/ValueExpressionLiteral.java
trunk/java/org/apache/el/lang/ELArithmetic.java
trunk/java/org/apache/el/lang/ELSupport.java
trunk/java/org/apache/el/lang/EvaluationContext.java
trunk/java/org/apache/el/lang/ExpressionBuilder.java
trunk/java/org/apache/el/lang/FunctionMapperFactory.java
trunk/java/org/apache/el/lang/FunctionMapperImpl.java
trunk/java/org/apache/el/lang/VariableMapperFactory.java
trunk/java/org/apache/el/lang/VariableMapperImpl.java
trunk/java/org/apache/el/parser/ArithmeticNode.java
trunk/java/org/apache/el/parser/AstAnd.java
trunk/java/org/apache/el/parser/AstBracketSuffix.java
trunk/java/org/apache/el/parser/AstChoice.java
trunk/java/org/apache/el/parser/AstCompositeExpression.java
trunk/java/org/apache/el/parser/AstDeferredExpression.java
trunk/java/org/apache/el/parser/AstDiv.java
trunk/java/org/apache/el/parser/AstDotSuffix.java
trunk/java/org/apache/el/parser/AstDynamicExpression.java
trunk/java/org/apache/el/parser/AstEmpty.java
trunk/java/org/apache/el/parser/AstEqual.java
trunk/java/org/apache/el/parser/AstFalse.java
trunk/java/org/apache/el/parser/AstFloatingPoint.java
trunk/java/org/apache/el/parser/AstFunction.java
trunk/java/org/apache/el/parser/AstGreaterThan.java
trunk/java/org/apache/el/parser/AstGreaterThanEqual.java
trunk/java/org/apache/el/parser/AstIdentifier.java
trunk/java/org/apache/el/parser/AstInteger.java
trunk/java/org/apache/el/parser/AstLessThan.java
trunk/java/org/apache/el/parser/AstLessThanEqual.java
trunk/java/org/apache/el/parser/AstLiteralExpression.java
trunk/java/org/apache/el/parser/AstMinus.java
trunk/java/org/apache/el/parser/AstMod.java
trunk/java/org/apache/el/parser/AstMult.java
trunk/java/org/apache/el/parser/AstNegative.java
trunk/java/org/apache/el/parser/AstNot.java
trunk/java/org/apache/el/parser/AstNotEqual.java
trunk/java/org/apache/el/parser/AstNull.java
trunk/java/org/apache/el/parser/AstOr.java
trunk/java/org/apache/el/parser/AstPlus.java
trunk/java/org/apache/el/parser/AstString.java
trunk/java/org/apache/el/parser/AstTrue.java
trunk/java/org/apache/el/parser/AstValue.java
trunk/java/org/apache/el/parser/BooleanNode.java
trunk/java/org/apache/el/parser/ELParser.java
trunk/java/org/apache/el/parser/ELParser.jjt
trunk/java/org/apache/el/parser/ELParserTokenManager.java
trunk/java/org/apache/el/parser/ELParserTreeConstants.java
trunk/java/org/apache/el/parser/JJTELParserState.java
trunk/java/org/apache/el/parser/Node.java
trunk/java/org/apache/el/parser/NodeVisitor.java
trunk/java/org/apache/el/parser/SimpleCharStream.java
trunk/java/org/apache/el/parser/SimpleNode.java
trunk/java/org/apache/el/parser/Token.java
trunk/java/org/apache/el/parser/TokenMgrError.java
trunk/java/org/apache/el/util/MessageFactory.java
trunk/java/org/apache/el/util/ReflectionUtil.java
trunk/java/org/apache/jasper/compiler/Validator.java
Log:
Rebase on Tomcat EL (the current EL was improved to pass the TCK, but does not have fixes
for complex things).
Modified: trunk/java/org/apache/el/ExpressionFactoryImpl.java
===================================================================
--- trunk/java/org/apache/el/ExpressionFactoryImpl.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/ExpressionFactoryImpl.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -29,35 +29,34 @@
/**
* @see javax.el.ExpressionFactory
- *
+ *
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class ExpressionFactoryImpl extends ExpressionFactory {
/**
- *
+ *
*/
public ExpressionFactoryImpl() {
super();
}
+ @Override
public Object coerceToType(Object obj, Class<?> type) {
return ELSupport.coerceToType(obj, type);
}
+ @Override
public MethodExpression createMethodExpression(ELContext context,
String expression, Class<?> expectedReturnType,
Class<?>[] expectedParamTypes) {
- if (expectedParamTypes == null) {
- throw new NullPointerException(MessageFactory
- .get("error.method.nullParms"));
- }
ExpressionBuilder builder = new ExpressionBuilder(expression, context);
return builder.createMethodExpression(expectedReturnType,
expectedParamTypes);
}
+ @Override
public ValueExpression createValueExpression(ELContext context,
String expression, Class<?> expectedType) {
if (expectedType == null) {
@@ -68,6 +67,7 @@
return builder.createValueExpression(expectedType);
}
+ @Override
public ValueExpression createValueExpression(Object instance,
Class<?> expectedType) {
if (expectedType == null) {
Modified: trunk/java/org/apache/el/Messages.properties
===================================================================
--- trunk/java/org/apache/el/Messages.properties 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/Messages.properties 2011-12-06 15:27:15 UTC (rev 1882)
@@ -1,3 +1,18 @@
+# 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.
+
# General Errors
error.convert=Cannot convert {0} of type {1} to {2}
error.compare=Cannot compare {0} to {1}
@@ -17,32 +32,23 @@
error.method.nullParms=Parameter types cannot be null
error.value.expectedType=Expected type cannot be null
-# ExpressionMediator
-error.eval=Error Evaluating {0} : {1}
+# ExpressionBuilder
+error.parseFail=Failed to parse the expression [{0}]
# ValueSetVisitor
error.syntax.set=Illegal Syntax for Set Operation
# ReflectionUtil
error.method.notfound=Method not found: {0}.{1}({2})
-error.property.notfound=Property ''{1}'' not found on {0}
+error.method.ambiguous=Unable to find unambiguous method: {0}.{1}({2})
# ValidatingVisitor
error.fnMapper.null=Expression uses functions, but no FunctionMapper was provided
error.fnMapper.method=Function ''{0}'' not found
error.fnMapper.paramcount=Function ''{0}'' specifies {1} params, but {2} were declared
-# **ExpressionImpl
+# ExpressionImpl
error.context.null=ELContext was null
-# ArrayELResolver
-error.array.outofbounds=Index {0} is out of bounds for array of size {1}
-
-# ListELResolver
-error.list.outofbounds=Index {0} is out of bounds for list of size {1}
-
-# BeanELResolver
-error.property.notfound=Property ''{1}'' not found on type: {0}
-error.property.invocation=Property ''{1}'' threw an exception from type: {0}
-error.property.notreadable=Property ''{1}'' doesn't have a 'get' specified on type: {0}
-error.property.notwritable=Property ''{1}'' doesn't have a 'set' specified on type: {0}
\ No newline at end of file
+# Parser
+error.identifier.notjava=The identifier [{0}] is not a valid Java identifier as required by section 1.19 of the EL specification (Identifier ::= Java language identifier). This check can be disabled by setting the system property org.apache.el.parser.SKIP_IDENTIFIER_CHECK to true.
\ No newline at end of file
Modified: trunk/java/org/apache/el/Messages_es.properties
===================================================================
--- trunk/java/org/apache/el/Messages_es.properties 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/Messages_es.properties 2011-12-06 15:27:15 UTC (rev 1882)
@@ -1,27 +1,35 @@
-error.convert = No puedo convertir {0} desde tipo {1} a {2}
-error.compare = No puedo comparar {0} con {1}
-error.function = Problemas llamando a funci\u00F3n ''{0}''
-error.unreachable.base = Objetivo inalcanzable, identificador ''{0}'' resuelto a nulo
-error.unreachable.property = Objetivo inalcanzable, ''{0}'' devolvi\u00F3 nulo
-error.resolver.unhandled = ELResolver no manej\u00F3 el tipo\: {0} con propiedad de ''{1}''
-error.resolver.unhandled.null = ELResolver no puede manejar un Objeto base nulo con identificador de ''{0}''
-error.value.literal.write = ValueExpression es un literal y no un grabable\: {0}
-error.null = La expresi\u00F3n no puede ser nula
-error.mixed = La expresi\u00F3n no puede contenera la vez '\#{..}' y '${..}' \: {0}
-error.method = No es una MethodExpression v\u00E1lida\: {0}
-error.method.nullParms = Los tipos de par\u00E1metro no pueden ser nulo
-error.value.expectedType = El tipo esperado no puede ser nulo
-error.eval = Error Evaluando {0} \: {1}
-error.syntax.set = Sit\u00E1xis ilegal para Operaci\u00F3n de Poner Valor
-error.method.notfound = M\u00E9todo no hallado\: {0}.{1}({2})
-error.property.notfound = Propiedad ''{1}'' no hallada en {0}
-error.fnMapper.null = La expresi\u00F3n usa funciones, pero no se ha suministrado FunctionMapper
-error.fnMapper.method = Funci\u00F3n "{0}" no hallada
-error.fnMapper.paramcount = La funci\u00F3n ''{0}'' especifica {1} par\u00E9metros, pero {2} fueron declarados
-error.context.null = ELContext era nulo
-error.array.outofbounds = \u00CDndice {0} fuera de l\u00EDmites para arreglo de medida {1}
-error.list.outofbounds = \u00CDndice {0} fuera de l\u00EDmites para lista de medida {1}
-error.property.notfound = Propiedad ''{1}'' no hallada en tipo\: {0}
-error.property.invocation = Propiedad ''{1}'' lanz\u00F3 una excepci\u00F3n desde tipo\: {0}
-error.property.notreadable = La propiedad ''{1}'' no tiene un 'get' especificado en el tipo\: {0}
-error.property.notwritable = La propiedad ''{1}'' no tiene un 'set' especificado en el tipo\: {0}
+# 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.
+error.convert = No puedo convertir {0} desde tipo {1} a {2}
+error.compare = No puedo comparar {0} con {1}
+error.function = Problemas llamando a funci\u00F3n ''{0}''
+error.unreachable.base = Objetivo inalcanzable, identificador ''{0}'' resuelto a nulo
+error.unreachable.property = Objetivo inalcanzable, ''{0}'' devolvi\u00F3 nulo
+error.resolver.unhandled = ELResolver no manej\u00F3 el tipo\: {0} con propiedad de ''{1}''
+error.resolver.unhandled.null = ELResolver no puede manejar un Objeto base nulo con identificador de ''{0}''
+error.value.literal.write = ValueExpression es un literal y no un grabable\: {0}
+error.null = La expresi\u00F3n no puede ser nula
+error.mixed = La expresi\u00F3n no puede contenera la vez '\#{..}' y '${..}' \: {0}
+error.method = No es una MethodExpression v\u00E1lida\: {0}
+error.method.nullParms = Los tipos de par\u00E1metro no pueden ser nulo
+error.value.expectedType = El tipo esperado no puede ser nulo
+error.syntax.set = Sit\u00E1xis ilegal para Operaci\u00F3n de Poner Valor
+error.method.notfound = M\u00E9todo no hallado\: {0}.{1}({2})
+error.method.ambiguous = No pude hallar m\u00E9todo ambiguo\: {0}.{1}({2})
+error.fnMapper.null = La expresi\u00F3n usa funciones, pero no se ha suministrado FunctionMapper
+error.fnMapper.method = Funci\u00F3n "{0}" no hallada
+error.fnMapper.paramcount = La funci\u00F3n ''{0}'' especifica {1} par\u00E9metros, pero {2} fueron declarados
+error.context.null = ELContext era nulo
+error.identifier.notjava = El identificador [{0}] no es un identificado Java v\u00E1lido seg\u00FAn se requiere en la secci\u00F3n 1.9 de la especificaci\u00F3n EL (Identificador \:\:\= identificador de lenguaje Java). Este chequeo se puede desactivar poniendo la propiedad del sistema org.apache.el.parser.SKIP_IDENTIFIER_CHECK a verdad (true).
Modified: trunk/java/org/apache/el/MethodExpressionImpl.java
===================================================================
--- trunk/java/org/apache/el/MethodExpressionImpl.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/MethodExpressionImpl.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -24,9 +24,6 @@
import javax.el.ELContext;
import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.Expression;
-import javax.el.ExpressionFactory;
import javax.el.FunctionMapper;
import javax.el.MethodExpression;
import javax.el.MethodInfo;
@@ -42,45 +39,45 @@
/**
* An <code>Expression</code> that refers to a method on an object.
- *
+ *
* <p>
- * <code>The {@link ExpressionFactory#createMethodExpression} method
+ * <code>The {@link javax.el.ExpressionFactory#createMethodExpression} method
* can be used to parse an expression string and return a concrete instance
* of <code>MethodExpression</code> that encapsulates the parsed expression.
- * The {@link FunctionMapper} is used at parse time, not evaluation time,
- * so one is not needed to evaluate an expression using this class.
+ * The {@link FunctionMapper} is used at parse time, not evaluation time,
+ * so one is not needed to evaluate an expression using this class.
* However, the {@link ELContext} is needed at evaluation time.</p>
*
- * <p>The {@link #getMethodInfo} and {@link #invoke} methods will evaluate the
- * expression each time they are called. The {@link ELResolver} in the
- * <code>ELContext</code> is used to resolve the top-level variables and to
- * determine the behavior of the <code>.</code> and <code>[]</code>
- * operators. For any of the two methods, the {@link ELResolver#getValue}
- * method is used to resolve all properties up to but excluding the last
- * one. This provides the <code>base</code> object on which the method
- * appears. If the <code>base</code> object is null, a
- * <code>NullPointerException</code> must be thrown. At the last resolution,
+ * <p>The {@link #getMethodInfo} and {@link #invoke} methods will evaluate the
+ * expression each time they are called. The {@link javax.el.ELResolver} in the
+ * <code>ELContext</code> is used to resolve the top-level variables and to
+ * determine the behavior of the <code>.</code> and <code>[]</code>
+ * operators. For any of the two methods, the
+ * {@link javax.el.ELResolver#getValue} method is used to resolve all properties
+ * up to but excluding the last one. This provides the <code>base</code> object
+ * on which the method appears. If the <code>base</code> object is null, a
+ * <code>NullPointerException</code> must be thrown. At the last resolution,
* the final <code>property</code> is then coerced to a <code>String</code>,
- * which provides the name of the method to be found. A method matching the
- * name and expected parameters provided at parse time is found and it is
+ * which provides the name of the method to be found. A method matching the
+ * name and expected parameters provided at parse time is found and it is
* either queried or invoked (depending on the method called on this
* <code>MethodExpression</code>).</p>
*
- * <p>See the notes about comparison, serialization and immutability in
- * the {@link Expression} javadocs.
+ * <p>See the notes about comparison, serialization and immutability in
+ * the {@link javax.el.Expression} javadocs.
*
* @see javax.el.ELResolver
* @see javax.el.Expression
* @see javax.el.ExpressionFactory
* @see javax.el.MethodExpression
- *
+ *
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class MethodExpressionImpl extends MethodExpression implements
Externalizable {
- private Class expectedType;
+ private Class<?> expectedType;
private String expr;
@@ -90,10 +87,10 @@
private transient Node node;
- private Class[] paramTypes;
+ private Class<?>[] paramTypes;
/**
- *
+ *
*/
public MethodExpressionImpl() {
super();
@@ -108,7 +105,7 @@
*/
public MethodExpressionImpl(String expr, Node node,
FunctionMapper fnMapper, VariableMapper varMapper,
- Class expectedType, Class[] paramTypes) {
+ Class<?> expectedType, Class<?>[] paramTypes) {
super();
this.expr = expr;
this.node = node;
@@ -121,7 +118,7 @@
/**
* Determines whether the specified object is equal to this
* <code>Expression</code>.
- *
+ *
* <p>
* The result is <code>true</code> if and only if the argument is not
* <code>null</code>, is an <code>Expression</code> object that is the
@@ -129,7 +126,7 @@
* <code>MethodExpression</code>), and has an identical parsed
* representation.
* </p>
- *
+ *
* <p>
* Note that two expressions can be equal if their expression Strings are
* different. For example, <code>${fn1:foo()}</code> and
@@ -137,7 +134,7 @@
* <code>FunctionMapper</code>s mapped <code>fn1:foo</code> and
* <code>fn2:foo</code> to the same method.
* </p>
- *
+ *
* @param obj
* the <code>Object</code> to test for equality.
* @return <code>true</code> if <code>obj</code> equals this
@@ -145,6 +142,7 @@
* @see java.util.Hashtable
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object obj) {
return (obj instanceof MethodExpressionImpl && obj.hashCode() == this
.hashCode());
@@ -153,24 +151,25 @@
/**
* Returns the original String used to create this <code>Expression</code>,
* unmodified.
- *
+ *
* <p>
* This is used for debugging purposes but also for the purposes of
* comparison (e.g. to ensure the expression in a configuration file has not
* changed).
* </p>
- *
+ *
* <p>
* This method does not provide sufficient information to re-create an
* expression. Two different expressions can have exactly the same
* expression string but different function mappings. Serialization should
* be used to save and restore the state of an <code>Expression</code>.
* </p>
- *
+ *
* @return The original expression String.
- *
+ *
* @see javax.el.Expression#getExpressionString()
*/
+ @Override
public String getExpressionString() {
return this.expr;
}
@@ -178,7 +177,7 @@
/**
* Evaluates the expression relative to the provided context, and returns
* information about the actual referenced method.
- *
+ *
* @param context
* The context of this evaluation
* @return an instance of <code>MethodInfo</code> containing information
@@ -197,6 +196,7 @@
* the cause property of this exception, if available.
* @see javax.el.MethodExpression#getMethodInfo(javax.el.ELContext)
*/
+ @Override
public MethodInfo getMethodInfo(ELContext context)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
@@ -219,7 +219,7 @@
/**
* Returns the hash code for this <code>Expression</code>.
- *
+ *
* <p>
* See the note in the {@link #equals} method on how two expressions can be
* equal if their expression Strings are different. Recall that if two
@@ -228,12 +228,13 @@
* objects must produce the same integer result. Implementations must take
* special note and implement <code>hashCode</code> correctly.
* </p>
- *
+ *
* @return The hash code for this <code>Expression</code>.
* @see #equals
* @see java.util.Hashtable
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
return this.expr.hashCode();
}
@@ -242,7 +243,7 @@
* Evaluates the expression relative to the provided context, invokes the
* method that was found using the supplied parameters, and returns the
* result of the method invocation.
- *
+ *
* @param context
* The context of this evaluation.
* @param params
@@ -268,6 +269,7 @@
* @see javax.el.MethodExpression#invoke(javax.el.ELContext,
* java.lang.Object[])
*/
+ @Override
public Object invoke(ELContext context, Object[] params)
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
@@ -278,9 +280,10 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
+ @Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.expr = in.readUTF();
@@ -296,9 +299,10 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(this.expr);
out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
@@ -308,10 +312,18 @@
out.writeObject(this.varMapper);
}
+ @Override
public boolean isLiteralText() {
return false;
}
+ /**
+ * @since EL 2.2
+ * Note: The spelling mistake is deliberate.
+ * isParmetersProvided() - Specification definition
+ * isParametersProvided() - Corrected spelling
+ */
+ @Override
public boolean isParmetersProvided() {
return this.getNode().isParametersProvided();
}
Modified: trunk/java/org/apache/el/MethodExpressionLiteral.java
===================================================================
--- trunk/java/org/apache/el/MethodExpressionLiteral.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/MethodExpressionLiteral.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -33,26 +33,29 @@
public class MethodExpressionLiteral extends MethodExpression implements Externalizable {
- private Class expectedType;
+ private Class<?> expectedType;
private String expr;
-
- private Class[] paramTypes;
-
+
+ private Class<?>[] paramTypes;
+
public MethodExpressionLiteral() {
// do nothing
}
-
- public MethodExpressionLiteral(String expr, Class expectedType, Class[] paramTypes) {
+
+ public MethodExpressionLiteral(String expr, Class<?> expectedType,
+ Class<?>[] paramTypes) {
this.expr = expr;
this.expectedType = expectedType;
this.paramTypes = paramTypes;
}
+ @Override
public MethodInfo getMethodInfo(ELContext context) throws ELException {
return new MethodInfo(this.expr, this.expectedType, this.paramTypes);
}
+ @Override
public Object invoke(ELContext context, Object[] params) throws ELException {
if (this.expectedType != null) {
return ELSupport.coerceToType(this.expr, this.expectedType);
@@ -61,22 +64,27 @@
}
}
+ @Override
public String getExpressionString() {
return this.expr;
}
+ @Override
public boolean equals(Object obj) {
return (obj instanceof MethodExpressionLiteral && this.hashCode() == obj.hashCode());
}
+ @Override
public int hashCode() {
return this.expr.hashCode();
}
+ @Override
public boolean isLiteralText() {
return true;
}
+ @Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
this.expr = in.readUTF();
String type = in.readUTF();
@@ -87,6 +95,7 @@
.readObject()));
}
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(this.expr);
out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
Modified: trunk/java/org/apache/el/ValueExpressionImpl.java
===================================================================
--- trunk/java/org/apache/el/ValueExpressionImpl.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/ValueExpressionImpl.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -24,9 +24,6 @@
import javax.el.ELContext;
import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.Expression;
-import javax.el.ExpressionFactory;
import javax.el.FunctionMapper;
import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
@@ -44,7 +41,7 @@
/**
* An <code>Expression</code> that can get or set a value.
- *
+ *
* <p>
* In previous incarnations of this API, expressions could only be read.
* <code>ValueExpression</code> objects can now be used both to retrieve a
@@ -56,44 +53,44 @@
* details. Expressions that cannot be used as l-values must always return
* <code>true</code> from <code>isReadOnly()</code>.
* </p>
- *
+ *
* <p>
- * <code>The {@link ExpressionFactory#createValueExpression} method
+ * <code>The {@link javax.el.ExpressionFactory#createValueExpression} method
* can be used to parse an expression string and return a concrete instance
* of <code>ValueExpression</code> that encapsulates the parsed expression.
- * The {@link FunctionMapper} is used at parse time, not evaluation time,
- * so one is not needed to evaluate an expression using this class.
+ * The {@link FunctionMapper} is used at parse time, not evaluation time,
+ * so one is not needed to evaluate an expression using this class.
* However, the {@link ELContext} is needed at evaluation time.</p>
*
* <p>The {@link #getValue}, {@link #setValue}, {@link #isReadOnly} and
* {@link #getType} methods will evaluate the expression each time they are
- * called. The {@link ELResolver} in the <code>ELContext</code> is used to
- * resolve the top-level variables and to determine the behavior of the
+ * called. The {@link javax.el.ELResolver} in the <code>ELContext</code> is used
+ * to resolve the top-level variables and to determine the behavior of the
* <code>.</code> and <code>[]</code> operators. For any of the four methods,
- * the {@link ELResolver#getValue} method is used to resolve all properties
- * up to but excluding the last one. This provides the <code>base</code>
- * object. At the last resolution, the <code>ValueExpression</code> will
- * call the corresponding {@link ELResolver#getValue},
- * {@link ELResolver#setValue}, {@link ELResolver#isReadOnly} or
- * {@link ELResolver#getType} method, depending on which was called on
- * the <code>ValueExpression</code>.
+ * the {@link javax.el.ELResolver#getValue} method is used to resolve all
+ * properties up to but excluding the last one. This provides the
+ * <code>base</code> object. At the last resolution, the
+ * <code>ValueExpression</code> will call the corresponding
+ * {@link javax.el.ELResolver#getValue}, {@link javax.el.ELResolver#setValue},
+ * {@link javax.el.ELResolver#isReadOnly} or {@link javax.el.ELResolver#getType}
+ * method, depending on which was called on the <code>ValueExpression</code>.
* </p>
*
- * <p>See the notes about comparison, serialization and immutability in
- * the {@link Expression} javadocs.
+ * <p>See the notes about comparison, serialization and immutability in
+ * the {@link javax.el.Expression} javadocs.
*
* @see javax.el.ELResolver
* @see javax.el.Expression
* @see javax.el.ExpressionFactory
* @see javax.el.ValueExpression
- *
+ *
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class ValueExpressionImpl extends ValueExpression implements
Externalizable {
- private Class expectedType;
+ private Class<?> expectedType;
private String expr;
@@ -104,14 +101,14 @@
private transient Node node;
public ValueExpressionImpl() {
-
+ super();
}
/**
- *
+ *
*/
public ValueExpressionImpl(String expr, Node node, FunctionMapper fnMapper,
- VariableMapper varMapper, Class expectedType) {
+ VariableMapper varMapper, Class<?> expectedType) {
this.expr = expr;
this.node = node;
this.fnMapper = fnMapper;
@@ -121,9 +118,10 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object obj) {
return (obj instanceof ValueExpressionImpl && obj.hashCode() == this
.hashCode());
@@ -131,23 +129,25 @@
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#getExpectedType()
*/
- public Class getExpectedType() {
+ @Override
+ public Class<?> getExpectedType() {
return this.expectedType;
}
/**
* Returns the type the result of the expression will be coerced to after
* evaluation.
- *
+ *
* @return the <code>expectedType</code> passed to the
* <code>ExpressionFactory.createValueExpression</code> method
* that created this <code>ValueExpression</code>.
- *
+ *
* @see javax.el.Expression#getExpressionString()
*/
+ @Override
public String getExpressionString() {
return this.expr;
}
@@ -165,10 +165,11 @@
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#getType(javax.el.ELContext)
*/
- public Class getType(ELContext context) throws PropertyNotFoundException,
+ @Override
+ public Class<?> getType(ELContext context) throws PropertyNotFoundException,
ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
@@ -177,9 +178,10 @@
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#getValue(javax.el.ELContext)
*/
+ @Override
public Object getValue(ELContext context) throws PropertyNotFoundException,
ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
@@ -193,32 +195,20 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
- StringBuilder hash = new StringBuilder();
- comparableRepresentation(hash, getNode());
- return hash.toString().hashCode();
+ return this.getNode().hashCode();
}
-
- private void comparableRepresentation(StringBuilder string, Node node) {
- if (node.toString() != null) {
- string.append(node.toString());
- }
- for (int i = 0; i < node.jjtGetNumChildren(); i++) {
- Node child = node.jjtGetChild(i);
- string.append('[');
- comparableRepresentation(string, child);
- string.append(']');
- }
- }
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#isLiteralText()
*/
+ @Override
public boolean isLiteralText() {
try {
return this.getNode() instanceof AstLiteralExpression;
@@ -229,9 +219,10 @@
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
*/
+ @Override
public boolean isReadOnly(ELContext context)
throws PropertyNotFoundException, ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
@@ -239,6 +230,7 @@
return this.getNode().isReadOnly(ctx);
}
+ @Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.expr = in.readUTF();
@@ -252,10 +244,11 @@
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.ValueExpression#setValue(javax.el.ELContext,
* java.lang.Object)
*/
+ @Override
public void setValue(ELContext context, Object value)
throws PropertyNotFoundException, PropertyNotWritableException,
ELException {
@@ -264,6 +257,7 @@
this.getNode().setValue(ctx, value);
}
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(this.expr);
out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
@@ -272,13 +266,19 @@
out.writeObject(this.varMapper);
}
+ @Override
+ public String toString() {
+ return "ValueExpression["+this.expr+"]";
+ }
+
+ /**
+ * @since EL 2.2
+ */
+ @Override
public ValueReference getValueReference(ELContext context) {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
return this.getNode().getValueReference(ctx);
}
-
- public String toString() {
- return "ValueExpression["+this.expr+"]";
- }
+
}
Modified: trunk/java/org/apache/el/ValueExpressionLiteral.java
===================================================================
--- trunk/java/org/apache/el/ValueExpressionLiteral.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/ValueExpressionLiteral.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -19,12 +19,11 @@
import java.io.Externalizable;
import java.io.IOException;
-import javax.el.ELContext;
-import javax.el.PropertyNotWritableException;
-
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import javax.el.ELContext;
+import javax.el.PropertyNotWritableException;
import javax.el.ValueExpression;
import org.apache.el.lang.ELSupport;
@@ -39,17 +38,18 @@
private Object value;
- private Class expectedType;
+ private Class<?> expectedType;
public ValueExpressionLiteral() {
super();
}
-
- public ValueExpressionLiteral(Object value, Class expectedType) {
+
+ public ValueExpressionLiteral(Object value, Class<?> expectedType) {
this.value = value;
this.expectedType = expectedType;
}
+ @Override
public Object getValue(ELContext context) {
if (this.expectedType != null) {
return ELSupport.coerceToType(this.value, this.expectedType);
@@ -57,27 +57,33 @@
return this.value;
}
+ @Override
public void setValue(ELContext context, Object value) {
throw new PropertyNotWritableException(MessageFactory.get(
"error.value.literal.write", this.value));
}
+ @Override
public boolean isReadOnly(ELContext context) {
return true;
}
- public Class getType(ELContext context) {
+ @Override
+ public Class<?> getType(ELContext context) {
return (this.value != null) ? this.value.getClass() : null;
}
- public Class getExpectedType() {
+ @Override
+ public Class<?> getExpectedType() {
return this.expectedType;
}
+ @Override
public String getExpressionString() {
return (this.value != null) ? this.value.toString() : null;
}
+ @Override
public boolean equals(Object obj) {
return (obj instanceof ValueExpressionLiteral && this
.equals((ValueExpressionLiteral) obj));
@@ -88,20 +94,24 @@
.equals(ve.value))));
}
+ @Override
public int hashCode() {
return (this.value != null) ? this.value.hashCode() : 0;
}
+ @Override
public boolean isLiteralText() {
return true;
}
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.value);
out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
: "");
}
+ @Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.value = in.readObject();
Modified: trunk/java/org/apache/el/lang/ELArithmetic.java
===================================================================
--- trunk/java/org/apache/el/lang/ELArithmetic.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/ELArithmetic.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -400,7 +400,6 @@
if (obj instanceof String) {
return coerce((String) obj);
}
-
if (obj instanceof Character) {
return coerce(Short.valueOf((short) ((Character) obj).charValue()));
}
Modified: trunk/java/org/apache/el/lang/ELSupport.java
===================================================================
--- trunk/java/org/apache/el/lang/ELSupport.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/ELSupport.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -23,62 +23,50 @@
import java.math.BigInteger;
import javax.el.ELException;
-import javax.el.PropertyNotFoundException;
import org.apache.el.util.MessageFactory;
/**
* A helper class that implements the EL Specification
- *
+ *
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$Date$$Author$
+ * @version $Id$
*/
public class ELSupport {
- private final static Long ZERO = new Long(0L);
+ private static final Long ZERO = Long.valueOf(0L);
- public final static void throwUnhandled(Object base, Object property)
- throws ELException {
- if (base == null) {
- throw new PropertyNotFoundException(MessageFactory.get(
- "error.resolver.unhandled.null", property));
- } else {
- throw new PropertyNotFoundException(MessageFactory.get(
- "error.resolver.unhandled", base.getClass(), property));
- }
- }
-
/**
* Compare two objects, after coercing to the same type if appropriate.
- *
- * If the objects are identical, or they are equal according to
+ *
+ * If the objects are identical, or they are equal according to
* {@link #equals(Object, Object)} then return 0.
- *
+ *
* If either object is a BigDecimal, then coerce both to BigDecimal first.
* Similarly for Double(Float), BigInteger, and Long(Integer, Char, Short, Byte).
- *
+ *
* Otherwise, check that the first object is an instance of Comparable, and compare
* against the second object. If that is null, return 1, otherwise
* return the result of comparing against the second object.
- *
+ *
* Similarly, if the second object is Comparable, if the first is null, return -1,
* else return the result of comparing against the first object.
- *
+ *
* A null object is considered as:
* <ul>
* <li>ZERO when compared with Numbers</li>
* <li>the empty string for String compares</li>
* <li>Otherwise null is considered to be lower than anything else.</li>
* </ul>
- *
+ *
* @param obj0 first object
* @param obj1 second object
* @return -1, 0, or 1 if this object is less than, equal to, or greater than val.
* @throws ELException if neither object is Comparable
* @throws ClassCastException if the objects are not mutually comparable
*/
- public final static int compare(final Object obj0, final Object obj1)
+ public static final int compare(final Object obj0, final Object obj1)
throws ELException {
if (obj0 == obj1 || equals(obj0, obj1)) {
return 0;
@@ -121,19 +109,19 @@
/**
* Compare two objects for equality, after coercing to the same type if appropriate.
- *
+ *
* If the objects are identical (including both null) return true.
* If either object is null, return false.
* If either object is Boolean, coerce both to Boolean and check equality.
* Similarly for Enum, String, BigDecimal, Double(Float), Long(Integer, Short, Byte, Character)
* Otherwise default to using Object.equals().
- *
+ *
* @param obj0 the first object
* @param obj1 the second object
* @return true if the objects are equal
* @throws ELException
*/
- public final static boolean equals(final Object obj0, final Object obj1)
+ public static final boolean equals(final Object obj0, final Object obj1)
throws ELException {
if (obj0 == obj1) {
return true;
@@ -173,19 +161,19 @@
}
}
- /**
- * @param obj
- * @param type
- * @return
- */
- public final static Enum<?> coerceToEnum(final Object obj, Class type) {
+ // Going to have to have some casts /raw types somewhere so doing it here
+ // keeps them all in one place. There might be a neater / better solution
+ // but I couldn't find it
+ @SuppressWarnings("unchecked")
+ public static final Enum<?> coerceToEnum(final Object obj,
+ @SuppressWarnings("rawtypes") Class type) {
if (obj == null || "".equals(obj)) {
return null;
}
if (type.isAssignableFrom(obj.getClass())) {
return (Enum<?>) obj;
}
-
+
if (!(obj instanceof String)) {
throw new ELException(MessageFactory.get("error.convert",
obj, obj.getClass(), type));
@@ -208,7 +196,7 @@
* @return the Boolean value of the object
* @throws ELException if object is not Boolean or String
*/
- public final static Boolean coerceToBoolean(final Object obj)
+ public static final Boolean coerceToBoolean(final Object obj)
throws ELException {
if (obj == null || "".equals(obj)) {
return Boolean.FALSE;
@@ -224,16 +212,16 @@
obj, obj.getClass(), Boolean.class));
}
- public final static Character coerceToCharacter(final Object obj)
+ public static final Character coerceToCharacter(final Object obj)
throws ELException {
if (obj == null || "".equals(obj)) {
- return new Character((char) 0);
+ return Character.valueOf((char) 0);
}
if (obj instanceof String) {
- return new Character(((String) obj).charAt(0));
+ return Character.valueOf(((String) obj).charAt(0));
}
if (ELArithmetic.isNumber(obj)) {
- return new Character((char) ((Number) obj).shortValue());
+ return Character.valueOf((char) ((Number) obj).shortValue());
}
Class<?> objType = obj.getClass();
if (obj instanceof Character) {
@@ -244,31 +232,16 @@
obj, objType, Character.class));
}
- public final static Number coerceToNumber(final Object obj) {
- if (obj == null) {
- return ZERO;
- } else if (obj instanceof Number) {
- return (Number) obj;
- } else {
- String str = coerceToString(obj);
- if (isStringFloat(str)) {
- return toFloat(str);
- } else {
- return toNumber(str);
- }
- }
- }
-
- protected final static Number coerceToNumber(final Number number,
+ protected static final Number coerceToNumber(final Number number,
final Class<?> type) throws ELException {
if (Long.TYPE == type || Long.class.equals(type)) {
- return new Long(number.longValue());
+ return Long.valueOf(number.longValue());
}
if (Double.TYPE == type || Double.class.equals(type)) {
return new Double(number.doubleValue());
}
if (Integer.TYPE == type || Integer.class.equals(type)) {
- return new Integer(number.intValue());
+ return Integer.valueOf(number.intValue());
}
if (BigInteger.class.equals(type)) {
if (number instanceof BigDecimal) {
@@ -289,10 +262,10 @@
return new BigDecimal(number.doubleValue());
}
if (Byte.TYPE == type || Byte.class.equals(type)) {
- return new Byte(number.byteValue());
+ return Byte.valueOf(number.byteValue());
}
if (Short.TYPE == type || Short.class.equals(type)) {
- return new Short(number.shortValue());
+ return Short.valueOf(number.shortValue());
}
if (Float.TYPE == type || Float.class.equals(type)) {
return new Float(number.floatValue());
@@ -305,7 +278,7 @@
number, number.getClass(), type));
}
- public final static Number coerceToNumber(final Object obj,
+ public static final Number coerceToNumber(final Object obj,
final Class<?> type) throws ELException {
if (obj == null || "".equals(obj)) {
return coerceToNumber(ZERO, type);
@@ -318,7 +291,7 @@
}
if (obj instanceof Character) {
- return coerceToNumber(new Short((short) ((Character) obj)
+ return coerceToNumber(Short.valueOf((short) ((Character) obj)
.charValue()), type);
}
@@ -326,7 +299,7 @@
obj, obj.getClass(), type));
}
- protected final static Number coerceToNumber(final String val,
+ protected static final Number coerceToNumber(final String val,
final Class<?> type) throws ELException {
if (Long.TYPE == type || Long.class.equals(type)) {
try {
@@ -402,7 +375,7 @@
* @param obj
* @return the String value of the object
*/
- public final static String coerceToString(final Object obj) {
+ public static final String coerceToString(final Object obj) {
if (obj == null) {
return "";
} else if (obj instanceof String) {
@@ -414,26 +387,7 @@
}
}
- public final static void checkType(final Object obj, final Class<?> type)
- throws ELException {
- if (String.class.equals(type)) {
- coerceToString(obj);
- }
- if (ELArithmetic.isNumberType(type)) {
- coerceToNumber(obj, type);
- }
- if (Character.class.equals(type) || Character.TYPE == type) {
- coerceToCharacter(obj);
- }
- if (Boolean.class.equals(type) || Boolean.TYPE == type) {
- coerceToBoolean(obj);
- }
- if (type.isEnum()) {
- coerceToEnum(obj, type);
- }
- }
-
- public final static Object coerceToType(final Object obj,
+ public static final Object coerceToType(final Object obj,
final Class<?> type) throws ELException {
if (type == null || Object.class.equals(type) ||
(obj != null && type.isAssignableFrom(obj.getClass()))) {
@@ -471,44 +425,24 @@
obj, obj.getClass(), type));
}
- /**
- * Check if an array contains any {@code null} entries.
- * @param obj array to be checked
- * @return true if the array contains a {@code null}
- */
- public final static boolean containsNulls(final Object[] obj) {
- for (int i = 0; i < obj.length; i++) {
- if (obj[0] == null) {
- return true;
- }
- }
- return false;
- }
-
- public final static boolean isBigDecimalOp(final Object obj0,
+ public static final boolean isBigDecimalOp(final Object obj0,
final Object obj1) {
return (obj0 instanceof BigDecimal || obj1 instanceof BigDecimal);
}
- public final static boolean isBigIntegerOp(final Object obj0,
+ public static final boolean isBigIntegerOp(final Object obj0,
final Object obj1) {
return (obj0 instanceof BigInteger || obj1 instanceof BigInteger);
}
- public final static boolean isDoubleOp(final Object obj0, final Object obj1) {
+ public static final boolean isDoubleOp(final Object obj0, final Object obj1) {
return (obj0 instanceof Double
|| obj1 instanceof Double
|| obj0 instanceof Float
|| obj1 instanceof Float);
}
- public final static boolean isDoubleStringOp(final Object obj0,
- final Object obj1) {
- return (isDoubleOp(obj0, obj1)
- || (obj0 instanceof String && isStringFloat((String) obj0)) || (obj1 instanceof String && isStringFloat((String) obj1)));
- }
-
- public final static boolean isLongOp(final Object obj0, final Object obj1) {
+ public static final boolean isLongOp(final Object obj0, final Object obj1) {
return (obj0 instanceof Long
|| obj1 instanceof Long
|| obj0 instanceof Integer
@@ -521,7 +455,7 @@
|| obj1 instanceof Byte);
}
- public final static boolean isStringFloat(final String str) {
+ public static final boolean isStringFloat(final String str) {
int len = str.length();
if (len > 1) {
for (int i = 0; i < len; i++) {
@@ -538,32 +472,8 @@
return false;
}
- public final static Number toFloat(final String value) {
- try {
- if (Double.parseDouble(value) > Double.MAX_VALUE) {
- return new BigDecimal(value);
- } else {
- return new Double(value);
- }
- } catch (NumberFormatException e0) {
- return new BigDecimal(value);
- }
- }
-
- public final static Number toNumber(final String value) {
- try {
- return new Integer(Integer.parseInt(value));
- } catch (NumberFormatException e0) {
- try {
- return new Long(Long.parseLong(value));
- } catch (NumberFormatException e1) {
- return new BigInteger(value);
- }
- }
- }
-
/**
- *
+ *
*/
public ELSupport() {
super();
Modified: trunk/java/org/apache/el/lang/EvaluationContext.java
===================================================================
--- trunk/java/org/apache/el/lang/EvaluationContext.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/EvaluationContext.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -18,6 +18,7 @@
package org.apache.el.lang;
import java.util.Locale;
+
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.FunctionMapper;
@@ -42,39 +43,51 @@
return this.elContext;
}
+ @Override
public FunctionMapper getFunctionMapper() {
return this.fnMapper;
}
+ @Override
public VariableMapper getVariableMapper() {
return this.varMapper;
}
- public Object getContext(Class key) {
+ @Override
+ // Can't use Class<?> because API needs to match specification in superclass
+ public Object getContext(@SuppressWarnings("rawtypes") Class key) {
return this.elContext.getContext(key);
}
+ @Override
public ELResolver getELResolver() {
return this.elContext.getELResolver();
}
+ @Override
public boolean isPropertyResolved() {
return this.elContext.isPropertyResolved();
}
- public void putContext(Class key, Object contextObject) {
+ @Override
+ // Can't use Class<?> because API needs to match specification in superclass
+ public void putContext(@SuppressWarnings("rawtypes") Class key,
+ Object contextObject) {
this.elContext.putContext(key, contextObject);
}
+ @Override
public void setPropertyResolved(boolean resolved) {
this.elContext.setPropertyResolved(resolved);
}
- public Locale getLocale() {
+ @Override
+ public Locale getLocale() {
return this.elContext.getLocale();
}
- public void setLocale(Locale locale) {
+ @Override
+ public void setLocale(Locale locale) {
this.elContext.setLocale(locale);
}
}
Modified: trunk/java/org/apache/el/lang/ExpressionBuilder.java
===================================================================
--- trunk/java/org/apache/el/lang/ExpressionBuilder.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/ExpressionBuilder.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -33,7 +33,6 @@
import org.apache.el.MethodExpressionImpl;
import org.apache.el.MethodExpressionLiteral;
import org.apache.el.ValueExpressionImpl;
-import org.apache.el.parser.AstCompositeExpression;
import org.apache.el.parser.AstDeferredExpression;
import org.apache.el.parser.AstDynamicExpression;
import org.apache.el.parser.AstFunction;
@@ -43,13 +42,12 @@
import org.apache.el.parser.ELParser;
import org.apache.el.parser.Node;
import org.apache.el.parser.NodeVisitor;
-import org.apache.el.parser.ParseException;
import org.apache.el.util.ConcurrentCache;
import org.apache.el.util.MessageFactory;
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class ExpressionBuilder implements NodeVisitor {
@@ -64,6 +62,7 @@
} else {
CACHE_SIZE = AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
+
@Override
public Integer run() {
return Integer.valueOf(
@@ -83,87 +82,87 @@
private static final ConcurrentCache<String, Node> cache;
private static final ConcurrentHashMap<String, Node> unlimitedCache;
- private FunctionMapper fnMapper;
+ private FunctionMapper fnMapper;
- private VariableMapper varMapper;
+ private VariableMapper varMapper;
- private String expression;
+ private String expression;
- /**
- *
- */
- public ExpressionBuilder(String expression, ELContext ctx)
- throws ELException {
- this.expression = expression;
+ /**
+ *
+ */
+ public ExpressionBuilder(String expression, ELContext ctx)
+ throws ELException {
+ this.expression = expression;
- FunctionMapper ctxFn = ctx.getFunctionMapper();
- VariableMapper ctxVar = ctx.getVariableMapper();
+ FunctionMapper ctxFn = ctx.getFunctionMapper();
+ VariableMapper ctxVar = ctx.getVariableMapper();
- if (ctxFn != null) {
- this.fnMapper = new FunctionMapperFactory(ctxFn);
- }
- if (ctxVar != null) {
- this.varMapper = new VariableMapperFactory(ctxVar);
- }
- }
+ if (ctxFn != null) {
+ this.fnMapper = new FunctionMapperFactory(ctxFn);
+ }
+ if (ctxVar != null) {
+ this.varMapper = new VariableMapperFactory(ctxVar);
+ }
+ }
- public final static Node createNode(String expr) throws ELException {
- Node n = createNodeInternal(expr);
- return n;
- }
+ public static final Node createNode(String expr) throws ELException {
+ Node n = createNodeInternal(expr);
+ return n;
+ }
- private final static Node createNodeInternal(String expr)
- throws ELException {
- if (expr == null) {
- throw new ELException(MessageFactory.get("error.null"));
- }
+ private static final Node createNodeInternal(String expr)
+ throws ELException {
+ if (expr == null) {
+ throw new ELException(MessageFactory.get("error.null"));
+ }
Node n = (cache != null) ? cache.get(expr) : unlimitedCache.get(expr);
- if (n == null) {
- try {
- n = (new ELParser(new StringReader(expr)))
- .CompositeExpression();
+ if (n == null) {
+ try {
+ n = (new ELParser(new StringReader(expr)))
+ .CompositeExpression();
- // validate composite expression
- if (n instanceof AstCompositeExpression) {
- int numChildren = n.jjtGetNumChildren();
- if (numChildren == 1) {
- n = n.jjtGetChild(0);
- } else {
- Class type = null;
- Node child = null;
- for (int i = 0; i < numChildren; i++) {
- child = n.jjtGetChild(i);
- if (child instanceof AstLiteralExpression)
- continue;
- if (type == null)
- type = child.getClass();
- else {
- if (!type.equals(child.getClass())) {
- throw new ELException(MessageFactory.get(
- "error.mixed", expr));
- }
- }
- }
- }
- }
- if (n instanceof AstDeferredExpression
- || n instanceof AstDynamicExpression) {
- n = n.jjtGetChild(0);
- }
+ // validate composite expression
+ int numChildren = n.jjtGetNumChildren();
+ if (numChildren == 1) {
+ n = n.jjtGetChild(0);
+ } else {
+ Class<?> type = null;
+ Node child = null;
+ for (int i = 0; i < numChildren; i++) {
+ child = n.jjtGetChild(i);
+ if (child instanceof AstLiteralExpression)
+ continue;
+ if (type == null)
+ type = child.getClass();
+ else {
+ if (!type.equals(child.getClass())) {
+ throw new ELException(MessageFactory.get(
+ "error.mixed", expr));
+ }
+ }
+ }
+ }
+
+ if (n instanceof AstDeferredExpression
+ || n instanceof AstDynamicExpression) {
+ n = n.jjtGetChild(0);
+ }
if (cache != null) {
- cache.put(expr, n);
- } else {
- unlimitedCache.put(expr, n);
- }
- } catch (ParseException pe) {
- throw new ELException("Error Parsing: " + expr, pe);
- }
- }
- return n;
- }
+ cache.put(expr, n);
+ } else {
+ unlimitedCache.put(expr, n);
+ }
+ } catch (Exception e) {
+ throw new ELException(
+ MessageFactory.get("error.parseFail", expr), e);
+ }
+ }
+ return n;
+ }
- private void prepare(Node node) throws ELException {
+ private void prepare(Node node) throws ELException {
try {
node.accept(this);
} catch (Exception e) {
@@ -173,76 +172,81 @@
throw (new ELException(e));
}
}
- if (this.fnMapper instanceof FunctionMapperFactory) {
- this.fnMapper = ((FunctionMapperFactory) this.fnMapper).create();
- }
- if (this.varMapper instanceof VariableMapperFactory) {
- this.varMapper = ((VariableMapperFactory) this.varMapper).create();
- }
- }
+ if (this.fnMapper instanceof FunctionMapperFactory) {
+ this.fnMapper = ((FunctionMapperFactory) this.fnMapper).create();
+ }
+ if (this.varMapper instanceof VariableMapperFactory) {
+ this.varMapper = ((VariableMapperFactory) this.varMapper).create();
+ }
+ }
- private Node build() throws ELException {
- Node n = createNodeInternal(this.expression);
- this.prepare(n);
- if (n instanceof AstDeferredExpression
- || n instanceof AstDynamicExpression) {
- n = n.jjtGetChild(0);
- }
- return n;
- }
+ private Node build() throws ELException {
+ Node n = createNodeInternal(this.expression);
+ this.prepare(n);
+ if (n instanceof AstDeferredExpression
+ || n instanceof AstDynamicExpression) {
+ n = n.jjtGetChild(0);
+ }
+ return n;
+ }
- /*
- * (non-Javadoc)
- *
- * @see com.sun.el.parser.NodeVisitor#visit(com.sun.el.parser.Node)
- */
- public void visit(Node node) throws ELException {
- if (node instanceof AstFunction) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.sun.el.parser.NodeVisitor#visit(com.sun.el.parser.Node)
+ */
+ @Override
+ public void visit(Node node) throws ELException {
+ if (node instanceof AstFunction) {
- AstFunction funcNode = (AstFunction) node;
+ AstFunction funcNode = (AstFunction) node;
- if (this.fnMapper == null) {
- throw new ELException(MessageFactory.get("error.fnMapper.null"));
- }
- Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode
- .getLocalName());
- if (m == null) {
- throw new ELException(MessageFactory.get(
- "error.fnMapper.method", funcNode.getOutputName()));
- }
- int pcnt = m.getParameterTypes().length;
- if (node.jjtGetNumChildren() != pcnt) {
- throw new ELException(MessageFactory.get(
- "error.fnMapper.paramcount", funcNode.getOutputName(),
- "" + pcnt, "" + node.jjtGetNumChildren()));
- }
- } else if (node instanceof AstIdentifier && this.varMapper != null) {
- String variable = ((AstIdentifier) node).getImage();
+ if (this.fnMapper == null) {
+ throw new ELException(MessageFactory.get("error.fnMapper.null"));
+ }
+ Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode
+ .getLocalName());
+ if (m == null) {
+ throw new ELException(MessageFactory.get(
+ "error.fnMapper.method", funcNode.getOutputName()));
+ }
+ int pcnt = m.getParameterTypes().length;
+ if (node.jjtGetNumChildren() != pcnt) {
+ throw new ELException(MessageFactory.get(
+ "error.fnMapper.paramcount", funcNode.getOutputName(),
+ "" + pcnt, "" + node.jjtGetNumChildren()));
+ }
+ } else if (node instanceof AstIdentifier && this.varMapper != null) {
+ String variable = ((AstIdentifier) node).getImage();
- // simply capture it
- this.varMapper.resolveVariable(variable);
- }
- }
+ // simply capture it
+ this.varMapper.resolveVariable(variable);
+ }
+ }
- public ValueExpression createValueExpression(Class expectedType)
- throws ELException {
- Node n = this.build();
- return new ValueExpressionImpl(this.expression, n, this.fnMapper,
- this.varMapper, expectedType);
- }
+ public ValueExpression createValueExpression(Class<?> expectedType)
+ throws ELException {
+ Node n = this.build();
+ return new ValueExpressionImpl(this.expression, n, this.fnMapper,
+ this.varMapper, expectedType);
+ }
- public MethodExpression createMethodExpression(Class expectedReturnType,
- Class[] expectedParamTypes) throws ELException {
- Node n = this.build();
- if (n instanceof AstValue || n instanceof AstIdentifier) {
- return new MethodExpressionImpl(expression, n, this.fnMapper,
- this.varMapper, expectedReturnType, expectedParamTypes);
- } else if (n instanceof AstLiteralExpression) {
- return new MethodExpressionLiteral(expression, expectedReturnType,
- expectedParamTypes);
- } else {
- throw new ELException("Not a Valid Method Expression: "
- + expression);
- }
- }
+ public MethodExpression createMethodExpression(Class<?> expectedReturnType,
+ Class<?>[] expectedParamTypes) throws ELException {
+ Node n = this.build();
+ if (!n.isParametersProvided() && expectedParamTypes == null) {
+ throw new NullPointerException(MessageFactory
+ .get("error.method.nullParms"));
+ }
+ if (n instanceof AstValue || n instanceof AstIdentifier) {
+ return new MethodExpressionImpl(expression, n, this.fnMapper,
+ this.varMapper, expectedReturnType, expectedParamTypes);
+ } else if (n instanceof AstLiteralExpression) {
+ return new MethodExpressionLiteral(expression, expectedReturnType,
+ expectedParamTypes);
+ } else {
+ throw new ELException("Not a Valid Method Expression: "
+ + expression);
+ }
+ }
}
Modified: trunk/java/org/apache/el/lang/FunctionMapperFactory.java
===================================================================
--- trunk/java/org/apache/el/lang/FunctionMapperFactory.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/FunctionMapperFactory.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -23,24 +23,25 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class FunctionMapperFactory extends FunctionMapper {
protected FunctionMapperImpl memento = null;
protected FunctionMapper target;
-
+
public FunctionMapperFactory(FunctionMapper mapper) {
if (mapper == null) {
throw new NullPointerException("FunctionMapper target cannot be null");
}
this.target = mapper;
}
-
-
+
+
/* (non-Javadoc)
* @see javax.el.FunctionMapper#resolveFunction(java.lang.String, java.lang.String)
*/
+ @Override
public Method resolveFunction(String prefix, String localName) {
if (this.memento == null) {
this.memento = new FunctionMapperImpl();
@@ -51,7 +52,7 @@
}
return m;
}
-
+
public FunctionMapper create() {
return this.memento;
}
Modified: trunk/java/org/apache/el/lang/FunctionMapperImpl.java
===================================================================
--- trunk/java/org/apache/el/lang/FunctionMapperImpl.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/FunctionMapperImpl.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -32,24 +32,25 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class FunctionMapperImpl extends FunctionMapper implements
Externalizable {
private static final long serialVersionUID = 1L;
-
- protected Map functions = null;
+ protected Map<String, Function> functions = null;
+
/*
* (non-Javadoc)
- *
+ *
* @see javax.el.FunctionMapper#resolveFunction(java.lang.String,
* java.lang.String)
*/
+ @Override
public Method resolveFunction(String prefix, String localName) {
if (this.functions != null) {
- Function f = (Function) this.functions.get(prefix + ":" + localName);
+ Function f = this.functions.get(prefix + ":" + localName);
return f.getMethod();
}
return null;
@@ -57,7 +58,7 @@
public void addFunction(String prefix, String localName, Method m) {
if (this.functions == null) {
- this.functions = new HashMap();
+ this.functions = new HashMap<String, Function>();
}
Function f = new Function(prefix, localName, m);
synchronized (this) {
@@ -67,34 +68,37 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.functions);
}
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
+ @SuppressWarnings("unchecked")
+ @Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
- this.functions = (Map) in.readObject();
+ this.functions = (Map<String, Function>) in.readObject();
}
-
+
public static class Function implements Externalizable {
-
+
protected transient Method m;
protected String owner;
protected String name;
protected String[] types;
protected String prefix;
protected String localName;
-
+
/**
- *
+ *
*/
public Function(String prefix, String localName, Method m) {
if (localName == null) {
@@ -107,41 +111,43 @@
this.localName = localName;
this.m = m;
}
-
+
public Function() {
// for serialization
}
-
+
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF((this.prefix != null) ? this.prefix : "");
out.writeUTF(this.localName);
// make sure m isn't null
getMethod();
- out.writeUTF((this.owner != null) ?
- this.owner :
+ out.writeUTF((this.owner != null) ?
+ this.owner :
this.m.getDeclaringClass().getName());
- out.writeUTF((this.name != null) ?
- this.name :
+ out.writeUTF((this.name != null) ?
+ this.name :
this.m.getName());
- out.writeObject((this.types != null) ?
- this.types :
+ out.writeObject((this.types != null) ?
+ this.types :
ReflectionUtil.toTypeNameArray(this.m.getParameterTypes()));
}
-
+
/*
* (non-Javadoc)
- *
+ *
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
+ @Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
-
+
this.prefix = in.readUTF();
if ("".equals(this.prefix)) this.prefix = null;
this.localName = in.readUTF();
@@ -149,12 +155,12 @@
this.name = in.readUTF();
this.types = (String[]) in.readObject();
}
-
+
public Method getMethod() {
if (this.m == null) {
try {
- Class t = ReflectionUtil.forName(this.owner);
- Class[] p = ReflectionUtil.toTypeArray(this.types);
+ Class<?> t = ReflectionUtil.forName(this.owner);
+ Class<?>[] p = ReflectionUtil.toTypeArray(this.types);
this.m = t.getMethod(this.name, p);
} catch (Exception e) {
e.printStackTrace();
@@ -162,28 +168,22 @@
}
return this.m;
}
-
- public boolean matches(String prefix, String localName) {
- if (this.prefix != null) {
- if (prefix == null) return false;
- if (!this.prefix.equals(prefix)) return false;
- }
- return this.localName.equals(localName);
- }
-
+
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object obj) {
if (obj instanceof Function) {
return this.hashCode() == obj.hashCode();
}
return false;
}
-
+
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
return (this.prefix + this.localName).hashCode();
}
Modified: trunk/java/org/apache/el/lang/VariableMapperFactory.java
===================================================================
--- trunk/java/org/apache/el/lang/VariableMapperFactory.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/VariableMapperFactory.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -24,18 +24,19 @@
private final VariableMapper target;
private VariableMapper momento;
-
+
public VariableMapperFactory(VariableMapper target) {
if (target == null) {
throw new NullPointerException("Target VariableMapper cannot be null");
}
this.target = target;
}
-
+
public VariableMapper create() {
return this.momento;
}
+ @Override
public ValueExpression resolveVariable(String variable) {
ValueExpression expr = this.target.resolveVariable(variable);
if (expr != null) {
@@ -47,6 +48,7 @@
return expr;
}
+ @Override
public ValueExpression setVariable(String variable, ValueExpression expression) {
throw new UnsupportedOperationException("Cannot Set Variables on Factory");
}
Modified: trunk/java/org/apache/el/lang/VariableMapperImpl.java
===================================================================
--- trunk/java/org/apache/el/lang/VariableMapperImpl.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/lang/VariableMapperImpl.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -30,26 +30,31 @@
public class VariableMapperImpl extends VariableMapper implements Externalizable {
private static final long serialVersionUID = 1L;
-
- private Map vars = new HashMap();
-
+
+ private Map<String, ValueExpression> vars = new HashMap<String, ValueExpression>();
+
public VariableMapperImpl() {
super();
}
+ @Override
public ValueExpression resolveVariable(String variable) {
- return (ValueExpression) this.vars.get(variable);
+ return this.vars.get(variable);
}
+ @Override
public ValueExpression setVariable(String variable,
ValueExpression expression) {
- return (ValueExpression) this.vars.put(variable, expression);
+ return this.vars.put(variable, expression);
}
+ @SuppressWarnings("unchecked")
+ @Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- this.vars = (Map) in.readObject();
+ this.vars = (Map<String, ValueExpression>) in.readObject();
}
+ @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.vars);
}
Modified: trunk/java/org/apache/el/parser/ArithmeticNode.java
===================================================================
--- trunk/java/org/apache/el/parser/ArithmeticNode.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/ArithmeticNode.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -24,7 +24,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class ArithmeticNode extends SimpleNode {
@@ -35,7 +35,8 @@
super(i);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return Number.class;
}
Modified: trunk/java/org/apache/el/parser/AstAnd.java
===================================================================
--- trunk/java/org/apache/el/parser/AstAnd.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstAnd.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstAnd extends BooleanNode {
public AstAnd(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj = children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstBracketSuffix.java
===================================================================
--- trunk/java/org/apache/el/parser/AstBracketSuffix.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstBracketSuffix.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,26 +25,16 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstBracketSuffix extends SimpleNode {
public AstBracketSuffix(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.children[0].getValue(ctx);
}
-
- public Object getParameters(EvaluationContext ctx)
- throws ELException {
- if (jjtGetNumChildren() < 2)
- return new Object[0];
- Object[] params = new Object[jjtGetNumChildren() - 1];
- for (int i = 1; i < jjtGetNumChildren(); i++) {
- params[i - 1] = jjtGetChild(i).getValue(ctx);
- }
- return params;
- }
}
Modified: trunk/java/org/apache/el/parser/AstChoice.java
===================================================================
--- trunk/java/org/apache/el/parser/AstChoice.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstChoice.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,19 +25,21 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstChoice extends SimpleNode {
public AstChoice(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
Object val = this.getValue(ctx);
return (val != null) ? val.getClass() : null;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstCompositeExpression.java
===================================================================
--- trunk/java/org/apache/el/parser/AstCompositeExpression.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstCompositeExpression.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,7 +26,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstCompositeExpression extends SimpleNode {
@@ -34,11 +34,13 @@
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return String.class;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
StringBuilder sb = new StringBuilder(16);
Modified: trunk/java/org/apache/el/parser/AstDeferredExpression.java
===================================================================
--- trunk/java/org/apache/el/parser/AstDeferredExpression.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstDeferredExpression.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,28 +25,32 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstDeferredExpression extends SimpleNode {
public AstDeferredExpression(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return this.children[0].getType(ctx);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.children[0].getValue(ctx);
}
+ @Override
public boolean isReadOnly(EvaluationContext ctx)
throws ELException {
return this.children[0].isReadOnly(ctx);
}
+ @Override
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
this.children[0].setValue(ctx, value);
Modified: trunk/java/org/apache/el/parser/AstDiv.java
===================================================================
--- trunk/java/org/apache/el/parser/AstDiv.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstDiv.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,13 +26,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstDiv extends ArithmeticNode {
public AstDiv(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstDotSuffix.java
===================================================================
--- trunk/java/org/apache/el/parser/AstDotSuffix.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstDotSuffix.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -21,28 +21,31 @@
import javax.el.ELException;
import org.apache.el.lang.EvaluationContext;
+import org.apache.el.util.MessageFactory;
+import org.apache.el.util.Validation;
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstDotSuffix extends SimpleNode {
public AstDotSuffix(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.image;
}
-
- public Object[] getParameters(EvaluationContext ctx)
- throws ELException {
- Object[] params = new Object[jjtGetNumChildren()];
- for (int i = 0; i < jjtGetNumChildren(); i++) {
- params[i] = jjtGetChild(i).getValue(ctx);
+
+ @Override
+ public void setImage(String image) {
+ if (!Validation.isIdentifier(image)) {
+ throw new ELException(MessageFactory.get("error.identifier.notjava",
+ image));
}
- return params;
+ this.image = image;
}
}
Modified: trunk/java/org/apache/el/parser/AstDynamicExpression.java
===================================================================
--- trunk/java/org/apache/el/parser/AstDynamicExpression.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstDynamicExpression.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,28 +25,32 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstDynamicExpression extends SimpleNode {
public AstDynamicExpression(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return this.children[0].getType(ctx);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.children[0].getValue(ctx);
}
+ @Override
public boolean isReadOnly(EvaluationContext ctx)
throws ELException {
return this.children[0].isReadOnly(ctx);
}
+ @Override
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
this.children[0].setValue(ctx, value);
Modified: trunk/java/org/apache/el/parser/AstEmpty.java
===================================================================
--- trunk/java/org/apache/el/parser/AstEmpty.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstEmpty.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -28,18 +28,20 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstEmpty extends SimpleNode {
public AstEmpty(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return Boolean.class;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj = this.children[0].getValue(ctx);
@@ -49,10 +51,10 @@
return Boolean.valueOf(((String) obj).length() == 0);
} else if (obj instanceof Object[]) {
return Boolean.valueOf(((Object[]) obj).length == 0);
- } else if (obj instanceof Collection) {
- return Boolean.valueOf(((Collection) obj).isEmpty());
- } else if (obj instanceof Map) {
- return Boolean.valueOf(((Map) obj).isEmpty());
+ } else if (obj instanceof Collection<?>) {
+ return Boolean.valueOf(((Collection<?>) obj).isEmpty());
+ } else if (obj instanceof Map<?,?>) {
+ return Boolean.valueOf(((Map<?,?>) obj).isEmpty());
}
return Boolean.FALSE;
}
Modified: trunk/java/org/apache/el/parser/AstEqual.java
===================================================================
--- trunk/java/org/apache/el/parser/AstEqual.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstEqual.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstEqual extends BooleanNode {
public AstEqual(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstFalse.java
===================================================================
--- trunk/java/org/apache/el/parser/AstFalse.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstFalse.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstFalse extends BooleanNode {
public AstFalse(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return Boolean.FALSE;
Modified: trunk/java/org/apache/el/parser/AstFloatingPoint.java
===================================================================
--- trunk/java/org/apache/el/parser/AstFloatingPoint.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstFloatingPoint.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -27,14 +27,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstFloatingPoint extends SimpleNode {
public AstFloatingPoint(int id) {
super(id);
}
- private Number number;
+ private volatile Number number;
public Number getFloatingPoint() {
if (this.number == null) {
@@ -47,12 +47,14 @@
return this.number;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.getFloatingPoint();
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return this.getFloatingPoint().getClass();
}
Modified: trunk/java/org/apache/el/parser/AstFunction.java
===================================================================
--- trunk/java/org/apache/el/parser/AstFunction.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstFunction.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -30,7 +30,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstFunction extends SimpleNode {
@@ -58,11 +58,12 @@
return prefix;
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
-
+
FunctionMapper fnMapper = ctx.getFunctionMapper();
-
+
// quickly validate again for this request
if (fnMapper == null) {
throw new ELException(MessageFactory.get("error.fnMapper.null"));
@@ -75,11 +76,12 @@
return m.getReturnType();
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
-
+
FunctionMapper fnMapper = ctx.getFunctionMapper();
-
+
// quickly validate again for this request
if (fnMapper == null) {
throw new ELException(MessageFactory.get("error.fnMapper.null"));
@@ -90,7 +92,7 @@
this.getOutputName()));
}
- Class[] paramTypes = m.getParameterTypes();
+ Class<?>[] paramTypes = m.getParameterTypes();
Object[] params = null;
Object result = null;
int numParams = this.jjtGetNumChildren();
@@ -112,8 +114,15 @@
throw new ELException(MessageFactory.get("error.function", this
.getOutputName()), iae);
} catch (InvocationTargetException ite) {
+ Throwable cause = ite.getCause();
+ if (cause instanceof ThreadDeath) {
+ throw (ThreadDeath) cause;
+ }
+ if (cause instanceof VirtualMachineError) {
+ throw (VirtualMachineError) cause;
+ }
throw new ELException(MessageFactory.get("error.function", this
- .getOutputName()), ite.getCause());
+ .getOutputName()), cause);
}
return result;
}
@@ -125,8 +134,9 @@
public void setPrefix(String prefix) {
this.prefix = prefix;
}
-
-
+
+
+ @Override
public String toString()
{
return ELParserTreeConstants.jjtNodeName[id] + "[" + this.getOutputName() + "]";
Modified: trunk/java/org/apache/el/parser/AstGreaterThan.java
===================================================================
--- trunk/java/org/apache/el/parser/AstGreaterThan.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstGreaterThan.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstGreaterThan extends BooleanNode {
public AstGreaterThan(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstGreaterThanEqual.java
===================================================================
--- trunk/java/org/apache/el/parser/AstGreaterThanEqual.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstGreaterThanEqual.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstGreaterThanEqual extends BooleanNode {
public AstGreaterThanEqual(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstIdentifier.java
===================================================================
--- trunk/java/org/apache/el/parser/AstIdentifier.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstIdentifier.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -27,18 +27,21 @@
import javax.el.VariableMapper;
import org.apache.el.lang.EvaluationContext;
+import org.apache.el.util.MessageFactory;
+import org.apache.el.util.Validation;
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstIdentifier extends SimpleNode {
public AstIdentifier(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx) throws ELException {
+ @Override
+ public Class<?> getType(EvaluationContext ctx) throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
if (varMapper != null) {
ValueExpression expr = varMapper.resolveVariable(this.image);
@@ -47,14 +50,15 @@
}
}
ctx.setPropertyResolved(false);
- Class result = ctx.getELResolver().getType(ctx, null, this.image);
- if (ctx.isPropertyResolved()) {
- return result;
- } else {
- throw new PropertyNotFoundException("Could not resolve property '" + this.image + "'");
+ Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled.null", this.image));
}
+ return result;
}
+ @Override
public Object getValue(EvaluationContext ctx) throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
if (varMapper != null) {
@@ -65,13 +69,14 @@
}
ctx.setPropertyResolved(false);
Object result = ctx.getELResolver().getValue(ctx, null, this.image);
- if (ctx.isPropertyResolved()) {
- return result;
- } else {
- throw new PropertyNotFoundException("Could not resolve property '" + this.image + "'");
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled.null", this.image));
}
+ return result;
}
+ @Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
if (varMapper != null) {
@@ -82,13 +87,14 @@
}
ctx.setPropertyResolved(false);
boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
- if (ctx.isPropertyResolved()) {
- return result;
- } else {
- throw new PropertyNotFoundException("Could not resolve property '" + this.image + "'");
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled.null", this.image));
}
+ return result;
}
+ @Override
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
@@ -102,38 +108,33 @@
ctx.setPropertyResolved(false);
ctx.getELResolver().setValue(ctx, null, this.image, value);
if (!ctx.isPropertyResolved()) {
- throw new PropertyNotFoundException("Could not resolve property '" + this.image + "'");
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled.null", this.image));
}
}
- private final Object invokeTarget(EvaluationContext ctx, Object target,
+ @Override
+ public Object invoke(EvaluationContext ctx, Class<?>[] paramTypes,
Object[] paramValues) throws ELException {
- if (target instanceof MethodExpression) {
- MethodExpression me = (MethodExpression) target;
- return me.invoke(ctx.getELContext(), paramValues);
- } else if (target == null) {
- throw new MethodNotFoundException("Identity '" + this.image
- + "' was null and was unable to invoke");
- } else {
- throw new ELException(
- "Identity '"
- + this.image
- + "' does not reference a MethodExpression instance, returned type: "
- + target.getClass().getName());
- }
- }
-
- public Object invoke(EvaluationContext ctx, Class[] paramTypes,
- Object[] paramValues) throws ELException {
return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues);
}
-
- public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes)
- throws ELException {
+
+ @Override
+ public MethodInfo getMethodInfo(EvaluationContext ctx,
+ Class<?>[] paramTypes) throws ELException {
return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext());
}
+ @Override
+ public void setImage(String image) {
+ if (!Validation.isIdentifier(image)) {
+ throw new ELException(MessageFactory.get("error.identifier.notjava",
+ image));
+ }
+ this.image = image;
+ }
+
private final MethodExpression getMethodExpression(EvaluationContext ctx)
throws ELException {
Object obj = null;
Modified: trunk/java/org/apache/el/parser/AstInteger.java
===================================================================
--- trunk/java/org/apache/el/parser/AstInteger.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstInteger.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -27,14 +27,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstInteger extends SimpleNode {
public AstInteger(int id) {
super(id);
}
- private Number number;
+ private volatile Number number;
protected Number getInteger() {
if (this.number == null) {
@@ -47,11 +47,13 @@
return number;
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return this.getInteger().getClass();
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.getInteger();
Modified: trunk/java/org/apache/el/parser/AstLessThan.java
===================================================================
--- trunk/java/org/apache/el/parser/AstLessThan.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstLessThan.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstLessThan extends BooleanNode {
public AstLessThan(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstLessThanEqual.java
===================================================================
--- trunk/java/org/apache/el/parser/AstLessThanEqual.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstLessThanEqual.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstLessThanEqual extends BooleanNode {
public AstLessThanEqual(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstLiteralExpression.java
===================================================================
--- trunk/java/org/apache/el/parser/AstLiteralExpression.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstLiteralExpression.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,21 +25,24 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstLiteralExpression extends SimpleNode {
public AstLiteralExpression(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx) throws ELException {
+ @Override
+ public Class<?> getType(EvaluationContext ctx) throws ELException {
return String.class;
}
+ @Override
public Object getValue(EvaluationContext ctx) throws ELException {
return this.image;
}
+ @Override
public void setImage(String image) {
if (image.indexOf('\\') == -1) {
this.image = image;
Added: trunk/java/org/apache/el/parser/AstMethodParameters.java
===================================================================
--- trunk/java/org/apache/el/parser/AstMethodParameters.java (rev 0)
+++ trunk/java/org/apache/el/parser/AstMethodParameters.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+/* Generated By:JJTree: Do not edit this line. AstDotSuffix.java */
+
+package org.apache.el.parser;
+
+import java.util.ArrayList;
+
+import org.apache.el.lang.EvaluationContext;
+
+/**
+ * $Id: AstMethodParameters.java 1187802 2011-10-22 21:17:12Z markt $
+ */
+public final class AstMethodParameters extends SimpleNode {
+ public AstMethodParameters(int id) {
+ super(id);
+ }
+
+ public Object[] getParameters(EvaluationContext ctx) {
+ ArrayList<Object> params = new ArrayList<Object>();
+ for (int i = 0; i < this.jjtGetNumChildren(); i++) {
+ params.add(this.jjtGetChild(i).getValue(ctx));
+ }
+ return params.toArray(new Object[params.size()]);
+ }
+
+ public Class<?>[] getParameterTypes(EvaluationContext ctx) {
+ ArrayList<Class<?>> paramTypes = new ArrayList<Class<?>>();
+ for (int i = 0; i < this.jjtGetNumChildren(); i++) {
+ paramTypes.add(this.jjtGetChild(i).getType(ctx));
+ }
+ return paramTypes.toArray(new Class<?>[paramTypes.size()]);
+ }
+}
Modified: trunk/java/org/apache/el/parser/AstMinus.java
===================================================================
--- trunk/java/org/apache/el/parser/AstMinus.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstMinus.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,13 +26,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstMinus extends ArithmeticNode {
public AstMinus(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstMod.java
===================================================================
--- trunk/java/org/apache/el/parser/AstMod.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstMod.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,13 +26,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstMod extends ArithmeticNode {
public AstMod(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstMult.java
===================================================================
--- trunk/java/org/apache/el/parser/AstMult.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstMult.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,13 +26,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstMult extends ArithmeticNode {
public AstMult(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstNegative.java
===================================================================
--- trunk/java/org/apache/el/parser/AstNegative.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstNegative.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -28,24 +28,26 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstNegative extends SimpleNode {
public AstNegative(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return Number.class;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj = this.children[0].getValue(ctx);
if (obj == null) {
- return new Long(0);
+ return Long.valueOf(0);
}
if (obj instanceof BigDecimal) {
return ((BigDecimal) obj).negate();
@@ -57,27 +59,27 @@
if (isStringFloat((String) obj)) {
return new Double(-Double.parseDouble((String) obj));
}
- return new Long(-Long.parseLong((String) obj));
+ return Long.valueOf(-Long.parseLong((String) obj));
}
if (obj instanceof Long) {
- return new Long(-((Long) obj).longValue());
+ return Long.valueOf(-((Long) obj).longValue());
}
if (obj instanceof Double) {
return new Double(-((Double) obj).doubleValue());
}
if (obj instanceof Integer) {
- return new Integer(-((Integer) obj).intValue());
+ return Integer.valueOf(-((Integer) obj).intValue());
}
if (obj instanceof Float) {
return new Float(-((Float) obj).floatValue());
}
if (obj instanceof Short) {
- return new Short((short) -((Short) obj).shortValue());
+ return Short.valueOf((short) -((Short) obj).shortValue());
}
if (obj instanceof Byte) {
- return new Byte((byte) -((Byte) obj).byteValue());
+ return Byte.valueOf((byte) -((Byte) obj).byteValue());
}
Long num = (Long) coerceToNumber(obj, Long.class);
- return new Long(-num.longValue());
+ return Long.valueOf(-num.longValue());
}
}
Modified: trunk/java/org/apache/el/parser/AstNot.java
===================================================================
--- trunk/java/org/apache/el/parser/AstNot.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstNot.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,18 +25,20 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstNot extends SimpleNode {
public AstNot(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return Boolean.class;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstNotEqual.java
===================================================================
--- trunk/java/org/apache/el/parser/AstNotEqual.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstNotEqual.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstNotEqual extends BooleanNode {
public AstNotEqual(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstNull.java
===================================================================
--- trunk/java/org/apache/el/parser/AstNull.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstNull.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,18 +25,20 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstNull extends SimpleNode {
public AstNull(int id) {
super(id);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return null;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return null;
Modified: trunk/java/org/apache/el/parser/AstOr.java
===================================================================
--- trunk/java/org/apache/el/parser/AstOr.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstOr.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstOr extends BooleanNode {
public AstOr(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstPlus.java
===================================================================
--- trunk/java/org/apache/el/parser/AstPlus.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstPlus.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -26,13 +26,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstPlus extends ArithmeticNode {
public AstPlus(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
Object obj0 = this.children[0].getValue(ctx);
Modified: trunk/java/org/apache/el/parser/AstString.java
===================================================================
--- trunk/java/org/apache/el/parser/AstString.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstString.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,14 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstString extends SimpleNode {
public AstString(int id) {
super(id);
}
- private String string;
+ private volatile String string;
public String getString() {
if (this.string == null) {
@@ -41,16 +41,19 @@
return this.string;
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return String.class;
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return this.getString();
}
+ @Override
public void setImage(String image) {
if (image.indexOf('\\') == -1) {
this.image = image;
Modified: trunk/java/org/apache/el/parser/AstTrue.java
===================================================================
--- trunk/java/org/apache/el/parser/AstTrue.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstTrue.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -25,13 +25,14 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstTrue extends BooleanNode {
public AstTrue(int id) {
super(id);
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
return Boolean.TRUE;
Modified: trunk/java/org/apache/el/parser/AstValue.java
===================================================================
--- trunk/java/org/apache/el/parser/AstValue.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/AstValue.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -18,8 +18,11 @@
package org.apache.el.parser;
+import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.el.ELException;
import javax.el.ELResolver;
@@ -35,16 +38,38 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class AstValue extends SimpleNode {
- protected static final boolean COERCE_TO_ZERO =
- Boolean.valueOf(System.getProperty(
- "org.apache.el.parser.COERCE_TO_ZERO", "true")).booleanValue();
+ private static final boolean IS_SECURITY_ENABLED =
+ (System.getSecurityManager() != null);
+ protected static final boolean COERCE_TO_ZERO;
+
+ static {
+ if (IS_SECURITY_ENABLED) {
+ COERCE_TO_ZERO = AccessController.doPrivileged(
+ new PrivilegedAction<Boolean>(){
+ @Override
+ public Boolean run() {
+ return Boolean.valueOf(System.getProperty(
+ "org.apache.el.parser.COERCE_TO_ZERO",
+ "true"));
+ }
+
+ }
+ ).booleanValue();
+ } else {
+ COERCE_TO_ZERO = Boolean.valueOf(System.getProperty(
+ "org.apache.el.parser.COERCE_TO_ZERO",
+ "true")).booleanValue();
+ }
+ }
+
protected static class Target {
protected Object base;
+
protected Object property;
}
@@ -52,25 +77,23 @@
super(id);
}
- public Class getType(EvaluationContext ctx) throws ELException {
+ @Override
+ public Class<?> getType(EvaluationContext ctx) throws ELException {
Target t = getTarget(ctx);
ctx.setPropertyResolved(false);
- return ctx.getELResolver().getType(ctx, t.base, t.property);
+ Class<?> result = ctx.getELResolver().getType(ctx, t.base, t.property);
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled", t.base, t.property));
+ }
+ return result;
}
- public ValueReference getValueReference(EvaluationContext ctx) {
- try {
- Target t = getTarget(ctx);
- return new ValueReference(t.base, t.property);
- } catch (Exception e) {
- return null;
- }
- }
private final Target getTarget(EvaluationContext ctx) throws ELException {
// evaluate expr-a to value-a
Object base = this.children[0].getValue(ctx);
- // if our base is null (we know there are more properites to evaluate)
+ // if our base is null (we know there are more properties to evaluate)
if (base == null) {
throw new PropertyNotFoundException(MessageFactory.get(
"error.unreachable.base", this.children[0].getImage()));
@@ -78,7 +101,15 @@
// set up our start/end
Object property = null;
- int propCount = this.jjtGetNumChildren() - 1;
+ int propCount = this.jjtGetNumChildren();
+
+ if (propCount > 2 &&
+ this.jjtGetChild(propCount - 1) instanceof AstMethodParameters) {
+ // Method call with paramaters.
+ propCount-=2;
+ } else {
+ propCount--;
+ }
int i = 1;
// evaluate any properties before our target
@@ -111,52 +142,74 @@
return t;
}
+ @Override
public Object getValue(EvaluationContext ctx) throws ELException {
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 AstMethodParameters)) {
+ AstMethodParameters mps =
+ (AstMethodParameters) this.children[i+1];
+ // This is a method
+ base = resolver.invoke(ctx, base, suffix, null,
+ mps.getParameters(ctx));
+ i+=2;
} else {
- Object[] params = null;
- if (this.children[i] instanceof AstDotSuffix) {
- params = ((AstDotSuffix) this.children[i]).getParameters(ctx);
+ // This is a property
+ if (suffix == null) {
+ return null;
}
- if (params != null && params.length > 0) {
- ctx.setPropertyResolved(false);
- base = resolver.invoke(ctx, base, property, null, params);
- } else {
- ctx.setPropertyResolved(false);
- base = resolver.getValue(ctx, base, property);
- }
+
+ ctx.setPropertyResolved(false);
+ base = resolver.getValue(ctx, base, suffix);
+ i++;
}
- i++;
}
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled", base, suffix));
+ }
return base;
}
+ @Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
Target t = getTarget(ctx);
ctx.setPropertyResolved(false);
- return ctx.getELResolver().isReadOnly(ctx, t.base, t.property);
+ boolean result =
+ ctx.getELResolver().isReadOnly(ctx, t.base, t.property);
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled", t.base, t.property));
+ }
+ return result;
}
+ @Override
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
Target t = getTarget(ctx);
ctx.setPropertyResolved(false);
ELResolver resolver = ctx.getELResolver();
+
// coerce to the expected type
Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
- if (COERCE_TO_ZERO
+ if (COERCE_TO_ZERO == true
|| !isAssignable(value, targetClass)) {
- value = ELSupport.coerceToType(value, targetClass);
+ resolver.setValue(ctx, t.base, t.property,
+ ELSupport.coerceToType(value, targetClass));
+ } else {
+ resolver.setValue(ctx, t.base, t.property, value);
}
- resolver.setValue(ctx, t.base, t.property, value);
+ if (!ctx.isPropertyResolved()) {
+ throw new PropertyNotFoundException(MessageFactory.get(
+ "error.resolver.unhandled", t.base, t.property));
+ }
}
private boolean isAssignable(Object value, Class<?> targetClass) {
@@ -170,7 +223,11 @@
return true;
}
- public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes)
+
+ @Override
+ // Interface el.parser.Node uses raw types (and is auto-generated)
+ public MethodInfo getMethodInfo(EvaluationContext ctx,
+ @SuppressWarnings("rawtypes") Class[] paramTypes)
throws ELException {
Target t = getTarget(ctx);
Method m = ReflectionUtil.getMethod(t.base, t.property, paramTypes);
@@ -178,37 +235,104 @@
.getParameterTypes());
}
- public Object invoke(EvaluationContext ctx, Class[] paramTypes,
+ @Override
+ // Interface el.parser.Node uses a raw type (and is auto-generated)
+ public Object invoke(EvaluationContext ctx,
+ @SuppressWarnings("rawtypes") Class[] paramTypes,
Object[] paramValues) throws ELException {
+
Target t = getTarget(ctx);
- Object[] params = null;
- if (jjtGetNumChildren() > 1 && this.children[1] instanceof AstDotSuffix) {
- params = ((AstDotSuffix) this.children[1]).getParameters(ctx);
+ Method m = null;
+ Object[] values = null;
+ if (isParametersProvided()) {
+ values = ((AstMethodParameters)
+ this.jjtGetChild(2)).getParameters(ctx);
+ Class<?>[] types = getTypesFromValues(values);
+ m = ReflectionUtil.getMethod(t.base, t.property, types);
+ } else {
+ m = ReflectionUtil.getMethod(t.base, t.property, paramTypes);
+ values = paramValues;
}
+ if (m.isVarArgs()) {
+ // May need to convert values
+ values = toVarArgs(values, m);
+ }
Object result = null;
- if (params != null && params.length > 0) {
- ELResolver resolver = ctx.getELResolver();
- ctx.setPropertyResolved(false);
- result = resolver.invoke(ctx, t.base, t.property, null, params);
- } else {
- Method m = ReflectionUtil.getMethod(t.base, t.property, paramTypes);
- try {
- result = m.invoke(t.base, (Object[]) paramValues);
- } catch (IllegalAccessException iae) {
- throw new ELException(iae);
- } catch (InvocationTargetException ite) {
- throw new ELException(ite.getCause());
+ try {
+ result = m.invoke(t.base, values);
+ } catch (IllegalAccessException iae) {
+ throw new ELException(iae);
+ } catch (IllegalArgumentException iae) {
+ throw new ELException(iae);
+ } catch (InvocationTargetException ite) {
+ Throwable cause = ite.getCause();
+ if (cause instanceof ThreadDeath) {
+ throw (ThreadDeath) cause;
}
+ if (cause instanceof VirtualMachineError) {
+ throw (VirtualMachineError) cause;
+ }
+ throw new ELException(cause);
}
return result;
}
-
+
+ private Object[] toVarArgs(Object[] src, Method m) {
+ int paramCount = m.getParameterTypes().length;
+
+ Object[] dest = new Object[paramCount];
+ Object[] varArgs = (Object[]) Array.newInstance(
+ m.getParameterTypes()[paramCount - 1].getComponentType(),
+ src.length - (paramCount - 1));
+ System.arraycopy(src, 0, dest, 0, paramCount - 1);
+ System.arraycopy(src, paramCount - 1, varArgs, 0,
+ src.length - (paramCount - 1));
+ dest[paramCount - 1] = varArgs;
+ return dest;
+ }
+
+ private Class<?>[] getTypesFromValues(Object[] values) {
+ if (values == null) {
+ return null;
+ }
+
+ Class<?> result[] = new Class<?>[values.length];
+ for (int i = 0; i < values.length; i++) {
+ if (values[i] == null) {
+ result[i] = null;
+ } else {
+ result[i] = values[i].getClass();
+ }
+ }
+ return result;
+ }
+
+
+ /**
+ * @since EL 2.2
+ */
+ @Override
+ public ValueReference getValueReference(EvaluationContext ctx) {
+ // Check this is a reference to a base and a property
+ if (this.children.length > 2 &&
+ this.jjtGetChild(2) instanceof AstMethodParameters) {
+ // This is a method call
+ return null;
+ }
+ Target t = getTarget(ctx);
+ return new ValueReference(t.base, t.property);
+ }
+
+
+ /**
+ * @since EL 2.2
+ */
+ @Override
public boolean isParametersProvided() {
- if (jjtGetNumChildren() > 1 && this.children[1] != null &&
- this.children[1] instanceof AstDotSuffix) {
- return (this.children[1].jjtGetNumChildren()) > 0;
+ if (this.children.length > 2
+ && this.jjtGetChild(2) instanceof AstMethodParameters) {
+ return true;
}
return false;
}
-
}
Modified: trunk/java/org/apache/el/parser/BooleanNode.java
===================================================================
--- trunk/java/org/apache/el/parser/BooleanNode.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/BooleanNode.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -23,7 +23,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class BooleanNode extends SimpleNode {
/**
@@ -32,7 +32,8 @@
public BooleanNode(int i) {
super(i);
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
return Boolean.class;
}
Modified: trunk/java/org/apache/el/parser/ELParser.java
===================================================================
--- trunk/java/org/apache/el/parser/ELParser.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/ELParser.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -1,7 +1,10 @@
/* Generated By:JJTree&JavaCC: Do not edit this line. ELParser.java */
package org.apache.el.parser;
import java.io.StringReader;
+
import javax.el.ELException;
+
+@SuppressWarnings("all") // Ignore warnings in generated code
public class ELParser/*@bgen(jjtree)*/implements ELParserTreeConstants, ELParserConstants {/*@bgen(jjtree)*/
protected JJTELParserState jjtree = new JJTELParserState();public static Node parse(String ref) throws ELException
{
@@ -1039,6 +1042,14 @@
jj_consume_token(-1);
throw new ParseException();
}
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LPAREN:
+ MethodParameters();
+ break;
+ default:
+ jj_la1[27] = jj_gen;
+ ;
+ }
}
/*
@@ -1053,17 +1064,29 @@
try {
jj_consume_token(DOT);
t = jj_consume_token(IDENTIFIER);
+ jjtree.closeNodeScope(jjtn000, true);
+ jjtc000 = false;
jjtn000.setImage(t.image);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LPAREN:
- jj_consume_token(LPAREN);
- Parameters();
- jj_consume_token(RPAREN);
- break;
- default:
- jj_la1[27] = jj_gen;
- ;
+ } finally {
+ if (jjtc000) {
+ jjtree.closeNodeScope(jjtn000, true);
}
+ }
+ }
+
+/*
+ * BracketSuffix
+ * Sub Expression Suffix
+ */
+ final public void BracketSuffix() throws ParseException {
+ /*@bgen(jjtree) BracketSuffix */
+ AstBracketSuffix jjtn000 = new AstBracketSuffix(JJTBRACKETSUFFIX);
+ boolean jjtc000 = true;
+ jjtree.openNodeScope(jjtn000);
+ try {
+ jj_consume_token(LBRACK);
+ Expression();
+ jj_consume_token(RBRACK);
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
@@ -1086,28 +1109,48 @@
}
/*
- * BracketSuffix
- * Sub Expression Suffix
+ * MethodParameters
*/
- final public void BracketSuffix() throws ParseException {
- /*@bgen(jjtree) BracketSuffix */
- AstBracketSuffix jjtn000 = new AstBracketSuffix(JJTBRACKETSUFFIX);
+ final public void MethodParameters() throws ParseException {
+ /*@bgen(jjtree) MethodParameters */
+ AstMethodParameters jjtn000 = new AstMethodParameters(JJTMETHODPARAMETERS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
try {
- jj_consume_token(LBRACK);
- Expression();
- jj_consume_token(RBRACK);
+ jj_consume_token(LPAREN);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case INTEGER_LITERAL:
+ case FLOATING_POINT_LITERAL:
+ case STRING_LITERAL:
+ case TRUE:
+ case FALSE:
+ case NULL:
case LPAREN:
- jj_consume_token(LPAREN);
- Parameters();
- jj_consume_token(RPAREN);
+ case NOT0:
+ case NOT1:
+ case EMPTY:
+ case MINUS:
+ case IDENTIFIER:
+ Expression();
+ label_10:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case COMMA:
+ ;
+ break;
+ default:
+ jj_la1[28] = jj_gen;
+ break label_10;
+ }
+ jj_consume_token(COMMA);
+ Expression();
+ }
break;
default:
- jj_la1[28] = jj_gen;
+ jj_la1[29] = jj_gen;
;
}
+ jj_consume_token(RPAREN);
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
@@ -1130,45 +1173,6 @@
}
/*
- * Parameters
- * Method parameters
- */
- final public void Parameters() throws ParseException {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case TRUE:
- case FALSE:
- case NULL:
- case LPAREN:
- case NOT0:
- case NOT1:
- case EMPTY:
- case MINUS:
- case IDENTIFIER:
- Expression();
- break;
- default:
- jj_la1[29] = jj_gen;
- ;
- }
- label_10:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- jj_la1[30] = jj_gen;
- break label_10;
- }
- jj_consume_token(COMMA);
- Expression();
- }
- }
-
-/*
* NonLiteral
* For Grouped Operations, Identifiers, and Functions
*/
@@ -1180,7 +1184,7 @@
jj_consume_token(RPAREN);
break;
default:
- jj_la1[31] = jj_gen;
+ jj_la1[30] = jj_gen;
if (jj_2_2(2147483647)) {
Function();
} else {
@@ -1189,7 +1193,7 @@
Identifier();
break;
default:
- jj_la1[32] = jj_gen;
+ jj_la1[31] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1264,7 +1268,7 @@
;
break;
default:
- jj_la1[33] = jj_gen;
+ jj_la1[32] = jj_gen;
break label_11;
}
jj_consume_token(COMMA);
@@ -1272,7 +1276,7 @@
}
break;
default:
- jj_la1[34] = jj_gen;
+ jj_la1[33] = jj_gen;
;
}
jj_consume_token(RPAREN);
@@ -1320,7 +1324,7 @@
Null();
break;
default:
- jj_la1[35] = jj_gen;
+ jj_la1[34] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1357,7 +1361,7 @@
}
break;
default:
- jj_la1[36] = jj_gen;
+ jj_la1[35] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1465,21 +1469,51 @@
finally { jj_save(2, xla); }
}
- private boolean jj_3R_59() {
- if (jj_3R_69()) return true;
+ private boolean jj_3R_13() {
+ if (jj_scan_token(IDENTIFIER)) return true;
+ if (jj_scan_token(COLON)) return true;
return false;
}
- private boolean jj_3R_58() {
- if (jj_3R_68()) return true;
+ private boolean jj_3_2() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_13()) jj_scanpos = xsp;
+ if (jj_scan_token(IDENTIFIER)) return true;
+ if (jj_scan_token(LPAREN)) return true;
return false;
}
+ private boolean jj_3R_69() {
+ if (jj_scan_token(IDENTIFIER)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_25() {
+ if (jj_3R_31()) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_32()) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
+ private boolean jj_3R_59() {
+ if (jj_3R_69()) return true;
+ return false;
+ }
+
private boolean jj_3R_34() {
if (jj_scan_token(MINUS)) return true;
return false;
}
+ private boolean jj_3R_58() {
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
private boolean jj_3R_26() {
Token xsp;
xsp = jj_scanpos;
@@ -1595,13 +1629,13 @@
return false;
}
- private boolean jj_3R_64() {
- if (jj_scan_token(INTEGER_LITERAL)) return true;
+ private boolean jj_3R_51() {
+ if (jj_3R_61()) return true;
return false;
}
- private boolean jj_3R_51() {
- if (jj_3R_61()) return true;
+ private boolean jj_3R_64() {
+ if (jj_scan_token(INTEGER_LITERAL)) return true;
return false;
}
@@ -1655,6 +1689,11 @@
return false;
}
+ private boolean jj_3R_50() {
+ if (jj_3R_60()) return true;
+ return false;
+ }
+
private boolean jj_3R_18() {
Token xsp;
xsp = jj_scanpos;
@@ -1665,16 +1704,6 @@
return false;
}
- private boolean jj_3R_71() {
- if (jj_scan_token(FALSE)) return true;
- return false;
- }
-
- private boolean jj_3R_50() {
- if (jj_3R_60()) return true;
- return false;
- }
-
private boolean jj_3R_47() {
Token xsp;
xsp = jj_scanpos;
@@ -1685,6 +1714,11 @@
return false;
}
+ private boolean jj_3R_71() {
+ if (jj_scan_token(FALSE)) return true;
+ return false;
+ }
+
private boolean jj_3R_17() {
if (jj_3R_19()) return true;
Token xsp;
@@ -1750,11 +1784,6 @@
return false;
}
- private boolean jj_3R_55() {
- if (jj_3R_65()) return true;
- return false;
- }
-
private boolean jj_3R_16() {
Token xsp;
xsp = jj_scanpos;
@@ -1765,6 +1794,11 @@
return false;
}
+ private boolean jj_3R_55() {
+ if (jj_3R_65()) return true;
+ return false;
+ }
+
private boolean jj_3R_54() {
if (jj_3R_64()) return true;
return false;
@@ -1938,36 +1972,6 @@
return false;
}
- private boolean jj_3R_13() {
- if (jj_scan_token(IDENTIFIER)) return true;
- if (jj_scan_token(COLON)) return true;
- return false;
- }
-
- private boolean jj_3_2() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_13()) jj_scanpos = xsp;
- if (jj_scan_token(IDENTIFIER)) return true;
- if (jj_scan_token(LPAREN)) return true;
- return false;
- }
-
- private boolean jj_3R_69() {
- if (jj_scan_token(IDENTIFIER)) return true;
- return false;
- }
-
- private boolean jj_3R_25() {
- if (jj_3R_31()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_32()) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
/** Generated Token Manager. */
public ELParserTokenManager token_source;
SimpleCharStream jj_input_stream;
@@ -1979,7 +1983,7 @@
private Token jj_scanpos, jj_lastpos;
private int jj_la;
private int jj_gen;
- final private int[] jj_la1 = new int[37];
+ final private int[] jj_la1 = new int[36];
static private int[] jj_la1_0;
static private int[] jj_la1_1;
static {
@@ -1987,10 +1991,10 @@
jj_la1_init_1();
}
private static void jj_la1_init_0() {
- jj_la1_0 = new int[] {0xe,0xe,0x0,0x0,0x0,0x0,0x80000000,0x80000000,0x0,0x80000000,0x7f800000,0x6000000,0x1800000,0x60000000,0x18000000,0x7f800000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x27b00,0x90000,0x27b00,0x90000,0x20000,0x20000,0x27b00,0x400000,0x20000,0x0,0x400000,0x27b00,0x7b00,0x3000,};
+ jj_la1_0 = new int[] {0xe,0xe,0x0,0x0,0x0,0x0,0x80000000,0x80000000,0x0,0x80000000,0x7f800000,0x6000000,0x1800000,0x60000000,0x18000000,0x7f800000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x27b00,0x90000,0x27b00,0x90000,0x20000,0x400000,0x27b00,0x20000,0x0,0x400000,0x27b00,0x7b00,0x3000,};
}
private static void jj_la1_init_1() {
- jj_la1_1 = new int[] {0x0,0x0,0x180,0x180,0x60,0x60,0x7,0x1,0x6,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x3000,0x3000,0x78800,0x18000,0x60000,0x78800,0x18,0x82218,0x0,0x80000,0x0,0x0,0x0,0x82218,0x0,0x0,0x80000,0x0,0x82218,0x0,0x0,};
+ jj_la1_1 = new int[] {0x0,0x0,0x180,0x180,0x60,0x60,0x7,0x1,0x6,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x3000,0x3000,0x78800,0x18000,0x60000,0x78800,0x18,0x82218,0x0,0x80000,0x0,0x0,0x0,0x82218,0x0,0x80000,0x0,0x82218,0x0,0x0,};
}
final private JJCalls[] jj_2_rtns = new JJCalls[3];
private boolean jj_rescan = false;
@@ -2007,7 +2011,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2023,7 +2027,7 @@
jj_ntk = -1;
jjtree.reset();
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2034,7 +2038,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2046,7 +2050,7 @@
jj_ntk = -1;
jjtree.reset();
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2056,7 +2060,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2067,7 +2071,7 @@
jj_ntk = -1;
jjtree.reset();
jj_gen = 0;
- for (int i = 0; i < 37; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 36; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2184,7 +2188,7 @@
la1tokens[jj_kind] = true;
jj_kind = -1;
}
- for (int i = 0; i < 37; i++) {
+ for (int i = 0; i < 36; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
Modified: trunk/java/org/apache/el/parser/ELParser.jjt
===================================================================
--- trunk/java/org/apache/el/parser/ELParser.jjt 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/ELParser.jjt 2011-12-06 15:27:15 UTC (rev 1882)
@@ -232,7 +232,7 @@
*/
void ValueSuffix() : {}
{
- DotSuffix() | BracketSuffix()
+ ( DotSuffix() | BracketSuffix() ) ( MethodParameters())?
}
/*
@@ -241,7 +241,7 @@
*/
void DotSuffix() #DotSuffix : { Token t = null; }
{
- <DOT> t=<IDENTIFIER> { jjtThis.setImage(t.image); } (<LPAREN> Parameters() <RPAREN>)?
+ <DOT> t=<IDENTIFIER> { jjtThis.setImage(t.image); }
}
/*
@@ -250,16 +250,15 @@
*/
void BracketSuffix() #BracketSuffix : {}
{
- <LBRACK> Expression() <RBRACK> (<LPAREN> Parameters() <RPAREN>)?
+ <LBRACK> Expression() <RBRACK>
}
/*
- * Parameters
- * Method parameters
+ * MethodParameters
*/
-void Parameters() : {}
+void MethodParameters() #MethodParameters : {}
{
- (Expression())? (<COMMA> Expression())*
+ <LPAREN> ( Expression() ( <COMMA> Expression())* )? <RPAREN>
}
/*
Modified: trunk/java/org/apache/el/parser/ELParserTokenManager.java
===================================================================
--- trunk/java/org/apache/el/parser/ELParserTokenManager.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/ELParserTokenManager.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -1,9 +1,8 @@
/* Generated By:JJTree&JavaCC: Do not edit this line. ELParserTokenManager.java */
package org.apache.el.parser;
-import java.io.StringReader;
-import javax.el.ELException;
/** Token Manager. */
+@SuppressWarnings("all") // Ignore warnings in generated code
public class ELParserTokenManager implements ELParserConstants
{
@@ -1036,9 +1035,9 @@
}
}
static final int[] jjnextStates = {
- 0, 1, 3, 4, 2, 0, 1, 4, 2, 0, 1, 4, 5, 2, 0, 1,
- 2, 6, 16, 17, 18, 23, 24, 11, 12, 14, 6, 7, 9, 3, 4, 21,
- 22, 25, 26,
+ 0, 1, 3, 4, 2, 0, 1, 4, 2, 0, 1, 4, 5, 2, 0, 1,
+ 2, 6, 16, 17, 18, 23, 24, 11, 12, 14, 6, 7, 9, 3, 4, 21,
+ 22, 25, 26,
};
private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
{
@@ -1075,12 +1074,12 @@
/** Token literal values. */
public static final String[] jjstrLiteralImages = {
-"", null, "\44\173", "\43\173", null, null, null, null, null, null, null, null,
-"\164\162\165\145", "\146\141\154\163\145", "\156\165\154\154", "\175", "\56", "\50", "\51",
-"\133", "\135", "\72", "\54", "\76", "\147\164", "\74", "\154\164", "\76\75",
-"\147\145", "\74\75", "\154\145", "\75\75", "\145\161", "\41\75", "\156\145", "\41",
-"\156\157\164", "\46\46", "\141\156\144", "\174\174", "\157\162", "\145\155\160\164\171",
-"\151\156\163\164\141\156\143\145\157\146", "\52", "\53", "\55", "\77", "\57", "\144\151\166", "\45", "\155\157\144", null,
+"", null, "\44\173", "\43\173", null, null, null, null, null, null, null, null,
+"\164\162\165\145", "\146\141\154\163\145", "\156\165\154\154", "\175", "\56", "\50", "\51",
+"\133", "\135", "\72", "\54", "\76", "\147\164", "\74", "\154\164", "\76\75",
+"\147\145", "\74\75", "\154\145", "\75\75", "\145\161", "\41\75", "\156\145", "\41",
+"\156\157\164", "\46\46", "\141\156\144", "\174\174", "\157\162", "\145\155\160\164\171",
+"\151\156\163\164\141\156\143\145\157\146", "\52", "\53", "\55", "\77", "\57", "\144\151\166", "\45", "\155\157\144", null,
null, null, null, null, null, };
/** Lexer state names. */
@@ -1091,15 +1090,15 @@
/** Lex State array. */
public static final int[] jjnewLexState = {
- -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1,
};
static final long[] jjtoToken = {
- 0x11ffffffffffb0fL,
+ 0x11ffffffffffb0fL,
};
static final long[] jjtoSkip = {
- 0xf0L,
+ 0xf0L,
};
protected SimpleCharStream input_stream;
private final int[] jjrounds = new int[30];
@@ -1182,7 +1181,7 @@
int jjmatchedKind;
/** Get the next Token. */
-public Token getNextToken()
+public Token getNextToken()
{
Token matchedToken;
int curPos = 0;
Modified: trunk/java/org/apache/el/parser/ELParserTreeConstants.java
===================================================================
--- trunk/java/org/apache/el/parser/ELParserTreeConstants.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/ELParserTreeConstants.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -28,14 +28,15 @@
public int JJTVALUE = 22;
public int JJTDOTSUFFIX = 23;
public int JJTBRACKETSUFFIX = 24;
- public int JJTIDENTIFIER = 25;
- public int JJTFUNCTION = 26;
- public int JJTTRUE = 27;
- public int JJTFALSE = 28;
- public int JJTFLOATINGPOINT = 29;
- public int JJTINTEGER = 30;
- public int JJTSTRING = 31;
- public int JJTNULL = 32;
+ public int JJTMETHODPARAMETERS = 25;
+ public int JJTIDENTIFIER = 26;
+ public int JJTFUNCTION = 27;
+ public int JJTTRUE = 28;
+ public int JJTFALSE = 29;
+ public int JJTFLOATINGPOINT = 30;
+ public int JJTINTEGER = 31;
+ public int JJTSTRING = 32;
+ public int JJTNULL = 33;
public String[] jjtNodeName = {
@@ -64,6 +65,7 @@
"Value",
"DotSuffix",
"BracketSuffix",
+ "MethodParameters",
"Identifier",
"Function",
"True",
@@ -74,4 +76,4 @@
"Null",
};
}
-/* JavaCC - OriginalChecksum=f9dfeaba39219034209bcc010ceeafc5 (do not edit this line) */
+/* JavaCC - OriginalChecksum=437008e736f149e8fa6712fb36d831a1 (do not edit this line) */
Modified: trunk/java/org/apache/el/parser/JJTELParserState.java
===================================================================
--- trunk/java/org/apache/el/parser/JJTELParserState.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/JJTELParserState.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -1,6 +1,7 @@
/* Generated By:JavaCC: Do not edit this line. JJTELParserState.java Version 5.0 */
package org.apache.el.parser;
+@SuppressWarnings("all") // Ignore warnings in generated code
public class JJTELParserState {
private java.util.List<Node> nodes;
private java.util.List<Integer> marks;
Modified: trunk/java/org/apache/el/parser/Node.java
===================================================================
--- trunk/java/org/apache/el/parser/Node.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/Node.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -7,9 +7,9 @@
* 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.
@@ -32,7 +32,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * $Id$
*/
public interface Node {
@@ -59,16 +59,26 @@
/** Return the number of children the node has. */
public int jjtGetNumChildren();
-
+
public String getImage();
-
+
public Object getValue(EvaluationContext ctx) throws ELException;
- public ValueReference getValueReference(EvaluationContext ctx);
public void setValue(EvaluationContext ctx, Object value) throws ELException;
- public Class getType(EvaluationContext ctx) throws ELException;
+ public Class<?> getType(EvaluationContext ctx) throws ELException;
public boolean isReadOnly(EvaluationContext ctx) throws ELException;
public void accept(NodeVisitor visitor) throws Exception;
- public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes) throws ELException;
- public Object invoke(EvaluationContext ctx, Class[] paramTypes, Object[] paramValues) throws ELException;
+ public MethodInfo getMethodInfo(EvaluationContext ctx, Class<?>[] paramTypes)
+ throws ELException;
+ public Object invoke(EvaluationContext ctx, Class<?>[] paramTypes,
+ Object[] paramValues) throws ELException;
+
+ /**
+ * @since EL 2.2
+ */
+ public ValueReference getValueReference(EvaluationContext ctx);
+
+ /**
+ * @since EL 2.2
+ */
public boolean isParametersProvided();
}
Modified: trunk/java/org/apache/el/parser/NodeVisitor.java
===================================================================
--- trunk/java/org/apache/el/parser/NodeVisitor.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/NodeVisitor.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -18,7 +18,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public interface NodeVisitor {
public void visit(Node node) throws Exception;
Modified: trunk/java/org/apache/el/parser/SimpleCharStream.java
===================================================================
--- trunk/java/org/apache/el/parser/SimpleCharStream.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/SimpleCharStream.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -6,7 +6,7 @@
* An implementation of interface CharStream, where the stream is assumed to
* contain only ASCII characters (without unicode processing).
*/
-
+@SuppressWarnings("all") // Ignore warnings in generated code
public class SimpleCharStream
{
/** Whether parser is static. */
Modified: trunk/java/org/apache/el/parser/SimpleNode.java
===================================================================
--- trunk/java/org/apache/el/parser/SimpleNode.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/SimpleNode.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -18,6 +18,8 @@
package org.apache.el.parser;
+import java.util.Arrays;
+
import javax.el.ELException;
import javax.el.MethodInfo;
import javax.el.PropertyNotWritableException;
@@ -30,7 +32,7 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public abstract class SimpleNode extends ELSupport implements Node {
protected Node parent;
@@ -45,20 +47,27 @@
id = i;
}
+ @Override
public void jjtOpen() {
+ // NOOP by default
}
+ @Override
public void jjtClose() {
+ // NOOP by default
}
+ @Override
public void jjtSetParent(Node n) {
parent = n;
}
+ @Override
public Node jjtGetParent() {
return parent;
}
+ @Override
public void jjtAddChild(Node n, int i) {
if (children == null) {
children = new Node[i + 1];
@@ -70,10 +79,12 @@
children[i] = n;
}
+ @Override
public Node jjtGetChild(int i) {
return children[i];
}
+ @Override
public int jjtGetNumChildren() {
return (children == null) ? 0 : children.length;
}
@@ -85,6 +96,7 @@
* otherwise overriding toString() is probably all you need to do.
*/
+ @Override
public String toString() {
if (this.image != null) {
return ELParserTreeConstants.jjtNodeName[id] + "[" + this.image
@@ -97,23 +109,7 @@
return prefix + toString();
}
- /*
- * Override this method if you want to customize how the node dumps out its
- * children.
- */
-
- public void dump(String prefix) {
- System.out.println(toString(prefix));
- if (children != null) {
- for (int i = 0; i < children.length; ++i) {
- SimpleNode n = (SimpleNode) children[i];
- if (n != null) {
- n.dump(prefix + " ");
- }
- }
- }
- }
-
+ @Override
public String getImage() {
return image;
}
@@ -122,30 +118,31 @@
this.image = image;
}
- public Class getType(EvaluationContext ctx)
+ @Override
+ public Class<?> getType(EvaluationContext ctx)
throws ELException {
throw new UnsupportedOperationException();
}
+ @Override
public Object getValue(EvaluationContext ctx)
throws ELException {
throw new UnsupportedOperationException();
}
- public ValueReference getValueReference(EvaluationContext ctx) {
- return null;
- }
-
+ @Override
public boolean isReadOnly(EvaluationContext ctx)
throws ELException {
return true;
}
+ @Override
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
throw new PropertyNotWritableException(MessageFactory.get("error.syntax.set"));
}
+ @Override
public void accept(NodeVisitor visitor) throws Exception {
visitor.visit(this);
if (this.children != null && this.children.length > 0) {
@@ -155,16 +152,67 @@
}
}
- public Object invoke(EvaluationContext ctx, Class[] paramTypes, Object[] paramValues) throws ELException {
+ @Override
+ public Object invoke(EvaluationContext ctx, Class<?>[] paramTypes,
+ Object[] paramValues) throws ELException {
throw new UnsupportedOperationException();
}
- public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes) throws ELException {
+ @Override
+ public MethodInfo getMethodInfo(EvaluationContext ctx,
+ Class<?>[] paramTypes) throws ELException {
throw new UnsupportedOperationException();
}
-
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(children);
+ result = prime * result + id;
+ result = prime * result + ((image == null) ? 0 : image.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof SimpleNode)) {
+ return false;
+ }
+ SimpleNode other = (SimpleNode) obj;
+ if (!Arrays.equals(children, other.children)) {
+ return false;
+ }
+ if (id != other.id) {
+ return false;
+ }
+ if (image == null) {
+ if (other.image != null) {
+ return false;
+ }
+ } else if (!image.equals(other.image)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @since EL 2.2
+ */
+ @Override
+ public ValueReference getValueReference(EvaluationContext ctx) {
+ return null;
+ }
+
+ /**
+ * @since EL 2.2
+ */
+ @Override
public boolean isParametersProvided() {
return false;
}
-
}
Modified: trunk/java/org/apache/el/parser/Token.java
===================================================================
--- trunk/java/org/apache/el/parser/Token.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/Token.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,7 +5,7 @@
/**
* Describes the input token stream.
*/
-
+@SuppressWarnings("all") // Ignore warnings in generated code
public class Token implements java.io.Serializable {
/**
Modified: trunk/java/org/apache/el/parser/TokenMgrError.java
===================================================================
--- trunk/java/org/apache/el/parser/TokenMgrError.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/parser/TokenMgrError.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -3,6 +3,7 @@
package org.apache.el.parser;
/** Token Manager Error. */
+@SuppressWarnings("all") // Ignore warnings in generated code
public class TokenMgrError extends Error
{
Modified: trunk/java/org/apache/el/util/MessageFactory.java
===================================================================
--- trunk/java/org/apache/el/util/MessageFactory.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/util/MessageFactory.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -21,50 +21,28 @@
/**
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public final class MessageFactory {
- protected final static ResourceBundle bundle = ResourceBundle
- .getBundle("org.apache.el.Messages");
- /**
- *
- */
+ protected static final ResourceBundle bundle =
+ ResourceBundle.getBundle("org.apache.el.Messages");
+
public MessageFactory() {
super();
}
-
+
public static String get(final String key) {
return bundle.getString(key);
}
- public static String get(final String key, final Object obj0) {
- return getArray(key, new Object[] { obj0 });
- }
+ public static String get(final String key, final Object... args) {
+ String value = get(key);
+ if (value == null) {
+ value = key;
+ }
- public static String get(final String key, final Object obj0,
- final Object obj1) {
- return getArray(key, new Object[] { obj0, obj1 });
+ MessageFormat mf = new MessageFormat(value);
+ return mf.format(args, new StringBuffer(), null).toString();
}
-
- public static String get(final String key, final Object obj0,
- final Object obj1, final Object obj2) {
- return getArray(key, new Object[] { obj0, obj1, obj2 });
- }
-
- public static String get(final String key, final Object obj0,
- final Object obj1, final Object obj2, final Object obj3) {
- return getArray(key, new Object[] { obj0, obj1, obj2, obj3 });
- }
-
- public static String get(final String key, final Object obj0,
- final Object obj1, final Object obj2, final Object obj3,
- final Object obj4) {
- return getArray(key, new Object[] { obj0, obj1, obj2, obj3, obj4 });
- }
-
- public static String getArray(final String key, final Object[] objA) {
- return MessageFormat.format(bundle.getString(key), objA);
- }
-
}
Modified: trunk/java/org/apache/el/util/ReflectionUtil.java
===================================================================
--- trunk/java/org/apache/el/util/ReflectionUtil.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/el/util/ReflectionUtil.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -5,9 +5,9 @@
* 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.
@@ -16,49 +16,40 @@
*/
package org.apache.el.util;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
-import javax.el.ELException;
import javax.el.MethodNotFoundException;
-import javax.el.PropertyNotFoundException;
-import org.apache.el.lang.ELSupport;
-
/**
* Utilities for Managing Serialization and Reflection
- *
+ *
* @author Jacob Hookom [jacob(a)hookom.net]
- * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ * @version $Id$
*/
public class ReflectionUtil {
- protected static final String[] EMPTY_STRING = new String[0];
-
protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean",
"byte", "char", "double", "float", "int", "long", "short", "void" };
- protected static final Class[] PRIMITIVES = new Class[] { boolean.class,
+ protected static final Class<?>[] PRIMITIVES = new Class[] { boolean.class,
byte.class, char.class, double.class, float.class, int.class,
long.class, short.class, Void.TYPE };
- /**
- *
- */
private ReflectionUtil() {
super();
}
- public static Class forName(String name) throws ClassNotFoundException {
+ public static Class<?> forName(String name) throws ClassNotFoundException {
if (null == name || "".equals(name)) {
return null;
}
- Class c = forNamePrimitive(name);
+ Class<?> c = forNamePrimitive(name);
if (c == null) {
if (name.endsWith("[]")) {
String nc = name.substring(0, name.length() - 2);
@@ -71,7 +62,7 @@
return c;
}
- protected static Class forNamePrimitive(String name) {
+ protected static Class<?> forNamePrimitive(String name) {
if (name.length() <= 8) {
int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
if (p >= 0) {
@@ -84,13 +75,12 @@
/**
* Converts an array of Class names to Class types
* @param s
- * @return
* @throws ClassNotFoundException
*/
- public static Class[] toTypeArray(String[] s) throws ClassNotFoundException {
+ public static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException {
if (s == null)
return null;
- Class[] c = new Class[s.length];
+ Class<?>[] c = new Class[s.length];
for (int i = 0; i < s.length; i++) {
c[i] = forName(s[i]);
}
@@ -100,9 +90,8 @@
/**
* Converts an array of Class types to Class names
* @param c
- * @return
*/
- public static String[] toTypeNameArray(Class[] c) {
+ public static String[] toTypeNameArray(Class<?>[] c) {
if (c == null)
return null;
String[] s = new String[c.length];
@@ -120,8 +109,9 @@
* @return the method specified
* @throws MethodNotFoundException
*/
+ @SuppressWarnings("null")
public static Method getMethod(Object base, Object property,
- Class[] paramTypes) throws MethodNotFoundException {
+ Class<?>[] paramTypes) throws MethodNotFoundException {
if (base == null || property == null) {
throw new MethodNotFoundException(MessageFactory.get(
"error.method.notfound", base, property,
@@ -131,18 +121,185 @@
String methodName = (property instanceof String) ? (String) property
: property.toString();
- Method method = null;
- try {
- method = base.getClass().getMethod(methodName, paramTypes);
- } catch (NoSuchMethodException nsme) {
+ int paramCount;
+ if (paramTypes == null) {
+ paramCount = 0;
+ } else {
+ paramCount = paramTypes.length;
+ }
+
+ Method[] methods = base.getClass().getMethods();
+ Map<Method,Integer> candidates = new HashMap<Method,Integer>();
+
+ for (Method m : methods) {
+ if (!m.getName().equals(methodName)) {
+ // Method name doesn't match
+ continue;
+ }
+
+ Class<?>[] mParamTypes = m.getParameterTypes();
+ int mParamCount;
+ if (mParamTypes == null) {
+ mParamCount = 0;
+ } else {
+ mParamCount = mParamTypes.length;
+ }
+
+ // Check the number of parameters
+ if (!(paramCount == mParamCount ||
+ (m.isVarArgs() && paramCount >= mParamCount))) {
+ // Method has wrong number of parameters
+ continue;
+ }
+
+ // Check the parameters match
+ int exactMatch = 0;
+ boolean noMatch = false;
+ for (int i = 0; i < mParamCount; i++) {
+ // Can't be null
+ if (mParamTypes[i].equals(paramTypes[i])) {
+ exactMatch++;
+ } else if (i == (mParamCount - 1) && m.isVarArgs()) {
+ Class<?> varType = mParamTypes[i].getComponentType();
+ for (int j = i; j < paramCount; j++) {
+ if (!isAssignableFrom(paramTypes[j], varType)) {
+ break;
+ }
+ // Don't treat a varArgs match as an exact match, it can
+ // lead to a varArgs method matching when the result
+ // should be ambiguous
+ }
+ } else if (!isAssignableFrom(paramTypes[i], mParamTypes[i])) {
+ noMatch = true;
+ break;
+ }
+ }
+ if (noMatch) {
+ continue;
+ }
+
+ // If a method is found where every parameter matches exactly,
+ // return it
+ if (exactMatch == paramCount) {
+ return m;
+ }
+
+ candidates.put(m, Integer.valueOf(exactMatch));
+ }
+
+ // Look for the method that has the highest number of parameters where
+ // the type matches exactly
+ int bestMatch = 0;
+ Method match = null;
+ boolean multiple = false;
+ for (Map.Entry<Method, Integer> entry : candidates.entrySet()) {
+ if (entry.getValue().intValue() > bestMatch ||
+ match == null) {
+ bestMatch = entry.getValue().intValue();
+ match = entry.getKey();
+ multiple = false;
+ } else if (entry.getValue().intValue() == bestMatch) {
+ multiple = true;
+ }
+ }
+ if (multiple) {
+ if (bestMatch == paramCount - 1) {
+ // Only one parameter is not an exact match - try using the
+ // super class
+ match = resolveAmbiguousMethod(candidates.keySet(), paramTypes);
+ } else {
+ match = null;
+ }
+
+ if (match == null) {
+ // If multiple methods have the same matching number of parameters
+ // the match is ambiguous so throw an exception
+ throw new MethodNotFoundException(MessageFactory.get(
+ "error.method.ambiguous", base, property,
+ paramString(paramTypes)));
+ }
+ }
+
+ // Handle case where no match at all was found
+ if (match == null) {
throw new MethodNotFoundException(MessageFactory.get(
- "error.method.notfound", base, property,
- paramString(paramTypes)));
+ "error.method.notfound", base, property,
+ paramString(paramTypes)));
}
- return method;
+
+ return match;
}
- protected static final String paramString(Class[] types) {
+ @SuppressWarnings("null")
+ private static Method resolveAmbiguousMethod(Set<Method> candidates,
+ Class<?>[] paramTypes) {
+ // Identify which parameter isn't an exact match
+ Method m = candidates.iterator().next();
+
+ int nonMatchIndex = 0;
+ Class<?> nonMatchClass = null;
+
+ for (int i = 0; i < paramTypes.length; i++) {
+ if (m.getParameterTypes()[i] != paramTypes[i]) {
+ nonMatchIndex = i;
+ nonMatchClass = paramTypes[i];
+ break;
+ }
+ }
+
+ for (Method c : candidates) {
+ if (c.getParameterTypes()[nonMatchIndex] ==
+ paramTypes[nonMatchIndex]) {
+ // Methods have different non-matching parameters
+ // Result is ambiguous
+ return null;
+ }
+ }
+
+ // Can't be null
+ nonMatchClass = nonMatchClass.getSuperclass();
+ while (nonMatchClass != null) {
+ for (Method c : candidates) {
+ if (c.getParameterTypes()[nonMatchIndex].equals(
+ nonMatchClass)) {
+ // Found a match
+ return c;
+ }
+ }
+ nonMatchClass = nonMatchClass.getSuperclass();
+ }
+
+ return null;
+ }
+
+ // src will always be an object
+ private static boolean isAssignableFrom(Class<?> src, Class<?> target) {
+ Class<?> targetClass;
+ if (target.isPrimitive()) {
+ if (target == Boolean.TYPE) {
+ targetClass = Boolean.class;
+ } else if (target == Character.TYPE) {
+ targetClass = Character.class;
+ } else if (target == Byte.TYPE) {
+ targetClass = Byte.class;
+ } else if (target == Short.TYPE) {
+ targetClass = Short.class;
+ } else if (target == Integer.TYPE) {
+ targetClass = Integer.class;
+ } else if (target == Long.TYPE) {
+ targetClass = Long.class;
+ } else if (target == Float.TYPE) {
+ targetClass = Float.class;
+ } else {
+ targetClass = Double.class;
+ }
+ } else {
+ targetClass = target;
+ }
+ return targetClass.isAssignableFrom(src);
+ }
+
+ protected static final String paramString(Class<?>[] types) {
if (types != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < types.length; i++) {
@@ -155,30 +312,4 @@
}
return null;
}
-
- /**
- * @param base
- * @param property
- * @return
- * @throws ELException
- * @throws PropertyNotFoundException
- */
- public static PropertyDescriptor getPropertyDescriptor(Object base,
- Object property) throws ELException, PropertyNotFoundException {
- String name = ELSupport.coerceToString(property);
- PropertyDescriptor p = null;
- try {
- PropertyDescriptor[] desc = Introspector.getBeanInfo(
- base.getClass()).getPropertyDescriptors();
- for (int i = 0; i < desc.length; i++) {
- if (desc[i].getName().equals(name)) {
- return desc[i];
- }
- }
- } catch (IntrospectionException ie) {
- throw new ELException(ie);
- }
- throw new PropertyNotFoundException(MessageFactory.get(
- "error.property.notfound", base, name));
- }
}
Added: trunk/java/org/apache/el/util/Validation.java
===================================================================
--- trunk/java/org/apache/el/util/Validation.java (rev 0)
+++ trunk/java/org/apache/el/util/Validation.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -0,0 +1,109 @@
+/*
+ * 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.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class Validation {
+
+ // Java keywords, boolean literals & the null literal in alphabetical order
+ private static final String invalidIdentifiers[] = { "abstract", "assert",
+ "boolean", "break", "byte", "case", "catch", "char", "class", "const",
+ "continue", "default", "do", "double", "else", "enum", "extends",
+ "false", "final", "finally", "float", "for", "goto", "if", "implements",
+ "import", "instanceof", "int", "interface", "long", "native", "new",
+ "null", "package", "private", "protected", "public", "return", "short",
+ "static", "strictfp", "super", "switch", "synchronized", "this",
+ "throw", "throws", "transient", "true", "try", "void", "volatile",
+ "while" };
+
+ private static final boolean IS_SECURITY_ENABLED =
+ (System.getSecurityManager() != null);
+
+ private static final boolean SKIP_IDENTIFIER_CHECK;
+
+ static {
+ if (IS_SECURITY_ENABLED) {
+ SKIP_IDENTIFIER_CHECK = AccessController.doPrivileged(
+ new PrivilegedAction<Boolean>(){
+ @Override
+ public Boolean run() {
+ return Boolean.valueOf(System.getProperty(
+ "org.apache.el.parser.SKIP_IDENTIFIER_CHECK",
+ "false"));
+ }
+ }
+ ).booleanValue();
+ } else {
+ SKIP_IDENTIFIER_CHECK = Boolean.valueOf(System.getProperty(
+ "org.apache.el.parser.SKIP_IDENTIFIER_CHECK",
+ "false")).booleanValue();
+ }
+ }
+
+
+ private Validation() {
+ // Utility class. Hide default constructor
+ }
+
+ /**
+ * Test whether the argument is a Java identifier.
+ */
+ public static boolean isIdentifier(String key) {
+
+ if (SKIP_IDENTIFIER_CHECK) {
+ return true;
+ }
+
+ // Should not be the case but check to be sure
+ if (key == null || key.length() == 0) {
+ return false;
+ }
+
+ // Check the list of known invalid values
+ int i = 0;
+ int j = invalidIdentifiers.length;
+ while (i < j) {
+ int k = (i + j) >>> 1; // Avoid overflow
+ int result = invalidIdentifiers[k].compareTo(key);
+ if (result == 0) {
+ return false;
+ }
+ if (result < 0) {
+ i = k + 1;
+ } else {
+ j = k;
+ }
+ }
+
+ // Check the start character that has more restrictions
+ if (!Character.isJavaIdentifierStart(key.charAt(0))) {
+ return false;
+ }
+
+ // Check each remaining character used is permitted
+ for (int idx = 1; idx < key.length(); idx++) {
+ if (!Character.isJavaIdentifierPart(key.charAt(idx))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
Modified: trunk/java/org/apache/jasper/compiler/Validator.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Validator.java 2011-12-01 11:54:47 UTC (rev 1881)
+++ trunk/java/org/apache/jasper/compiler/Validator.java 2011-12-06 15:27:15 UTC (rev 1882)
@@ -497,6 +497,9 @@
new JspUtil.ValidAttribute("doctype-public"),
new JspUtil.ValidAttribute("doctype-system") };
+ private static final ExpressionFactory EXPRESSION_FACTORY =
+ ExpressionFactory.newInstance();
+
/*
* Constructor
*/
@@ -1148,13 +1151,27 @@
(n, "jsp.error.unknown_attribute_type",
tldAttr.getName(), expectedType);
}
- // Check casting
- try {
- ELSupport.checkType(attrs.getValue(i), expectedClass);
- } catch (Exception e) {
- err.jspError
- (n, "jsp.error.coerce_to_type",
- tldAttr.getName(), expectedType, attrs.getValue(i));
+ // Check casting - not possible for all types
+ if (String.class.equals(expectedClass) ||
+ expectedClass == Long.TYPE ||
+ expectedClass == Double.TYPE ||
+ expectedClass == Byte.TYPE ||
+ expectedClass == Short.TYPE ||
+ expectedClass == Integer.TYPE ||
+ expectedClass == Float.TYPE ||
+ Number.class.isAssignableFrom(expectedClass) ||
+ Character.class.equals(expectedClass) ||
+ Character.TYPE == expectedClass ||
+ Boolean.class.equals(expectedClass) ||
+ Boolean.TYPE == expectedClass ||
+ expectedClass.isEnum()) {
+ try {
+ EXPRESSION_FACTORY.coerceToType(attrs.getValue(i), expectedClass);
+ } catch (Exception e) {
+ err.jspError
+ (n, "jsp.error.coerce_to_type",
+ tldAttr.getName(), expectedType, attrs.getValue(i));
+ }
}
}
13 years
JBossWeb SVN: r1881 - branches/2.1.x/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2011-12-01 06:54:47 -0500 (Thu, 01 Dec 2011)
New Revision: 1881
Modified:
branches/2.1.x/java/org/jboss/web/cluster/ClusterListener.java
Log:
Overwise: java.lang.NullPointerException :-(
Modified: branches/2.1.x/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- branches/2.1.x/java/org/jboss/web/cluster/ClusterListener.java 2011-12-01 11:47:33 UTC (rev 1880)
+++ branches/2.1.x/java/org/jboss/web/cluster/ClusterListener.java 2011-12-01 11:54:47 UTC (rev 1881)
@@ -569,8 +569,10 @@
} else if (source instanceof Server) {
stopListener();
stopServer((Server) source, -1);
- for (int i = 0; i < connections.length; i++) {
- closeConnection(i);
+ if (connections != null) {
+ for (int i = 0; i < connections.length; i++) {
+ closeConnection(i);
+ }
}
init = false;
} else {
13 years
JBossWeb SVN: r1880 - trunk/java/org/apache/catalina/core.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2011-12-01 06:47:33 -0500 (Thu, 01 Dec 2011)
New Revision: 1880
Modified:
trunk/java/org/apache/catalina/core/StandardHostValve.java
Log:
AS7-2844: The check was probably correct, but not in the right location.
Modified: trunk/java/org/apache/catalina/core/StandardHostValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardHostValve.java 2011-11-30 13:54:33 UTC (rev 1879)
+++ trunk/java/org/apache/catalina/core/StandardHostValve.java 2011-12-01 11:47:33 UTC (rev 1880)
@@ -284,11 +284,11 @@
} else {
status(request, response);
}
+ // An error page (if any) must call complete or dispatch, if not the container calls complete
+ if (request.isEventMode() && asyncContext.getPath() == null) {
+ asyncContext.complete();
+ }
}
- // AS7-2844 if (request.isEventMode() && asyncContext.getPath() == null) {
- if (!asyncContext.isReady()) {
- asyncContext.complete();
- }
}
// Exit application scope
13 years