sessionitemstatemanager.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 968 行 · 第 1/3 页
JAVA
968 行
throw new ItemStateException(msg); } PropertyState state = new PropertyState(overlayedState, initialStatus, true); // put transient state in the map transientStore.put(state); state.setContainer(this); return state; } } /** * Disconnect a transient item state from its underlying persistent state. * Notifies the <code>HierarchyManager</code> about the changed identity. * * @param state the transient <code>ItemState</code> instance that should * be disconnected */ public void disconnectTransientItemState(ItemState state) { state.disconnect(); } /** * Disposes the specified transient item state instance, i.e. discards it * and clears it from cache. * * @param state the transient <code>ItemState</code> instance that should * be disposed * @see ItemState#discard() */ public void disposeTransientItemState(ItemState state) { // discard item state, this will invalidate the wrapping Item // instance of the transient state state.discard(); // remove from map transientStore.remove(state.getId()); // give the instance a chance to prepare to get gc'ed state.onDisposed(); } /** * Transfers the specified transient item state instance from the 'active' * cache to the attic. * * @param state the transient <code>ItemState</code> instance that should * be moved to the attic */ public void moveTransientItemStateToAttic(ItemState state) { // remove from map transientStore.remove(state.getId()); // add to attic atticStore.put(state); } /** * Disposes the specified transient item state instance in the attic, i.e. * discards it and removes it from the attic. * * @param state the transient <code>ItemState</code> instance that should * be disposed @see ItemState#discard() */ public void disposeTransientItemStateInAttic(ItemState state) { // discard item state, this will invalidate the wrapping Item // instance of the transient state state.discard(); // remove from attic atticStore.remove(state.getId()); // give the instance a chance to prepare to get gc'ed state.onDisposed(); } /** * Disposes all transient item states in the cache and in the attic. */ public void disposeAllTransientItemStates() { // dispose item states in transient map & attic // (use temp collection to avoid ConcurrentModificationException) Collection tmp = new ArrayList(transientStore.values()); Iterator iter = tmp.iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); disposeTransientItemState(state); } tmp = new ArrayList(atticStore.values()); iter = tmp.iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); disposeTransientItemStateInAttic(state); } } /** * Add an <code>ItemStateListener</code> * * @param listener the new listener to be informed on modifications */ public void addListener(ItemStateListener listener) { dispatcher.addListener(listener); } /** * Remove an <code>ItemStateListener</code> * * @param listener an existing listener */ public void removeListener(ItemStateListener listener) { dispatcher.removeListener(listener); } /** * Return the attic item state provider that holds all items * moved into the attic. * * @return attic */ ItemStateManager getAttic() { if (attic == null) { attic = new AtticItemStateManager(); } return attic; } //----------------------------------------------------< ItemStateListener > /** * {@inheritDoc} * <p/> * Notification handler gets called for both transient states that this state manager * has created, as well as states that were created by the local state manager * we're listening to. */ public void stateCreated(ItemState created) { ItemState visibleState = created; if (created.getContainer() != this) { // local state was created ItemState transientState = transientStore.get(created.getId()); if (transientState != null) { // underlying state has been permanently created transientState.pull(); transientState.setStatus(ItemState.STATUS_EXISTING); visibleState = transientState; } } dispatcher.notifyStateCreated(visibleState); } /** * {@inheritDoc} * <p/> * Notification handler gets called for both transient states that this state manager * has created, as well as states that were created by the local state manager * we're listening to. */ public void stateModified(ItemState modified) { ItemState visibleState = modified; if (modified.getContainer() != this) { // local state was modified ItemState transientState = transientStore.get(modified.getId()); if (transientState != null) { if (transientState.isNode() && !transientState.isStale()) { // try to silently merge non-conflicting changes (JCR-584) NodeStateMerger.MergeContext context = new NodeStateMerger.MergeContext() { public boolean isAdded(ItemId id) { ItemState is = transientStore.get(id); return is != null && is.getStatus() == ItemState.STATUS_NEW; } public boolean isDeleted(ItemId id) { return atticStore.contains(id); } }; if (NodeStateMerger.merge((NodeState) transientState, context)) { // merge succeeded return; } } transientState.setStatus(ItemState.STATUS_STALE_MODIFIED); visibleState = transientState; } } dispatcher.notifyStateModified(visibleState); } /** * {@inheritDoc} * <p/> * Notification handler gets called for both transient states that this state manager * has created, as well as states that were created by the local state manager * we're listening to. */ public void stateDestroyed(ItemState destroyed) { ItemState visibleState = destroyed; if (destroyed.getContainer() != this) { // local state was destroyed ItemState transientState = transientStore.get(destroyed.getId()); if (transientState != null) { transientState.setStatus(ItemState.STATUS_STALE_DESTROYED); visibleState = transientState; } } dispatcher.notifyStateDestroyed(visibleState); } /** * {@inheritDoc} * <p/> * Notification handler gets called for both transient states that this state manager * has created, as well as states that were created by the local state manager * we're listening to. */ public void stateDiscarded(ItemState discarded) { ItemState visibleState = discarded; if (discarded.getContainer() != this) { // local state was discarded ItemState transientState = transientStore.get(discarded.getId()); if (transientState != null) { transientState.setStatus(ItemState.STATUS_UNDEFINED); visibleState = transientState; } } dispatcher.notifyStateDiscarded(visibleState); } /** * {@inheritDoc} * <p/> * Pass notification to listeners if a transient state was modified * or if the local state is not overlayed. */ public void nodeAdded(NodeState state, QName name, int index, NodeId id) { if (state.getContainer() == this || !transientStore.contains(state.getId())) { dispatcher.notifyNodeAdded(state, name, index, id); } } /** * {@inheritDoc} * <p/> * Pass notification to listeners if a transient state was modified * or if the local state is not overlayed. */ public void nodesReplaced(NodeState state) { if (state.getContainer() == this || !transientStore.contains(state.getId())) { dispatcher.notifyNodesReplaced(state); } } /** * {@inheritDoc} * <p/> * Pass notification to listeners if a transient state was modified * or if the local state is not overlayed. */ public void nodeModified(NodeState state) { if (state.getContainer() == this || !transientStore.contains(state.getId())) { dispatcher.notifyNodeModified(state); } } /** * {@inheritDoc} * <p/> * Pass notification to listeners if a transient state was modified * or if the local state is not overlayed. */ public void nodeRemoved(NodeState state, QName name, int index, NodeId id) { if (state.getContainer() == this || !transientStore.contains(state.getId())) { dispatcher.notifyNodeRemoved(state, name, index, id); } } //--------------------------------------------------------< inner classes > /** * ItemStateManager view of the states in the attic * * @see SessionItemStateManager#getAttic */ private class AtticItemStateManager implements ItemStateManager { /** * {@inheritDoc} */ public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException { ItemState state = atticStore.get(id); if (state != null) { return state; } else { throw new NoSuchItemStateException(id.toString()); } } /** * {@inheritDoc} */ public boolean hasItemState(ItemId id) { return atticStore.contains(id); } /** * {@inheritDoc} */ public NodeReferences getNodeReferences(NodeReferencesId id) throws NoSuchItemStateException, ItemStateException { // n/a throw new ItemStateException("getNodeReferences() not implemented"); } /** * {@inheritDoc} */ public boolean hasNodeReferences(NodeReferencesId id) { // n/a return false; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?