You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/09/01 13:52:13 UTC
svn commit: r1164026 [5/11] - in
/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi:
./ config/ hierarchy/ lock/ nodetype/ observation/ operation/ query/
security/ state/ util/ version/ xml/
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java Thu Sep 1 11:52:08 2011
@@ -16,22 +16,7 @@
*/
package org.apache.jackrabbit.jcr2spi.hierarchy;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-
+import com.sun.org.apache.bcel.internal.classfile.Unknown;
import org.apache.commons.collections.iterators.IteratorChain;
import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
import org.apache.jackrabbit.jcr2spi.operation.AddNode;
@@ -64,13 +49,27 @@ import org.apache.jackrabbit.spi.commons
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* <code>NodeEntryImpl</code> implements common functionality for child
* node entry implementations.
*/
public class NodeEntryImpl extends HierarchyEntryImpl implements NodeEntry {
-
- private static Logger log = LoggerFactory.getLogger(NodeEntryImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(NodeEntryImpl.class);
/**
* UniqueID identifying this NodeEntry or <code>null</code> if either
@@ -123,8 +122,7 @@ public class NodeEntryImpl extends Hiera
* @param name the name of the child node.
* @param factory the entry factory.
*/
- private NodeEntryImpl(NodeEntryImpl parent, Name name, String uniqueID,
- EntryFactory factory) {
+ private NodeEntryImpl(NodeEntryImpl parent, Name name, String uniqueID, EntryFactory factory) {
super(parent, name, factory);
this.uniqueID = uniqueID; // NOTE: don't use setUniqueID (for mod only)
@@ -161,6 +159,7 @@ public class NodeEntryImpl extends Hiera
*
* @see HierarchyEntry#denotesNode()
*/
+ @Override
public boolean denotesNode() {
return true;
}
@@ -189,7 +188,7 @@ public class NodeEntryImpl extends Hiera
}
/**
- * Calls {@link HierarchyEntryImpl#revert()} and moves all properties from the
+ * Calls and moves all properties from the
* attic back into the properties map. If this HierarchyEntry has been
* transiently moved, it is in addition moved back to its old parent.
* Similarly reordering of child node entries is reverted.
@@ -237,7 +236,7 @@ public class NodeEntryImpl extends Hiera
public void remove() {
// handle this entry first
super.internalRemove(false);
- boolean staleParent = (getStatus() == Status.STALE_DESTROYED);
+ boolean staleParent = getStatus() == Status.STALE_DESTROYED;
// now remove all child-entries (or mark them accordingly)
for (Iterator<HierarchyEntry> it = getAllChildEntries(true); it.hasNext();) {
HierarchyEntryImpl ce = (HierarchyEntryImpl) it.next();
@@ -249,7 +248,7 @@ public class NodeEntryImpl extends Hiera
void internalRemove(boolean staleParent) {
// handle this entry first
super.internalRemove(staleParent);
- staleParent = (staleParent || (getStatus() == Status.STALE_DESTROYED));
+ staleParent = staleParent || getStatus() == Status.STALE_DESTROYED;
// now remove all child-entries (or mark them accordingly)
for (Iterator<HierarchyEntry> it = getAllChildEntries(true); it.hasNext();) {
@@ -261,6 +260,7 @@ public class NodeEntryImpl extends Hiera
/**
* @see HierarchyEntry#complete(Operation)
*/
+ @Override
public void complete(Operation operation) throws RepositoryException {
if (operation instanceof AddNode) {
complete((AddNode) operation);
@@ -280,18 +280,16 @@ public class NodeEntryImpl extends Hiera
throw new IllegalArgumentException();
}
}
+
//----------------------------------------------------------< NodeEntry >---
- /**
- * @see NodeEntry#getId()
- */
- public NodeId getId() throws InvalidItemStateException, RepositoryException {
+
+ @Override
+ public NodeId getId() throws RepositoryException {
return getId(false);
}
- /**
- * @see NodeEntry#getWorkspaceId()
- */
- public NodeId getWorkspaceId() throws InvalidItemStateException, RepositoryException {
+ @Override
+ public NodeId getWorkspaceId() throws RepositoryException {
return getId(true);
}
@@ -313,7 +311,7 @@ public class NodeEntryImpl extends Hiera
PathBuilder pathBuilder = new PathBuilder(pathFactory);
while (entry.getParent() != null && entry.getUniqueID() == null) {
pathBuilder.addFirst(entry.getName(wspId), entry.getIndex(wspId));
- entry = (wspId && entry.revertInfo != null)
+ entry = wspId && entry.revertInfo != null
? entry.revertInfo.oldParent
: entry.parent;
}
@@ -330,43 +328,33 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#getUniqueID()
- */
+ @Override
public String getUniqueID() {
return uniqueID;
}
- /**
- * @see NodeEntry#setUniqueID(String)
- */
+ @Override
public void setUniqueID(String uniqueID) {
String old = this.uniqueID;
- boolean mod = (uniqueID == null) ? old != null : !uniqueID.equals(old);
+ boolean mod = uniqueID == null ? old != null : !uniqueID.equals(old);
if (mod) {
this.uniqueID = uniqueID;
factory.notifyIdChange(this, old);
}
}
- /**
- * @see NodeEntry#getIndex()
- */
- public int getIndex() throws InvalidItemStateException, RepositoryException {
+ @Override
+ public int getIndex() throws RepositoryException {
return getIndex(false);
}
- /**
- * @see NodeEntry#getNodeState()
- */
- public NodeState getNodeState() throws ItemNotFoundException, RepositoryException {
+ @Override
+ public NodeState getNodeState() throws RepositoryException {
return (NodeState) getItemState();
}
- /**
- * @see NodeEntry#getDeepNodeEntry(Path)
- */
- public NodeEntry getDeepNodeEntry(Path path) throws PathNotFoundException, RepositoryException {
+ @Override
+ public NodeEntry getDeepNodeEntry(Path path) throws RepositoryException {
NodeEntryImpl entry = this;
Path.Element[] elems = path.getElements();
for (int i = 0; i < elems.length; i++) {
@@ -394,28 +382,29 @@ public class NodeEntryImpl extends Hiera
if (entry.childNodeEntries.isComplete()) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
+
// -> check for moved child entry in node-attic
// -> check if child points to a removed/moved sns
List<NodeEntry> siblings = entry.childNodeEntries.get(name);
if (entry.containsAtticChild(siblings, name, index)) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
+
// shortcut: entry is NEW and still unresolved remaining path
// elements -> hierarchy doesn't exist anyway.
if (entry.getStatus() == Status.NEW) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
- /*
- * Unknown entry (not-existing or not yet loaded):
- * Skip all intermediate entries and directly try to load the ItemState
- * (including building the intermediate entries. If that fails
- * ItemNotFoundException is thrown.
- *
- * Since 'path' might be ambiguous (Node or Property):
- * 1) first try Node
- * 2) if the NameElement does not have SNS-index => try Property
- * 3) else throw
- */
+
+ // Unknown entry (not-existing or not yet loaded):
+ // Skip all intermediate entries and directly try to load the ItemState
+ // (including building the intermediate entries. If that fails
+ // ItemNotFoundException is thrown.
+ //
+ // Since 'path' might be ambiguous (Node or Property):
+ // 1) first try Node
+ // 2) if the NameElement does not have SNS-index => try Property
+ // 3) else throw
PathBuilder pb = new PathBuilder(getPathFactory());
for (int j = i; j < elems.length; j++) {
pb.addLast(elems[j]);
@@ -437,10 +426,8 @@ public class NodeEntryImpl extends Hiera
return entry;
}
- /**
- * @see NodeEntry#getDeepPropertyEntry(Path)
- */
- public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
+ @Override
+ public PropertyEntry getDeepPropertyEntry(Path path) throws RepositoryException {
NodeEntryImpl entry = this;
Path.Element[] elems = path.getElements();
int i = 0;
@@ -487,13 +474,11 @@ public class NodeEntryImpl extends Hiera
// retrieve property entry from SPI
pe = entry.properties.get(path.getName());
} else {
- /*
- * Unknown parent entry (not-existing or not yet loaded) or a parent
- * entry that has been invalidated:
- * Skip all intermediate entries and directly try to load the
- * PropertyState (including building the intermediate entries. If that
- * fails ItemNotFoundException is thrown.
- */
+ // Unknown parent entry (not-existing or not yet loaded) or a parent
+ // entry that has been invalidated:
+ // Skip all intermediate entries and directly try to load the
+ // PropertyState (including building the intermediate entries. If that
+ // fails ItemNotFoundException is thrown.
PathBuilder pb = new PathBuilder(getPathFactory());
for (int j = i; j < elems.length; j++) {
pb.addLast(elems[j]);
@@ -515,9 +500,7 @@ public class NodeEntryImpl extends Hiera
return pe;
}
- /**
- * @see NodeEntry#lookupDeepEntry(Path)
- */
+ @Override
public HierarchyEntry lookupDeepEntry(Path workspacePath) {
NodeEntryImpl entry = this;
for (int i = 0; i < workspacePath.getLength(); i++) {
@@ -548,21 +531,13 @@ public class NodeEntryImpl extends Hiera
return entry;
}
- /**
- * @see NodeEntry#hasNodeEntry(Name)
- */
+ @Override
public synchronized boolean hasNodeEntry(Name nodeName) {
List<NodeEntry> namedEntries = childNodeEntries.get(nodeName);
- if (namedEntries.isEmpty()) {
- return false;
- } else {
- return EntryValidation.containsValidNodeEntry(namedEntries.iterator());
- }
+ return !namedEntries.isEmpty() && EntryValidation.containsValidNodeEntry(namedEntries.iterator());
}
- /**
- * @see NodeEntry#hasNodeEntry(Name, int)
- */
+ @Override
public synchronized boolean hasNodeEntry(Name nodeName, int index) {
try {
return getNodeEntry(nodeName, index) != null;
@@ -572,16 +547,12 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#getNodeEntry(Name, int)
- */
+ @Override
public synchronized NodeEntry getNodeEntry(Name nodeName, int index) throws RepositoryException {
return getNodeEntry(nodeName, index, false);
}
- /**
- * @see NodeEntry#getNodeEntry(Name, int, boolean)
- */
+ @Override
public NodeEntry getNodeEntry(Name nodeName, int index, boolean loadIfNotFound) throws RepositoryException {
List<NodeEntry> entries = childNodeEntries.get(nodeName);
NodeEntry cne = null;
@@ -611,9 +582,7 @@ public class NodeEntryImpl extends Hiera
return cne;
}
- /**
- * @see NodeEntry#getNodeEntries()
- */
+ @Override
public synchronized Iterator<NodeEntry> getNodeEntries() throws RepositoryException {
Collection<NodeEntry> entries = new ArrayList<NodeEntry>();
for (Iterator<NodeEntry> it = getCompleteChildNodeEntries().iterator(); it.hasNext();) {
@@ -625,9 +594,7 @@ public class NodeEntryImpl extends Hiera
return new RangeIteratorAdapter(Collections.unmodifiableCollection(entries));
}
- /**
- * @see NodeEntry#getNodeEntries(Name)
- */
+ @Override
public synchronized List<NodeEntry> getNodeEntries(Name nodeName) throws RepositoryException {
List<NodeEntry> namedEntries = getCompleteChildNodeEntries().get(nodeName);
if (namedEntries.isEmpty()) {
@@ -637,8 +604,7 @@ public class NodeEntryImpl extends Hiera
// get array of the list, since during validation the childNodeEntries
// may be modified if upon NodeEntry.getItemState the entry gets removed.
NodeEntry[] arr = namedEntries.toArray(new NodeEntry[namedEntries.size()]);
- for (int i = 0; i < arr.length; i++) {
- NodeEntry cne = arr[i];
+ for (NodeEntry cne : arr) {
if (EntryValidation.isValidNodeEntry(cne)) {
entries.add(cne);
}
@@ -647,9 +613,7 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#setNodeEntries(Iterator)
- */
+ @Override
public void setNodeEntries(Iterator<ChildInfo> childInfos) throws RepositoryException {
if (childNodeAttic.isEmpty()) {
((ChildNodeEntriesImpl) childNodeEntries).update(childInfos);
@@ -666,9 +630,7 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#getOrAddNodeEntry(Name, int, String)
- */
+ @Override
public NodeEntry getOrAddNodeEntry(Name nodeName, int index, String uniqueID) throws RepositoryException {
NodeEntry ne = lookupNodeEntry(uniqueID, nodeName, index);
if (ne == null) {
@@ -679,9 +641,7 @@ public class NodeEntryImpl extends Hiera
return ne;
}
- /**
- * @see NodeEntry#addNewNodeEntry(Name, String, Name, QNodeDefinition)
- */
+ @Override
public NodeEntry addNewNodeEntry(Name nodeName, String uniqueID,
Name primaryNodeType, QNodeDefinition definition) throws RepositoryException {
NodeEntry entry = internalAddNodeEntry(nodeName, uniqueID, Path.INDEX_UNDEFINED);
@@ -690,17 +650,13 @@ public class NodeEntryImpl extends Hiera
return entry;
}
- /**
- * @see NodeEntry#hasPropertyEntry(Name)
- */
+ @Override
public synchronized boolean hasPropertyEntry(Name propName) {
PropertyEntry entry = properties.get(propName);
return EntryValidation.isValidPropertyEntry(entry);
}
- /**
- * @see NodeEntry#getPropertyEntry(Name)
- */
+ @Override
public synchronized PropertyEntry getPropertyEntry(Name propName) {
PropertyEntry entry = properties.get(propName);
if (EntryValidation.isValidPropertyEntry(entry)) {
@@ -714,15 +670,13 @@ public class NodeEntryImpl extends Hiera
* Ignores the <code>loadIfNotFound</code> flag due to the fact, that
* {@link org.apache.jackrabbit.spi.NodeInfo#getPropertyIds()} returns the
* complete list of property names currently available.
- * @see NodeEntry#getPropertyEntry(Name, boolean)
*/
+ @Override
public PropertyEntry getPropertyEntry(Name propName, boolean loadIfNotFound) throws RepositoryException {
return getPropertyEntry(propName);
}
- /**
- * @see NodeEntry#getPropertyEntries()
- */
+ @Override
public synchronized Iterator<PropertyEntry> getPropertyEntries() {
Collection<PropertyEntry> props;
if (getStatus() == Status.EXISTING_MODIFIED) {
@@ -730,8 +684,8 @@ public class NodeEntryImpl extends Hiera
props = new ArrayList<PropertyEntry>();
// use array since upon validation the entry might be removed.
Object[] arr = properties.getPropertyEntries().toArray();
- for (int i = 0; i < arr.length; i++) {
- PropertyEntry propEntry = (PropertyEntry) arr[i];
+ for (Object anArr : arr) {
+ PropertyEntry propEntry = (PropertyEntry) anArr;
if (EntryValidation.isValidPropertyEntry(propEntry)) {
props.add(propEntry);
}
@@ -743,9 +697,7 @@ public class NodeEntryImpl extends Hiera
return new RangeIteratorAdapter(Collections.unmodifiableCollection(props));
}
- /**
- * @see NodeEntry#getOrAddPropertyEntry(Name)
- */
+ @Override
public PropertyEntry getOrAddPropertyEntry(Name propName) throws ItemExistsException {
PropertyEntry pe = lookupPropertyEntry(propName);
if (pe == null) {
@@ -756,17 +708,14 @@ public class NodeEntryImpl extends Hiera
return pe;
}
- /**
- * @see NodeEntry#setPropertyEntries(Collection)
- */
- public void setPropertyEntries(Collection<Name> propNames) throws ItemExistsException, RepositoryException {
+ @Override
+ public void setPropertyEntries(Collection<Name> propNames) throws RepositoryException {
Set<Name> diff = new HashSet<Name>();
diff.addAll(properties.getPropertyNames());
boolean containsExtra = diff.removeAll(propNames);
// add all entries that are missing
- for (Iterator<Name> it = propNames.iterator(); it.hasNext();) {
- Name propName = it.next();
+ for (Name propName : propNames) {
if (!properties.contains(propName)) {
// TODO: check again.
// setPropertyEntries is used by WorkspaceItemStateFactory upon
@@ -782,8 +731,7 @@ public class NodeEntryImpl extends Hiera
// collection of property names are removed from this NodeEntry.
ItemState state = internalGetItemState();
if (containsExtra && (state == null || state.getStatus() == Status.INVALIDATED)) {
- for (Iterator<Name> it = diff.iterator(); it.hasNext();) {
- Name propName = it.next();
+ for (Name propName : diff) {
PropertyEntry pEntry = properties.get(propName);
if (pEntry != null) {
pEntry.remove();
@@ -792,11 +740,10 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#addNewPropertyEntry(Name, QPropertyDefinition, QValue[], int)
- */
- public PropertyEntry addNewPropertyEntry(Name propName, QPropertyDefinition definition, QValue[] values, int propertyType)
- throws ItemExistsException, RepositoryException {
+ @Override
+ public PropertyEntry addNewPropertyEntry(Name propName, QPropertyDefinition definition, QValue[] values,
+ int propertyType) throws RepositoryException {
+
// check for an existing property
PropertyEntry existing = properties.get(propName);
if (existing != null) {
@@ -833,9 +780,7 @@ public class NodeEntryImpl extends Hiera
return entry;
}
- /**
- * @see NodeEntry#orderBefore(NodeEntry)
- */
+ @Override
public void orderBefore(NodeEntry beforeEntry) throws RepositoryException {
if (Status.NEW == getStatus()) {
// new states get remove upon revert
@@ -847,9 +792,7 @@ public class NodeEntryImpl extends Hiera
}
}
- /**
- * @see NodeEntry#move(Name, NodeEntry, boolean)
- */
+ @Override
public NodeEntry move(Name newName, NodeEntry newParent, boolean transientMove) throws RepositoryException {
if (parent == null) {
// the root may never be moved
@@ -861,13 +804,13 @@ public class NodeEntryImpl extends Hiera
if (transientMove) {
createRevertInfo();
if (Status.NEW != getStatus()) {
- if (newParent != revertInfo.oldParent) {
- revertInfo.oldParent.childNodeAttic.add(this);
- } else {
+ if (newParent == revertInfo.oldParent) {
// entry is either rename OR moved back to it's original
// parent. for the latter case make sure, there is no attic
// entry remaining referring to the entry that is being added.
revertInfo.oldParent.childNodeAttic.remove(this);
+ } else {
+ revertInfo.oldParent.childNodeAttic.add(this);
}
}
}
@@ -887,16 +830,12 @@ public class NodeEntryImpl extends Hiera
return this;
}
- /**
- * @see NodeEntry#isTransientlyMoved()
- */
+ @Override
public boolean isTransientlyMoved() {
return revertInfo != null && revertInfo.isMoved();
}
- /**
- * @see NodeEntry#refresh(Event)
- */
+ @Override
public void refresh(Event childEvent) {
ItemId eventId = childEvent.getItemId();
Path eventPath = childEvent.getPath();
@@ -910,7 +849,7 @@ public class NodeEntryImpl extends Hiera
// no such child or a colliding new child existed but got
// removed already -> add the new entry.
if (childEvent.getType() == Event.NODE_ADDED) {
- String uniqueChildID = (eventId.getPath() == null) ? eventId.getUniqueID() : null;
+ String uniqueChildID = eventId.getPath() == null ? eventId.getUniqueID() : null;
int index = eventPath.getNormalizedIndex();
internalAddNodeEntry(eventName, uniqueChildID, index);
} else {
@@ -979,20 +918,14 @@ public class NodeEntryImpl extends Hiera
throw new IllegalArgumentException("Illegal event type " + childEvent.getType() + " for NodeState.");
}
}
+
//-------------------------------------------------< HierarchyEntryImpl >---
- /**
- * @see HierarchyEntryImpl#doResolve()
- * <p/>
- * Returns a <code>NodeState</code>.
- */
+
@Override
- ItemState doResolve() throws ItemNotFoundException, RepositoryException {
+ ItemState doResolve() throws RepositoryException {
return getItemStateFactory().createNodeState(getWorkspaceId(), this);
}
- /**
- * @see HierarchyEntryImpl#buildPath(boolean)
- */
@Override
Path buildPath(boolean wspPath) throws RepositoryException {
PathFactory pf = getPathFactory();
@@ -1015,7 +948,7 @@ public class NodeEntryImpl extends Hiera
* @param wspPath true if the workspace path should be built
*/
private static void buildPath(PathBuilder builder, NodeEntryImpl nEntry, boolean wspPath) throws RepositoryException {
- NodeEntryImpl parentEntry = (wspPath && nEntry.revertInfo != null) ? nEntry.revertInfo.oldParent : nEntry.parent;
+ NodeEntryImpl parentEntry = wspPath && nEntry.revertInfo != null ? nEntry.revertInfo.oldParent : nEntry.parent;
// shortcut for root state
if (parentEntry == null) {
builder.addRoot();
@@ -1031,6 +964,7 @@ public class NodeEntryImpl extends Hiera
}
//-----------------------------------------------< private || protected >---
+
/**
* @param nodeName
* @param uniqueID
@@ -1134,7 +1068,7 @@ public class NodeEntryImpl extends Hiera
}
}
- private int getIndex(boolean wspIndex) throws InvalidItemStateException, RepositoryException {
+ private int getIndex(boolean wspIndex) throws RepositoryException {
if (parent == null) {
// the root state may never have siblings
return Path.INDEX_DEFAULT;
@@ -1198,7 +1132,7 @@ public class NodeEntryImpl extends Hiera
Name childName = eventPath.getName();
HierarchyEntry child;
if (eventId.denotesNode()) {
- String uniqueChildID = (eventId.getPath() == null) ? eventId.getUniqueID() : null;
+ String uniqueChildID = eventId.getPath() == null ? eventId.getUniqueID() : null;
int index = eventPath.getNormalizedIndex();
child = lookupNodeEntry(uniqueChildID, childName, index);
} else {
@@ -1251,7 +1185,7 @@ public class NodeEntryImpl extends Hiera
if (state != null) {
PropertyState ps = child.getPropertyState();
state.setMixinTypeNames(StateUtility.getMixinNames(ps));
- } // nodestate not yet loaded -> ignore change
+ } // node state not yet loaded -> ignore change
}
} catch (ItemNotFoundException e) {
log.debug("Property with name " + child.getName() + " does not exist (anymore)");
@@ -1283,7 +1217,7 @@ public class NodeEntryImpl extends Hiera
* <code>null</code>, since the child node entries are loaded/reloaded
* in case they have not been loaded yet.
*/
- private ChildNodeEntries getCompleteChildNodeEntries() throws InvalidItemStateException, RepositoryException {
+ private ChildNodeEntries getCompleteChildNodeEntries() throws RepositoryException {
try {
childNodeEntries.reload();
} catch (ItemNotFoundException e) {
@@ -1331,13 +1265,12 @@ public class NodeEntryImpl extends Hiera
* @throws ItemNotFoundException if the given entry isn't a valid child of
* this <code>NodeEntry</code>.
*/
- private int getChildIndex(NodeEntry cne, boolean wspIndex) throws ItemNotFoundException, RepositoryException {
+ private int getChildIndex(NodeEntry cne, boolean wspIndex) throws RepositoryException {
List<NodeEntry> sns = new ArrayList<NodeEntry>(childNodeEntries.get(cne.getName()));
if (wspIndex) {
List<NodeEntryImpl> atticSiblings = childNodeAttic.get(cne.getName());
- for (Iterator<NodeEntryImpl> it = atticSiblings.iterator(); it.hasNext();) {
- NodeEntryImpl sibl = it.next();
+ for (NodeEntryImpl sibl : atticSiblings) {
if (sibl.revertInfo != null) {
sns.add(sibl.revertInfo.oldIndex - 1, sibl);
} else {
@@ -1360,15 +1293,14 @@ public class NodeEntryImpl extends Hiera
} else {
// siblings exist.
int index = Path.INDEX_DEFAULT;
- for (Iterator<NodeEntry> it = sns.iterator(); it.hasNext(); ) {
- NodeEntry entry = it.next();
+ for (NodeEntry entry : sns) {
if (entry == cne) { // TODO see below
return index;
}
// for wsp index ignore all transiently added items.
// otherwise: skip entries that belong to removed or invalid states.
- // NOTE, that in this case the nodestate must be available from the cne.
- boolean isValid = (wspIndex) ?
+ // NOTE, that in this case the node state must be available from the cne.
+ boolean isValid = wspIndex ?
EntryValidation.isValidWorkspaceNodeEntry(entry) :
EntryValidation.isValidNodeEntry(entry);
if (isValid) {
@@ -1409,15 +1341,15 @@ public class NodeEntryImpl extends Hiera
}
}
if (getStatus() == Status.EXISTING_MODIFIED) {
- for (Iterator<NodeEntry> it = siblings.iterator(); it.hasNext();) {
- NodeEntry child = it.next();
- if (!EntryValidation.isValidNodeEntry(child) || ((NodeEntryImpl)child).revertInfo != null && ((NodeEntryImpl)child).revertInfo.oldIndex == childIndex) {
+ for (NodeEntry child : siblings) {
+ if (!EntryValidation.isValidNodeEntry(child) || ((NodeEntryImpl) child).revertInfo != null && ((NodeEntryImpl) child).revertInfo.oldIndex == childIndex) {
return true;
}
}
}
return false;
}
+
/**
* If 'revertInfo' is null it gets created from the current information
* present on this entry.
@@ -1433,8 +1365,8 @@ public class NodeEntryImpl extends Hiera
throw new IllegalArgumentException();
}
- for (Iterator<ItemState> it = operation.getAddedStates().iterator(); it.hasNext();) {
- HierarchyEntry he = it.next().getHierarchyEntry();
+ for (ItemState itemState : operation.getAddedStates()) {
+ HierarchyEntry he = itemState.getHierarchyEntry();
if (he.getStatus() == Status.NEW) {
switch (operation.getStatus()) {
case Operation.STATUS_PERSISTED:
@@ -1620,6 +1552,7 @@ public class NodeEntryImpl extends Hiera
}
//--------------------------------------------------------< inner class >---
+
/**
* Upon move or reorder of this entry the original hierarchy information is
* stored in the RevertInfo for later operation undo and in order to be able
@@ -1633,12 +1566,12 @@ public class NodeEntryImpl extends Hiera
private final NodeEntry oldSuccessor;
private final NodeEntry oldPredecessor;
- private RevertInfo() throws InvalidItemStateException, RepositoryException {
- this.oldParent = parent;
- this.oldName = name;
- this.oldIndex = getIndex();
- this.oldSuccessor = ((ChildNodeEntriesImpl) parent.childNodeEntries).getNext(NodeEntryImpl.this);
- this.oldPredecessor = ((ChildNodeEntriesImpl) parent.childNodeEntries).getPrevious(NodeEntryImpl.this);
+ private RevertInfo() throws RepositoryException {
+ oldParent = parent;
+ oldName = name;
+ oldIndex = getIndex();
+ oldSuccessor = ((ChildNodeEntriesImpl) parent.childNodeEntries).getNext(NodeEntryImpl.this);
+ oldPredecessor = ((ChildNodeEntriesImpl) parent.childNodeEntries).getPrevious(NodeEntryImpl.this);
}
private boolean isMoved() {
@@ -1652,7 +1585,7 @@ public class NodeEntryImpl extends Hiera
parentCNEs.reorderAfter(ne, revertInfo.oldPredecessor);
try {
if (oldIndex != ne.getIndex()) {
- // TODO: TOBEFIXED
+ // TODO: fix
log.warn("Reverting didn't restore the correct index.");
}
} catch (RepositoryException e) {
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java Thu Sep 1 11:52:08 2011
@@ -31,7 +31,7 @@ public interface PropertyEntry extends H
/**
* @return the <code>NodeId</code> of this child node entry.
*/
- public PropertyId getId() throws InvalidItemStateException, RepositoryException;
+ PropertyId getId() throws InvalidItemStateException, RepositoryException;
/**
* Returns the ID that must be used for resolving this entry OR loading its
@@ -42,7 +42,7 @@ public interface PropertyEntry extends H
* @return
* @see #getId()
*/
- public PropertyId getWorkspaceId() throws InvalidItemStateException, RepositoryException;
+ PropertyId getWorkspaceId() throws InvalidItemStateException, RepositoryException;
/**
* @return the referenced <code>PropertyState</code>.
@@ -51,6 +51,6 @@ public interface PropertyEntry extends H
* @throws RepositoryException if an error occurs while retrieving the
* <code>PropertyState</code>.
*/
- public PropertyState getPropertyState() throws ItemNotFoundException, RepositoryException;
+ PropertyState getPropertyState() throws ItemNotFoundException, RepositoryException;
}
\ No newline at end of file
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntryImpl.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntryImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntryImpl.java Thu Sep 1 11:52:08 2011
@@ -59,19 +59,11 @@ public class PropertyEntryImpl extends H
}
//------------------------------------------------------< HierarchyEntryImpl >---
- /**
- * @see HierarchyEntryImpl#doResolve()
- * <p/>
- * Returns a <code>PropertyState</code>.
- */
@Override
- ItemState doResolve() throws ItemNotFoundException, RepositoryException {
+ ItemState doResolve() throws RepositoryException {
return getItemStateFactory().createPropertyState(getWorkspaceId(), this);
}
- /**
- * @see HierarchyEntryImpl#buildPath(boolean)
- */
@Override
Path buildPath(boolean workspacePath) throws RepositoryException {
Path parentPath = parent.buildPath(workspacePath);
@@ -79,24 +71,18 @@ public class PropertyEntryImpl extends H
}
//------------------------------------------------------< PropertyEntry >---
- /**
- * @see PropertyEntry#getId()
- */
- public PropertyId getId() throws InvalidItemStateException, RepositoryException {
+ @Override
+ public PropertyId getId() throws RepositoryException {
return getIdFactory().createPropertyId(parent.getId(), getName());
}
- /**
- * @see PropertyEntry#getWorkspaceId()
- */
- public PropertyId getWorkspaceId() throws InvalidItemStateException, RepositoryException {
+ @Override
+ public PropertyId getWorkspaceId() throws RepositoryException {
return getIdFactory().createPropertyId(parent.getWorkspaceId(), getName());
}
- /**
- * @see PropertyEntry#getPropertyState()
- */
- public PropertyState getPropertyState() throws ItemNotFoundException, RepositoryException {
+ @Override
+ public PropertyState getPropertyState() throws RepositoryException {
return (PropertyState) getItemState();
}
@@ -106,6 +92,7 @@ public class PropertyEntryImpl extends H
*
* @see HierarchyEntry#denotesNode()
*/
+ @Override
public boolean denotesNode() {
return false;
}
@@ -113,6 +100,7 @@ public class PropertyEntryImpl extends H
/**
* @see HierarchyEntry#complete(Operation)
*/
+ @Override
public void complete(Operation operation) throws RepositoryException {
if (!(operation instanceof SetPropertyValue)) {
throw new IllegalArgumentException();
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java Thu Sep 1 11:52:08 2011
@@ -36,8 +36,7 @@ import java.util.Map;
* that are identified by a uniqueID.
*/
public class UniqueIdResolver implements ItemStateCreationListener, EntryFactory.NodeEntryListener {
-
- private static Logger log = LoggerFactory.getLogger(UniqueIdResolver.class);
+ private static final Logger log = LoggerFactory.getLogger(UniqueIdResolver.class);
private final ItemStateFactory isf;
@@ -50,7 +49,7 @@ public class UniqueIdResolver implements
* Creates a new <code>UniqueIdResolver</code>.
*/
public UniqueIdResolver(ItemStateFactory isf) {
- this.lookUp = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+ lookUp = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
this.isf = isf;
isf.addCreationListener(this);
}
@@ -67,7 +66,7 @@ public class UniqueIdResolver implements
return lookUp.get(uniqueId);
}
- public NodeEntry resolve(NodeId nodeId, NodeEntry rootEntry) throws ItemNotFoundException, RepositoryException {
+ public NodeEntry resolve(NodeId nodeId, NodeEntry rootEntry) throws RepositoryException {
NodeEntry entry = lookup(nodeId.getUniqueID());
if (entry == null) {
NodeState state = isf.createDeepNodeState(nodeId, rootEntry);
@@ -77,6 +76,7 @@ public class UniqueIdResolver implements
}
//-----------------------------------------< ItemStateLifeCycleListener >---
+
/**
* Updates the internal id-lookup if the given state
* - is identify by a uniqueID and got removed
@@ -87,9 +87,10 @@ public class UniqueIdResolver implements
* @param previousStatus
* @see ItemStateLifeCycleListener#statusChanged(ItemState, int)
*/
+ @Override
public void statusChanged(ItemState state, int previousStatus) {
synchronized (lookUp) {
- if (Status.isTerminal((state.getStatus()))) {
+ if (Status.isTerminal(state.getStatus())) {
if (state.isNode()) {
NodeEntry entry = (NodeEntry) state.getHierarchyEntry();
String uniqueID = entry.getUniqueID();
@@ -110,13 +111,14 @@ public class UniqueIdResolver implements
}
//------------------------------------------< ItemStateCreationListener >---
+
/**
* Nothing to do. The lookUp is filled entry creation and/or modification
* of its uniqueID
*
* @param state
- * @see ItemStateCreationListener#created(ItemState)
*/
+ @Override
public void created(ItemState state) {
if (state.isNode()) {
NodeEntry entry = (NodeEntry) state.getHierarchyEntry();
@@ -130,9 +132,8 @@ public class UniqueIdResolver implements
}
//-------------------------------------< EntryFactory.NodeEntryListener >---
- /**
- * @see EntryFactory.NodeEntryListener#entryCreated(NodeEntry)
- */
+
+ @Override
public void entryCreated(NodeEntry entry) {
synchronized (lookUp) {
String uniqueID = entry.getUniqueID();
@@ -142,9 +143,7 @@ public class UniqueIdResolver implements
}
}
- /**
- * @see EntryFactory.NodeEntryListener#uniqueIdChanged(NodeEntry, String)
- */
+ @Override
public void uniqueIdChanged(NodeEntry entry, String previousUniqueID) {
synchronized (lookUp) {
if (previousUniqueID != null) {
@@ -161,11 +160,14 @@ public class UniqueIdResolver implements
}
//------------------------------------------------------------< private >---
+
private void putToLookup(String uniqueID, NodeEntry entry) {
Object previous = lookUp.put(uniqueID, entry);
if (previous != null) {
// some other entry existed before with the same uniqueID
- if (!sameEntry((NodeEntry) previous, entry)) {
+ if (sameEntry((NodeEntry) previous, entry)) {
+ log.debug("Replacement of NodeEntry identified by UniqueID");
+ } else {
// if the new entry represents the externally moved/renamed
// correspondence of the previous the latter needs to marked
// removed/stale-destroyed.
@@ -175,8 +177,6 @@ public class UniqueIdResolver implements
// the previous entry. instead it is just removed from this
// cache and left for collection.
((NodeEntry) previous).remove();
- } else {
- log.debug("Replacement of NodeEntry identified by UniqueID");
}
}
}
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java Thu Sep 1 11:52:08 2011
@@ -51,11 +51,11 @@ import java.util.Date;
/**
* <code>LockManagerImpl</code>...
- * TODO: TOBEFIXED. Lock objects obtained through this mgr are not informed if another session is or becomes lock-holder and removes the lock again.
+ * TODO: Lock objects obtained through this mgr are not informed if another session is or becomes lock-holder and
+ * removes the lock again.
*/
public class LockManagerImpl implements LockStateManager, SessionListener {
-
- private static Logger log = LoggerFactory.getLogger(LockManagerImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(LockManagerImpl.class);
private static final long TIMEOUT_EXPIRED = -1;
private static final long TIMEOUT_INFINITE = Long.MAX_VALUE;
@@ -78,8 +78,7 @@ public class LockManagerImpl implements
*/
private final Map<NodeState, LockImpl> lockMap;
- public LockManagerImpl(WorkspaceManager wspManager, ItemManager itemManager,
- CacheBehaviour cacheBehaviour) {
+ public LockManagerImpl(WorkspaceManager wspManager, ItemManager itemManager, CacheBehaviour cacheBehaviour) {
this.wspManager = wspManager;
this.itemManager = itemManager;
this.cacheBehaviour = cacheBehaviour;
@@ -89,17 +88,16 @@ public class LockManagerImpl implements
}
//----------------< org.apache.jackrabbit.jcr2spi.lock.LockStateManager >---
- /**
- * @see LockStateManager#lock(NodeState,boolean,boolean)
- */
- public Lock lock(NodeState nodeState, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
+
+ @Override
+ public Lock lock(NodeState nodeState, boolean isDeep, boolean isSessionScoped) throws RepositoryException {
return lock(nodeState, isDeep, isSessionScoped, Long.MAX_VALUE, null);
}
- /**
- * @see LockStateManager#lock(NodeState,boolean,boolean,long,String)
- */
- public Lock lock(NodeState nodeState, boolean isDeep, boolean isSessionScoped, long timeoutHint, String ownerHint) throws RepositoryException {
+ @Override
+ public Lock lock(NodeState nodeState, boolean isDeep, boolean isSessionScoped, long timeoutHint, String ownerHint)
+ throws RepositoryException {
+
// retrieve node first
Node lhNode;
Item item = itemManager.getItem(nodeState.getHierarchyEntry());
@@ -113,14 +111,11 @@ public class LockManagerImpl implements
LockOperation op = LockOperation.create(nodeState, isDeep, isSessionScoped, timeoutHint, ownerHint);
wspManager.execute(op);
- Lock lock = new LockImpl(new LockState(nodeState, op.getLockInfo()), lhNode);
- return lock;
+ return new LockImpl(new LockState(nodeState, op.getLockInfo()), lhNode);
}
- /**
- * @see LockStateManager#unlock(NodeState)
- */
- public void unlock(NodeState nodeState) throws LockException, RepositoryException {
+ @Override
+ public void unlock(NodeState nodeState) throws RepositoryException {
// execute the operation. Note, that its possible that the session is
// lock holder and still the lock was never accessed. thus the lockMap
// does not provide sufficient and reliable information.
@@ -138,15 +133,15 @@ public class LockManagerImpl implements
/**
* If the session created a lock on the node with the given state, we already
- * know the lock. Otherwise, the node state and its ancestores are searched
+ * know the lock. Otherwise, the node state and its ancestors are searched
* for properties indicating a lock.<br>
* Note, that the flag indicating session-scoped lock cannot be retrieved
* unless the current session is the lock holder.
*
- * @see LockStateManager#getLock(NodeState)
* @param nodeState
*/
- public Lock getLock(NodeState nodeState) throws LockException, RepositoryException {
+ @Override
+ public Lock getLock(NodeState nodeState) throws RepositoryException {
LockImpl l = getLockImpl(nodeState, false);
// no-lock found or lock doesn't apply to this state -> throw
if (l == null) {
@@ -158,18 +153,14 @@ public class LockManagerImpl implements
return l;
}
- /**
- * @see LockStateManager#isLocked(NodeState)
- */
+ @Override
public boolean isLocked(NodeState nodeState) throws RepositoryException {
LockImpl l = getLockImpl(nodeState, false);
return l != null;
}
- /**
- * @see LockStateManager#checkLock(NodeState)
- */
- public void checkLock(NodeState nodeState) throws LockException, RepositoryException {
+ @Override
+ public void checkLock(NodeState nodeState) throws RepositoryException {
// shortcut: new status indicates that a new state was already added
// thus, the parent state is not locked by foreign lock.
if (nodeState.getStatus() == Status.NEW) {
@@ -188,9 +179,9 @@ public class LockManagerImpl implements
* Returns the lock tokens present on the <code>SessionInfo</code> this
* manager has been created with.
*
- * @see LockStateManager#getLockTokens()
*/
- public String[] getLockTokens() throws UnsupportedRepositoryOperationException, RepositoryException {
+ @Override
+ public String[] getLockTokens() throws RepositoryException {
return wspManager.getLockTokens();
}
@@ -199,9 +190,9 @@ public class LockManagerImpl implements
* If this succeeds this method will inform all locks stored in the local
* map in order to give them the chance to update their lock information.
*
- * @see LockStateManager#addLockToken(String)
*/
- public void addLockToken(String lt) throws LockException, RepositoryException {
+ @Override
+ public void addLockToken(String lt) throws RepositoryException {
wspManager.addLockToken(lt);
notifyTokenAdded(lt);
}
@@ -214,9 +205,9 @@ public class LockManagerImpl implements
* All locks stored in the local lock map are notified by the removed
* token in order have them updated their lock information.
*
- * @see LockStateManager#removeLockToken(String)
*/
- public void removeLockToken(String lt) throws LockException, RepositoryException {
+ @Override
+ public void removeLockToken(String lt) throws RepositoryException {
// JSR170 v. 1.0.1 defines that the token of a session-scoped lock may
// not be moved over to another session. Thus removal is not possible
// and the lock is always present in the lock map.
@@ -243,9 +234,8 @@ public class LockManagerImpl implements
}
//----------------------------------------------------< SessionListener >---
- /**
- * @see SessionListener#loggingOut(Session)
- */
+
+ @Override
public void loggingOut(Session session) {
// remove any session scoped locks:
NodeState[] lhStates = lockMap.keySet().toArray(new NodeState[lockMap.size()]);
@@ -263,9 +253,7 @@ public class LockManagerImpl implements
}
}
- /**
- * @see SessionListener#loggedOut(Session)
- */
+ @Override
public void loggedOut(Session session) {
// release all remaining locks without modifying their lock status
LockImpl[] locks = lockMap.values().toArray(new LockImpl[lockMap.size()]);
@@ -288,11 +276,11 @@ public class LockManagerImpl implements
* verification regarding nodetypes present.
*
* @param nodeState <code>NodeState</code> from which searching starts.
- * Note, that the given state must not have an overlayed state.
+ * Note, that the given state must not have an overlaid state.
* @return a state holding a lock or <code>null</code> if neither the
* given state nor any of its ancestors is locked.
*/
- private NodeState getLockHoldingState(NodeState nodeState) {
+ private static NodeState getLockHoldingState(NodeState nodeState) {
NodeEntry entry = nodeState.getNodeEntry();
while (!entry.hasPropertyEntry(NameConstants.JCR_LOCKISDEEP)) {
NodeEntry parent = entry.getParent();
@@ -392,7 +380,7 @@ public class LockManagerImpl implements
}
if (lState != null) {
- // Test again if a Lock object is stored in the lockmap. Otherwise
+ // Test again if a Lock object is stored in the lock map. Otherwise
// build the lock object and retrieve lock holding node. note that this
// may fail if the session does not have permission to see this node.
LockImpl lock = getLockFromMap(lState.lockHoldingState);
@@ -402,7 +390,7 @@ public class LockManagerImpl implements
Item lockHoldingNode = itemManager.getItem(lState.lockHoldingState.getHierarchyEntry());
lock = new LockImpl(lState, (Node)lockHoldingNode);
}
- // test if lock applies to the original nodestate
+ // test if lock applies to the original node state
if (lState.appliesToNodeState(nodeState)) {
return lock;
} else {
@@ -427,6 +415,7 @@ public class LockManagerImpl implements
}
//----------------------------< Notification about modified lock-tokens >---
+
/**
* Notify all <code>Lock</code>s that have been accessed so far about the
* new lock token present on the session and allow them to reload their
@@ -457,6 +446,7 @@ public class LockManagerImpl implements
}
//--------------------------------------------------------------------------
+
private class LockState implements ItemStateLifeCycleListener {
private final NodeState lockHoldingState;
@@ -477,10 +467,10 @@ public class LockManagerImpl implements
}
/**
- * Returns true, if the given node state is the lockholding state of
+ * Returns true, if the given node state is the lock holding state of
* this Lock object OR if this Lock is deep.
* Note, that in the latter case this method does not assert, that the
- * given node state is a child state of the lockholding state.
+ * given node state is a child state of the lock holding state.
*
* @param nodeState that must be the same or a child of the lock holding
* state stored within this lock object.
@@ -490,11 +480,7 @@ public class LockManagerImpl implements
if (nodeState.getStatus() == Status.NEW) {
return lockInfo.isDeep();
} else {
- if (lockHoldingState == nodeState) {
- return true;
- } else {
- return lockInfo != null && lockInfo.isDeep();
- }
+ return lockHoldingState == nodeState || lockInfo != null && lockInfo.isDeep();
}
}
@@ -559,7 +545,7 @@ public class LockManagerImpl implements
}
/**
- * Release this lock by removing from the lock map and unregistering
+ * Release this lock by removing from the lock map and un-registering
* it from event listening
*/
private void release() {
@@ -585,7 +571,7 @@ public class LockManagerImpl implements
// LockState must be aware of removal of the Node.
lockHoldingState.addListener(this);
- // in case of CacheBehaviour.OBSERVATION this lockstate can also
+ // in case of CacheBehaviour.OBSERVATION this lock state can also
// be aware of another session removing the lock -> listen to
// status changes of the jcr:lockIsDeep property.
if (cacheBehaviour == CacheBehaviour.OBSERVATION) {
@@ -620,9 +606,8 @@ public class LockManagerImpl implements
}
//-------------------------------------< ItemStateLifeCycleListener >---
- /**
- * @see ItemStateLifeCycleListener#statusChanged(ItemState, int)
- */
+
+ @Override
public void statusChanged(ItemState state, int previousStatus) {
if (!isLive()) {
// since we only monitor the removal of the lock (by means
@@ -645,6 +630,7 @@ public class LockManagerImpl implements
}
//---------------------------------------------------------------< Lock >---
+
/**
* Inner class implementing the {@link Lock} interface.
*/
@@ -652,17 +638,17 @@ public class LockManagerImpl implements
private final LockState lockState;
private final Node node;
- private boolean reloadInfo = false; // TODO: find better solution
+ private boolean reloadInfo; // TODO: find better solution
/**
*
* @param lockState
- * Note, that the given state must not have an overlayed state.
+ * Note, that the given state must not have an overlaid state.
* @param lockHoldingNode the lock holding <code>Node</code> itself.
*/
public LockImpl(LockState lockState, Node lockHoldingNode) {
this.lockState = lockState;
- this.node = lockHoldingNode;
+ node = lockHoldingNode;
// if observation is supported OR if this is a session-scoped lock
// hold by this session -> store lock in the map
@@ -684,9 +670,7 @@ public class LockManagerImpl implements
}
}
- /**
- * @see Lock#getLockOwner()
- */
+ @Override
public String getLockOwner() {
LockInfo info = getLockInfo();
if (info != null) {
@@ -696,24 +680,18 @@ public class LockManagerImpl implements
}
}
- /**
- * @see Lock#isDeep()
- */
+ @Override
public boolean isDeep() {
LockInfo info = getLockInfo();
return info != null && info.isDeep();
}
- /**
- * @see Lock#getNode()
- */
+ @Override
public Node getNode() {
return node;
}
- /**
- * @see Lock#getLockToken()
- */
+ @Override
public String getLockToken() {
// shortcut for jsr 283 session scoped locks: they never expose
// the lock token to the API users.
@@ -730,56 +708,47 @@ public class LockManagerImpl implements
}
}
- /**
- * @see Lock#isLive()
- */
+ @Override
public boolean isLive() throws RepositoryException {
updateLockInfo();
return lockState.isLive();
}
- /**
- * @see Lock#isSessionScoped()
- */
+ @Override
public boolean isSessionScoped() {
LockInfo info = getLockInfo();
return info != null && info.isSessionScoped();
}
- /**
- * @see Lock#refresh()
- */
- public void refresh() throws LockException, RepositoryException {
+ @Override
+ public void refresh() throws RepositoryException {
if (!isLive()) {
throw new LockException("Lock is not alive any more.");
}
- if (!isLockOwningSession()) {
+ if (isLockOwningSession()) {
+ lockState.refresh();
+ } else {
// shortcut, since lock is always updated if the session became
// lock-holder of a foreign lock.
throw new LockException("Session does not hold lock.");
- } else {
- lockState.refresh();
}
}
- /**
- * @see javax.jcr.lock.Lock#getSecondsRemaining()
- */
+ @Override
public long getSecondsRemaining() throws RepositoryException {
updateLockInfo();
return lockState.getSecondsRemaining();
}
- /**
- * @see javax.jcr.lock.Lock#isLockOwningSession()
- */
+ @Override
public boolean isLockOwningSession(){
LockInfo info = getLockInfo();
return info != null && info.isLockOwner();
}
//----------------------------------------------< LockTokenListener >---
+
/**
* A lock token as been added to the current Session. If this Lock
* object is not yet hold by the Session (thus does not know whether
@@ -788,8 +757,8 @@ public class LockManagerImpl implements
*
* @param lockToken
* @throws RepositoryException
- * @see LockTokenListener#lockTokenAdded(String)
*/
+ @Override
public void lockTokenAdded(String lockToken) throws RepositoryException {
if (!isSessionScoped() && !isLockOwningSession()) {
// unless this lock is session-scoped (token is never transferred)
@@ -800,12 +769,7 @@ public class LockManagerImpl implements
}
}
- /**
- *
- * @param lockToken
- * @throws LockException
- * @see LockTokenListener#lockTokenRemoved(String)
- */
+ @Override
public void lockTokenRemoved(String lockToken) throws RepositoryException {
// reload lock info, if session gave away its lock-holder status
// for this lock. this will never be true for session-scoped locks
@@ -816,6 +780,7 @@ public class LockManagerImpl implements
}
//--------------------------------------------------------< private >---
+
/**
* @return <code>LockInfo</code> stored within the <code>LockState</code>
*/
@@ -840,6 +805,7 @@ public class LockManagerImpl implements
}
//--------------------------------------------------< LockTokenListener >---
+
/**
*
*/
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/BitsetENTCacheImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/BitsetENTCacheImpl.java?rev=1164026&r1=1164025&r2=1164026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/BitsetENTCacheImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/BitsetENTCacheImpl.java Thu Sep 1 11:52:08 2011
@@ -16,13 +16,14 @@
*/
package org.apache.jackrabbit.jcr2spi.nodetype;
+import org.apache.jackrabbit.spi.Name;
+
import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.jackrabbit.spi.Name;
-
/**
* Implements an effective node type cache that uses a bit set for storing the
* information about participating node types in a set.
@@ -77,31 +78,23 @@ class BitsetENTCacheImpl implements Effe
}
//---------------------------------------------< EffectiveNodeTypeCache >---
- /**
- * @see EffectiveNodeTypeCache#getKey(Name[])
- */
+ @Override
public Key getKey(Name[] ntNames) {
return new BitsetKey(ntNames, nameIndex.size() + ntNames.length);
}
- /**
- * @see EffectiveNodeTypeCache#put(EffectiveNodeType)
- */
+ @Override
public void put(EffectiveNodeType ent) {
put(getKey(ent.getMergedNodeTypes()), ent);
}
- /**
- * @see EffectiveNodeTypeCache#put(Key, EffectiveNodeType)
- */
+ @Override
public void put(Key key, EffectiveNodeType ent) {
aggregates.put(key, ent);
sortedKeys.add(key);
}
- /**
- * @see EffectiveNodeTypeCache#findBest(Key)
- */
+ @Override
public Key findBest(Key key) {
// quick check for already cached key
if (contains(key)) {
@@ -115,14 +108,10 @@ class BitsetENTCacheImpl implements Effe
return null;
}
- /**
- * @see EffectiveNodeTypeCache#invalidate(Name)
- */
+ @Override
public void invalidate(Name name) {
- /**
- * remove all affected effective node types from aggregates cache
- * (copy keys first to prevent ConcurrentModificationException)
- */
+ // remove all affected effective node types from aggregates cache
+ // (copy keys first to prevent ConcurrentModificationException)
ArrayList<Key> keys = new ArrayList<Key>(aggregates.keySet());
for (Key k : keys) {
EffectiveNodeType ent = get(k);
@@ -132,23 +121,17 @@ class BitsetENTCacheImpl implements Effe
}
}
- /**
- * @see EffectiveNodeTypeCache#contains(Key)
- */
+ @Override
public boolean contains(Key key) {
return aggregates.containsKey(key);
}
- /**
- * @see EffectiveNodeTypeCache#get(Key)
- */
+ @Override
public EffectiveNodeType get(Key key) {
return aggregates.get(key);
}
- /**
- * @see EffectiveNodeTypeCache#clear()
- */
+ @Override
public void clear() {
sortedKeys.clear();
aggregates.clear();
@@ -156,6 +139,7 @@ class BitsetENTCacheImpl implements Effe
}
//------------------------------------------------------------< private >---
+
/**
* Returns the bit number for the given name. If the name does not exist
* a new new bit number for that name is created.
@@ -204,7 +188,7 @@ class BitsetENTCacheImpl implements Effe
EffectiveNodeType removed = aggregates.remove(key);
if (removed != null) {
// other than the original implementation, the weights in the
- // treeset are now the same as in the given keys. so we can use
+ // tree set are now the same as in the given keys. so we can use
// the normal remove method
sortedKeys.remove(key);
}
@@ -212,11 +196,10 @@ class BitsetENTCacheImpl implements Effe
}
//----------------------------------------------------------< Cloneable >---
- /**
- * @see Cloneable#clone()
- */
+
@Override
- public Object clone() {
+ public Object clone() throws CloneNotSupportedException {
+ super.clone();
BitsetENTCacheImpl clone = new BitsetENTCacheImpl();
clone.sortedKeys.addAll(sortedKeys);
clone.aggregates.putAll(aggregates);
@@ -233,7 +216,7 @@ class BitsetENTCacheImpl implements Effe
*/
public String toString() {
StringBuilder builder = new StringBuilder();
- builder.append("EffectiveNodeTypeCache (" + super.toString() + ")\n");
+ builder.append("EffectiveNodeTypeCache (").append(super.toString()).append(")\n");
builder.append("EffectiveNodeTypes in cache:\n");
for (Key k : sortedKeys) {
builder.append(k);
@@ -243,6 +226,7 @@ class BitsetENTCacheImpl implements Effe
}
//----------------------------------------------------------------< Key >---
+
/**
* Implements a {@link Key} by storing the node type aggregate information
* in a bit set. We do not use the {@link java.util.BitSet} because it
@@ -262,22 +246,22 @@ class BitsetENTCacheImpl implements Effe
private final long[] bits;
/**
- * the hashcode, only calculated once
+ * the hash code, only calculated once
*/
private final int hashCode;
/**
* Creates a ew bitset key.
* @param names the node type names
- * @param maxBit the approximative number of the geatest bit
+ * @param maxBit the approximate number of the greatest bit
*/
public BitsetKey(Name[] names, int maxBit) {
this.names = names;
bits = new long[maxBit/BPW+1];
- for (int i=0; i<names.length; i++) {
- int n = getBitNumber(names[i]);
- bits[n/BPW] |= OR_MASK[n%BPW];
+ for (Name name : names) {
+ int n = getBitNumber(name);
+ bits[n / BPW] |= OR_MASK[n % BPW];
}
hashCode = calcHashCode();
}
@@ -293,7 +277,7 @@ class BitsetENTCacheImpl implements Effe
int i = nextSetBit(0);
int j=0;
while (i >= 0) {
- names[j++] = BitsetENTCacheImpl.this.getName(i);
+ names[j++] = getName(i);
i = nextSetBit(i+1);
}
hashCode = calcHashCode();
@@ -336,16 +320,16 @@ class BitsetENTCacheImpl implements Effe
*/
private int bitCount(long val) {
val -= (val & 0xaaaaaaaaaaaaaaaaL) >>> 1;
- val = (val & 0x3333333333333333L) + ((val >>> 2) & 0x3333333333333333L);
- val = (val + (val >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
+ val = (val & 0x3333333333333333L) + (val >>> 2 & 0x3333333333333333L);
+ val = val + (val >>> 4) & 0x0f0f0f0f0f0f0f0fL;
val += val >>> 8;
val += val >>> 16;
- return ((int)(val) + (int)(val >>> 32)) & 0xff;
+ return (int) val + (int) (val >>> 32) & 0xff;
}
/**
- * Calculates the hashcode.
- * @return the calculated hashcode
+ * Calculates the hash code.
+ * @return the calculated hash code
*/
private int calcHashCode() {
long h = 1234;
@@ -357,28 +341,23 @@ class BitsetENTCacheImpl implements Effe
h ^= bits[addr] * (addr + 1);
addr--;
}
- return (int)((h >> 32) ^ h);
+ return (int)(h >> 32 ^ h);
}
//------------------------------------------------------------< Key >---
- /**
- * @see Key#getNames()
- */
+
+ @Override
public Name[] getNames() {
return names;
}
- /**
- * @see Key#contains(Key)
- */
+ @Override
public boolean contains(Key otherKey) {
- /*
- * 0 - 0 => 0
- * 0 - 1 => 1
- * 1 - 0 => 0
- * 1 - 1 => 0
- * !a and b
- */
+ // 0 - 0 => 0
+ // 0 - 1 => 1
+ // 1 - 0 => 0
+ // 1 - 1 => 0
+ // !a and b
BitsetKey other = (BitsetKey) otherKey;
int len = Math.max(bits.length, other.bits.length);
for (int i=0; i<len; i++) {
@@ -392,17 +371,13 @@ class BitsetENTCacheImpl implements Effe
return true;
}
- /**
- * @see Key#subtract(Key)
- */
+ @Override
public Key subtract(Key otherKey) {
- /*
- * 0 - 0 => 0
- * 0 - 1 => 0
- * 1 - 0 => 1
- * 1 - 1 => 0
- * a and !b
- */
+ // 0 - 0 => 0
+ // 0 - 1 => 0
+ // 1 - 0 => 1
+ // 1 - 1 => 0
+ // a and !b
BitsetKey other = (BitsetKey) otherKey;
int len = Math.max(bits.length, other.bits.length);
long[] newBits = new long[len];
@@ -417,14 +392,16 @@ class BitsetENTCacheImpl implements Effe
}
//-----------------------------------------------------< Comparable >---
+
/**
* {@inheritDoc}
*
* This compares 1. the cardinality (number of set bits) and 2. the
- * numeric value of the bitsets in descending order.
+ * numeric value of the bit sets in descending order.
*
* @see Comparable#compareTo(Object)
*/
+ @Override
public int compareTo(Key other) {
BitsetKey o = (BitsetKey) other;
int res = o.names.length - names.length;
@@ -450,9 +427,7 @@ class BitsetENTCacheImpl implements Effe
}
//---------------------------------------------------------< Object >---
- /**
- * @see Object#equals(Object)
- */
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -477,25 +452,19 @@ class BitsetENTCacheImpl implements Effe
return false;
}
- /**
- * @see Object#hashCode()
- */
@Override
public int hashCode() {
return hashCode;
}
- /**
- * @see Object#toString()
- */
@Override
public String toString() {
- StringBuffer buf = new StringBuffer("w=");
+ StringBuilder buf = new StringBuilder("w=");
buf.append(names.length);
int i = nextSetBit(0);
while (i>=0) {
- buf.append(", ").append(i).append("=");
- buf.append(BitsetENTCacheImpl.this.getName(i));
+ buf.append(", ").append(i).append('=');
+ buf.append(getName(i));
i = nextSetBit(i+1);
}
return buf.toString();