jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r164473 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: CachingHierarchyManager.java HierarchyManager.java HierarchyManagerImpl.java nodetype/ItemDefImpl.java
Date Sun, 24 Apr 2005 12:44:31 GMT
Author: stefan
Date: Sun Apr 24 05:44:30 2005
New Revision: 164473

URL: http://svn.apache.org/viewcvs?rev=164473&view=rev
Log:
- added HierarchyManager.isAncestor(NodeId, ItemId) method
- some small javadoc fixes

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=164473&r1=164472&r2=164473&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Sun Apr 24 05:44:30 2005
@@ -146,6 +146,26 @@
     /**
      * {@inheritDoc}
      */
+    public boolean isAncestor(NodeId nodeId, ItemId itemId)
+            throws ItemNotFoundException, RepositoryException {
+        if (pathCache.containsKey(nodeId) && pathCache.containsKey(itemId)) {
+            // use cached Path objects rather than calling delegatee
+            try {
+                return getPath(nodeId).isAncestorOf(getPath(itemId));
+            } catch (MalformedPathException mpe) {
+                // should never get here...
+                String msg = "failed to determine degree of relationship of "
+                        + nodeId + " and " + itemId;
+                throw new ItemNotFoundException(msg, mpe);
+            }
+        } else {
+            return delegatee.isAncestor(nodeId, itemId);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public synchronized Path[] getAllPaths(ItemId id)
             throws ItemNotFoundException, RepositoryException {
         return getAllPaths(id, false);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java?rev=164473&r1=164472&r2=164473&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java Sun
Apr 24 05:44:30 2005
@@ -51,13 +51,34 @@
 
     /**
      * Returns the depth of the specified item which is equivalent to
-     * <code>getPath(id).getAncestorCount()</code>.
-     * @param id
-     * @return
-     * @throws ItemNotFoundException
-     * @throws RepositoryException
+     * <code>getPath(id).getAncestorCount()</code>. The depth reflects the
+     * absolute hierarchy level.
+     *
+     * @param id item id
+     * @return the depth of the specified item
+     * @throws ItemNotFoundException if the specified <code>id</code> does not
+     *                               denote an existing item.
+     * @throws RepositoryException   if another error occurs
      */
     int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException;
+
+    /**
+     * Determines whether the node with the specified <code>nodeId</code>
+     * is an ancestor of the item denoted by the given <code>itemId</code>.
+     * This is equivalent to
+     * <code>getPath(nodeId).isAncestorOf(getPath(itemId))</code>.
+     *
+     * @param nodeId node id
+     * @param itemId item id
+     * @return <code>true</code> if the node with the specified
+     *         <code>nodeId</code> is an ancestor of the item denoted by the
+     *         given <code>itemId</code; <code>false</code> otherwise
+     * @throws ItemNotFoundException if any of the specified id's does not
+     *                               denote an existing item.
+     * @throws RepositoryException   if another error occurs
+     */
+    boolean isAncestor(NodeId nodeId, ItemId itemId)
+            throws ItemNotFoundException, RepositoryException;
 
     /**
      * @param id

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java?rev=164473&r1=164472&r2=164473&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
Sun Apr 24 05:44:30 2005
@@ -101,7 +101,8 @@
     /**
      * {@inheritDoc}
      */
-    public NodeId[] listParents(ItemId id) throws ItemNotFoundException, RepositoryException
{
+    public NodeId[] listParents(ItemId id)
+            throws ItemNotFoundException, RepositoryException {
         ArrayList list = new ArrayList();
         try {
             if (id.denotesNode()) {
@@ -129,7 +130,8 @@
     /**
      * {@inheritDoc}
      */
-    public ItemId[] listChildren(NodeId id) throws ItemNotFoundException, RepositoryException
{
+    public ItemId[] listChildren(NodeId id)
+            throws ItemNotFoundException, RepositoryException {
         NodeState parentState;
         try {
             parentState = (NodeState) getItemState(id);
@@ -228,13 +230,15 @@
             }
             if (parentState.hasChildNodeEntry(name, index)) {
                 // child node
-                NodeState.ChildNodeEntry nodeEntry = parentState.getChildNodeEntry(name,
index);
+                NodeState.ChildNodeEntry nodeEntry =
+                        parentState.getChildNodeEntry(name, index);
                 if (i == elems.length - 1) {
                     // last element in the path
                     return new NodeId(nodeEntry.getUUID());
                 }
                 try {
-                    parentState = (NodeState) getItemState(new NodeId(nodeEntry.getUUID()));
+                    parentState =
+                            (NodeState) getItemState(new NodeId(nodeEntry.getUUID()));
                 } catch (ItemStateException e) {
                     String msg = "failed to retrieve state of intermediary node";
                     log.debug(msg);
@@ -265,7 +269,8 @@
     /**
      * {@inheritDoc}
      */
-    public synchronized Path getPath(ItemId id) throws ItemNotFoundException, RepositoryException
{
+    public synchronized Path getPath(ItemId id)
+            throws ItemNotFoundException, RepositoryException {
         try {
             Path.PathBuilder builder = new Path.PathBuilder();
 
@@ -284,13 +289,16 @@
                     String uuid = nodeState.getUUID();
                     List entries = parent.getChildNodeEntries(uuid);
                     if (entries.isEmpty()) {
-                        String msg = "failed to build path of " + id + ": " + parent.getUUID()
+ " has no child entry for " + uuid;
+                        String msg = "failed to build path of " + id + ": "
+                                + parent.getUUID() + " has no child entry for "
+                                + uuid;
                         log.debug(msg);
                         throw new RepositoryException(msg);
                     }
                     // if the parent has more than one child node entries pointing
                     // to the same child node, always use the first one
-                    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
+                    NodeState.ChildNodeEntry entry =
+                            (NodeState.ChildNodeEntry) entries.get(0);
                     // add to path
                     if (entry.getIndex() == 1) {
                         builder.addFirst(entry.getName());
@@ -334,7 +342,8 @@
     /**
      * {@inheritDoc}
      */
-    public QName getName(ItemId itemId) throws ItemNotFoundException, RepositoryException
{
+    public QName getName(ItemId itemId)
+            throws ItemNotFoundException, RepositoryException {
         if (itemId.denotesNode()) {
             NodeId nodeId = (NodeId) itemId;
             NodeState parentState;
@@ -364,7 +373,8 @@
                 log.debug(msg);
                 throw new RepositoryException(msg);
             }
-            NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
+            NodeState.ChildNodeEntry entry =
+                    (NodeState.ChildNodeEntry) entries.get(0);
             return entry.getName();
         } else {
             PropertyId propId = (PropertyId) itemId;
@@ -401,7 +411,37 @@
     /**
      * {@inheritDoc}
      */
-    public synchronized Path[] getAllPaths(ItemId id) throws ItemNotFoundException, RepositoryException
{
+    public boolean isAncestor(NodeId nodeId, ItemId itemId)
+            throws ItemNotFoundException, RepositoryException {
+        try {
+            ItemState state = getItemState(itemId, true);
+            String parentUUID = state.getParentUUID();
+            while (parentUUID != null) {
+                if (parentUUID.equals(nodeId.getUUID())) {
+                    return true;
+                }
+                state = getItemState(new NodeId(parentUUID), true);
+                parentUUID = state.getParentUUID();
+            }
+            return false;
+        } catch (NoSuchItemStateException nsise) {
+            String msg = "failed to determine degree of relationship of "
+                    + nodeId + " and " + itemId;
+            log.debug(msg);
+            throw new ItemNotFoundException(msg, nsise);
+        } catch (ItemStateException ise) {
+            String msg = "failed to determine degree of relationship of "
+                    + nodeId + " and " + itemId;
+            log.debug(msg);
+            throw new RepositoryException(msg, ise);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized Path[] getAllPaths(ItemId id)
+            throws ItemNotFoundException, RepositoryException {
         return getAllPaths(id, false);
     }
 
@@ -417,7 +457,8 @@
         NodeId nodeId;
         if (!id.denotesNode()) {
             try {
-                PropertyState propState = (PropertyState) getItemState(id, includeZombies);
+                PropertyState propState =
+                        (PropertyState) getItemState(id, includeZombies);
                 QName name = propState.getName();
                 // add to path
                 builder.addFirst(name);
@@ -537,12 +578,14 @@
             Iterator iter = parentUUIDs.iterator();
             while (iter.hasNext()) {
                 String parentUUID = (String) iter.next();
-                NodeState parent = (NodeState) getItemState(new NodeId(parentUUID), includeZombies);
+                NodeState parent =
+                        (NodeState) getItemState(new NodeId(parentUUID), includeZombies);
                 ArrayList entries = new ArrayList(parent.getChildNodeEntries(uuid));
                 if (includeZombies) {
                     Iterator riter = parent.getRemovedChildNodeEntries().iterator();
                     while (riter.hasNext()) {
-                        NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) riter.next();
+                        NodeState.ChildNodeEntry entry =
+                                (NodeState.ChildNodeEntry) riter.next();
                         if (entry.getUUID().equals(uuid)) {
                             entries.add(entry);
                         }
@@ -569,7 +612,8 @@
                     builders.add(clone);
                 }
                 for (int i = 0; i < entries.size(); i++) {
-                    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(i);
+                    NodeState.ChildNodeEntry entry =
+                            (NodeState.ChildNodeEntry) entries.get(i);
 
                     // get a path builder clone from the tail of the queue
                     Path.PathBuilder pb = (Path.PathBuilder) queue.removeLast();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java?rev=164473&r1=164472&r2=164473&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java
Sun Apr 24 05:44:30 2005
@@ -22,7 +22,7 @@
 
 /**
  * This abstract class implements the <code>ItemDef</code>
- * interface and additionaly provides setter's for the
+ * interface and additionally provides setter's for the
  * various item definition attributes.
  */
 public abstract class ItemDefImpl implements ItemDef {



Mime
View raw message