You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2005/09/08 22:25:44 UTC
svn commit: r279619 - in
/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator:
DecoratingNodeIterator.java DecoratingRangeIterator.java
Author: jukka
Date: Thu Sep 8 13:25:21 2005
New Revision: 279619
URL: http://svn.apache.org/viewcvs?rev=279619&view=rev
Log:
JCR-EXT: Added decorating iterator utility classes.
Added:
incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java (with props)
incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java (with props)
Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java?rev=279619&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java Thu Sep 8 13:25:21 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.decorator;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+
+/**
+ * Node iterator that decorates all iterated nodes. This utility class is
+ * used by the decorator layer to manage the decoration of all the nodes
+ * returned by an underlying node iterator. This class delegates
+ * all method calls to the underlying node iterator and uses the given
+ * decorator factory to decorate all the returned node instances.
+ */
+public class DecoratingNodeIterator extends DecoratingRangeIterator
+ implements NodeIterator {
+
+ /** The decorator factory. Used to decorate all returned node instances. */
+ private final DecoratorFactory factory;
+
+ /** The decorated session to which the returned nodes belong. */
+ private final Session session;
+
+ /** The underlying node iterator. */
+ private final NodeIterator iterator;
+
+ /**
+ * Creates a decorating node iterator.
+ *
+ * @param factory decorator factory
+ * @param session decorated session
+ * @param iterator underlying node iterator
+ */
+ public DecoratingNodeIterator(
+ DecoratorFactory factory, Session session, NodeIterator iterator) {
+ super(factory, session, iterator);
+ this.factory = factory;
+ this.session = session;
+ this.iterator = iterator;
+ }
+
+ /**
+ * Decorates and returns the next node from the underlying node iterator.
+ *
+ * @return next node (decorated)
+ * @see NodeIterator#nextNode()
+ */
+ public Node nextNode() {
+ Node node = iterator.nextNode();
+ return factory.getNodeDecorator(session, node);
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingNodeIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java?rev=279619&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java Thu Sep 8 13:25:21 2005
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.decorator;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RangeIterator;
+import javax.jcr.Session;
+
+/**
+ * Range iterator that decorates all iterated objects. This class is used
+ * as the base class of the various decorating iterator utility classes used
+ * by the decorator layer.
+ * <p>
+ * All the method calls are delegated to the underlying iterator,
+ * and best effort is made to decorate the objects returned by the
+ * {@link #next() next()} method.
+ */
+public class DecoratingRangeIterator implements RangeIterator {
+
+ /** The decorator factory. Used to decorate returned objects. */
+ private final DecoratorFactory factory;
+
+ /** The decorated session to which the returned objects belong. */
+ private final Session session;
+
+ /** The underlying iterator. */
+ private final RangeIterator iterator;
+
+ /**
+ * Creates a decorating iterator.
+ *
+ * @param factory decorator factory
+ * @param session decorated session
+ * @param iterator underlying iterator
+ */
+ public DecoratingRangeIterator(
+ DecoratorFactory factory, Session session, RangeIterator iterator) {
+ this.factory = factory;
+ this.session = session;
+ this.iterator = iterator;
+ }
+
+ /**
+ * Advances the underlying iterator.
+ *
+ * @param skipNum number of elements to skip
+ * @see RangeIterator#skip(long)
+ */
+ public void skip(long skipNum) {
+ iterator.skip(skipNum);
+ }
+
+ /**
+ * Returns the size of the underlying iterator.
+ *
+ * @return size of the iterator
+ * @see RangeIterator#getSize()
+ */
+ public long getSize() {
+ return iterator.getSize();
+ }
+
+ /**
+ * Returns the position of the underlying iterator.
+ *
+ * @return position of the iterator
+ * @see RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return iterator.getPosition();
+ }
+
+ /**
+ * Checks whether the underlying iterator has more elements.
+ *
+ * @return <code>true</code> if more elements exist,
+ * <code>false</code> otherwise
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * Decorates and returns the next objects from the underlying iterator.
+ *
+ * @return decorated object
+ * @throws UnsupportedOperationException if the returned object can not
+ * be decorated
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ Object object = iterator.next();
+ if (object instanceof Node) {
+ return factory.getNodeDecorator(session, (Node) object);
+ } else if (object instanceof Property) {
+ return factory.getPropertyDecorator(session, (Property) object);
+ } else if (object instanceof Item) {
+ return factory.getItemDecorator(session, (Item) object);
+ } else {
+ throw new UnsupportedOperationException(
+ "No decorator available for " + object);
+ }
+ }
+
+ /**
+ * Removes the current object from the underlying iterator.
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ iterator.remove();
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/decorator/DecoratingRangeIterator.java
------------------------------------------------------------------------------
svn:eol-style = native