jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r795046 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/
Date Fri, 17 Jul 2009 11:24:54 GMT
Author: jukka
Date: Fri Jul 17 11:24:53 2009
New Revision: 795046

URL: http://svn.apache.org/viewvc?rev=795046&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform

Some more Java 5 cleanups.

Modified:
    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/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java

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=795046&r1=795045&r2=795046&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
Fri Jul 17 11:24:53 2009
@@ -18,8 +18,10 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 import javax.jcr.AccessDeniedException;
@@ -43,7 +45,6 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.VersionException;
 
-import org.apache.commons.collections.iterators.IteratorChain;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
@@ -342,35 +343,34 @@
         return removed;
     }
 
-    private void validateTransientItems(Iterator<ItemState> dirtyIter, Iterator<ItemState>
removedIter)
+    /**
+     * the following validations/checks are performed on transient items:
+     *
+     * for every transient item:
+     * - if it is 'modified' or 'new' check the corresponding write permission.
+     * - if it is 'removed' check the REMOVE permission
+     *
+     * for every transient node:
+     * - if it is 'new' check that its node type satisfies the
+     *   'required node type' constraint specified in its definition
+     * - check if 'mandatory' child items exist
+     *
+     * for every transient property:
+     * - check if the property value satisfies the value constraints
+     *   specified in the property's definition
+     *
+     * note that the protected flag is checked in Node.addNode/Node.remove
+     * (for adding/removing child entries of a node), in
+     * Node.addMixin/removeMixin/setPrimaryType (for type changes on nodes)
+     * and in Property.setValue (for properties to be modified).
+     */
+    private void validateTransientItems(Iterable<ItemState> dirty, Iterable<ItemState>
removed)
             throws AccessDeniedException, ConstraintViolationException,
             RepositoryException {
-        /**
-         * the following validations/checks are performed on transient items:
-         *
-         * for every transient item:
-         * - if it is 'modified' or 'new' check the corresponding write permission.
-         * - if it is 'removed' check the REMOVE permission
-         *
-         * for every transient node:
-         * - if it is 'new' check that its node type satisfies the
-         *   'required node type' constraint specified in its definition
-         * - check if 'mandatory' child items exist
-         *
-         * for every transient property:
-         * - check if the property value satisfies the value constraints
-         *   specified in the property's definition
-         *
-         * note that the protected flag is checked in Node.addNode/Node.remove
-         * (for adding/removing child entries of a node), in
-         * Node.addMixin/removeMixin/setPrimaryType (for type changes on nodes)
-         * and in Property.setValue (for properties to be modified).
-         */
         AccessManager accessMgr = session.getAccessManager();
         NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
         // walk through list of dirty transient items and validate each
-        while (dirtyIter.hasNext()) {
-            ItemState itemState = dirtyIter.next();
+        for (ItemState itemState : dirty) {
             ItemDefinition def;
             if (itemState.isNode()) {
                 def = ntMgr.getNodeDefinition(((NodeState) itemState).getDefinitionId());
@@ -578,8 +578,7 @@
         }
 
         // walk through list of removed transient items and check REMOVE permission
-        while (removedIter.hasNext()) {
-            ItemState itemState = removedIter.next();
+        for (ItemState itemState : removed) {
             ItemDefinition def;
             if (itemState.isNode()) {
                 def = ntMgr.getNodeDefinition(((NodeState) itemState).getDefinitionId());
@@ -600,14 +599,12 @@
         }
     }
 
-    private void removeTransientItems(Iterator<ItemState> iter) {
-
-        /**
-         * walk through list of transient items marked 'removed' and
-         * definitively remove each one
-         */
-        while (iter.hasNext()) {
-            ItemState transientState = iter.next();
+    /**
+     * walk through list of transient items marked 'removed' and
+     * definitively remove each one
+     */
+    private void removeTransientItems(Iterable<ItemState> states) {
+        for (ItemState transientState : states) {
             ItemState persistentState = transientState.getOverlayedState();
             /**
              * remove persistent state
@@ -619,22 +616,22 @@
         }
     }
 
-    private void persistTransientItems(Iterator<ItemState> iter)
+    /**
+     * walk through list of transient items and persist each one
+     */
+    private void persistTransientItems(Iterable<ItemState> states)
             throws RepositoryException {
-
-        // walk through list of transient items and persist each one
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
-            ItemImpl item = itemMgr.getItem(state.getId());
+        for (ItemState state : states) {
             // persist state of transient item
-            item.makePersistent();
+            itemMgr.getItem(state.getId()).makePersistent();
         }
     }
 
-    private void restoreTransientItems(Iterator<ItemState> iter) {
-        // walk through list of transient states and re-apply transient changes
-        while (iter.hasNext()) {
-            ItemState itemState = iter.next();
+    /**
+     * walk through list of transient states and re-apply transient changes
+     */
+    private void restoreTransientItems(Iterable<ItemState> items) {
+        for (ItemState itemState : items) {
             ItemId id = itemState.getId();
             ItemImpl item;
 
@@ -687,9 +684,8 @@
      * has been removed, throw.</li>
      * </ul>
      */
-    private void processShareableNodes(Iterator<ItemState> iter) throws RepositoryException
{
-        while (iter.hasNext()) {
-            ItemState is = iter.next();
+    private void processShareableNodes(Iterable<ItemState> states) throws RepositoryException
{
+        for (ItemState is : states) {
             if (is.isNode()) {
                 NodeState ns = (NodeState) is;
                 boolean wasShareable = false;
@@ -721,15 +717,14 @@
      * <p/>
      * Called by {@link #save()}.
      *
-     * @param iter
+     * @param states
      * @return true if this call generated new transient state; otherwise false
      * @throws RepositoryException
      */
-    private boolean initVersionHistories(Iterator<ItemState> iter) throws RepositoryException
{
+    private boolean initVersionHistories(Iterable<ItemState> states) throws RepositoryException
{
         // walk through list of transient items and search for new versionable nodes
         boolean createdTransientState = false;
-        while (iter.hasNext()) {
-            ItemState itemState = iter.next();
+        for (ItemState itemState : states) {
             if (itemState.isNode()) {
                 NodeState nodeState = (NodeState) itemState;
                 EffectiveNodeType nt = getEffectiveNodeType(nodeState);
@@ -958,15 +953,15 @@
              */
             Collection<ItemState> removed = getRemovedStates();
 
-            /**
-             * build set of item id's which are within the scope of
-             * (i.e. affected by) this save operation
-             */
-            Set<ItemId> affectedIds = new HashSet<ItemId>(dirty.size() + removed.size());
-            for (Iterator<ItemState> it =
-                    new IteratorChain(dirty.iterator(), removed.iterator());
-                 it.hasNext();) {
-                affectedIds.add(it.next().getId());
+            // All affected item states. They keys are used to look up whether
+            // an item is affected, and the values are iterated through below
+            Map<ItemId, ItemState> affected =
+                new HashMap<ItemId, ItemState>(dirty.size() + removed.size());
+            for (ItemState state : dirty) {
+                affected.put(state.getId(), state);
+            }
+            for (ItemState state : removed) {
+                affected.put(state.getId(), state);
             }
 
             /**
@@ -976,10 +971,7 @@
              * (e.g. moving a node requires that the target node including both
              * old and new parents are saved)
              */
-            for (Iterator<ItemState> it =
-                    new IteratorChain(dirty.iterator(), removed.iterator());
-                 it.hasNext();) {
-                ItemState transientState = it.next();
+            for (ItemState transientState : affected.values()) {
                 if (transientState.isNode()) {
                     NodeState nodeState = (NodeState) transientState;
                     Set<NodeId> dependentIDs = new HashSet<NodeId>();
@@ -1006,16 +998,12 @@
                                 } else {
                                     // parent id hasn't changed, check whether
                                     // the node has been renamed (JCR-1034)
-                                    if (!affectedIds.contains(newParentId)
+                                    if (!affected.containsKey(newParentId)
                                             && stateMgr.hasTransientItemState(newParentId))
{
                                         try {
                                             NodeState parent = (NodeState) stateMgr.getTransientItemState(newParentId);
                                             // check parent's renamed child node entries
-                                            for (Iterator<ChildNodeEntry> cneIt =
-                                                    parent.getRenamedChildNodeEntries().iterator();
-                                                 cneIt.hasNext();) {
-                                                ChildNodeEntry cne =
-                                                        cneIt.next();
+                                            for (ChildNodeEntry cne : parent.getRenamedChildNodeEntries())
{
                                                 if (cne.getId().equals(nodeState.getId()))
{
                                                     // node has been renamed,
                                                     // add parent to dependencies
@@ -1033,26 +1021,18 @@
                     }
 
                     // removed child node entries
-                    for (Iterator<ChildNodeEntry> cneIt =
-                            nodeState.getRemovedChildNodeEntries().iterator();
-                         cneIt.hasNext();) {
-                        ChildNodeEntry cne = cneIt.next();
+                    for (ChildNodeEntry cne : nodeState.getRemovedChildNodeEntries()) {
                         dependentIDs.add(cne.getId());
                     }
                     // added child node entries
-                    for (Iterator<ChildNodeEntry> cneIt =
-                            nodeState.getAddedChildNodeEntries().iterator();
-                         cneIt.hasNext();) {
-                        ChildNodeEntry cne = cneIt.next();
+                    for (ChildNodeEntry cne : nodeState.getAddedChildNodeEntries()) {
                         dependentIDs.add(cne.getId());
                     }
 
                     // now walk through dependencies and check whether they
                     // are within the scope of this save operation
-                    Iterator<NodeId> depIt = dependentIDs.iterator();
-                    while (depIt.hasNext()) {
-                        NodeId id = depIt.next();
-                        if (!affectedIds.contains(id)) {
+                    for (NodeId id : dependentIDs) {
+                        if (!affected.containsKey(id)) {
                             // JCR-1359 workaround: check whether unresolved
                             // dependencies originate from 'this' session;
                             // otherwise ignore them
@@ -1069,11 +1049,9 @@
                 }
             }
 
-            /**
-             * validate access and node type constraints
-             * (this will also validate child removals)
-             */
-            validateTransientItems(dirty.iterator(), removed.iterator());
+            // validate access and node type constraints
+            // (this will also validate child removals)
+            validateTransientItems(dirty, removed);
 
             // start the update operation
             try {
@@ -1089,20 +1067,20 @@
             try {
 
                 // process transient items marked as 'removed'
-                removeTransientItems(removed.iterator());
+                removeTransientItems(removed);
 
                 // process transient items that have change in mixins
-                processShareableNodes(dirty.iterator());
+                processShareableNodes(dirty);
 
                 // initialize version histories for new nodes (might generate new transient
state)
-                if (initVersionHistories(dirty.iterator())) {
+                if (initVersionHistories(dirty)) {
                     // re-build the list of transient states because the previous call
                     // generated new transient state
                     dirty = getTransientStates();
                 }
 
                 // process 'new' or 'modified' transient states
-                persistTransientItems(dirty.iterator());
+                persistTransientItems(dirty);
 
                 // dispose the transient states marked 'new' or 'modified'
                 // at this point item state data is pushed down one level,
@@ -1111,8 +1089,7 @@
                 // transient item states must be removed now. otherwise
                 // the session item state provider will return an orphaned
                 // item state which is not referenced by any node instance.
-                for (Iterator<ItemState> it = dirty.iterator(); it.hasNext();) {
-                    ItemState transientState = it.next();
+                for (ItemState transientState : dirty) {
                     // dispose the transient state, it is no longer used
                     stateMgr.disposeTransientItemState(transientState);
                 }
@@ -1136,7 +1113,7 @@
                     // applied by persistTransientItems() and we need to
                     // restore transient state, i.e. undo the effect of
                     // persistTransientItems()
-                    restoreTransientItems(dirty.iterator());
+                    restoreTransientItems(dirty);
                 }
             }
 
@@ -1145,8 +1122,7 @@
             // item states in attic are removed after store, because
             // the observation mechanism needs to build paths of removed
             // items in store().
-            for (Iterator<ItemState> it = removed.iterator(); it.hasNext();) {
-                ItemState transientState = it.next();
+            for (ItemState transientState : removed) {
                 // dispose the transient state, it is no longer used
                 stateMgr.disposeTransientItemStateInAttic(transientState);
             }
@@ -1236,19 +1212,17 @@
         }
 
         // process list of 'new', 'modified' or 'stale' transient states
-        Iterator<ItemState> iter = list.iterator();
-        while (iter.hasNext()) {
-            transientState = iter.next();
+        for (ItemState state : list) {
             // dispose the transient state, it is no longer used;
             // this will indirectly (through stateDiscarded listener method)
             // either restore or permanently invalidate the wrapping Item instances
-            stateMgr.disposeTransientItemState(transientState);
+            stateMgr.disposeTransientItemState(state);
         }
 
         if (isNode()) {
             // discard all transient descendants in the attic (i.e. those marked
             // as 'removed'); this will resurrect the removed items
-            iter = stateMgr.getDescendantTransientItemStatesInAttic((NodeId) id);
+            Iterator<ItemState> iter = stateMgr.getDescendantTransientItemStatesInAttic((NodeId)
id);
             while (iter.hasNext()) {
                 transientState = iter.next();
                 // dispose the transient state; this will indirectly (through

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=795046&r1=795045&r2=795046&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
Fri Jul 17 11:24:53 2009
@@ -577,10 +577,9 @@
             log.debug(msg);
             throw new RepositoryException(msg);
         }
-        Iterator iter = ((NodeState) data.getState()).getChildNodeEntries().iterator();
 
-        while (iter.hasNext()) {
-            ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+        NodeState state = (NodeState) data.getState();
+        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
             // make sure any of the properties can be read.
             if (canRead(entry.getId())) {
                 return true;

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=795046&r1=795045&r2=795046&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
Fri Jul 17 11:24:53 2009
@@ -2970,10 +2970,7 @@
         // check state of this instance
         sanityCheck();
 
-        ArrayList nodes = new ArrayList();
-        // traverse children using a special filtering 'collector'
-        accept(new ChildrenCollectorFilter(namePattern, nodes, true, false, 1));
-        return new NodeIteratorAdapter(nodes);
+        return ChildrenCollectorFilter.collectChildNodes(this, namePattern);
     }
 
     /**
@@ -2984,10 +2981,7 @@
         // check state of this instance
         sanityCheck();
 
-        ArrayList properties = new ArrayList();
-        // traverse children using a special filtering 'collector'
-        accept(new ChildrenCollectorFilter(namePattern, properties, false, true, 1));
-        return new PropertyIteratorAdapter(properties);
+        return ChildrenCollectorFilter.collectProperties(this, namePattern);
     }
 
     /**
@@ -3462,10 +3456,8 @@
             throws NoSuchWorkspaceException, AccessDeniedException,
             VersionException, LockException, InvalidItemStateException,
             RepositoryException {
-
-        List failedIds = new ArrayList();
+        List<ItemId> failedIds = new ArrayList<ItemId>();
         internalMerge(srcWorkspace, failedIds, bestEffort, isShallow);
-
         return new LazyItemIterator(itemMgr, failedIds);
     }
 
@@ -4772,10 +4764,7 @@
         // check state of this instance
         sanityCheck();
 
-        ArrayList nodes = new ArrayList();
-        // traverse children using a special filtering 'collector'
-        accept(new ChildrenCollectorFilter(nameGlobs, nodes, true, false, 1));
-        return new NodeIteratorAdapter(nodes);
+        return ChildrenCollectorFilter.collectChildNodes(this, nameGlobs);
     }
 
     /**
@@ -4786,10 +4775,7 @@
         // check state of this instance
         sanityCheck();
 
-        ArrayList props = new ArrayList();
-        // traverse children using a special filtering 'collector'
-        accept(new ChildrenCollectorFilter(nameGlobs, props, false, true, 1));
-        return new PropertyIteratorAdapter(props);
+        return ChildrenCollectorFilter.collectProperties(this, nameGlobs);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=795046&r1=795045&r2=795046&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Fri Jul 17 11:24:53 2009
@@ -25,11 +25,12 @@
 import java.io.StringReader;
 import java.security.AccessControlContext;
 import java.security.AccessController;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
@@ -205,7 +206,7 @@
     /**
      * active sessions (weak references)
      */
-    private final ReferenceMap activeSessions =
+    private final Map<SessionImpl, SessionImpl> activeSessions =
             new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK);
 
     // misc. statistics
@@ -1109,17 +1110,16 @@
         // (copy sessions to array to avoid ConcurrentModificationException;
         // manually copy entries rather than calling ReferenceMap#toArray() in
         // order to work around  http://issues.apache.org/bugzilla/show_bug.cgi?id=25551)
-        SessionImpl[] sa;
+        List<SessionImpl> sa;
         synchronized (activeSessions) {
-            int cnt = 0;
-            sa = new SessionImpl[activeSessions.size()];
-            for (Iterator<SessionImpl> it = activeSessions.values().iterator(); it.hasNext();
cnt++) {
-                sa[cnt] = it.next();
+            sa = new ArrayList<SessionImpl>(activeSessions.size());
+            for (SessionImpl session : activeSessions.values()) {
+                sa.add(session);
             }
         }
-        for (int i = 0; i < sa.length; i++) {
-            if (sa[i] != null) {
-                sa[i].logout();
+        for (SessionImpl session : sa) {
+            if (session != null) {
+                session.logout();
             }
         }
 
@@ -2264,8 +2264,7 @@
 
                 synchronized (activeSessions) {
                     // remove workspaces with active sessions
-                    for (Iterator it = activeSessions.values().iterator(); it.hasNext();)
{
-                        SessionImpl ses = (SessionImpl) it.next();
+                    for (SessionImpl ses : activeSessions.values()) {
                         wspNames.remove(ses.getWorkspace().getName());
                     }
                 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=795046&r1=795045&r2=795046&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
Fri Jul 17 11:24:53 2009
@@ -54,7 +54,8 @@
     /**
      * Global transactions
      */
-    private static final Map txGlobal = Collections.synchronizedMap(new HashMap());
+    private static final Map<Xid, TransactionContext> txGlobal =
+        Collections.synchronizedMap(new HashMap<Xid, TransactionContext>());
 
     /**
      * System property specifying the default Transaction Timeout
@@ -386,9 +387,7 @@
      */
     public synchronized void associate(TransactionContext tx) {
         this.tx = tx;
-
-        for (int i = 0; i < txResources.length; i++) {
-            InternalXAResource txResource = txResources[i];
+        for (InternalXAResource txResource : txResources) {
             txResource.associate(tx);
         }
     }

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=795046&r1=795045&r2=795046&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
Fri Jul 17 11:24:53 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.core;
 
-import java.util.Iterator;
-
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
@@ -102,10 +100,7 @@
                                                          Name name,
                                                          int index) {
         // check removed child node entries first
-        Iterator iter = parent.getRemovedChildNodeEntries().iterator();
-        while (iter.hasNext()) {
-            ChildNodeEntry entry =
-                    (ChildNodeEntry) iter.next();
+        for (ChildNodeEntry entry : parent.getRemovedChildNodeEntries()) {
             if (entry.getName().equals(name)
                     && entry.getIndex() == index) {
                 return entry;
@@ -124,10 +119,7 @@
     protected ChildNodeEntry getChildNodeEntry(NodeState parent,
                                                          NodeId id) {
         // check removed child node entries first
-        Iterator iter = parent.getRemovedChildNodeEntries().iterator();
-        while (iter.hasNext()) {
-            ChildNodeEntry entry =
-                    (ChildNodeEntry) iter.next();
+        for (ChildNodeEntry entry : parent.getRemovedChildNodeEntries()) {
             if (entry.getId().equals(id)) {
                 return entry;
             }

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java?rev=795046&r1=795045&r2=795046&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
Fri Jul 17 11:24:53 2009
@@ -16,10 +16,18 @@
  */
 package org.apache.jackrabbit.util;
 
+import javax.jcr.Item;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.util.TraversingItemVisitor;
+
+import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
+
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.StringTokenizer;
 
@@ -33,7 +41,7 @@
     static final char WILDCARD_CHAR = '*';
     static final String OR = "|";
 
-    private final Collection children;
+    private final Collection<Item> children;
     private final boolean collectNodes;
     private final boolean collectProperties;
     // namePattern and nameGlobs fields are used mutually exclusive
@@ -52,7 +60,7 @@
      *                          (e.g. 1 for direct children only, 2 for children and their
children, and so on)
      */
     public ChildrenCollectorFilter(
-            String namePattern, Collection children,
+            String namePattern, Collection<Item> children,
             boolean collectNodes, boolean collectProperties, int maxLevel) {
         super(false, maxLevel);
         this.namePattern = namePattern;
@@ -74,7 +82,7 @@
      *                          (e.g. 1 for direct children only, 2 for children and their
children, and so on)
      */
     public ChildrenCollectorFilter(
-            String[] nameGlobs, Collection children,
+            String[] nameGlobs, Collection<Item> children,
             boolean collectNodes, boolean collectProperties, int maxLevel) {
         super(false, maxLevel);
         this.nameGlobs = nameGlobs;
@@ -84,6 +92,38 @@
         this.collectProperties = collectProperties;
     }
 
+    public static NodeIterator collectChildNodes(
+            Node node, String namePattern) throws RepositoryException {
+        Collection<Item> nodes = new ArrayList<Item>();
+        node.accept(new ChildrenCollectorFilter(
+                namePattern, nodes, true, false, 1));
+        return new NodeIteratorAdapter(nodes);
+    }
+
+    public static NodeIterator collectChildNodes(
+            Node node, String[] nameGlobs) throws RepositoryException {
+        Collection<Item> nodes = new ArrayList<Item>();
+        node.accept(new ChildrenCollectorFilter(
+                nameGlobs, nodes, true, false, 1));
+        return new NodeIteratorAdapter(nodes);
+    }
+
+    public static PropertyIterator collectProperties(
+            Node node, String namePattern) throws RepositoryException {
+        Collection<Item> properties = new ArrayList<Item>();
+        node.accept(new ChildrenCollectorFilter(
+                namePattern, properties, false, true, 1));
+        return new PropertyIteratorAdapter(properties);
+    }
+
+    public static PropertyIterator collectProperties(
+            Node node, String[] nameGlobs) throws RepositoryException {
+        Collection<Item> properties = new ArrayList<Item>();
+        node.accept(new ChildrenCollectorFilter(
+                nameGlobs, properties, false, true, 1));
+        return new PropertyIteratorAdapter(properties);
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=795046&r1=795045&r2=795046&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Fri Jul 17 11:24:53 2009
@@ -52,8 +52,6 @@
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 
-import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
-import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.lock.LockStateManager;
@@ -447,10 +445,8 @@
      */
     public NodeIterator getNodes(String namePattern) throws RepositoryException {
         checkStatus();
-        ArrayList nodes = new ArrayList();
-        // traverse children using a special filtering item visitor
-        accept(new ChildrenCollectorFilter(namePattern, nodes, true, false, 1));
-        return new NodeIteratorAdapter(nodes);
+
+        return ChildrenCollectorFilter.collectChildNodes(this, namePattern);
     }
 
     /**
@@ -458,10 +454,8 @@
      */
     public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
         checkStatus();
-        List nodes = new ArrayList();
-        // traverse child nodes using a filtering item visitor
-        accept(new ChildrenCollectorFilter(nameGlobs, nodes, true, false, 1));
-        return new NodeIteratorAdapter(nodes);
+
+        return ChildrenCollectorFilter.collectChildNodes(this, nameGlobs);
     }
 
     /**
@@ -505,10 +499,8 @@
      */
     public PropertyIterator getProperties(String namePattern) throws RepositoryException
{
         checkStatus();
-        ArrayList properties = new ArrayList();
-        // traverse children using a filtering item visitor
-        accept(new ChildrenCollectorFilter(namePattern, properties, false, true, 1));
-        return new PropertyIteratorAdapter(properties);
+
+        return ChildrenCollectorFilter.collectProperties(this, namePattern);
     }
 
     /**
@@ -517,10 +509,8 @@
     public PropertyIterator getProperties(String[] nameGlobs)
             throws RepositoryException {
         checkStatus();
-        List properties = new ArrayList();
-        // traverse child properties using a filtering item visitor
-        accept(new ChildrenCollectorFilter(nameGlobs, properties, false, true, 1));
-        return new PropertyIteratorAdapter(properties);
+
+        return ChildrenCollectorFilter.collectProperties(this, nameGlobs);
     }
 
     /**



Mime
View raw message