public void restoreState(FacesContext context, Object state) {

        if (context == null) {
            throw new NullPointerException();
        }
        if (state == null) {
            return;
        }

        Object[] attachedObjects = (Object[]) state;
        if (attachedObjects.length > 0 && attachedObjects[0] instanceof StateHolderSaver) {
            // overwrite the existing attachedObjects with those included
            // in the full state.
            if (this.attachedObjects != null) {
                this.attachedObjects.clear();
            } else {
                this.attachedObjects = new ArrayList<T>(2);
            }
            for (int i = 0, len = attachedObjects.length; i < len; i++) {
                T restored = (T) ((StateHolderSaver) attachedObjects[i]).restore(context);
                if (restored != null) {
                    add(restored);
                }
            }
        } else {
            // assume 1:1 relation between existing attachedObjects and state
            for (int i = 0, len = attachedObjects.length; i < len; i++) {
                T l = this.attachedObjects.get(i);
                if (l instanceof StateHolder) {
                    ((StateHolder) l).restoreState(context, attachedObjects[i]);
                }
            }
        }

    }