You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by rd...@apache.org on 2011/05/27 12:27:35 UTC
svn commit: r1128241 - in /myfaces/test/trunk/test12/src:
main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java
main/java/org/apache/myfaces/test/mock/MockApplication12.java
test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java
Author: rdebusscher
Date: Fri May 27 10:27:34 2011
New Revision: 1128241
URL: http://svn.apache.org/viewvc?rev=1128241&view=rev
Log:
MYFACESTEST-53: MockApplication12 elResolver cannot interpret EL reserved words. Thx to Matt Benson
Added:
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java
myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java
Modified:
myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java?rev=1128241&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java Fri May 27 10:27:34 2011
@@ -0,0 +1,104 @@
+/*
+ * 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.myfaces.test.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.PropertyNotWritableException;
+
+/**
+ * {@code ELResolver} for reserved words.
+ */
+public class ReservedWordsELResolver extends AbstractELResolver {
+ private static final Map<String, Object> VALUES;
+ static {
+ HashMap<String, Object> values = new HashMap<String, Object>();
+ values.put("true", Boolean.TRUE);
+ values.put("false", Boolean.FALSE);
+ values.put("null", null);
+ VALUES = Collections.unmodifiableMap(values);
+ }
+
+ private List<FeatureDescriptor> featureDescriptors;
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ return VALUES.get(property);
+ }
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ Object value = VALUES.get(property);
+ return value == null ? null : value.getClass();
+ }
+ return null;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ throw new PropertyNotWritableException(property.toString());
+ }
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized Iterator<FeatureDescriptor> getFeatureDescriptors(
+ ELContext context, Object base) {
+ if (featureDescriptors == null) {
+ featureDescriptors = new ArrayList<FeatureDescriptor>();
+ for (Map.Entry<String, Object> e : VALUES.entrySet()) {
+ final Class<?> type =
+ e.getValue() == null ? null : e.getValue().getClass();
+ featureDescriptors.add(descriptor(e.getKey(), e.getKey(),
+ e.getKey(), false, false, true, type, true));
+ }
+ featureDescriptors =
+ Collections.unmodifiableList(featureDescriptors);
+ }
+ return featureDescriptors.iterator();
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return base == null ? String.class : null;
+ }
+
+}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java?rev=1128241&r1=1128240&r2=1128241&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java Fri May 27 10:27:34 2011
@@ -48,6 +48,7 @@ import org.apache.myfaces.test.el.FacesR
import org.apache.myfaces.test.el.FacesScopedAttributeELResolver;
import org.apache.myfaces.test.el.FacesVariableResolverChainWrapper;
import org.apache.myfaces.test.el.MockExpressionFactory;
+import org.apache.myfaces.test.el.ReservedWordsELResolver;
/**
* <p>Mock implementation of <code>Application</code> that includes the semantics
@@ -237,6 +238,7 @@ public class MockApplication12 extends M
composite.add(new ArrayELResolver());
composite.add(new BeanELResolver());
composite.add(new FacesScopedAttributeELResolver());
+ composite.add(new ReservedWordsELResolver());
// Make the resolver we have configured the application wide one
resolver = composite;
Added: myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java?rev=1128241&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java (added)
+++ myfaces/test/trunk/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java Fri May 27 10:27:34 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.myfaces.test.el;
+
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+
+import javax.el.ELContext;
+
+/**
+ * @author Matt Benson
+ */
+public class ReservedWordsELResolverTest extends AbstractJsfTestCase {
+
+ /**
+ * <p>Construct a new instance of this test case.</p>
+ *
+ * @param name Name of this test case
+ */
+ public ReservedWordsELResolverTest(String name) {
+ super(name);
+ }
+
+ public void testGetReservedWords() {
+ ELContext elContext = facesContext.getELContext();
+ assertEquals(Boolean.TRUE, application.getExpressionFactory()
+ .createValueExpression(elContext, "#{true}", Boolean.class)
+ .getValue(elContext));
+ assertEquals(Boolean.FALSE, application.getExpressionFactory()
+ .createValueExpression(elContext, "#{false}", Boolean.class)
+ .getValue(elContext));
+ assertNull(application.getExpressionFactory()
+ .createValueExpression(elContext, "#{null}", Object.class)
+ .getValue(elContext));
+ }
+}