org.icefaces.ace.component.animation.BehaviorBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of icefaces-ace Show documentation
Show all versions of icefaces-ace Show documentation
${icefaces.product.name} ACE Component Library
/*
* Copyright 2004-2013 ICEsoft Technologies Canada Corp.
*
* Licensed 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 org.icefaces.ace.component.animation;
import javax.el.ValueExpression;
import javax.faces.component.StateHolder;
import javax.faces.component.behavior.ClientBehaviorBase;
import javax.faces.context.FacesContext;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BehaviorBase extends ClientBehaviorBase {
protected Map bindings;
public Object saveBindingsState(FacesContext context) {
if (bindings == null) {
return (null);
}
Object values[] = new Object[2];
values[0] = bindings.keySet().toArray(new String[bindings.size()]);
Object[] bindingValues = bindings.values().toArray();
for (int i = 0; i < bindingValues.length; i++) {
bindingValues[i] = saveAttachedState(context,
bindingValues[i]);
}
values[1] = bindingValues;
return (values);
}
public static Map restoreBindingsState(FacesContext context, Object state) {
if (state == null) {
return (null);
}
Object values[] = (Object[]) state;
String names[] = (String[]) values[0];
Object states[] = (Object[]) values[1];
Map bindings = new HashMap(names.length);
for (int i = 0; i < names.length; i++) {
bindings.put(names[i],
(ValueExpression) restoreAttachedState(context, states[i]));
}
return (bindings);
}
public static Object restoreAttachedState(FacesContext context,
Object stateObj)
throws IllegalStateException {
if (null == context) {
throw new NullPointerException();
}
if (null == stateObj) {
return null;
}
Object result;
if (stateObj instanceof List) {
List stateList = (List) stateObj;
BehaviorStateHolderSaver collectionSaver = stateList.get(0);
Class mapOrCollection = (Class) collectionSaver.restore(context);
if (Collection.class.isAssignableFrom(mapOrCollection)) {
Collection