You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/12/16 22:17:33 UTC
svn commit: r1215281 -
/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java
Author: lu4242
Date: Fri Dec 16 21:17:32 2011
New Revision: 1215281
URL: http://svn.apache.org/viewvc?rev=1215281&view=rev
Log:
MYFACES-3423 [perf] Use ArrayList instead LinkedList in UIComponent.pushComponentToEL / popComponentFromEL
Modified:
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java?rev=1215281&r1=1215280&r2=1215281&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponent.java Fri Dec 16 21:17:32 2011
@@ -61,10 +61,10 @@ import javax.faces.view.ViewDeclarationL
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
/**
- *
+ *
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">J
* SF Specification</a>
- *
+ *
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
*/
@@ -74,22 +74,22 @@ public abstract class UIComponent implem
/**
* Constant used in component attribute map to retrieve the BeanInfo of a composite
* component.
- *
- * @see ViewDeclarationLanguage#getComponentMetadata(FacesContext, Resource)
- * @see ViewDeclarationLanguage#retargetAttachedObjects(FacesContext, UIComponent, List)
- * @see ViewDeclarationLanguage#retargetMethodExpressions(FacesContext, UIComponent)
- * @see Application#createComponent(FacesContext, Resource)
+ *
+ * @see javax.faces.view.ViewDeclarationLanguage#getComponentMetadata(FacesContext, Resource)
+ * @see javax.faces.view.ViewDeclarationLanguage#retargetAttachedObjects(FacesContext, UIComponent, List)
+ * @see javax.faces.view.ViewDeclarationLanguage#retargetMethodExpressions(FacesContext, UIComponent)
+ * @see javax.faces.application.Application#createComponent(FacesContext, Resource)
*/
public static final String BEANINFO_KEY = "javax.faces.component.BEANINFO_KEY";
-
+
/**
* Constant used in BeanInfo descriptor as a key for retrieve an alternate component type
* for create the composite base component.
- *
- * @see Application#createComponent(FacesContext, Resource)
+ *
+ * @see javax.faces.application.Application#createComponent(FacesContext, Resource)
*/
public static final String COMPOSITE_COMPONENT_TYPE_KEY = "javax.faces.component.COMPOSITE_COMPONENT_TYPE";
-
+
/**
* Constant used to define the facet inside this component that store the component hierarchy
* generated by a composite component implementation, and then rendered. In other words,
@@ -97,23 +97,23 @@ public abstract class UIComponent implem
* this face are rendered.
*/
public static final String COMPOSITE_FACET_NAME = "javax.faces.component.COMPOSITE_FACET_NAME";
-
+
/**
* Constant used to store the current component that is being processed.
- *
+ *
* @see #pushComponentToEL(FacesContext, UIComponent)
* @see #popComponentFromEL(FacesContext)
*/
public static final String CURRENT_COMPONENT = "javax.faces.component.CURRENT_COMPONENT";
-
+
/**
* Constant used to store the current composite component that is being processed.
- *
+ *
* @see #pushComponentToEL(FacesContext, UIComponent)
* @see #popComponentFromEL(FacesContext)
- */
+ */
public static final String CURRENT_COMPOSITE_COMPONENT = "javax.faces.component.CURRENT_COMPOSITE_COMPONENT";
-
+
/**
* This constant has two usages. The first one is in component attribute map to identify the
* facet name under this component is child of its parent. The second one is on BeanInfo descriptor
@@ -122,21 +122,21 @@ public abstract class UIComponent implem
* by COMPOSITE_FACET_NAME constant).
*/
public static final String FACETS_KEY = "javax.faces.component.FACETS_KEY";
-
+
/**
* Constant used in component attribute map to store the {@link javax.faces.view.Location} object
* where the definition of this component is.
*/
public static final String VIEW_LOCATION_KEY = "javax.faces.component.VIEW_LOCATION_KEY";
-
+
/**
* The key under which the component stack is stored in the FacesContext.
* ATTENTION: this constant is duplicate in CompositeComponentExpressionUtils.
*/
private static final String _COMPONENT_STACK = "componentStack:" + UIComponent.class.getName();
-
+
Map<Class<? extends SystemEvent>, List<SystemEventListener>> _systemEventListenerClassMap;
-
+
/**
* @deprecated
*/
@@ -151,7 +151,7 @@ public abstract class UIComponent implem
private transient Map<String, String> _resourceBundleMap = null;
private boolean _inView = false;
private StateHelper _stateHelper = null;
-
+
/**
* In JSF 2.0 bindings map was deprecated, and replaced with a map
* inside stateHelper. We need this one here because stateHelper needs
@@ -159,15 +159,16 @@ public abstract class UIComponent implem
*/
private boolean _initialStateMarked = false;
- public UIComponent() {
+ public UIComponent()
+ {
}
public abstract Map<String, Object> getAttributes();
/**
- *
+ *
* {@inheritDoc}
- *
+ *
* @since 2.0
*/
public boolean initialStateMarked()
@@ -188,9 +189,11 @@ public abstract class UIComponent implem
* @throws javax.faces.FacesException
*/
public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)
- throws FacesException {
+ throws FacesException
+ {
// java.lang.NullPointerException - if any of the arguments are null
- if (context == null || clientId == null || callback == null) {
+ if (context == null || clientId == null || callback == null)
+ {
throw new NullPointerException();
}
@@ -199,16 +202,21 @@ public abstract class UIComponent implem
{
// searching for this component?
boolean found = clientId.equals(this.getClientId(context));
- if (found) {
- try {
+ if (found)
+ {
+ try
+ {
callback.invokeContextCallback(context, this);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
return found;
}
// Searching for this component's children/facets
- for (Iterator<UIComponent> it = this.getFacetsAndChildren(); !found && it.hasNext();) {
+ for (Iterator<UIComponent> it = this.getFacetsAndChildren(); !found && it.hasNext(); )
+ {
found = it.next().invokeOnComponent(context, clientId, callback);
}
return found;
@@ -221,15 +229,16 @@ public abstract class UIComponent implem
}
/**
- *
+ *
* @param component
* @return true if the component is a composite component otherwise false is returned
- *
+ *
*
* @throws NullPointerException if the component is null
* @since 2.0
*/
- public static boolean isCompositeComponent(UIComponent component) {
+ public static boolean isCompositeComponent(UIComponent component)
+ {
//since _isCompositeComponent does it the same way we do it here also although I
//would prefer following method
@@ -245,15 +254,16 @@ public abstract class UIComponent implem
* instance (which represents the view). If this component
* is a UIViewRoot instance, the components "always"
* is on the view.
- *
+ *
* By default it is false but for UIViewRoot instances is
* true.
- *
+ *
* @return
- *
+ *
* @since 2.0
*/
- public boolean isInView() {
+ public boolean isInView()
+ {
return _inView;
}
@@ -276,18 +286,23 @@ public abstract class UIComponent implem
*
* @param context
* @return
- *
+ *
* @since 2.0
*/
- protected boolean isVisitable(VisitContext context) {
+ protected boolean isVisitable(VisitContext context)
+ {
Collection<VisitHint> hints = context.getHints();
if (hints.contains(VisitHint.SKIP_TRANSIENT) && this.isTransient())
+ {
return false;
+ }
if (hints.contains(VisitHint.SKIP_UNRENDERED) && !this.isRendered())
+ {
return false;
+ }
//executable cannot be handled here because we do not have any method to determine
//whether a component is executable or not, this seems to be a hole in the spec!
@@ -302,18 +317,23 @@ public abstract class UIComponent implem
*/
public abstract void setValueBinding(String name, ValueBinding binding);
- public void setValueExpression(String name, ValueExpression expression) {
- if (name == null) {
+ public void setValueExpression(String name, ValueExpression expression)
+ {
+ if (name == null)
+ {
throw new NullPointerException("name");
}
- if (name.equals("id")) {
+ if (name.equals("id"))
+ {
throw new IllegalArgumentException("Can't set a ValueExpression for the 'id' property.");
}
- if (name.equals("parent")) {
+ if (name.equals("parent"))
+ {
throw new IllegalArgumentException("Can't set a ValueExpression for the 'parent' property.");
}
- if (expression == null) {
+ if (expression == null)
+ {
//if (bindings != null) {
// bindings.remove(name);
// if (bindings.isEmpty()) {
@@ -321,13 +341,19 @@ public abstract class UIComponent implem
// }
//}
getStateHelper().remove(PropertyKeys.bindings, name);
- } else {
- if (expression.isLiteralText()) {
- try {
+ }
+ else
+ {
+ if (expression.isLiteralText())
+ {
+ try
+ {
Object value = expression.getValue(getFacesContext().getELContext());
getAttributes().put(name, value);
return;
- } catch (ELException e) {
+ }
+ catch (ELException e)
+ {
throw new FacesException(e);
}
}
@@ -341,7 +367,8 @@ public abstract class UIComponent implem
}
}
- public String getClientId() {
+ public String getClientId()
+ {
return getClientId(getFacesContext());
}
@@ -355,30 +382,36 @@ public abstract class UIComponent implem
*
* @param component the component to start from
* @return the parent composite component if found otherwise null
- *
+ *
* @since 2.0
*/
- public static UIComponent getCompositeComponentParent(UIComponent component) {
+ public static UIComponent getCompositeComponentParent(UIComponent component)
+ {
- if(component == null) {
+ if (component == null)
+ {
return null;
}
UIComponent parent = component;
- do {
+ do
+ {
parent = parent.getParent();
- if(parent != null && UIComponent.isCompositeComponent(parent)) {
+ if (parent != null && UIComponent.isCompositeComponent(parent))
+ {
return parent;
}
- } while(parent != null);
+ } while (parent != null);
return null;
}
/**
* @since 1.2
*/
- public String getContainerClientId(FacesContext ctx) {
- if (ctx == null) {
+ public String getContainerClientId(FacesContext ctx)
+ {
+ if (ctx == null)
+ {
throw new NullPointerException("FacesContext ctx");
}
@@ -386,24 +419,26 @@ public abstract class UIComponent implem
}
/**
- *
+ *
* @param context
* @return
- *
+ *
* @since 2.0
*/
- public static UIComponent getCurrentComponent(FacesContext context) {
+ public static UIComponent getCurrentComponent(FacesContext context)
+ {
return (UIComponent) context.getAttributes().get(UIComponent.CURRENT_COMPONENT);
}
/**
- *
+ *
* @param context
* @return
- *
+ *
* @since 2.0
*/
- public static UIComponent getCurrentCompositeComponent(FacesContext context) {
+ public static UIComponent getCurrentCompositeComponent(FacesContext context)
+ {
return (UIComponent) context.getAttributes().get(UIComponent.CURRENT_COMPOSITE_COMPONENT);
}
@@ -411,15 +446,22 @@ public abstract class UIComponent implem
public abstract String getId();
- public List<SystemEventListener> getListenersForEventClass(Class<? extends SystemEvent> eventClass) {
+ public List<SystemEventListener> getListenersForEventClass(Class<? extends SystemEvent> eventClass)
+ {
List<SystemEventListener> listeners;
- if (_systemEventListenerClassMap == null) {
+ if (_systemEventListenerClassMap == null)
+ {
listeners = Collections.emptyList();
- } else {
+ }
+ else
+ {
listeners = _systemEventListenerClassMap.get(eventClass);
- if (listeners == null) {
+ if (listeners == null)
+ {
listeners = Collections.emptyList();
- } else {
+ }
+ else
+ {
listeners = Collections.unmodifiableList(listeners);
}
}
@@ -428,17 +470,20 @@ public abstract class UIComponent implem
}
/**
- *
+ *
* @return
- *
+ *
* @since 2.0
*/
- public UIComponent getNamingContainer() {
+ public UIComponent getNamingContainer()
+ {
// Starting with "this", return the closest component in the ancestry that is a NamingContainer
// or null if none can be found.
UIComponent component = this;
- do {
- if (component instanceof NamingContainer) {
+ do
+ {
+ if (component instanceof NamingContainer)
+ {
return component;
}
@@ -464,10 +509,11 @@ public abstract class UIComponent implem
* otherwise take no action</li>
* <ul>
* @param isInView
- *
+ *
* @since 2.0
*/
- public void setInView(boolean isInView) {
+ public void setInView(boolean isInView)
+ {
_inView = isInView;
}
@@ -491,48 +537,63 @@ public abstract class UIComponent implem
public abstract boolean getRendersChildren();
- public Map<String, String> getResourceBundleMap() {
- if (_resourceBundleMap == null) {
+ public Map<String, String> getResourceBundleMap()
+ {
+ if (_resourceBundleMap == null)
+ {
FacesContext context = getFacesContext();
Locale locale = context.getViewRoot().getLocale();
ClassLoader loader = _ClassUtils.getContextClassLoader();
- try {
+ try
+ {
// looks for a ResourceBundle with a base name equal to the fully qualified class
// name of the current UIComponent this and Locale equal to the Locale of the current UIViewRoot.
_resourceBundleMap = new BundleMap(ResourceBundle.getBundle(getClass().getName(), locale, loader));
- } catch (MissingResourceException e) {
+ }
+ catch (MissingResourceException e)
+ {
// If no such bundle is found, and the component is a composite component
- if (this._isCompositeComponent()) {
+ if (this._isCompositeComponent())
+ {
// No need to check componentResource (the resource used to build the composite
// component instance) to null since it is already done on this._isCompositeComponent()
Resource componentResource = (Resource) getAttributes().get(Resource.COMPONENT_RESOURCE_KEY);
// Let resourceName be the resourceName of the Resource for this composite component,
// replacing the file extension with ".properties"
int extensionIndex = componentResource.getResourceName().lastIndexOf('.');
- String resourceName = (extensionIndex < 0 ? componentResource.getResourceName() : componentResource.getResourceName().substring(0, extensionIndex)) + ".properties";
+ String resourceName = (extensionIndex < 0
+ ? componentResource.getResourceName()
+ : componentResource.getResourceName().substring(0, extensionIndex)) + ".properties";
// Let libraryName be the libraryName of the the Resource for this composite component.
// Call ResourceHandler.createResource(java.lang.String,java.lang.String), passing the derived
// resourceName and
// libraryName.
- Resource bundleResource = context.getApplication().getResourceHandler().createResource(resourceName, componentResource.getLibraryName());
+ Resource bundleResource = context.getApplication().getResourceHandler()
+ .createResource(resourceName, componentResource.getLibraryName());
- if (bundleResource != null) {
+ if (bundleResource != null)
+ {
// If the resultant Resource exists and can be found, the InputStream for the resource
// is used to create a ResourceBundle. If either of the two previous steps for obtaining the
// ResourceBundle
// for this component is successful, the ResourceBundle is wrapped in a Map<String, String> and
// returned.
- try {
- _resourceBundleMap = new BundleMap(new PropertyResourceBundle(bundleResource.getInputStream()));
- } catch (IOException e1) {
+ try
+ {
+ _resourceBundleMap
+ = new BundleMap(new PropertyResourceBundle(bundleResource.getInputStream()));
+ }
+ catch (IOException e1)
+ {
// Nothing happens, then resourceBundleMap is set as empty map
}
}
}
// Otherwise Collections.EMPTY_MAP is returned.
- if (_resourceBundleMap == null) {
+ if (_resourceBundleMap == null)
+ {
_resourceBundleMap = Collections.emptyMap();
}
}
@@ -546,26 +607,33 @@ public abstract class UIComponent implem
*/
public abstract ValueBinding getValueBinding(String name);
- public ValueExpression getValueExpression(String name) {
- if (name == null) {
+ public ValueExpression getValueExpression(String name)
+ {
+ if (name == null)
+ {
throw new NullPointerException("name can not be null");
}
-
- Map<String,Object> bindings = (Map<String,Object>) getStateHelper().
- get(PropertyKeys.bindings);
- if (bindings == null) {
- if (!(this instanceof UIComponentBase)) {
+ Map<String, Object> bindings = (Map<String, Object>) getStateHelper().
+ get(PropertyKeys.bindings);
+
+ if (bindings == null)
+ {
+ if (!(this instanceof UIComponentBase))
+ {
// if the component does not inherit from UIComponentBase and don't implements JSF 1.2 or later
ValueBinding vb = getValueBinding(name);
- if (vb != null) {
+ if (vb != null)
+ {
//bindings = new HashMap<String, ValueExpression>();
ValueExpression ve = new _ValueBindingToValueExpression(vb);
- getStateHelper().put(PropertyKeys.bindings , name, ve);
+ getStateHelper().put(PropertyKeys.bindings, name, ve);
return ve;
}
}
- } else {
+ }
+ else
+ {
//return bindings.get(name);
return (ValueExpression) bindings.get(name);
}
@@ -588,7 +656,7 @@ public abstract class UIComponent implem
/**
* {@inheritDoc}
- *
+ *
* @since 2.0
*/
public void clearInitialState()
@@ -604,8 +672,10 @@ public abstract class UIComponent implem
public abstract void encodeEnd(FacesContext context) throws IOException;
- public void encodeAll(FacesContext context) throws IOException {
- if (context == null) {
+ public void encodeAll(FacesContext context) throws IOException
+ {
+ if (context == null)
+ {
throw new NullPointerException();
}
@@ -621,23 +691,27 @@ public abstract class UIComponent implem
{
popComponentFromEL(context);
}
-
+
//if (isRendered()) {
- this.encodeBegin(context);
+ this.encodeBegin(context);
- // rendering children
- if (this.getRendersChildren()) {
- this.encodeChildren(context);
- } // let children render itself
- else {
- if (this.getChildCount() > 0) {
- for (int i =0; i < this.getChildCount(); i++) {
- UIComponent comp = this.getChildren().get(i);
- comp.encodeAll(context);
- }
+ // rendering children
+ if (this.getRendersChildren())
+ {
+ this.encodeChildren(context);
+ } // let children render itself
+ else
+ {
+ if (this.getChildCount() > 0)
+ {
+ for (int i = 0; i < this.getChildCount(); i++)
+ {
+ UIComponent comp = this.getChildren().get(i);
+ comp.encodeAll(context);
}
}
- this.encodeEnd(context);
+ }
+ this.encodeEnd(context);
//}
}
@@ -653,16 +727,19 @@ public abstract class UIComponent implem
public abstract void processDecodes(FacesContext context);
- public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
+ public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
+ {
// The default implementation performs the following action. If the argument event is an instance of
// AfterRestoreStateEvent,
- if (event instanceof PostRestoreStateEvent) {
+ if (event instanceof PostRestoreStateEvent)
+ {
// call this.getValueExpression(java.lang.String) passing the literal string "binding"
ValueExpression expression = getValueExpression("binding");
// If the result is non-null, set the value of the ValueExpression to be this.
- if (expression != null) {
+ if (expression != null)
+ {
expression.setValue(getFacesContext().getELContext(), this);
}
@@ -674,7 +751,8 @@ public abstract class UIComponent implem
// and jsp restore state triggers, a central point is preferrble so we do it here
//TODO ask the EG the spec clearly contradicts blackbox RI behavior here
- //getFacesContext().getApplication().publishEvent(getFacesContext(), PostRestoreStateEvent.class, UIComponent.class, this);
+ //getFacesContext().getApplication().publishEvent(getFacesContext(),
+ // PostRestoreStateEvent.class, UIComponent.class, this);
}
}
@@ -685,7 +763,9 @@ public abstract class UIComponent implem
public abstract java.lang.Object processSaveState(FacesContext context);
- public void subscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener) {
+ public void subscribeToEvent(Class<? extends SystemEvent> eventClass,
+ ComponentSystemEventListener componentListener)
+ {
// The default implementation creates an inner SystemEventListener instance that wraps argument
// componentListener as the listener argument.
if (eventClass == null)
@@ -696,17 +776,19 @@ public abstract class UIComponent implem
{
throw new NullPointerException("componentListener required");
}
-
+
SystemEventListener listener = new EventListenerWrapper(this, componentListener);
// Make sure the map exists
- if (_systemEventListenerClassMap == null) {
+ if (_systemEventListenerClassMap == null)
+ {
_systemEventListenerClassMap = new HashMap<Class<? extends SystemEvent>, List<SystemEventListener>>();
}
List<SystemEventListener> listeners = _systemEventListenerClassMap.get(eventClass);
// Make sure the list for class exists
- if (listeners == null) {
+ if (listeners == null)
+ {
listeners = new _DeltaList<SystemEventListener>(new ArrayList<SystemEventListener>(2));
_systemEventListenerClassMap.put(eventClass, listeners);
}
@@ -716,13 +798,15 @@ public abstract class UIComponent implem
}
public void unsubscribeFromEvent(Class<? extends SystemEvent> eventClass,
- ComponentSystemEventListener componentListener) {
+ ComponentSystemEventListener componentListener)
+ {
/*
* When doing the comparison to determine if an existing listener is equal to the argument componentListener
* (and thus must be removed), the equals() method on the existing listener must be invoked, passing the
* argument componentListener, rather than the other way around.
*
- * -=Simon Lessard=- What is that supposed to mean? Are we supposed to keep an internal map of created listener wrappers?
+ * -=Simon Lessard=- What is that supposed to mean? Are we supposed to keep
+ * an internal map of created listener wrappers?
* -= Leonardo Uribe=- Yes, it is supposed a wrapper should be used to hold listener references, to prevent
* serialize component instances on the state.
*/
@@ -738,12 +822,13 @@ public abstract class UIComponent implem
if (_systemEventListenerClassMap != null)
{
List<SystemEventListener> listeners = _systemEventListenerClassMap.get(eventClass);
-
+
if (listeners != null && !listeners.isEmpty())
{
- for (Iterator<SystemEventListener> it = listeners.iterator(); it.hasNext();)
+ for (Iterator<SystemEventListener> it = listeners.iterator(); it.hasNext(); )
{
- ComponentSystemEventListener listener = ((EventListenerWrapper) it.next()).getComponentSystemEventListener();
+ ComponentSystemEventListener listener
+ = ((EventListenerWrapper) it.next()).getComponentSystemEventListener();
if (listener != null && listener.equals(componentListener))
{
it.remove();
@@ -774,48 +859,59 @@ public abstract class UIComponent implem
* @param callback the callback to be performed
* @return false if the processing is not done true if we can shortcut
* the visiting because we are done with everything
- *
+ *
* @since 2.0
*/
- public boolean visitTree(VisitContext context, VisitCallback callback) {
- try {
+ public boolean visitTree(VisitContext context, VisitCallback callback)
+ {
+ try
+ {
pushComponentToEL(context.getFacesContext(), this);
-
- if (!isVisitable(context)) {
- return false;
- }
-
- VisitResult res = context.invokeVisitCallback(this, callback);
- switch (res) {
- //we are done nothing has to be processed anymore
- case COMPLETE:
- return true;
- case REJECT:
+ if (!isVisitable(context))
+ {
return false;
+ }
- //accept
- default:
- if (getFacetCount() > 0) {
- for (UIComponent facet : getFacets().values()) {
- if (facet.visitTree(context, callback)) {
- return true;
+ VisitResult res = context.invokeVisitCallback(this, callback);
+ switch (res)
+ {
+ //we are done nothing has to be processed anymore
+ case COMPLETE:
+ return true;
+
+ case REJECT:
+ return false;
+
+ //accept
+ default:
+ if (getFacetCount() > 0)
+ {
+ for (UIComponent facet : getFacets().values())
+ {
+ if (facet.visitTree(context, callback))
+ {
+ return true;
+ }
}
}
- }
- int childCount = getChildCount();
- if (childCount > 0) {
- for (int i =0; i < childCount; i++) {
- UIComponent child = getChildren().get(i);
- if (child.visitTree(context, callback)) {
- return true;
+ int childCount = getChildCount();
+ if (childCount > 0)
+ {
+ for (int i = 0; i < childCount; i++)
+ {
+ UIComponent child = getChildren().get(i);
+ if (child.visitTree(context, callback))
+ {
+ return true;
+ }
}
}
- }
- return false;
+ return false;
}
}
- finally {
+ finally
+ {
//all components must call popComponentFromEl after visiting is finished
popComponentFromEL(context.getFacesContext());
}
@@ -833,14 +929,14 @@ public abstract class UIComponent implem
* (Note that rendererType is suspicious, in theory this field is
* initialized on constructor, but on 1.1 and 1.2 is saved and restored,
* so to keep backward behavior we put it on StateHelper )
- *
+ *
* Also, facesListeners can't be wrapped on StateHelper because it
* needs to handle PartialStateHolder instances when it is saved and
* restored and this interface does not implement PartialStateHolder,
* so we can't propagate calls to markInitialState and clearInitialState,
* in other words, the List wrapped by StateHelper does not handle
* PartialStateHolder items.
- *
+ *
* "bindings" map does not need to deal with PartialStateHolder instances,
* so we can use StateHelper feature (handle delta for this map or in
* other words track add/removal from bindings map as delta).
@@ -854,7 +950,8 @@ public abstract class UIComponent implem
facesListeners
}
- protected StateHelper getStateHelper() {
+ protected StateHelper getStateHelper()
+ {
return getStateHelper(true);
}
@@ -864,25 +961,30 @@ public abstract class UIComponent implem
* @param create if true a state helper is created if not already existing
* @return an implementation of the StateHelper interface or null if none exists and create is set to false
*/
- protected StateHelper getStateHelper(boolean create) {
- if(_stateHelper != null) {
+ protected StateHelper getStateHelper(boolean create)
+ {
+ if (_stateHelper != null)
+ {
return _stateHelper;
}
- if(create) {
+ if (create)
+ {
_stateHelper = new _DeltaStateHelper(this);
}
return _stateHelper;
}
@SuppressWarnings("unchecked")
- public final void popComponentFromEL(FacesContext context) {
- Map<Object, Object> contextAttributes = context.getAttributes();
-
+ public final void popComponentFromEL(FacesContext context)
+ {
+ Map<Object, Object> contextAttributes = context.getAttributes();
+
// Pop the current UIComponent from the FacesContext attributes map so that the previous
// UIComponent, if any, becomes the current component.
- LinkedList<UIComponent> componentStack = (LinkedList<UIComponent>) contextAttributes.get(UIComponent._COMPONENT_STACK);
-
- UIComponent oldCurrent = (UIComponent)contextAttributes.get(UIComponent.CURRENT_COMPONENT);
+ List<UIComponent> componentStack
+ = (List<UIComponent>) contextAttributes.get(UIComponent._COMPONENT_STACK);
+
+ UIComponent oldCurrent = (UIComponent) contextAttributes.get(UIComponent.CURRENT_COMPONENT);
UIComponent newCurrent = null;
if (componentStack != null && !componentStack.isEmpty())
@@ -890,12 +992,13 @@ public abstract class UIComponent implem
if (!this.equals(oldCurrent))
{
//Check on the componentStack if it can be found
- int componentIndex = componentStack.indexOf(this);
+ int componentIndex = componentStack.lastIndexOf(this);
if (componentIndex >= 0)
{
- for (int i = 0; i < (componentIndex+1); i++)
+ //for (int i = 0; i < (componentIndex + 1); i++)
+ for (int i = componentStack.size()-1; i >= componentIndex ; i--)
{
- newCurrent = componentStack.removeFirst();
+ newCurrent = componentStack.remove(componentStack.size()-1);
}
}
else
@@ -906,7 +1009,7 @@ public abstract class UIComponent implem
}
else
{
- newCurrent = componentStack.removeFirst();
+ newCurrent = componentStack.remove(componentStack.size()-1);
}
}
else
@@ -914,8 +1017,8 @@ public abstract class UIComponent implem
//Reset the current composite component
contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, null);
}
- oldCurrent = (UIComponent)contextAttributes.put(UIComponent.CURRENT_COMPONENT, newCurrent);
-
+ oldCurrent = (UIComponent) contextAttributes.put(UIComponent.CURRENT_COMPONENT, newCurrent);
+
if (oldCurrent != null && oldCurrent._isCompositeComponent())
{
// Recalculate the current composite component
@@ -928,9 +1031,9 @@ public abstract class UIComponent implem
else
{
UIComponent previousCompositeComponent = null;
- for (Iterator<UIComponent> it = componentStack.iterator(); it.hasNext();)
+ for (int i = componentStack.size()-1; i >= 0; i--)
{
- UIComponent component = it.next();
+ UIComponent component = componentStack.get(i);
if (component._isCompositeComponent())
{
previousCompositeComponent = component;
@@ -944,31 +1047,33 @@ public abstract class UIComponent implem
}
@SuppressWarnings("unchecked")
- public final void pushComponentToEL(FacesContext context, UIComponent component) {
+ public final void pushComponentToEL(FacesContext context, UIComponent component)
+ {
if (component == null)
{
component = this;
}
- Map<Object, Object> contextAttributes = context.getAttributes();
+ Map<Object, Object> contextAttributes = context.getAttributes();
UIComponent currentComponent = (UIComponent) contextAttributes.get(UIComponent.CURRENT_COMPONENT);
-
- if(currentComponent != null)
+
+ if (currentComponent != null)
{
- LinkedList<UIComponent> componentStack = (LinkedList<UIComponent>) contextAttributes.get(UIComponent._COMPONENT_STACK);
- if(componentStack == null)
+ List<UIComponent> componentStack
+ = (List<UIComponent>) contextAttributes.get(UIComponent._COMPONENT_STACK);
+ if (componentStack == null)
{
- componentStack = new LinkedList<UIComponent>();
+ componentStack = new ArrayList<UIComponent>();
contextAttributes.put(UIComponent._COMPONENT_STACK, componentStack);
}
-
- componentStack.addFirst(currentComponent);
+
+ componentStack.add(currentComponent);
}
-
+
// Push the current UIComponent this to the FacesContext attribute map using the key CURRENT_COMPONENT
// saving the previous UIComponent associated with CURRENT_COMPONENT for a subsequent call to
// popComponentFromEL(javax.faces.context.FacesContext).
contextAttributes.put(UIComponent.CURRENT_COMPONENT, component);
-
+
if (component._isCompositeComponent())
{
contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, component);
@@ -978,53 +1083,69 @@ public abstract class UIComponent implem
/**
* @since 1.2
*/
- public int getFacetCount() {
+ public int getFacetCount()
+ {
// not sure why the RI has this method in both
// UIComponent and UIComponentBase
Map<String, UIComponent> facets = getFacets();
return facets == null ? 0 : facets.size();
}
- private boolean _isCompositeComponent() {
+ private boolean _isCompositeComponent()
+ {
//moved to the static method
return UIComponent.isCompositeComponent(this);
}
-
- private static class BundleMap implements Map<String, String> {
+
+ private static class BundleMap implements Map<String, String>
+ {
private ResourceBundle _bundle;
private List<String> _values;
- public BundleMap(ResourceBundle bundle) {
+ public BundleMap(ResourceBundle bundle)
+ {
_bundle = bundle;
}
// Optimized methods
- public String get(Object key) {
- try {
+ public String get(Object key)
+ {
+ try
+ {
return (String) _bundle.getObject(key.toString());
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return "???" + key + "???";
}
}
- public boolean isEmpty() {
+ public boolean isEmpty()
+ {
return !_bundle.getKeys().hasMoreElements();
}
- public boolean containsKey(Object key) {
- try {
+ public boolean containsKey(Object key)
+ {
+ try
+ {
return _bundle.getObject(key.toString()) != null;
- } catch (MissingResourceException e) {
+ }
+ catch (MissingResourceException e)
+ {
return false;
}
}
// Unoptimized methods
- public Collection<String> values() {
- if (_values == null) {
+ public Collection<String> values()
+ {
+ if (_values == null)
+ {
_values = new ArrayList<String>();
- for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();) {
+ for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements(); )
+ {
String v = _bundle.getString(enumer.nextElement());
_values.add(v);
}
@@ -1032,29 +1153,37 @@ public abstract class UIComponent implem
return _values;
}
- public int size() {
+ public int size()
+ {
return values().size();
}
- public boolean containsValue(Object value) {
+ public boolean containsValue(Object value)
+ {
return values().contains(value);
}
- public Set<Map.Entry<String, String>> entrySet() {
+ public Set<Map.Entry<String, String>> entrySet()
+ {
Set<Entry<String, String>> set = new HashSet<Entry<String, String>>();
- for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();) {
+ for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements(); )
+ {
final String k = enumer.nextElement();
- set.add(new Map.Entry<String, String>() {
+ set.add(new Map.Entry<String, String>()
+ {
- public String getKey() {
+ public String getKey()
+ {
return k;
}
- public String getValue() {
+ public String getValue()
+ {
return (String) _bundle.getObject(k);
}
- public String setValue(String value) {
+ public String setValue(String value)
+ {
throw new UnsupportedOperationException();
}
});
@@ -1063,37 +1192,44 @@ public abstract class UIComponent implem
return set;
}
- public Set<String> keySet() {
+ public Set<String> keySet()
+ {
Set<String> set = new HashSet<String>();
- for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements();) {
+ for (Enumeration<String> enumer = _bundle.getKeys(); enumer.hasMoreElements(); )
+ {
set.add(enumer.nextElement());
}
return set;
}
// Unsupported methods
- public String remove(Object key) {
+ public String remove(Object key)
+ {
throw new UnsupportedOperationException();
}
- public void putAll(Map<? extends String, ? extends String> t) {
+ public void putAll(Map<? extends String, ? extends String> t)
+ {
throw new UnsupportedOperationException();
}
- public String put(String key, String value) {
+ public String put(String key, String value)
+ {
throw new UnsupportedOperationException();
}
- public void clear() {
+ public void clear()
+ {
throw new UnsupportedOperationException();
}
}
- static class EventListenerWrapper implements SystemEventListener, PartialStateHolder {
+ static class EventListenerWrapper implements SystemEventListener, PartialStateHolder
+ {
private Class<?> componentClass;
private ComponentSystemEventListener listener;
-
+
private boolean _initialStateMarked;
private int listenerCapability;
@@ -1103,16 +1239,16 @@ public abstract class UIComponent implem
private static final int LISTENER_TYPE_COMPONENT = 4;
private static final int LISTENER_TYPE_RENDERER = 8;
private static final int LISTENER_TYPE_OTHER = 16;
-
+
public EventListenerWrapper()
{
//need a no-arg constructor for state saving purposes
super();
}
-
+
/**
* Note we have two cases:
- *
+ *
* 1. listener is an instance of UIComponent. In this case we cannot save and restore
* it because we need to point to the real component, but we can assume the instance
* is the same because UIComponent.subscribeToEvent says so. Also take into account
@@ -1122,11 +1258,12 @@ public abstract class UIComponent implem
* 3. listener is an instance of ComponentSystemEventListener but not from UIComponent.
* In this case, the instance could implement StateHolder, PartialStateHolder or do
* implement anything, so we have to deal with that case as usual.
- *
+ *
* @param component
* @param listener
*/
- public EventListenerWrapper(UIComponent component, ComponentSystemEventListener listener) {
+ public EventListenerWrapper(UIComponent component, ComponentSystemEventListener listener)
+ {
assert component != null;
assert listener != null;
@@ -1135,7 +1272,7 @@ public abstract class UIComponent implem
initListenerCapability();
}
-
+
private void initListenerCapability()
{
this.listenerCapability = 0;
@@ -1151,7 +1288,7 @@ public abstract class UIComponent implem
{
if (this.listener instanceof PartialStateHolder)
{
- this.listenerCapability = LISTENER_TYPE_OTHER | LISTENER_SAVE_PARTIAL_STATE_HOLDER;
+ this.listenerCapability = LISTENER_TYPE_OTHER | LISTENER_SAVE_PARTIAL_STATE_HOLDER;
}
else if (this.listener instanceof StateHolder)
{
@@ -1165,7 +1302,8 @@ public abstract class UIComponent implem
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(Object o)
+ {
if (o == this)
{
return true;
@@ -1174,13 +1312,16 @@ public abstract class UIComponent implem
{
EventListenerWrapper other = (EventListenerWrapper) o;
return componentClass.equals(other.componentClass) && listener.equals(other.listener);
- } else {
+ }
+ else
+ {
return false;
}
}
@Override
- public int hashCode() {
+ public int hashCode()
+ {
return componentClass.hashCode() + listener.hashCode();
}
@@ -1191,7 +1332,7 @@ public abstract class UIComponent implem
return source.getClass().isAssignableFrom(componentClass);
}
-
+
public ComponentSystemEventListener getComponentSystemEventListener()
{
return listener;
@@ -1210,9 +1351,9 @@ public abstract class UIComponent implem
public void clearInitialState()
{
//if (!(listener instanceof UIComponent) && listener instanceof PartialStateHolder)
- if ( (listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
+ if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
{
- ((PartialStateHolder)listener).clearInitialState();
+ ((PartialStateHolder) listener).clearInitialState();
}
_initialStateMarked = false;
}
@@ -1220,9 +1361,9 @@ public abstract class UIComponent implem
public boolean initialStateMarked()
{
//if (!(listener instanceof UIComponent) && listener instanceof PartialStateHolder)
- if ( (listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
+ if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
{
- return ((PartialStateHolder)listener).initialStateMarked();
+ return ((PartialStateHolder) listener).initialStateMarked();
}
//return false;
return _initialStateMarked;
@@ -1231,9 +1372,9 @@ public abstract class UIComponent implem
public void markInitialState()
{
//if (!(listener instanceof UIComponent) && listener instanceof PartialStateHolder)
- if ( (listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
+ if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
{
- ((PartialStateHolder)listener).markInitialState();
+ ((PartialStateHolder) listener).markInitialState();
}
_initialStateMarked = true;
}
@@ -1241,11 +1382,11 @@ public abstract class UIComponent implem
public boolean isTransient()
{
//if ( listener instanceof StateHolder)
- if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0 ||
- (listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0 )
+ if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0 ||
+ (listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0)
{
- return ((StateHolder)listener).isTransient();
- }
+ return ((StateHolder) listener).isTransient();
+ }
return false;
}
@@ -1259,24 +1400,27 @@ public abstract class UIComponent implem
componentClass = (Class) values[0];
if (values[1] instanceof _AttachedDeltaWrapper)
{
- ((StateHolder)listener).restoreState(context, ((_AttachedDeltaWrapper)values[1]).getWrappedStateObject());
+ ((StateHolder) listener).restoreState(context,
+ ((_AttachedDeltaWrapper) values[1]).getWrappedStateObject());
}
else
{
//Full restore
listenerCapability = (Integer) values[2];
-
- if ( (listenerCapability & LISTENER_TYPE_COMPONENT) != 0 )
+
+ if ((listenerCapability & LISTENER_TYPE_COMPONENT) != 0)
{
listener = UIComponent.getCurrentComponent(context);
}
- else if ( (listenerCapability & LISTENER_TYPE_RENDERER) != 0)
+ else if ((listenerCapability & LISTENER_TYPE_RENDERER) != 0)
{
- listener = (ComponentSystemEventListener) UIComponent.getCurrentComponent(context).getRenderer(context);
+ listener = (ComponentSystemEventListener)
+ UIComponent.getCurrentComponent(context).getRenderer(context);
}
else
{
- listener = (ComponentSystemEventListener) UIComponentBase.restoreAttachedState(context, values[1]);
+ listener = (ComponentSystemEventListener)
+ UIComponentBase.restoreAttachedState(context, values[1]);
}
/*
listener = values[1] == null ?
@@ -1302,8 +1446,8 @@ public abstract class UIComponent implem
Object[] state = new Object[3];
state[0] = componentClass;
//If this is not a component or a renderer, save it calling UIComponent.saveAttachedState
- if (!( (listenerCapability & LISTENER_TYPE_COMPONENT) != 0 ||
- (listenerCapability & LISTENER_TYPE_RENDERER) != 0 ) )
+ if (!((listenerCapability & LISTENER_TYPE_COMPONENT) != 0 ||
+ (listenerCapability & LISTENER_TYPE_RENDERER) != 0))
{
state[1] = UIComponentBase.saveAttachedState(context, listener);
}
@@ -1318,25 +1462,26 @@ public abstract class UIComponent implem
{
// If initialStateMarked() == true means two things:
// 1. PSS is being used
- if ( (listenerCapability & LISTENER_TYPE_COMPONENT) != 0)
+ if ((listenerCapability & LISTENER_TYPE_COMPONENT) != 0)
{
return null;
}
- else if ( (listenerCapability & LISTENER_TYPE_RENDERER) != 0)
+ else if ((listenerCapability & LISTENER_TYPE_RENDERER) != 0)
{
return null;
}
else
{
- if ( (listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0 ||
- (listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
+ if ((listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0 ||
+ (listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0)
{
Object listenerSaved = ((StateHolder) listener).saveState(context);
if (listenerSaved == null)
{
return null;
}
- return new Object[]{componentClass, new _AttachedDeltaWrapper(listener.getClass(), listenerSaved)};
+ return new Object[]{componentClass,
+ new _AttachedDeltaWrapper(listener.getClass(), listenerSaved)};
}
else
{
@@ -1357,11 +1502,11 @@ public abstract class UIComponent implem
public void setTransient(boolean newTransientValue)
{
- if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0 ||
- (listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0 )
+ if ((listenerCapability & LISTENER_SAVE_PARTIAL_STATE_HOLDER) != 0 ||
+ (listenerCapability & LISTENER_SAVE_STATE_HOLDER) != 0)
{
- ((StateHolder)listener).setTransient(newTransientValue);
- }
+ ((StateHolder) listener).setTransient(newTransientValue);
+ }
}
}
}