You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2006/08/18 09:14:03 UTC
svn commit: r432506 - in
/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state:
ChildNodeReference.java NodeState.java NodeStateListener.java
PathElementReference.java PropertyState.java UUIDReference.java
Author: mreutegg
Date: Fri Aug 18 00:14:02 2006
New Revision: 432506
URL: http://svn.apache.org/viewvc?rev=432506&view=rev
Log:
- Create a factory method in ChildNodeReference, which creates a UUIDReference or a PathElementReference based on the availability of a UUID in the child NodeState.
- Introduce a propertiesInAttic in NodeState, which contains properties that are marked removed in the transient space and have been overlayed with a new property with the same name.
- Reviewed NodeState.moveChildNodeEntry()
- Removed unused NodeStateListener.
Removed:
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeStateListener.java
Modified:
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java?rev=432506&r1=432505&r2=432506&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java Fri Aug 18 00:14:02 2006
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.jcr2spi.state;
import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.IdFactory;
/**
* <code>ChildNodeReference</code> implements common functionality for child
@@ -38,14 +39,33 @@
}
/**
+ * Creates a new <code>ChildNodeEntry</code> for an already initialized
+ * child node state. The child node must already be attached to its parent.
+ *
+ * @param child the child node state.
+ * @param isf the item state factory to re-create node states.
+ * @param idFactory the <code>IdFactory</code> to create new ItemIds
+ */
+ public static ChildNodeEntry create(NodeState child, ItemStateFactory isf,
+ IdFactory idFactory) {
+ ChildNodeEntry cne;
+ if (child.getUUID() == null) {
+ cne = new PathElementReference(child, isf, idFactory);
+ } else {
+ cne = new UUIDReference(child, isf);
+ }
+ return cne;
+ }
+
+ /**
* Creates a new <code>ChildNodeReference</code> with the given parent
* <code>NodeState</code> and an already initialized child node state.
*
* @param child the child node state.
* @param isf the item state factory to re-create the node state.
*/
- public ChildNodeReference(NodeState child, ItemStateFactory isf) {
- super(child.getParent(), child, null, isf); // TODO: get name from child instead of null
+ protected ChildNodeReference(NodeState child, ItemStateFactory isf) {
+ super(child.getParent(), child, child.getName(), isf);
}
/**
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=432506&r1=432505&r2=432506&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Fri Aug 18 00:14:02 2006
@@ -18,7 +18,6 @@
import org.apache.commons.collections.list.AbstractLinkedList;
import org.apache.commons.collections.iterators.UnmodifiableIterator;
-import org.apache.jackrabbit.util.WeakIdentityCollection;
import org.apache.jackrabbit.spi.IdFactory;
import org.apache.jackrabbit.spi.QNodeDefinition;
import org.apache.jackrabbit.name.Path;
@@ -109,14 +108,15 @@
private HashMap properties = new HashMap();
/**
- * NodeReferences for this node state.
+ * Map of properties which are deleted and have been re-created as transient
+ * property with the same name.
*/
- private NodeReferences references;
+ private HashMap propertiesInAttic = new HashMap();
/**
- * Listeners (weak references)
+ * NodeReferences for this node state.
*/
- private final transient Collection listeners = new WeakIdentityCollection(3);
+ private NodeReferences references;
/**
* The <code>ItemStateFactory</code> which is used to create new
@@ -178,11 +178,12 @@
NodeState nodeState = (NodeState) state;
name = nodeState.name;
uuid = nodeState.uuid;
- parent = nodeState.parent; // TODO: parent from wrong ism layer
+ //parent = nodeState.parent; // TODO: parent from wrong ism layer
nodeTypeName = nodeState.nodeTypeName;
mixinTypeNames = nodeState.mixinTypeNames;
def = nodeState.def;
// re-create property references
+ propertiesInAttic.clear();
properties.clear(); // TODO: any more cleanup work to do? try some kind of merging?
Iterator it = nodeState.getPropertyNames().iterator();
while (it.hasNext()) {
@@ -482,9 +483,7 @@
*/
synchronized ChildNodeEntry addChildNodeEntry(QName nodeName,
String uuid) {
- ChildNodeEntry entry = childNodeEntries.add(nodeName, uuid);
- notifyNodeAdded(entry);
- return entry;
+ return childNodeEntries.add(nodeName, uuid);
}
/**
@@ -502,17 +501,25 @@
if (child.getParent() != this) {
throw new IllegalArgumentException("This NodeState is not the parent of child");
}
- ChildNodeEntry cne;
- if (uuid != null) {
- cne = new UUIDReference(child, isf);
- } else {
- cne = new PathElementReference(child, isf, idFactory);
- }
+ ChildNodeEntry cne = ChildNodeReference.create(child, isf, idFactory);
childNodeEntries.add(cne);
markModified();
}
/**
+ * Renames this node to <code>newName</code>.
+ *
+ * @param newName the new name for this node state.
+ * @throws IllegalStateException if this is the root node.
+ */
+ private synchronized void rename(QName newName) {
+ if (parent == null) {
+ throw new IllegalStateException("root node cannot be renamed");
+ }
+ name = newName;
+ }
+
+ /**
* Notifies this node state that a child node state has been removed.
*
* @param nodeState the node state that has been removed.
@@ -556,9 +563,14 @@
if (propState.isValid()) {
propState.remove();
} else {
- // already removed
+ // remove invalid property state from properties map
+ it.remove();
}
}
+ // move all properties from attic back to properties map
+ properties.putAll(propertiesInAttic);
+ propertiesInAttic.clear();
+
// then remove child node entries
for (Iterator it = childNodeEntries.iterator(); it.hasNext(); ) {
NodeState nodeState = ((ChildNodeEntry) it.next()).getNodeState();
@@ -636,8 +648,24 @@
throw new IllegalArgumentException("This NodeState is not the parent of propState");
}
QName propertyName = propState.getQName();
- if (properties.containsKey(propertyName)) {
- throw new ItemExistsException(propertyName.toString());
+ // check for an existing property
+ PropertyReference ref = (PropertyReference) properties.get(propertyName);
+ if (ref != null) {
+ PropertyState existingState = null;
+ try {
+ existingState = ref.getPropertyState();
+ } catch (ItemStateException e) {
+ // probably does not exist anymore, remove from properties map
+ properties.remove(propertyName);
+ }
+ if (existingState != null) {
+ if (existingState.getStatus() == STATUS_EXISTING_REMOVED) {
+ // move to attic
+ propertiesInAttic.put(propertyName, ref);
+ } else {
+ throw new ItemExistsException(propertyName.toString());
+ }
+ }
}
properties.put(propertyName, new PropertyReference(propState, isf, idFactory));
markModified();
@@ -771,13 +799,22 @@
}
/**
+ * Reorders the child node <code>insertNode</code> before the child node
+ * <code>beforeNode</code>.
*
- * @param insertNode
- * @param beforeNode
+ * @param insertNode the child node to reorder.
+ * @param beforeNode the child node where to insert the node before. If
+ * <code>null</code> the child node <code>insertNode</code>
+ * is moved to the end of the child node entries.
+ * @throws NoSuchItemStateException if <code>insertNode</code> or
+ * <code>beforeNode</code> is not a child
+ * node of this <code>NodeState</code>.
*/
synchronized void reorderChildNodeEntries(NodeState insertNode, NodeState beforeNode)
throws NoSuchItemStateException {
childNodeEntries.reorder(insertNode, beforeNode);
+ // mark this state as modified
+ markModified();
}
/**
@@ -790,23 +827,15 @@
* @throws RepositoryException if the given child state is not a child
* of this node state.
*/
- // TODO: review. move with SPI Ids
synchronized void moveChildNodeEntry(NodeState newParent, NodeState childState, QName newName)
throws RepositoryException {
- // rename only
ChildNodeEntry oldEntry = childNodeEntries.remove(childState);
if (oldEntry != null) {
- if (newParent == this) {
- ChildNodeEntry newEntry = childNodeEntries.add(name, childState.getUUID());
- notifyNodeAdded(newEntry);
- notifyNodeRemoved(oldEntry);
- } else {
- notifyNodeRemoved(oldEntry);
- // re-parent target node
- childState.setParent(newParent);
- // add child node entry to new parent
- newParent.addChildNodeEntry(newName, childState.getUUID());
- }
+ childState.rename(newName);
+ // re-parent target node
+ childState.setParent(newParent);
+ // add child node entry to new parent
+ newParent.childNodeEntries.add(childState);
} else {
throw new RepositoryException("Unexpected error: Child state to be renamed does not exist.");
}
@@ -854,90 +883,6 @@
return sns.indexOf(cne) + 1;
}
- //---------------------------------------------------< Listener support >---
- /**
- * {@inheritDoc}
- * <p/>
- * If the listener passed is at the same time a <code>NodeStateListener</code>
- * we add it to our list of specialized listeners.
- */
- public void addListener(ItemStateListener listener) {
- if (listener instanceof NodeStateListener) {
- synchronized (listeners) {
- if (listeners.contains(listener)) {
- log.debug("listener already registered: " + listener);
- // no need to add to call ItemState.addListener()
- return;
- } else {
- listeners.add(listener);
- }
- }
- }
- super.addListener(listener);
- }
-
- /**
- * {@inheritDoc}
- * <p/>
- * If the listener passed is at the same time a <code>NodeStateListener</code>
- * we remove it from our list of specialized listeners.
- */
- public void removeListener(ItemStateListener listener) {
- if (listener instanceof NodeStateListener) {
- synchronized (listeners) {
- listeners.remove(listener);
- }
- }
- super.removeListener(listener);
- }
-
- //----------------------------------------------< Listener notification >---
- /**
- * Notify the listeners that a child node entry has been added
- */
- private void notifyNodeAdded(ChildNodeEntry added) {
- synchronized (listeners) {
- Iterator iter = listeners.iterator();
- while (iter.hasNext()) {
- NodeStateListener l = (NodeStateListener) iter.next();
- if (l != null) {
- l.nodeAdded(this, added.getName(), added.getIndex(), added.getId());
- }
- }
- }
- }
-
- /**
- * Notify the listeners that the child node entries have been replaced
- */
- private void notifyNodesReplaced() {
- synchronized (listeners) {
- Iterator iter = listeners.iterator();
- while (iter.hasNext()) {
- NodeStateListener l = (NodeStateListener) iter.next();
- if (l != null) {
- l.nodesReplaced(this);
- }
- }
- }
- }
-
- /**
- * Notify the listeners that a child node entry has been removed
- */
- private void notifyNodeRemoved(ChildNodeEntry removed) {
- synchronized (listeners) {
- Iterator iter = listeners.iterator();
- while (iter.hasNext()) {
- NodeStateListener l = (NodeStateListener) iter.next();
- if (l != null) {
- l.nodeRemoved(this, removed.getName(),
- removed.getIndex(), removed.getId());
- }
- }
- }
- }
-
//------------------------------------------------------< inner classes >---
/**
@@ -1155,6 +1100,19 @@
} else {
nameMap.put(nodeName, ln);
}
+ }
+
+ /**
+ * Adds a <code>childNode</code> to the end of the list.
+ *
+ * @param childNode the <code>NodeState</code> to add.
+ * @return the <code>ChildNodeEntry</code> which was created for
+ * <code>childNode</code>.
+ */
+ ChildNodeEntry add(NodeState childNode) {
+ ChildNodeEntry cne = ChildNodeReference.create(childNode, isf, idFactory);
+ add(cne);
+ return cne;
}
/**
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java?rev=432506&r1=432505&r2=432506&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java Fri Aug 18 00:14:02 2006
@@ -25,7 +25,7 @@
* <code>PathElementReference</code> implements a {@link ChildNodeEntry} based
* on a {@link Path.PathElement}.
*/
-public class PathElementReference extends ChildNodeReference implements ChildNodeEntry {
+class PathElementReference extends ChildNodeReference implements ChildNodeEntry {
/**
* IdFactory to create an ItemId based on the parent NodeId
@@ -41,8 +41,8 @@
* @param isf the item state factory to create the node state.
* @param idFactory the <code>IdFactory</code> to create new ItemIds
*/
- public PathElementReference(NodeState parent, QName name,
- ItemStateFactory isf, IdFactory idFactory) {
+ PathElementReference(NodeState parent, QName name,
+ ItemStateFactory isf, IdFactory idFactory) {
super(parent, name, isf);
this.idFactory = idFactory;
}
@@ -55,8 +55,8 @@
* @param isf the item state factory to re-create the node state.
* @param idFactory the <code>IdFactory</code> to create new ItemIds
*/
- public PathElementReference(NodeState child, ItemStateFactory isf,
- IdFactory idFactory) {
+ PathElementReference(NodeState child, ItemStateFactory isf,
+ IdFactory idFactory) {
super(child, isf);
this.idFactory = idFactory;
}
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=432506&r1=432505&r2=432506&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java Fri Aug 18 00:14:02 2006
@@ -114,7 +114,7 @@
synchronized (state) {
PropertyState propState = (PropertyState) state;
name = propState.name;
- parent = propState.parent;
+ //parent = propState.parent; // TODO: parent from wrong layer
type = propState.type;
def = propState.def;
values = propState.values;
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java?rev=432506&r1=432505&r2=432506&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java Fri Aug 18 00:14:02 2006
@@ -42,7 +42,7 @@
* @throws IllegalArgumentException if <code>childId</code> has a relative
* path component.
*/
- public UUIDReference(NodeState parent, NodeId childId, ItemStateFactory isf, QName name) {
+ UUIDReference(NodeState parent, NodeId childId, ItemStateFactory isf, QName name) {
super(parent, name, isf);
if (childId.getRelativePath() == null) {
throw new IllegalArgumentException("childId must not contain a relative path");
@@ -59,7 +59,7 @@
* @throws IllegalArgumentException if the id of <code>child</code> has a
* relative path component.
*/
- public UUIDReference(NodeState child, ItemStateFactory isf) {
+ UUIDReference(NodeState child, ItemStateFactory isf) {
super(child, isf);
this.childId = child.getNodeId();
if (childId.getRelativePath() == null) {