Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 javax.faces.component;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Resource;
import javax.faces.context.FacesContext;
/**
* A custom implementation of the Map interface, where get and put calls
* try to access getter/setter methods of an associated UIComponent before
* falling back to accessing a real Map object.
*
* Some of the behaviours of this class don't really comply with the
* definitions of the Map class; for example the key parameter to all
* methods is required to be of type String only, and after clear(),
* calls to get can return non-null values. However the JSF spec
* requires that this class behave in the way implemented below. See
* UIComponent.getAttributes for more details.
*
* The term "property" is used here to refer to real javabean properties
* on the underlying UIComponent, while "attribute" refers to an entry
* in the associated Map.
*
* @author Manfred Geiler (latest modification by $Author: lu4242 $)
* @version $Revision: 1157591 $ $Date: 2011-08-14 13:10:45 -0500 (Sun, 14 Aug 2011) $
*/
class _ComponentAttributesMap implements Map, Serializable
{
private static final long serialVersionUID = -9106832179394257866L;
private static final Object[] EMPTY_ARGS = new Object[0];
// The component that is read/written via this map.
private UIComponent _component;
// We delegate instead of derive from HashMap, so that we can later
// optimize Serialization
// JSF 2.0 Changed getUnderlyingMap to point to StateHelper attributesMap
//private Map _attributes = null;
// A cached hashmap of propertyName => PropertyDescriptor object for all
// the javabean properties of the associated component. This is built by
// introspection on the associated UIComponent. Don't serialize this as
// it can always be recreated when needed.
private transient Map _propertyDescriptorMap = null;
// Cache for component property descriptors
private static Map, Map> _propertyDescriptorCache =
new WeakHashMap, Map>();
private boolean _isCompositeComponent;
private boolean _isCompositeComponentSet;
/**
* Create a map backed by the specified component.
*
* This method is expected to be called when a component is first created.
*/
_ComponentAttributesMap(UIComponent component)
{
_component = component;
}
/**
* Create a map backed by the specified component. Attributes already
* associated with the component are provided in the specified Map
* class. A reference to the provided map is kept; this object's contents
* are updated during put calls on this instance.
*
* This method is expected to be called during the "restore view" phase.
*/
//JSF 2.0 removed because _attributes has been replaced with StateHelper attributesMap
//_ComponentAttributesMap(UIComponent component, Map attributes)
//{
// _component = component;
//_attributes = new HashMap(attributes);
//}
/**
* Return the number of attributes in this map. Properties of the
* underlying UIComponent are not counted.
*
* Note that because the get method can read properties of the
* UIComponent and evaluate value-bindings, it is possible to have
* size return zero while calls to the get method return non-null
* values.
*/
public int size()
{
return getUnderlyingMap().size();
}
/**
* Clear all the attributes in this map. Properties of the
* underlying UIComponent are not modified.
*
* Note that because the get method can read properties of the
* UIComponent and evaluate value-bindings, it is possible to have
* calls to the get method return non-null values immediately after
* a call to clear.
*/
public void clear()
{
getUnderlyingMap().clear();
}
/**
* Return true if there are no attributes in this map. Properties
* of the underlying UIComponent are not counted.
*
* Note that because the get method can read properties of the
* UIComponent and evaluate value-bindings, it is possible to have
* isEmpty return true, while calls to the get method return non-null
* values.
*/
public boolean isEmpty()
{
return getUnderlyingMap().isEmpty();
}
/**
* Return true if there is an attribute with the specified name,
* but false if there is a javabean property of that name on the
* associated UIComponent.
*
* Note that it should be impossible for the attributes map to contain
* an entry with the same name as a javabean property on the associated
* UIComponent.
*
* @param key must be a String. Anything else will cause a
* ClassCastException to be thrown.
*/
public boolean containsKey(Object key)
{
checkKey(key);
// The most common call to this method comes from UIComponent.isCompositeComponent()
// to reduce the impact. This is better than two lookups, once over property descriptor map
// and the other one from the underlying map.
if (Resource.COMPONENT_RESOURCE_KEY.length() == ((String)key).length() &&
Resource.COMPONENT_RESOURCE_KEY.equals(key))
{
if (!_isCompositeComponentSet)
{
// Note we are not setting _isCompositeComponentSet, because when the component tree is built
// using JSF 1.2 state saving, PostAddToViewEvent is propagated and the component is check
// if is a composite component, but the state is not restored, so the check return always
// false. A check for processing events was added to prevent that scenario, but anyway that
// makes invalid set _isCompositeComponentSet to true on this location.
_isCompositeComponent = getUnderlyingMap().containsKey(Resource.COMPONENT_RESOURCE_KEY);
}
return _isCompositeComponent;
}
return getPropertyDescriptor((String) key) == null ? getUnderlyingMap().containsKey(key) : false;
}
/**
* Returns true if there is an attribute with the specified
* value. Properties of the underlying UIComponent aren't examined,
* nor value-bindings.
*
* @param value null is allowed
*/
public boolean containsValue(Object value)
{
return getUnderlyingMap().containsValue(value);
}
/**
* Return a collection of the values of all attributes. Property
* values are not included, nor value-bindings.
*/
public Collection