You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/07/14 20:06:27 UTC
svn commit: r1503008 - in /tomcat/trunk:
java/org/apache/el/parser/AstMapData.java
test/org/apache/el/parser/TestAstMapData.java
Author: markt
Date: Sun Jul 14 18:06:27 2013
New Revision: 1503008
URL: http://svn.apache.org/r1503008
Log:
Implement the Map construction syntax.
Includes the initial unit tests for this syntax.
Added:
tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java (with props)
Modified:
tomcat/trunk/java/org/apache/el/parser/AstMapData.java
Modified: tomcat/trunk/java/org/apache/el/parser/AstMapData.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstMapData.java?rev=1503008&r1=1503007&r2=1503008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstMapData.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstMapData.java Sun Jul 14 18:06:27 2013
@@ -17,10 +17,40 @@
/* Generated By:JJTree: Do not edit this line. AstMapData.java Version 4.3 */
package org.apache.el.parser;
-public
-class AstMapData extends SimpleNode {
- public AstMapData(int id) {
- super(id);
- }
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.el.ELException;
+
+import org.apache.el.lang.EvaluationContext;
+
+public class AstMapData extends SimpleNode {
+
+ public AstMapData(int id) {
+ super(id);
+ }
+
+
+ @Override
+ public Object getValue(EvaluationContext ctx) throws ELException {
+ Map<Object,Object> result = new HashMap<>();
+
+ if (children != null) {
+ for (Node child : children) {
+ AstMapEntry mapEntry = (AstMapEntry) child;
+ Object key = mapEntry.children[0].getValue(ctx);
+ Object value = mapEntry.children[1].getValue(ctx);
+ result.put(key, value);
+ }
+ }
+
+ return result;
+ }
+
+
+ @Override
+ public Class<?> getType(EvaluationContext ctx) throws ELException {
+ return Map.class;
+ }
}
/* JavaCC - OriginalChecksum=a68b5c6f0a0708f478fdf8c0e6e1263e (do not edit this line) */
Added: tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java?rev=1503008&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java (added)
+++ tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java Sun Jul 14 18:06:27 2013
@@ -0,0 +1,90 @@
+/*
+ * 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 java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ELManager;
+import javax.el.ELProcessor;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAstMapData {
+
+ private static final Map<String,String> simpleMap = new HashMap<>();
+ private static final Map<Object,Object> nestedMap = new HashMap<>();
+
+ static {
+ simpleMap.put("a", "1");
+ simpleMap.put("b", "2");
+ simpleMap.put("c", "3");
+
+ nestedMap.put("simple", simpleMap);
+ // {} will get parsed as an empty Set as there is nothing to hint to the
+ // parser that Map is expected here.
+ nestedMap.put("empty", Collections.EMPTY_SET);
+ nestedMap.put("d", "4");
+ }
+
+
+ @Test
+ public void testSimple01() {
+ ELProcessor processor = new ELProcessor();
+ Object result = processor.getValue(
+ "{'a':'1','b':'2','c':'3'}", Map.class);
+ Assert.assertEquals(simpleMap, result);
+ }
+
+
+ @Test
+ public void testSimple02() {
+ ELProcessor processor = new ELProcessor();
+ Object result = processor.getValue("{}", Map.class);
+ Assert.assertEquals(Collections.EMPTY_MAP, result);
+ }
+
+
+ @Test
+ public void testNested01() {
+ ELProcessor processor = new ELProcessor();
+ Object result = processor.getValue(
+ "{'simple':{'a':'1','b':'2','c':'3'}," +
+ "'empty':{}," +
+ "'d':'4'}", Map.class);
+ Assert.assertEquals(nestedMap, result);
+ }
+
+
+ @Test
+ public void testGetType() {
+ ELProcessor processor = new ELProcessor();
+ ELContext context = processor.getELManager().getELContext();
+ ExpressionFactory factory = ELManager.getExpressionFactory();
+
+ ValueExpression ve = factory.createValueExpression(
+ context, "${{'a':'1','b':'2','c':'3'}}", Map.class);
+
+ Assert.assertEquals(Map.class, ve.getType(context));
+ Assert.assertEquals(simpleMap, ve.getValue(context));
+ }
+}
Propchange: tomcat/trunk/test/org/apache/el/parser/TestAstMapData.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org