dev@javaserverfaces.java.net

Seeking review: [1611-isCompositeComponentPerformance]

From: Edward Burns <edward.burns_at_oracle.com>
Date: Wed, 14 Jul 2010 16:42:20 -0400

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

improve the performance of UIComponent.isCompositeComponent() by adding
a cache https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1611

SECTION: Modified Files
----------------------------
M jsf-api/src/main/java/javax/faces/component/UIComponent.java

- add a transient ivar.

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

- first time in years I've used the goldenfile approach, but it was the
   most appropriate in this case.

A jsf-ri/systest/web/composite/isCompositeComponentUsing.xhtml
A jsf-ri/systest/web/golden/composite
A jsf-ri/systest/web/golden/composite/isCompositeComponentUsing.txt
A jsf-ri/systest/web/resources/composite/isCompositeComponent.xhtml

- test content

SECTION: Diffs
----------------------------
Index: jsf-api/src/main/java/javax/faces/component/UIComponent.java
===================================================================
--- jsf-api/src/main/java/javax/faces/component/UIComponent.java
(revision 8486)
+++ jsf-api/src/main/java/javax/faces/component/UIComponent.java
(working copy)
@@ -1779,7 +1779,11 @@

      }

+ // It is safe to cache this because components never go from being
+ // composite to non-composite.
+ private transient Boolean isCompositeComponent;

+
      /**
       * <p class="changed_added_2_0">Return <code>true</code> if
       * <code>component</code> is a composite component, otherwise
@@ -1795,7 +1799,15 @@
          if (component == null) {
              throw new NullPointerException();
          }
- return
(component.getAttributes().containsKey(Resource.COMPONENT_RESOURCE_KEY));
+ boolean result = false;
+ if (null != component.isCompositeComponent) {
+ result = component.isCompositeComponent.booleanValue();
+ } else {
+ result = component.isCompositeComponent =
+ (component.getAttributes().containsKey(
+ Resource.COMPONENT_RESOURCE_KEY));
+ }
+ return result;

      }

Index: jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java
===================================================================
--- jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java
(revision 8486)
+++ jsf-ri/systest/src/com/sun/faces/systest/model/TestBean.java
(working copy)
@@ -962,4 +962,13 @@
          return null;
      }

+ public String getIsCompositeComponentValue() {
+ String result = null;
+
+ UIComponent currentComposite =
UIComponent.getCurrentCompositeComponent(FacesContext.getCurrentInstance());
+ result = "" + UIComponent.isCompositeComponent(currentComposite);
+
+ return result;
+ }
+
  }
Index: jsf-ri/systest/web/composite/isCompositeComponentUsing.xhtml
===================================================================
--- jsf-ri/systest/web/composite/isCompositeComponentUsing.xhtml
(revision 0)
+++ jsf-ri/systest/web/composite/isCompositeComponentUsing.xhtml
(revision 0)
@@ -0,0 +1,62 @@
+<!--
+
+ 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.
+
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ez="http://java.sun.com/jsf/composite/composite">
+<h:head>
+<title>isCompositeComponent test</title>
+</h:head>
+
+<h:body>
+
+<h:form id="form">
+
+ <ez:isCompositeComponent id="composite" >
+
+ <p>isCompositeComponent: <h:outputText
value="#{test1.isCompositeComponentValue}" /></p>
+
+ </ez:isCompositeComponent>
+
+
+</h:form>
+
+</h:body>
+
+</html>
Index: jsf-ri/systest/web/golden/composite/isCompositeComponentUsing.txt
===================================================================
--- jsf-ri/systest/web/golden/composite/isCompositeComponentUsing.txt
(revision 0)
+++ jsf-ri/systest/web/golden/composite/isCompositeComponentUsing.txt
(revision 0)
@@ -0,0 +1,48 @@
+<!--
+
+ 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.
+
+--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<title>isCompositeComponent test</title></head><body>
+<form id="form" name="form" method="post"
action="/jsf-systest/faces/composite/isCompositeComponentUsing.xhtml;jsessionid=2a8e3194d4a0be67a6561007d653"
enctype="application/x-www-form-urlencoded">
+<input type="hidden" name="form" value="form" />
+<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="j_id1:j_id2" autocomplete="off" />
+
+
+ <p>isCompositeComponent: true</p>
+</form></body>
+
+</html>
Index: jsf-ri/systest/web/resources/composite/isCompositeComponent.xhtml
===================================================================
--- jsf-ri/systest/web/resources/composite/isCompositeComponent.xhtml
(revision 0)
+++ jsf-ri/systest/web/resources/composite/isCompositeComponent.xhtml
(revision 0)
@@ -0,0 +1,63 @@
+<!--
+
+ 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.
+
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:cc="http://java.sun.com/jsf/composite">
+<head>
+
+<title>Not present in rendered output</title>
+
+</head>
+
+<body>
+
+<cc:interface>
+
+</cc:interface>
+
+<cc:implementation>
+
+ <cc:insertChildren />
+
+</cc:implementation>
+
+</body>
+
+</html>
Index: jsf-ri/systest/build-tests.xml
===================================================================
--- jsf-ri/systest/build-tests.xml (revision 8486)
+++ jsf-ri/systest/build-tests.xml (working copy)
@@ -969,6 +969,11 @@
      <target name="test.composite"
              description="Test composite components">

+ <jsf.tester
+ ignoreIfContains="${ignore.path}/ignoreIfContains.txt"
+
request="${context.path}/faces/composite/isCompositeComponentUsing.xhtml"
+
golden="${golden.path}/composite/isCompositeComponentUsing.txt"/>
+
          <jsf.junit context-path="${context.path}"
                     classpath-refid="html.classpath"
                     test-results-dir="${impl.test.results.dir}">
@@ -976,7 +981,7 @@
                  <fileset dir="${basedir}/build/classes"
 
includes="com/sun/faces/composite/*TestCase.class"/>
              </tests>
- </jsf.junit>
+ </jsf.junit>

          <if>
              <equals arg1="${container.name}" arg2="glassfishV3"/>
@@ -1364,16 +1369,11 @@
      </target>

      <target name="passthru">
- <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/jsf2jsp/Jsf2JspTestCase.class"
- />
-<!-- 139-StateSaving edburns remove excludes -->
- </tests>
- </jsf.junit>
+ <jsf.tester
+ ignoreIfContains="${ignore.path}/ignoreIfContains.txt"
+
request="${context.path}/faces/composite/isCompositeComponentUsing.xhtml"
+
golden="${golden.path}/composite/isCompositeComponentUsing.txt"/>
+
      </target>