Author: mreutegg
Date: Wed Aug 6 06:17:00 2008
New Revision: 683257
URL: http://svn.apache.org/viewvc?rev=683257&view=rev
Log:
JCR-1710: Promote ChildNodeEntry and ChildNodeEntries to top level classes.
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntries.java (with props)
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SecurityItemModifier.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OnWorkspaceInconsistency.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ChildAxisQuery.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/CachingHierarchyManagerTest.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java Wed Aug 6 06:17:00 2008
@@ -34,6 +34,7 @@
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.core.version.VersionManager;
@@ -765,7 +766,7 @@
// there's already a node with that name...
// get definition of existing conflicting node
- NodeState.ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
+ ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
NodeState conflictingState;
NodeId conflictingId = entry.getId();
try {
@@ -1667,7 +1668,7 @@
ArrayList tmp = new ArrayList(targetState.getChildNodeEntries());
// remove from tail to avoid problems with same-name siblings
for (int i = tmp.size() - 1; i >= 0; i--) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) tmp.get(i);
+ ChildNodeEntry entry = (ChildNodeEntry) tmp.get(i);
NodeId nodeId = entry.getId();
try {
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
@@ -1826,7 +1827,7 @@
// copy child nodes
Iterator iter = srcState.getChildNodeEntries().iterator();
while (iter.hasNext()) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
Path srcChildPath = PathFactoryImpl.getInstance().create(srcPath, entry.getName(), true);
if (!srcAccessMgr.isGranted(srcChildPath, Permission.READ)) {
continue;
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java Wed Aug 6 06:17:00 2008
@@ -22,6 +22,7 @@
import org.apache.jackrabbit.core.state.ItemStateManager;
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.NodeStateListener;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.util.Dumpable;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
@@ -312,7 +313,7 @@
Iterator iter = elements[i].getChildren();
while (iter.hasNext()) {
PathMap.Element child = (PathMap.Element) iter.next();
- NodeState.ChildNodeEntry cne = modified.getChildNodeEntry(
+ ChildNodeEntry cne = modified.getChildNodeEntry(
child.getName(), child.getNormalizedIndex());
if (cne == null) {
// Item does not exist, remove
@@ -412,7 +413,7 @@
continue;
}
NodeId childId = childEntry.getId();
- NodeState.ChildNodeEntry cne = state.getChildNodeEntry(childId);
+ ChildNodeEntry cne = state.getChildNodeEntry(childId);
if (cne == null) {
/* Child no longer in parent node state, so remove it */
evict(child, false);
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java Wed Aug 6 06:17:00 2008
@@ -27,10 +27,10 @@
import org.apache.jackrabbit.core.state.NoSuchItemStateException;
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
-import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
import org.apache.jackrabbit.spi.commons.name.PathBuilder;
import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
@@ -38,7 +38,6 @@
import org.slf4j.LoggerFactory;
import javax.jcr.ItemNotFoundException;
-import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
/**
@@ -113,7 +112,7 @@
}
NodeState parentState = (NodeState) getItemState(parentId);
if ((typeExpected & RETURN_NODE) != 0) {
- NodeState.ChildNodeEntry nodeEntry =
+ ChildNodeEntry nodeEntry =
getChildNodeEntry(parentState, name, index);
if (nodeEntry != null) {
id = nodeEntry.getId();
@@ -222,7 +221,7 @@
* no such entry.
* @see ZombieHierarchyManager#getChildNodeEntry(NodeState, NodeId)
*/
- protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+ protected ChildNodeEntry getChildNodeEntry(NodeState parent,
NodeId id) {
return parent.getChildNodeEntry(id);
}
@@ -242,7 +241,7 @@
* null if there's no such entry.
* @see ZombieHierarchyManager#getChildNodeEntry(NodeState, Name, int)
*/
- protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+ protected ChildNodeEntry getChildNodeEntry(NodeState parent,
Name name,
int index) {
return parent.getChildNodeEntry(name, index);
@@ -281,7 +280,7 @@
if (state.isNode()) {
NodeState nodeState = (NodeState) state;
NodeId id = nodeState.getNodeId();
- NodeState.ChildNodeEntry entry = getChildNodeEntry(parent, id);
+ ChildNodeEntry entry = getChildNodeEntry(parent, id);
if (entry == null) {
String msg = "failed to build path of " + state.getId() + ": "
+ parent.getNodeId() + " has no child entry for "
@@ -458,7 +457,7 @@
throw new RepositoryException(msg, ise);
}
- NodeState.ChildNodeEntry entry =
+ ChildNodeEntry entry =
getChildNodeEntry(parentState, id);
if (entry == null) {
String msg = "failed to resolve name of " + id;
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java Wed Aug 6 06:17:00 2008
@@ -31,6 +31,7 @@
import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.state.SessionItemStateManager;
import org.apache.jackrabbit.core.state.StaleItemStateException;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.core.version.VersionManager;
import org.apache.jackrabbit.spi.Name;
@@ -392,7 +393,7 @@
NodeState nState = (NodeState) itemState;
for (Iterator it = nState.getAddedChildNodeEntries().iterator();
it.hasNext() && isGranted;) {
- Name nodeName = ((NodeState.ChildNodeEntry) it.next()).getName();
+ Name nodeName = ((ChildNodeEntry) it.next()).getName();
isGranted = accessMgr.isGranted(path, nodeName, Permission.ADD_NODE);
}
for (Iterator it = nState.getAddedPropertyNames().iterator();
@@ -993,8 +994,8 @@
for (Iterator cneIt =
parent.getRenamedChildNodeEntries().iterator();
cneIt.hasNext();) {
- NodeState.ChildNodeEntry cne =
- (NodeState.ChildNodeEntry) cneIt.next();
+ ChildNodeEntry cne =
+ (ChildNodeEntry) cneIt.next();
if (cne.getId().equals(nodeState.getId())) {
// node has been renamed,
// add parent to dependencies
@@ -1015,16 +1016,16 @@
for (Iterator cneIt =
nodeState.getRemovedChildNodeEntries().iterator();
cneIt.hasNext();) {
- NodeState.ChildNodeEntry cne =
- (NodeState.ChildNodeEntry) cneIt.next();
+ ChildNodeEntry cne =
+ (ChildNodeEntry) cneIt.next();
dependentIDs.add(cne.getId());
}
// added child node entries
for (Iterator cneIt =
nodeState.getAddedChildNodeEntries().iterator();
cneIt.hasNext();) {
- NodeState.ChildNodeEntry cne =
- (NodeState.ChildNodeEntry) cneIt.next();
+ ChildNodeEntry cne =
+ (ChildNodeEntry) cneIt.next();
dependentIDs.add(cne.getId());
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java Wed Aug 6 06:17:00 2008
@@ -30,6 +30,7 @@
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.state.SessionItemStateManager;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.util.Dumpable;
import org.apache.jackrabbit.core.version.VersionHistoryImpl;
import org.apache.jackrabbit.core.version.VersionImpl;
@@ -151,7 +152,7 @@
// fallback: try finding applicable definition
NodeImpl parent = (NodeImpl) getItem(state.getParentId());
NodeState parentState = (NodeState) parent.getItemState();
- NodeState.ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
+ ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
def = parent.getApplicableChildNodeDefinition(cne.getName(), state.getNodeTypeName());
state.setDefinitionId(def.unwrap().getId());
}
@@ -561,7 +562,7 @@
Iterator iter = ((NodeState) data.getState()).getChildNodeEntries().iterator();
while (iter.hasNext()) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
// make sure any of the properties can be read.
if (canRead(entry.getId())) {
return true;
@@ -592,7 +593,7 @@
Iterator iter = ((NodeState) data.getState()).getChildNodeEntries().iterator();
while (iter.hasNext()) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
// delay check for read-access until item is being built
// thus avoid duplicate check
childIds.add(entry.getId());
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Wed Aug 6 06:17:00 2008
@@ -36,6 +36,7 @@
import org.apache.jackrabbit.core.state.NodeReferencesId;
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.core.version.DateVersionSelector;
import org.apache.jackrabbit.core.version.InternalFreeze;
@@ -207,7 +208,7 @@
if (index == 0) {
index = 1;
}
- NodeState.ChildNodeEntry cne =
+ ChildNodeEntry cne =
thisState.getChildNodeEntry(pe.getName(), index);
if (cne != null) {
return cne.getId();
@@ -588,7 +589,7 @@
if (index == 0) {
index = 1;
}
- NodeState.ChildNodeEntry entry =
+ ChildNodeEntry entry =
thisState.getChildNodeEntry(nodeName, index);
if (entry == null) {
String msg = "failed to remove child " + nodeName + " of "
@@ -646,8 +647,8 @@
ArrayList tmp = new ArrayList(thisState.getChildNodeEntries());
// remove from tail to avoid problems with same-name siblings
for (int i = tmp.size() - 1; i >= 0; i--) {
- NodeState.ChildNodeEntry entry =
- (NodeState.ChildNodeEntry) tmp.get(i);
+ ChildNodeEntry entry =
+ (ChildNodeEntry) tmp.get(i);
// recursively remove child node
NodeId childId = entry.getId();
//NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId);
@@ -774,7 +775,7 @@
// check for name collisions
NodeState thisState = data.getNodeState();
- NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(nodeName, 1);
+ ChildNodeEntry cne = thisState.getChildNodeEntry(nodeName, 1);
if (cne != null) {
// there's already a child node entry with that name;
// check same-name sibling setting of new node
@@ -1230,7 +1231,7 @@
ArrayList list = new ArrayList(thisState.getChildNodeEntries());
// start from tail to avoid problems with same-name siblings
for (int i = list.size() - 1; i >= 0; i--) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
+ ChildNodeEntry entry = (ChildNodeEntry) list.get(i);
NodeImpl node = (NodeImpl) itemMgr.getItem(entry.getId());
// check if node has been defined by mixin type (or one of its supertypes)
NodeTypeImpl declaringNT = (NodeTypeImpl) node.getDefinition().getDeclaringNodeType();
@@ -1437,7 +1438,7 @@
if (index == 0) {
index = 1;
}
- NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);
+ ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);
if (cne == null) {
throw new ItemNotFoundException();
}
@@ -1479,7 +1480,7 @@
if (index == 0) {
index = 1;
}
- NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);
+ ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);
if (cne == null) {
return false;
}
@@ -1821,7 +1822,7 @@
ArrayList list = new ArrayList(data.getNodeState().getChildNodeEntries());
int srcInd = -1, destInd = -1;
for (int i = 0; i < list.size(); i++) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
+ ChildNodeEntry entry = (ChildNodeEntry) list.get(i);
if (srcInd == -1) {
if (entry.getName().equals(srcName.getName())
&& (entry.getIndex() == srcName.getIndex()
@@ -1909,7 +1910,7 @@
// => backup list of child node entries beforehand in order
// to restore it afterwards
NodeState state = data.getNodeState();
- NodeState.ChildNodeEntry cneExisting = state.getChildNodeEntry(id);
+ ChildNodeEntry cneExisting = state.getChildNodeEntry(id);
if (cneExisting == null) {
throw new ItemNotFoundException(safeGetJCRPath()
+ ": no child node entry with id " + id);
@@ -1939,7 +1940,7 @@
// but preserving original position
state.removeAllChildNodeEntries();
for (Iterator iter = cneList.iterator(); iter.hasNext();) {
- NodeState.ChildNodeEntry cne = (NodeState.ChildNodeEntry) iter.next();
+ ChildNodeEntry cne = (ChildNodeEntry) iter.next();
if (cne.getId().equals(id)) {
// replace entry with different name
state.addChildNodeEntry(nodeName, id);
@@ -2002,7 +2003,7 @@
throw new ConstraintViolationException(msg, re);
}
NodeState thisState = data.getNodeState();
- NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
+ ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
if (cne != null) {
// there's already a child node entry with that name;
// check same-name sibling setting of new node
@@ -3060,7 +3061,7 @@
try {
NodeState parent =
(NodeState) stateMgr.getItemState(parentId);
- NodeState.ChildNodeEntry parentEntry =
+ ChildNodeEntry parentEntry =
parent.getChildNodeEntry(getNodeId());
return parentEntry.getIndex();
} catch (ItemStateException ise) {
@@ -3257,7 +3258,7 @@
Path parentPath = parentNode.getPrimaryPath();
PathBuilder builder = new PathBuilder(parentPath);
- NodeState.ChildNodeEntry entry = ((NodeState) parentNode.getItemState()).
+ ChildNodeEntry entry = ((NodeState) parentNode.getItemState()).
getChildNodeEntry(getNodeId());
if (entry == null) {
String msg = "failed to build path of " + id + ": "
@@ -4908,7 +4909,7 @@
ArrayList list = new ArrayList(thisState.getChildNodeEntries());
// start from tail to avoid problems with same-name siblings
for (int i = list.size() - 1; i >= 0; i--) {
- NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
+ ChildNodeEntry entry = (ChildNodeEntry) list.get(i);
try {
NodeState nodeState =
(NodeState) stateMgr.getItemState(entry.getId());
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SecurityItemModifier.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SecurityItemModifier.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SecurityItemModifier.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SecurityItemModifier.java Wed Aug 6 06:17:00 2008
@@ -23,6 +23,7 @@
import org.apache.jackrabbit.core.nodetype.NodeDefinitionImpl;
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.core.security.user.UserManagerImpl;
import org.apache.jackrabbit.core.security.authorization.acl.ACLEditor;
@@ -69,7 +70,7 @@
// check for name collisions
// TODO: improve. copied from NodeImpl
NodeState thisState = (NodeState) parentImpl.getItemState();
- NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
+ ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
if (cne != null) {
// there's already a child node entry with that name;
// check same-name sibling setting of new node
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java?rev=683257&r1=683256&r2=683257&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java Wed Aug 6 06:17:00 2008
@@ -21,6 +21,7 @@
import org.apache.jackrabbit.core.state.ItemStateManager;
import org.apache.jackrabbit.core.state.NoSuchItemStateException;
import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
import org.apache.jackrabbit.spi.Name;
import java.util.Iterator;
@@ -95,14 +96,14 @@
*
ChildNodeEntries represents an insertion-ordered
+ * collection of ChildNodeEntrys that also maintains
+ * the index values of same-name siblings on insertion and removal.
+ *
+ * ChildNodeEntries also provides an unmodifiable
+ * List view.
+ */
+class ChildNodeEntries implements List, Cloneable {
+
+ // insertion-ordered map of entries (key=NodeId, value=entry)
+ private LinkedMap entries;
+ // map used for lookup by name
+ // (key=name, value=either a single entry or a list of sns entries)
+ private HashMap nameMap;
+
+ ChildNodeEntries() {
+ entries = new LinkedMap();
+ nameMap = new HashMap();
+ }
+
+ ChildNodeEntry get(NodeId id) {
+ return (ChildNodeEntry) entries.get(id);
+ }
+
+ List get(Name nodeName) {
+ Object obj = nameMap.get(nodeName);
+ if (obj == null) {
+ return Collections.EMPTY_LIST;
+ }
+ if (obj instanceof ArrayList) {
+ // map entry is a list of siblings
+ return Collections.unmodifiableList((ArrayList) obj);
+ } else {
+ // map entry is a single child node entry
+ return Collections.singletonList(obj);
+ }
+ }
+
+ ChildNodeEntry get(Name nodeName, int index) {
+ if (index < 1) {
+ throw new IllegalArgumentException("index is 1-based");
+ }
+
+ Object obj = nameMap.get(nodeName);
+ if (obj == null) {
+ return null;
+ }
+ if (obj instanceof ArrayList) {
+ // map entry is a list of siblings
+ ArrayList siblings = (ArrayList) obj;
+ if (index <= siblings.size()) {
+ return (ChildNodeEntry) siblings.get(index - 1);
+ }
+ } else {
+ // map entry is a single child node entry
+ if (index == 1) {
+ return (ChildNodeEntry) obj;
+ }
+ }
+ return null;
+ }
+
+ ChildNodeEntry add(Name nodeName, NodeId id) {
+ List siblings = null;
+ int index = 0;
+ Object obj = nameMap.get(nodeName);
+ if (obj != null) {
+ if (obj instanceof ArrayList) {
+ // map entry is a list of siblings
+ siblings = (ArrayList) obj;
+ if (siblings.size() > 0) {
+ // reuse immutable Name instance from 1st same name sibling
+ // in order to help gc conserving memory
+ nodeName = ((ChildNodeEntry) siblings.get(0)).getName();
+ }
+ } else {
+ // map entry is a single child node entry,
+ // convert to siblings list
+ siblings = new ArrayList();
+ siblings.add(obj);
+ nameMap.put(nodeName, siblings);
+ }
+ index = siblings.size();
+ }
+
+ index++;
+
+ ChildNodeEntry entry = new ChildNodeEntry(nodeName, id, index);
+ if (siblings != null) {
+ siblings.add(entry);
+ } else {
+ nameMap.put(nodeName, entry);
+ }
+ entries.put(id, entry);
+
+ return entry;
+ }
+
+ void addAll(List entriesList) {
+ Iterator iter = entriesList.iterator();
+ while (iter.hasNext()) {
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+ // delegate to add(Name, String) to maintain consistency
+ add(entry.getName(), entry.getId());
+ }
+ }
+
+ public ChildNodeEntry remove(Name nodeName, int index) {
+ if (index < 1) {
+ throw new IllegalArgumentException("index is 1-based");
+ }
+
+ Object obj = nameMap.get(nodeName);
+ if (obj == null) {
+ return null;
+ }
+
+ if (obj instanceof ChildNodeEntry) {
+ // map entry is a single child node entry
+ if (index != 1) {
+ return null;
+ }
+ ChildNodeEntry removedEntry = (ChildNodeEntry) obj;
+ nameMap.remove(nodeName);
+ entries.remove(removedEntry.getId());
+ return removedEntry;
+ }
+
+ // map entry is a list of siblings
+ List siblings = (ArrayList) obj;
+ if (index > siblings.size()) {
+ return null;
+ }
+
+ // remove from siblings list
+ ChildNodeEntry removedEntry = (ChildNodeEntry) siblings.remove(index - 1);
+ // remove from ordered entries map
+ entries.remove(removedEntry.getId());
+
+ // update indices of subsequent same-name siblings
+ for (int i = index - 1; i < siblings.size(); i++) {
+ ChildNodeEntry oldEntry = (ChildNodeEntry) siblings.get(i);
+ ChildNodeEntry newEntry = new ChildNodeEntry(nodeName, oldEntry.getId(), oldEntry.getIndex() - 1);
+ // overwrite old entry with updated entry in siblings list
+ siblings.set(i, newEntry);
+ // overwrite old entry with updated entry in ordered entries map
+ entries.put(newEntry.getId(), newEntry);
+ }
+
+ // clean up name lookup map if necessary
+ if (siblings.size() == 0) {
+ // no more entries with that name left:
+ // remove from name lookup map as well
+ nameMap.remove(nodeName);
+ } else if (siblings.size() == 1) {
+ // just one entry with that name left:
+ // discard siblings list and update name lookup map accordingly
+ nameMap.put(nodeName, siblings.get(0));
+ }
+
+ // we're done
+ return removedEntry;
+ }
+
+ /**
+ * Removes the child node entry refering to the node with the given id.
+ *
+ * @param id id of node whose entry is to be removed.
+ * @return the removed entry or null if there is no such entry.
+ */
+ ChildNodeEntry remove(NodeId id) {
+ ChildNodeEntry entry = (ChildNodeEntry) entries.get(id);
+ if (entry != null) {
+ return remove(entry.getName(), entry.getIndex());
+ }
+ return entry;
+ }
+
+ /**
+ * Removes the given child node entry.
+ *
+ * @param entry entry to be removed.
+ * @return the removed entry or null if there is no such entry.
+ */
+ public ChildNodeEntry remove(ChildNodeEntry entry) {
+ return remove(entry.getName(), entry.getIndex());
+ }
+
+ /**
+ * Removes all child node entries
+ */
+ public void removeAll() {
+ nameMap.clear();
+ entries.clear();
+ }
+
+ /**
+ * Returns a list of ChildNodeEntrys who do only exist in
+ * this but not in other.
+ *
+ * Note that two entries are considered identical in this context if
+ * they have the same name and uuid, i.e. the index is disregarded
+ * whereas ChildNodeEntry.equals(Object) also compares
+ * the index.
+ *
+ * @param other entries to be removed
+ * @return a new list of those entries that do only exist in
+ * this but not in other
+ */
+ List removeAll(ChildNodeEntries other) {
+ if (entries.isEmpty()) {
+ return Collections.EMPTY_LIST;
+ }
+ if (other.isEmpty()) {
+ return this;
+ }
+
+ List result = new ArrayList();
+ Iterator iter = iterator();
+ while (iter.hasNext()) {
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+ ChildNodeEntry otherEntry = other.get(entry.getId());
+ if (entry == otherEntry) {
+ continue;
+ }
+ if (otherEntry == null
+ || !entry.getName().equals(otherEntry.getName())) {
+ result.add(entry);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns a list of ChildNodeEntrys who do exist in
+ * this and in other.
+ *
+ * Note that two entries are considered identical in this context if
+ * they have the same name and uuid, i.e. the index is disregarded
+ * whereas ChildNodeEntry.equals(Object) also compares
+ * the index.
+ *
+ * @param other entries to be retained
+ * @return a new list of those entries that do exist in
+ * this and in other
+ */
+ List retainAll(ChildNodeEntries other) {
+ if (entries.isEmpty()
+ || other.isEmpty()) {
+ return Collections.EMPTY_LIST;
+ }
+
+ List result = new ArrayList();
+ Iterator iter = iterator();
+ while (iter.hasNext()) {
+ ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+ ChildNodeEntry otherEntry = other.get(entry.getId());
+ if (entry == otherEntry) {
+ result.add(entry);
+ } else if (otherEntry != null
+ && entry.getName().equals(otherEntry.getName())) {
+ result.add(entry);
+ }
+ }
+
+ return result;
+ }
+
+ //-------------------------------------------< unmodifiable List view >
+ public boolean contains(Object o) {
+ if (o instanceof ChildNodeEntry) {
+ return entries.containsKey(((ChildNodeEntry) o).getId());
+ } else {
+ return false;
+ }
+ }
+
+ public boolean containsAll(Collection c) {
+ Iterator iter = c.iterator();
+ while (iter.hasNext()) {
+ if (!contains(iter.next())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public Object get(int index) {
+ return entries.getValue(index);
+ }
+
+ public int indexOf(Object o) {
+ if (o instanceof ChildNodeEntry) {
+ return entries.indexOf(((ChildNodeEntry) o).getId());
+ } else {
+ return -1;
+ }
+ }
+
+ public boolean isEmpty() {
+ return entries.isEmpty();
+ }
+
+ public int lastIndexOf(Object o) {
+ // entries are unique
+ return indexOf(o);
+ }
+
+ public Iterator iterator() {
+ return new EntriesIterator();
+ }
+
+ public ListIterator listIterator() {
+ return new EntriesIterator();
+ }
+
+ public ListIterator listIterator(int index) {
+ if (index < 0 || index >= entries.size()) {
+ throw new IndexOutOfBoundsException();
+ }
+ ListIterator iter = new EntriesIterator();
+ while (index-- > 0) {
+ iter.next();
+ }
+ return iter;
+ }
+
+ public int size() {
+ return entries.size();
+ }
+
+ public List subList(int fromIndex, int toIndex) {
+ // @todo FIXME does not fulfill the contract of List.subList(int,int)
+ return Collections.unmodifiableList(new ArrayList(this).subList(fromIndex, toIndex));
+ }
+
+ public Object[] toArray() {
+ ChildNodeEntry[] array = new ChildNodeEntry[size()];
+ return toArray(array);
+ }
+
+ public Object[] toArray(Object[] a) {
+ if (!a.getClass().getComponentType().isAssignableFrom(ChildNodeEntry.class)) {
+ throw new ArrayStoreException();
+ }
+ if (a.length < size()) {
+ a = new ChildNodeEntry[size()];
+ }
+ MapIterator iter = entries.mapIterator();
+ int i = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ a[i] = entries.getValue(i);
+ i++;
+ }
+ while (i < a.length) {
+ a[i++] = null;
+ }
+ return a;
+ }
+
+ public void add(int index, Object element) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean add(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(int index, Collection c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object remove(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object set(int index, Object element) {
+ throw new UnsupportedOperationException();
+ }
+
+ //------------------------------------------------< Cloneable support >
+ /**
+ * Returns a shallow copy of this ChildNodeEntries instance;
+ * the entries themselves are not cloned.
+ *
+ * @return a shallow copy of this instance.
+ */
+ protected Object clone() {
+ ChildNodeEntries clone = new ChildNodeEntries();
+ clone.entries = (LinkedMap) entries.clone();
+ clone.nameMap = new HashMap(nameMap.size());
+ for (Iterator it = nameMap.keySet().iterator(); it.hasNext();) {
+ Object key = it.next();
+ Object obj = nameMap.get(key);
+ if (obj instanceof ArrayList) {
+ // clone List
+ obj = ((ArrayList) obj).clone();
+ }
+ clone.nameMap.put(key, obj);
+ }
+ return clone;
+ }
+
+ //----------------------------------------------------< inner classes >
+ class EntriesIterator implements ListIterator {
+
+ private final OrderedMapIterator mapIter;
+
+ EntriesIterator() {
+ mapIter = entries.orderedMapIterator();
+ }
+
+ public boolean hasNext() {
+ return mapIter.hasNext();
+ }
+
+ public Object next() {
+ mapIter.next();
+ return mapIter.getValue();
+ }
+
+ public boolean hasPrevious() {
+ return mapIter.hasPrevious();
+ }
+
+ public int nextIndex() {
+ return entries.indexOf(mapIter.getKey()) + 1;
+ }
+
+ public Object previous() {
+ mapIter.previous();
+ return mapIter.getValue();
+ }
+
+ public int previousIndex() {
+ return entries.indexOf(mapIter.getKey()) - 1;
+ }
+
+ public void add(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void set(Object o) {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntries.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java?rev=683257&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java Wed Aug 6 06:17:00 2008
@@ -0,0 +1,92 @@
+/*
+ * $URL:$
+ * $Id:$
+ *
+ * Copyright 1997-2008 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.core.state;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.core.NodeId;
+
+/**
+ * ChildNodeEntry specifies the name, index (in the case of
+ * same-name siblings) and the UUID of a child node entry.
+ *
+ * ChildNodeEntry instances are immutable.
+ */
+public final class ChildNodeEntry {
+
+ private int hash = 0;
+
+ private final Name name;
+ private final int index; // 1-based index for same-name siblings
+ private final NodeId id;
+
+ ChildNodeEntry(Name name, NodeId id, int index) {
+ if (name == null) {
+ throw new IllegalArgumentException("name can not be null");
+ }
+ this.name = name;
+
+ if (id == null) {
+ throw new IllegalArgumentException("id can not be null");
+ }
+ this.id = id;
+
+ if (index < 1) {
+ throw new IllegalArgumentException("index is 1-based");
+ }
+ this.index = index;
+ }
+
+ public NodeId getId() {
+ return id;
+ }
+
+ public Name getName() {
+ return name;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ //---------------------------------------< java.lang.Object overrides >
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ChildNodeEntry) {
+ ChildNodeEntry other = (ChildNodeEntry) obj;
+ return (name.equals(other.name) && id.equals(other.id)
+ && index == other.index);
+ }
+ return false;
+ }
+
+ public String toString() {
+ return name.toString() + "[" + index + "] -> " + id;
+ }
+
+ public int hashCode() {
+ // ChildNodeEntry is immutable, we can store the computed hash code value
+ int h = hash;
+ if (h == 0) {
+ h = 17;
+ h = 37 * h + name.hashCode();
+ h = 37 * h + id.hashCode();
+ h = 37 * h + index;
+ hash = h;
+ }
+ return h;
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChildNodeEntry.java
------------------------------------------------------------------------------
svn:eol-style = native