sessionitemstatemanager.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 968 行 · 第 1/3 页

JAVA
968
字号
     * @throws NoSuchItemStateException     * @throws ItemStateException     */    public ItemState getTransientItemState(ItemId id)            throws NoSuchItemStateException, ItemStateException {        ItemState state = transientStore.get(id);        if (state != null) {            return state;        } else {            throw new NoSuchItemStateException(id.toString());        }    }    /**     *     * @param id     * @return     */    public boolean hasTransientItemState(ItemId id) {        return transientStore.contains(id);    }    /**     *     * @param id     * @return     */    public boolean hasTransientItemStateInAttic(ItemId id) {        return atticStore.contains(id);    }    /**     * @return <code>true</code> if this manager has any transient state;     *         <code>false</code> otherwise.     */    public boolean hasAnyTransientItemStates() {        return !transientStore.isEmpty();    }    /**     * Returns an iterator over those transient item state instances that are     * direct or indirect descendents of the item state with the given     * <code>parentId</code>. The transient item state instance with the given     * <code>parentId</code> itself (if there is such) will not be included.     * <p/>     * The instances are returned in depth-first tree traversal order.     *     * @param parentId the id of the common parent of the transient item state     *                 instances to be returned.     * @return an iterator over descendant transient item state instances     * @throws InvalidItemStateException if any descendant item state has been     *                                   deleted externally     * @throws RepositoryException       if another error occurs     */    public Iterator getDescendantTransientItemStates(NodeId parentId)            throws InvalidItemStateException, RepositoryException {        if (transientStore.isEmpty()) {            return Collections.EMPTY_LIST.iterator();        }        // build ordered collection of descendant transient states        // sorted by decreasing relative depth        // use an array of lists to group the descendants by relative depth;        // the depth is used as array index        List[] la = new List[10];        try {            Iterator iter = transientStore.values().iterator();            while (iter.hasNext()) {                ItemState state = (ItemState) iter.next();                // determine relative depth: > 0 means it's a descendant                int depth;                try {                    depth = hierMgr.getRelativeDepth(parentId, state.getId());                } catch (ItemNotFoundException infe) {                    /**                     * one of the parents of the specified item has been                     * removed externally; as we don't know its path,                     * we can't determine if it is a descendant;                     * InvalidItemStateException should only be thrown if                     * a descendant is affected;                     * => throw InvalidItemStateException for now                     * todo FIXME                     */                    // unable to determine relative depth, assume that the item                    // (or any of its ancestors) has been removed externally                    String msg = state.getId()                            + ": the item seems to have been removed externally.";                    log.debug(msg);                    throw new InvalidItemStateException(msg);                }                if (depth < 1) {                    // not a descendant                    continue;                }                // ensure capacity                if (depth > la.length) {                    List[] old = la;                    la = new List[depth + 10];                    System.arraycopy(old, 0, la, 0, old.length);                }                List list = la[depth - 1];                if (list == null) {                    list = new ArrayList();                    la[depth - 1] = list;                }                list.add(state);            }        } catch (RepositoryException re) {            log.warn("inconsistent hierarchy state", re);        }        // create an iterator over the collected descendants        // in decreasing depth order        IteratorChain resultIter = new IteratorChain();        for (int i = la.length - 1; i >= 0; i--) {            List list = la[i];            if (list != null) {                resultIter.addIterator(list.iterator());            }        }        /**         * if the resulting iterator chain is empty return         * EMPTY_LIST.iterator() instead because older versions         * of IteratorChain (pre Commons Collections 3.1)         * would throw UnsupportedOperationException in this         * situation         */        if (resultIter.getIterators().isEmpty()) {            return Collections.EMPTY_LIST.iterator();        }        return resultIter;    }    /**     * Same as <code>{@link #getDescendantTransientItemStates(NodeId)}</code>     * except that item state instances in the attic are returned.     *     * @param parentId the id of the common parent of the transient item state     *                 instances to be returned.     * @return an iterator over descendant transient item state instances in the attic     */    public Iterator getDescendantTransientItemStatesInAttic(NodeId parentId) {        if (atticStore.isEmpty()) {            return Collections.EMPTY_LIST.iterator();        }        // build ordered collection of descendant transient states in attic        // sorted by decreasing relative depth        // use a special attic-aware hierarchy manager        ZombieHierarchyManager zombieHierMgr =            new ZombieHierarchyManager(hierMgr, this, getAttic());        // use an array of lists to group the descendants by relative depth;        // the depth is used as array index        List[] la = new List[10];        try {            Iterator iter = atticStore.values().iterator();            while (iter.hasNext()) {                ItemState state = (ItemState) iter.next();                // determine relative depth: > 0 means it's a descendant                int depth = zombieHierMgr.getRelativeDepth(parentId, state.getId());                if (depth < 1) {                    // not a descendant                    continue;                }                // ensure capacity                if (depth > la.length) {                    List[] old = la;                    la = new List[depth + 10];                    System.arraycopy(old, 0, la, 0, old.length);                }                List list = la[depth - 1];                if (list == null) {                    list = new ArrayList();                    la[depth - 1] = list;                }                list.add(state);            }        } catch (RepositoryException re) {            log.warn("inconsistent hierarchy state", re);        }        // create an iterator over the collected descendants        // in decreasing depth order        IteratorChain resultIter = new IteratorChain();        for (int i = la.length - 1; i >= 0; i--) {            List list = la[i];            if (list != null) {                resultIter.addIterator(list.iterator());            }        }        /**         * if the resulting iterator chain is empty return         * EMPTY_LIST.iterator() instead because older versions         * of IteratorChain (pre Commons Collections 3.1)         * would throw UnsupportedOperationException in this         * situation         */        if (resultIter.getIterators().isEmpty()) {            return Collections.EMPTY_LIST.iterator();        }        return resultIter;    }    /**     * Return a flag indicating whether the specified item is in the transient     * item state manager's attic space.     *     * @param id item id     * @return <code>true</code> if the item state is in the attic space;     *         <code>false</code> otherwise     */    public boolean isItemStateInAttic(ItemId id) {        return atticStore.contains(id);    }    //------< methods for creating & discarding transient ItemState instances >    /**     * @param id     * @param nodeTypeName     * @param parentId     * @param initialStatus     * @return     * @throws ItemStateException     */    public NodeState createTransientNodeState(NodeId id, QName nodeTypeName, NodeId parentId, int initialStatus)            throws ItemStateException {        // check map; synchronized to ensure an entry is not created twice.        synchronized (transientStore) {            if (transientStore.contains(id)) {                String msg = "there's already a node state instance with id " + id;                log.debug(msg);                throw new ItemStateException(msg);            }            NodeState state = new NodeState(id, nodeTypeName, parentId,                    initialStatus, true);            // put transient state in the map            transientStore.put(state);            state.setContainer(this);            return state;        }    }    /**     * @param overlayedState     * @param initialStatus     * @return     * @throws ItemStateException     */    public NodeState createTransientNodeState(NodeState overlayedState, int initialStatus)            throws ItemStateException {        ItemId id = overlayedState.getNodeId();        // check map; synchronized to ensure an entry is not created twice.        synchronized (transientStore) {            if (transientStore.contains(id)) {                String msg = "there's already a node state instance with id " + id;                log.debug(msg);                throw new ItemStateException(msg);            }            NodeState state = new NodeState(overlayedState, initialStatus, true);            // put transient state in the map            transientStore.put(state);            state.setContainer(this);            return state;        }    }    /**     * @param parentId     * @param propName     * @param initialStatus     * @return     * @throws ItemStateException     */    public PropertyState createTransientPropertyState(NodeId parentId, QName propName, int initialStatus)            throws ItemStateException {        PropertyId id = new PropertyId(parentId, propName);        // check map; synchronized to ensure an entry is not created twice.        synchronized (transientStore) {            if (transientStore.contains(id)) {                String msg = "there's already a property state instance with id " + id;                log.debug(msg);                throw new ItemStateException(msg);            }            PropertyState state = new PropertyState(id, initialStatus, true);            // put transient state in the map            transientStore.put(state);            state.setContainer(this);            return state;        }    }    /**     * @param overlayedState     * @param initialStatus     * @return     * @throws ItemStateException     */    public PropertyState createTransientPropertyState(PropertyState overlayedState, int initialStatus)            throws ItemStateException {        PropertyId id = overlayedState.getPropertyId();        // check map; synchronized to ensure an entry is not created twice.        synchronized (transientStore) {            if (transientStore.contains(id)) {                String msg = "there's already a property state instance with id " + id;                log.debug(msg);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?