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.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 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.
*/
package javax.faces.component;
import javax.faces.context.FacesContext;
import static javax.faces.component.UIComponentBase.saveAttachedState;
import static javax.faces.component.UIComponentBase.restoreAttachedState;
import javax.el.ValueExpression;
import java.util.*;
import java.io.Serializable;
/**A base implementation for
* maps which implement the PartialStateHolder interface.
*
* This can be used as a base-class for all
* state-holder implementations in components,
* converters and validators and other implementations
* of the StateHolder interface.
*/
@SuppressWarnings({"unchecked"})
class ComponentStateHelper implements StateHelper {
private UIComponent component;
private boolean isTransient;
private Map deltaMap;
private Map defaultMap;
// ------------------------------------------------------------ Constructors
public ComponentStateHelper(UIComponent component) {
this.component = component;
this.deltaMap = new HashMap();
this.defaultMap = new HashMap();
}
// ------------------------------------------------ Methods from StateHelper
/**
* Put the object in the main-map
* and/or the delta-map, if necessary.
*
* @param key
* @param value
* @return the original value in the delta-map, if not present, the old value in the main map
*/
public Object put(Serializable key, Object value) {
if(component.initialStateMarked() || value instanceof PartialStateHolder) {
Object retVal = deltaMap.put(key, value);
if(retVal==null) {
return defaultMap.put(key,value);
}
else {
defaultMap.put(key,value);
return retVal;
}
}
else {
return defaultMap.put(key,value);
}
}
/**
* We need to remove from both
* maps, if we do remove an existing key.
*
* @param key
* @return the removed object in the delta-map. if not present, the removed object from the main map
*/
public Object remove(Serializable key) {
if(component.initialStateMarked()) {
Object retVal = deltaMap.remove(key);
if(retVal==null) {
return defaultMap.remove(key);
}
else {
defaultMap.remove(key);
return retVal;
}
}
else {
return defaultMap.remove(key);
}
}
/**
* @see StateHelper#put(java.io.Serializable, String, Object)
*/
public Object put(Serializable key, String mapKey, Object value) {
Object ret = null;
if (component.initialStateMarked()) {
Map dMap = (Map) deltaMap.get(key);
if (dMap == null) {
dMap = new HashMap(5);
deltaMap.put(key, dMap);
}
ret = dMap.put(mapKey, value);
}
Map map = (Map) get(key);
if (map == null) {
map = new HashMap(8);
defaultMap.put(key, map);
}
if (ret == null) {
return map.put(mapKey, value);
} else {
map.put(mapKey, value);
return ret;
}
}
/**
* Get the object from the main-map.
* As everything is written through
* from the delta-map to the main-map, this
* should be enough.
*
* @param key
* @return
*/
public Object get(Serializable key) {
return defaultMap.get(key);
}
/**
* @see StateHelper#eval(java.io.Serializable)
*/
public Object eval(Serializable key) {
return eval(key, null);
}
/**
* @see StateHelper#eval(java.io.Serializable, Object)
*/
public Object eval(Serializable key, Object defaultValue) {
Object retVal = get(key);
if (retVal == null) {
ValueExpression ve = component.getValueExpression(key.toString());
if (ve != null) {
retVal = ve.getValue(component.getFacesContext().getELContext());
}
}
return ((retVal != null) ? retVal : defaultValue);
}
/**
* @see StateHelper#add(java.io.Serializable, Object)
*/
public void add(Serializable key, Object value) {
if (component.initialStateMarked()) {
List