dev@javaserverfaces.java.net

Seeking Review: 1669: ResourceBundleELResolver.getType()

From: Ed Burns <edward.burns_at_oracle.com>
Date: Wed, 19 May 2010 11:29:56 -0700

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1669

Issue:

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1669

M jsf-ri/src/com/sun/faces/el/VariableResolverChainWrapper.java

- Make it so all methods overridden from ELResolver take no action
  unless the system's VariableResolver has, in fact, been replaced.
  This was not an issue before, because the legacy VariableResolver was
  not even called in most (all?) cases. Now, with the fix to 1644, the
  legacy VariableResolver *is* called. However, this fix is to make it
  so the legacy VariableResolver only takes action if the user actually
  decorates it.

M jsf-ri/systest/build-tests.xml
M jsf-ri/systest/build.xml
M jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java
A jsf-ri/systest/web/resourceBundle05.jsp

- new tests, passthru

SECTION: Diffs

Index: jsf-ri/src/com/sun/faces/el/VariableResolverChainWrapper.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/el/VariableResolverChainWrapper.java,v
retrieving revision 1.16.4.3
diff -u -r1.16.4.3 VariableResolverChainWrapper.java
--- jsf-ri/src/com/sun/faces/el/VariableResolverChainWrapper.java 17 May 2010 19:51:05 -0000 1.16.4.3
+++ jsf-ri/src/com/sun/faces/el/VariableResolverChainWrapper.java 19 May 2010 18:15:22 -0000
@@ -72,6 +72,11 @@
     public Object getValue(ELContext context, Object base, Object property)
         throws ELException {
 
+ // Don't call into the chain unless it's been decorated.
+ if (legacyVR instanceof ChainAwareVariableResolver) {
+ return null;
+ }
+
         if (base != null) {
             return null;
         }
@@ -129,6 +134,11 @@
     public Class<?> getType(ELContext context, Object base, Object property)
         throws ELException {
 
+ // Don't call into the chain unless it's been decorated.
+ if (legacyVR instanceof ChainAwareVariableResolver) {
+ return null;
+ }
+
         Object result = getValue(context, base, property);
         context.setPropertyResolved(result != null);
         if (result != null) {
@@ -140,14 +150,25 @@
     @Override
     public void setValue(ELContext context, Object base, Object property,
                           Object val) throws ELException {
- if (null == base && null == property) {
- throw new PropertyNotFoundException();
- }
+ // Don't call into the chain unless it's been decorated.
+ if (legacyVR instanceof ChainAwareVariableResolver) {
+ return;
+ }
+
+ if (null == base && null == property) {
+ throw new PropertyNotFoundException();
+ }
     }
 
     @Override
     public boolean isReadOnly(ELContext context, Object base, Object property)
         throws ELException {
+
+ // Don't call into the chain unless it's been decorated.
+ if (legacyVR instanceof ChainAwareVariableResolver) {
+ return false;
+ }
+
         if (null == base && null == property) {
         throw new PropertyNotFoundException();
     }
@@ -162,6 +183,12 @@
 
     @Override
     public Class<?> getCommonPropertyType(ELContext context, Object base) {
+
+ // Don't call into the chain unless it's been decorated.
+ if (legacyVR instanceof ChainAwareVariableResolver) {
+ return null;
+ }
+
         if ( base == null ) {
             return String.class;
         }
Index: jsf-ri/systest/build-tests.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/systest/build-tests.xml,v
retrieving revision 1.133.4.4
diff -u -r1.133.4.4 build-tests.xml
--- jsf-ri/systest/build-tests.xml 19 May 2009 17:11:24 -0000 1.133.4.4
+++ jsf-ri/systest/build-tests.xml 19 May 2010 18:15:23 -0000
@@ -900,6 +900,16 @@
                  recordGolden="${local.golden.path}/resourceBundle04.txt"
                  golden="${golden.path}/resourceBundle04.txt"/>
         -->
+
+ <jsf.junit context-path="${context.path}"
+ classpath-refid="html.classpath"
+ test-results-dir="${impl.test.results.dir}">
+ <tests>
+ <fileset dir="${basedir}/build/classes"
+ includes="com/sun/faces/systest/resources/*TestCase.class"/>
+ </tests>
+ </jsf.junit>
+
     </target>
 
 
Index: jsf-ri/systest/build.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/systest/build.xml,v
retrieving revision 1.44
diff -u -r1.44 build.xml
--- jsf-ri/systest/build.xml 27 Apr 2007 22:01:07 -0000 1.44
+++ jsf-ri/systest/build.xml 19 May 2010 18:15:23 -0000
@@ -160,5 +160,12 @@
         <undeploy.artifact artifact="${build.dir}/jsf-systest.war"
                   appName="jsf-systest"/>
     </target>
+
+ <target name="passthru"
+ description="The same as 'test', but with no deployment">
+ <ant antfile="build-tests.xml" target="test.resourceBundleELResolver"/>
+ </target>
+
+
         
 </project>
Index: jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java,v
retrieving revision 1.30
diff -u -r1.30 TestBean.java
--- jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java 27 Apr 2007 22:01:13 -0000 1.30
+++ jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java 19 May 2010 18:15:23 -0000
@@ -64,6 +64,8 @@
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.el.ELContext;
+import javax.el.ELResolver;
 import javax.faces.context.ExternalContext;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
@@ -822,6 +824,16 @@
         return this.referencedSuit;
     }
 
+ // taken from TCK facesResourceBundleResolverGetTypeTest
+ public String getResourceBundleType() {
+ FacesContext context = FacesContext.getCurrentInstance();
+ ELContext elContext = context.getELContext();
+ ELResolver elResolver = elContext.getELResolver();
+ Class type = elResolver.getType(elContext, null, "resourceBundle03");
+
+ return type.toString();
+ }
+
     /**
      * Setter for property referencedSuit.
      * @param referencedSuit New value of property referencedSuit.

SECTION: New Files

A jsf-ri/systest/web/resourceBundle05.jsp

<%--
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
 Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
 
 The contents of this file are subject to the terms of either the GNU
 General Public License Version 2 only ("GPL") or the Common Development
 and Distribution License("CDDL") (collectively, the "License"). You
 may not use this file except in compliance with the License. You can obtain
 a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
 or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
 language governing permissions and limitations under the License.
 
 When distributing the software, include this License Header Notice in each
 file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
 Sun designates this particular file as subject to the "Classpath" exception
 as provided by Sun in the GPL Version 2 section of the License file that
 accompanied this code. If applicable, add the following below the License
 Header, with the fields enclosed by brackets [] replaced by your own
 identifying information: "Portions Copyrighted [year]
 [name of copyright owner]"
 
 Contributor(s):
 
 If you wish your version of this file to be governed by only the CDDL or
 only the GPL Version 2, indicate your decision by adding "[Contributor]
 elects to include this software in this distribution under the [CDDL or GPL
 Version 2] license." If you don't indicate a single choice of license, a
 recipient has the option to distribute your version of this file under
 either the CDDL, the GPL Version 2 or to extend the choice of license to
 its licensees as provided above. However, if you add GPL Version 2 code
 and therefore, elected the GPL Version 2 license, then the option applies
 only if the new code is made subject to such option by the copyright
 holder.
--%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>

<p>Testing ResourceBundleELResolver for Faces getType. Result:
<h:outputText value="#{test1.resourceBundleType}" /></p>

</f:view>

-- 
| edburns_at_oracle.com | 
| homepage:          | http://ridingthecrest.com/