public Object saveState(FacesContext context) {

        if (context == null) {
            throw new NullPointerException();
        }
        if (attachedObjects == null) {
            return null;
        }
        if (initialState) {
            Object[] attachedObjects = new Object[this.attachedObjects.size()];
            boolean stateWritten = false;
            for (int i = 0, len = attachedObjects.length; i < len; i++) {
                T attachedObject = this.attachedObjects.get(i);
                if (attachedObject instanceof StateHolder) {
                    StateHolder sh = (StateHolder) attachedObject;
                    if (!sh.isTransient()) {
                        attachedObjects[i] = sh.saveState(context);
                    }
                    if (attachedObjects[i] != null) {
                        stateWritten = true;
                    }
                }
            }
            return ((stateWritten) ? attachedObjects : null);
        } else {

            Object[] attachedObjects = new Object[this.attachedObjects.size()];
            for (int i = 0, len = attachedObjects.length; i < len; i++) {
                attachedObjects[i] = UIComponentBase.saveAttachedState(context, this.attachedObjects.get(i));
            }
            return (attachedObjects);
        }

    }