Author: rhauch
Date: 2009-03-03 19:36:43 -0500 (Tue, 03 Mar 2009)
New Revision: 750
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
Log:
DNA-290 Getting child nodes or properties by pattern is not implemented
Implemented the AbstractJcrNode.getNodes(String pattern) and
AbstractJcrNode.getProperties(String pattern), which makes a few more of the JCR TCK tests
pass. In the process, the way AbstractJcrNode stores children was (dramatically)
simplified, and a few different kinds of NodeIterator and PropertyIterator implementations
were added (including empty ones).
Also changed how DNA Path.Segment objects are created when no SNS index is specified, so
the objects are now created with an index of 1 rather than -1. This was done because it
was leaking -1 in some cases, and it also more closely aligns with JCR. Found and
corrected minor related bugs in a few test cases.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -474,7 +474,7 @@
if (childrenWithSameNames.size() == 0) return;
if (childrenWithSameNames.size() == 1) {
InMemoryNode childWithSameName = childrenWithSameNames.get(0);
- Path.Segment newName =
context.getValueFactories().getPathFactory().createSegment(name, Path.NO_INDEX);
+ Path.Segment newName =
context.getValueFactories().getPathFactory().createSegment(name, Path.DEFAULT_INDEX);
childWithSameName.setName(newName);
return;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-03
22:02:41 UTC (rev 749)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -139,9 +139,9 @@
public static final String SELF = ".";
/**
- * The index that will be returned for a {@link Segment} that {@link
Segment#hasIndex() has no index}.
+ * The default index for a {@link Segment}.
*/
- public static final int NO_INDEX = -1;
+ public static final int DEFAULT_INDEX = 1;
/**
* Representation of the segments that occur within a path.
@@ -159,7 +159,7 @@
public Name getName();
/**
- * Get the index for this segment, which will be {@link Path#NO_INDEX -1} if this
segment has no specific index.
+ * Get the index for this segment, which will be 1 by default.
*
* @return the index
*/
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -48,7 +48,9 @@
* @throws IllegalArgumentException if the name is null or if the index is invalid
*/
public BasicPathSegment( Name name ) {
- this(name, Path.NO_INDEX);
+ assert name != null;
+ this.name = name;
+ this.index = Path.DEFAULT_INDEX;
}
/**
@@ -59,9 +61,9 @@
public BasicPathSegment( Name name,
int index ) {
assert name != null;
- assert index >= Path.NO_INDEX;
+ assert index >= Path.DEFAULT_INDEX;
this.name = name;
- this.index = (this.isSelfReference() || this.isParentReference()) ? Path.NO_INDEX
: index;
+ this.index = (this.isSelfReference() || this.isParentReference()) ?
Path.DEFAULT_INDEX : index;
}
/**
@@ -82,7 +84,7 @@
* {@inheritDoc}
*/
public boolean hasIndex() {
- return this.index != Path.NO_INDEX;
+ return this.index != Path.DEFAULT_INDEX;
}
/**
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -84,7 +84,7 @@
@Test
public void shouldNotHaveIndexByDefault() {
segment = new BasicPathSegment(validName);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(false));
@@ -94,7 +94,7 @@
@Test
public void
shouldCreateSelfReferenceSegmentIfPassedSelfReferenceStringRegardlessOfIndex() {
segment = factory.createSegment(Path.SELF);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(true));
assertThat(segment.isParentReference(), is(false));
@@ -102,7 +102,7 @@
assertThat(segment.getName().getNamespaceUri().length(), is(0));
segment = factory.createSegment(Path.SELF, 1);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(true));
assertThat(segment.isParentReference(), is(false));
@@ -113,7 +113,7 @@
@Test
public void
shouldCreateParentReferenceSegmentIfPassedParentReferenceStringRegardlessOfIndex() {
segment = factory.createSegment(Path.PARENT);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(true));
@@ -121,7 +121,7 @@
assertThat(segment.getName().getNamespaceUri().length(), is(0));
segment = factory.createSegment(Path.PARENT, 1);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(true));
@@ -143,14 +143,14 @@
@Test
public void
shouldConsiderSegmentWithSameNameSiblingIndexOfOneToBeEqualToSegmentWithSameNameButNoIndex()
{
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
Path.Segment segment2 = new BasicPathSegment(validName, 1);
assertThat(segment, is(segment2));
}
@Test
public void
shouldConsiderSegmentWithSameNameSiblingIndexOfTwoOrMoreToNotBeEqualToSegmentWithSameNameButNoIndex()
{
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
Path.Segment segment2 = new BasicPathSegment(validName, 2);
assertThat(segment, is(not(segment2)));
segment2 = new BasicPathSegment(validName, 3);
@@ -161,7 +161,7 @@
public void shouldUseDelimiterEncoderToEncodeDelimiterBetweenPrefixAndLocalPart() {
TextEncoder encoder = new Jsr283Encoder();
validName = new BasicName(DnaLexicon.Namespace.URI,
"some:name:with:colons");
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
TextEncoder delimiterEncoder = new TextEncoder() {
public String encode( String text ) {
if (":".equals(text)) return "\\:";
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-03 22:02:41
UTC (rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-04 00:36:43
UTC (rev 750)
@@ -27,9 +27,11 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
+import java.util.regex.Pattern;
import javax.jcr.Item;
import javax.jcr.ItemNotFoundException;
import javax.jcr.ItemVisitor;
@@ -51,6 +53,9 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.Path.Segment;
/**
@@ -61,8 +66,7 @@
private final JcrSession session;
Set<Property> properties;
- List<Name> children;
- List<Integer> childNameCounts;
+ List<Path.Segment> children;
private UUID uuid;
AbstractJcrNode( JcrSession session ) {
@@ -213,7 +217,8 @@
* @see javax.jcr.Node#getMixinNodeTypes()
*/
public NodeType[] getMixinNodeTypes() throws RepositoryException {
- PropertyIterator mixinProperties =
getProperties(JcrLexicon.MIXIN_TYPES.getString(session.getExecutionContext().getNamespaceRegistry()));
+ PropertyIterator mixinProperties =
getProperties(JcrLexicon.MIXIN_TYPES.getString(session.getExecutionContext()
+
.getNamespaceRegistry()));
List<NodeType> mixinNodeTypes = new
ArrayList<NodeType>((int)mixinProperties.getSize());
while (mixinProperties.hasNext()) {
@@ -236,7 +241,8 @@
*/
public final Node getNode( String relativePath ) throws RepositoryException {
CheckArg.isNotEmpty(relativePath, "relativePath");
- Item item = getSession().getItem(getPath(getPath(), relativePath));
+ String path = getPath(getPath(), relativePath);
+ Item item = getSession().getItem(path);
if (item instanceof Node) {
return (Node)item;
}
@@ -249,7 +255,10 @@
* @see javax.jcr.Node#getNodes()
*/
public final NodeIterator getNodes() {
- return new JcrNodeIterator(this, children, childNameCounts);
+ if (children == null) {
+ return new JcrEmptyNodeIterator();
+ }
+ return new JcrChildNodeIterator(this,
this.session.getExecutionContext().getNamespaceRegistry(), children);
}
/**
@@ -258,32 +267,35 @@
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#getNodes(java.lang.String)
*/
- public NodeIterator getNodes( String namePattern ) {
- // TODO: Implement after changing impl to delegate to Graph API
- throw new UnsupportedOperationException();
- /*
- CheckArg.isNotEmpty(namePattern, "namePattern");
- String[] disjuncts = namePattern.split("\\|");
- List<Segment> nodes = new ArrayList<Segment>();
- for (String disjunct : disjuncts) {
- String pattern = disjunct.trim();
- CheckArg.isNotEmpty(pattern, "namePattern");
- String ndxPattern;
- int endNdx = pattern.length() - 1;
- if (pattern.charAt(endNdx) == ']') {
- int ndx = pattern.indexOf('[');
- ndxPattern = pattern.substring(ndx + 1, endNdx);
- pattern = pattern.substring(0, ndx);
- } else ndxPattern = null;
- for (Entry<Name, Integer> child : getChildCountsByName().entrySet()) {
- if (child.getKey().getLocalName().matches(pattern)) {
- if (ndxPattern != null &&
!child.getValue().toString().matches(ndxPattern)) continue;
- if (child.getValue() > 1) nodes.add(new
BasicPathSegment(child.getKey(), child.getValue()));
- else nodes.add(new BasicPathSegment(child.getKey()));
+ public NodeIterator getNodes( String namePattern ) throws RepositoryException {
+ CheckArg.isNotNull(namePattern, "namePattern");
+ namePattern = namePattern.trim();
+ if (namePattern.length() == 0) return new JcrEmptyNodeIterator();
+ if ("*".equals(namePattern)) return getNodes();
+ List<Object> patterns = createPatternsFor(namePattern);
+
+ // Implementing exact-matching only for now to prototype types as properties
+ List<Path.Segment> matchingChildren = new
LinkedList<Path.Segment>();
+ NamespaceRegistry registry = session.executionContext.getNamespaceRegistry();
+ boolean foundMatch = false;
+ for (Path.Segment child : children) {
+ String childName = child.getName().getString(registry);
+ for (Object patternOrMatch : patterns) {
+ if (patternOrMatch instanceof Pattern) {
+ Pattern pattern = (Pattern)patternOrMatch;
+ if (pattern.matcher(childName).matches()) foundMatch = true;
+ } else {
+ String match = (String)patternOrMatch;
+ if (childName.equals(match)) foundMatch = true;
}
+ if (foundMatch) {
+ foundMatch = false;
+ matchingChildren.add(child);
+ break;
+ }
}
}
- */
+ return new JcrChildNodeIterator(this,
this.session.executionContext.getNamespaceRegistry(), matchingChildren);
}
/**
@@ -334,18 +346,89 @@
* @see javax.jcr.Node#getProperties(java.lang.String)
*/
public PropertyIterator getProperties( String namePattern ) throws
RepositoryException {
- // TODO: Implement after changing impl to delegate to Graph API
+ CheckArg.isNotNull(namePattern, "namePattern");
+ namePattern = namePattern.trim();
+ if (namePattern.length() == 0) return new JcrEmptyPropertyIterator();
+ if ("*".equals(namePattern)) return new
JcrPropertyIterator(properties);
+ List<Object> patterns = createPatternsFor(namePattern);
// Implementing exact-matching only for now to prototype types as properties
Set<Property> matchingProps = new HashSet<Property>();
- for (Property prop : properties) {
- String propName = prop.getName();
- if (propName.equals(namePattern)) matchingProps.add(prop);
+ for (Object patternOrMatch : patterns) {
+ if (patternOrMatch instanceof Pattern) {
+ Pattern pattern = (Pattern)patternOrMatch;
+ for (Property prop : properties) {
+ String propName = prop.getName();
+ if (pattern.matcher(propName).matches()) matchingProps.add(prop);
+ }
+ } else {
+ String match = (String)patternOrMatch;
+ for (Property prop : properties) {
+ String propName = prop.getName();
+ if (propName.equals(match)) matchingProps.add(prop);
+ }
+ }
}
-
return new JcrPropertyIterator(matchingProps);
}
+ protected static List<Object> createPatternsFor( String namePattern ) throws
RepositoryException {
+ List<Object> patterns = new LinkedList<Object>();
+ for (String stringPattern : namePattern.split("[|]")) {
+ stringPattern = stringPattern.trim();
+ int length = stringPattern.length();
+ if (length == 0) continue;
+ if (stringPattern.indexOf("*") == -1) {
+ // Doesn't use wildcard, so use String not Pattern
+ patterns.add(stringPattern);
+ } else {
+ // We need to escape the regular expression characters ...
+ StringBuilder sb = new StringBuilder(length);
+ for (int i = 0; i != length; i++) {
+ char c = stringPattern.charAt(i);
+ switch (c) {
+ // Per the spec, the the following characters are not allowed in
patterns:
+ case '/':
+ case '[':
+ case ']':
+ case '\'':
+ case '"':
+ case '|':
+ case '\t':
+ case '\n':
+ case '\r':
+ String msg = JcrI18n.invalidNamePattern.text(c,
namePattern);
+ throw new RepositoryException(msg);
+ // The following characters must be escaped when used in
regular expressions ...
+ case '?':
+ case '(':
+ case ')':
+ case '$':
+ case '^':
+ case '.':
+ case '{':
+ case '}':
+ case '\\':
+ sb.append("\\");
+ sb.append(c);
+ break;
+ case '*':
+ // replace with the regular expression wildcard
+ sb.append(".*");
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ String escapedString = sb.toString();
+ Pattern pattern = Pattern.compile(escapedString);
+ patterns.add(pattern);
+ }
+ }
+ return patterns;
+ }
+
/**
* {@inheritDoc}
*
@@ -433,19 +516,17 @@
if (relativePath.indexOf('/') >= 0) {
return (getNode(relativePath) != null);
}
- int ndxNdx = relativePath.indexOf('[');
- String name = (ndxNdx < 0 ? relativePath : relativePath.substring(0,
ndxNdx));
- CheckArg.isNotEmpty(name, "relativePath");
- int childNdx = 0;
if (children != null) {
- for (Name child : children) {
- if
(name.equals(child.getString(session.getExecutionContext().getNamespaceRegistry()))) {
- if (ndxNdx >= 0) {
- return (Integer.parseInt(relativePath.substring(ndxNdx + 1,
relativePath.length() - 1)) <= childNameCounts.get(childNdx));
- }
- return true;
+ try {
+ Path.Segment segment = session.getExecutionContext()
+ .getValueFactories()
+ .getPathFactory()
+ .createSegment(relativePath);
+ for (Path.Segment child : children) {
+ if (child.equals(segment)) return true;
}
- childNdx++;
+ } catch (ValueFormatException e) {
+ throw new
RepositoryException(JcrI18n.invalidRelativePath.text(relativePath));
}
}
return false;
@@ -662,21 +743,7 @@
final void setChildren( List<Segment> children ) {
assert children != null;
- if (this.children == null) {
- this.children = new ArrayList<Name>(children.size());
- childNameCounts = new ArrayList<Integer>(children.size());
- }
- for (Segment seg : children) {
- Name name = seg.getName();
- int ndx = this.children.indexOf(name);
- if (ndx >= 0) {
- childNameCounts.set(ndx, childNameCounts.get(ndx) + 1);
- } else {
- this.children.add(name);
- childNameCounts.add(1);
- }
- }
- assert this.children.size() == childNameCounts.size();
+ this.children = children;
}
final void setInternalUuid( UUID uuid ) {
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -0,0 +1,134 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.Iterator;
+import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+
+/**
+ * @author jverhaeg
+ */
+@Immutable
+final class JcrChildNodeIterator implements NodeIterator {
+
+ private final NamespaceRegistry registry;
+ private final Node parent;
+ private final Iterator<Path.Segment> iterator;
+ private int ndx;
+ private int size;
+
+ JcrChildNodeIterator( Node parent,
+ NamespaceRegistry registry,
+ List<Path.Segment> children ) {
+ assert parent != null;
+ assert registry != null;
+ assert children != null;
+ this.registry = registry;
+ this.parent = parent;
+ iterator = children.iterator();
+ size = children.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return ndx;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ return nextNode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.NodeIterator#nextNode()
+ */
+ public Node nextNode() {
+ Path.Segment childSegment = iterator.next();
+ ndx++;
+ String childName = childSegment.getString(registry);
+ try {
+ return parent.getNode(childName);
+ } catch (RepositoryException error) {
+ throw new RuntimeException(error);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>count</code> is negative.
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long count ) {
+ CheckArg.isNonNegative(count, "count");
+ while (--count >= 0) {
+ nextNode();
+ }
+ }
+}
Property changes on:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -0,0 +1,101 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.NoSuchElementException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ *
+ */
+public class JcrEmptyNodeIterator implements NodeIterator {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.NodeIterator#nextNode()
+ */
+ public Node nextNode() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long skipNum ) {
+ CheckArg.isNonNegative(skipNum, "skipNum");
+ if (skipNum == 0L) return;
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -0,0 +1,101 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.NoSuchElementException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ *
+ */
+public class JcrEmptyPropertyIterator implements PropertyIterator {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.PropertyIterator#nextProperty()
+ */
+ public Property nextProperty() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long skipNum ) {
+ CheckArg.isNonNegative(skipNum, "skipNum");
+ if (skipNum == 0L) return;
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-03 22:02:41 UTC
(rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-04 00:36:43 UTC
(rev 750)
@@ -58,14 +58,16 @@
public static I18n unableToRemapUriUsingPrefixUsedInNamespaceRegistry;
public static I18n errorWhileInitializingTheNamespaceRegistry;
+ public static I18n invalidRelativePath;
public static I18n invalidPathParameter;
+ public static I18n invalidNamePattern;
public static I18n typeNotFound;
-
+
// Used in AbstractJcrNode#getAncestor
public static I18n noNegativeDepth;
public static I18n tooDeep;
-
+
public static I18n REP_NAME_DESC;
public static I18n REP_VENDOR_DESC;
public static I18n SPEC_NAME_DESC;
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2009-03-03 22:02:41
UTC (rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2009-03-04 00:36:43
UTC (rev 750)
@@ -1,143 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.property.Name;
-
-/**
- * @author jverhaeg
- */
-final class JcrNodeIterator implements NodeIterator {
-
- private final Node parent;
- private final Iterator<Name> childIterator;
- private final Iterator<Integer> childNameCountIterator;
- private transient Name child;
- private transient int childNameCount;
- private transient int childNdx = 1;
- private transient int ndx;
- private transient Node node;
-
- JcrNodeIterator( Node parent,
- List<Name> children,
- List<Integer> childNameCounts ) {
- assert parent != null;
- this.parent = parent;
- childIterator = (children == null ? null : children.iterator());
- childNameCountIterator = (childNameCounts == null ? null :
childNameCounts.iterator());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.RangeIterator#getPosition()
- */
- public long getPosition() {
- return ndx;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return -1L
- * @see javax.jcr.RangeIterator#getSize()
- */
- public long getSize() {
- return -1L;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return ((childIterator != null && childIterator.hasNext()) || (child !=
null && childNdx <= childNameCount));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#next()
- */
- public Object next() {
- return nextNode();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.NodeIterator#nextNode()
- */
- public Node nextNode() {
- if (childIterator == null) {
- throw new NoSuchElementException();
- }
- if (child == null || childNdx > childNameCount) {
- child = childIterator.next();
- childNameCount = childNameCountIterator.next();
- childNdx = 1;
- }
- try {
- node =
parent.getNode(child.getString(((JcrSession)parent.getSession()).getExecutionContext().getNamespaceRegistry())
- + '[' + childNdx + ']');
- childNdx++;
- ndx++;
- return node;
- } catch (RepositoryException error) {
- // TODO: Change to DnaException once DNA-180 is addressed
- throw new RuntimeException(error);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws IllegalArgumentException if <code>count</code> is negative.
- * @see javax.jcr.RangeIterator#skip(long)
- */
- public void skip( long count ) {
- CheckArg.isNonNegative(count, "count");
- while (--count >= 0) {
- nextNode();
- }
- }
-}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03
22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-04
00:36:43 UTC (rev 750)
@@ -48,7 +48,9 @@
unableToRemapUriUsingPrefixUsedInNamespaceRegistry = Unable to remap the namespace
"{1}" to prefix "{0}" because the prefix is already used as the prefix
for the namespace "{2}" in the workspace's namespace registry
errorWhileInitializingTheNamespaceRegistry = Error while initializing the namespace
registry for workspace "{0}"
+invalidRelativePath = "{0}" is not a valid relative path
invalidPathParameter = The "{1}" parameter value "{0}" was not a
valid path
+invalidNamePattern = The "{1}" name pattern contained the '{0}'
character, which is not allowed in a name pattern
REP_NAME_DESC = DNA Repository
REP_VENDOR_DESC = JBoss - A division of Red Hat Middleware LLC
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-03
22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -46,9 +46,7 @@
import javax.jcr.Workspace;
import javax.jcr.version.Version;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path.Segment;
-import org.jboss.dna.graph.property.basic.BasicName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -66,10 +64,11 @@
List<Segment> children,
Node parent ) throws Exception {
MockAbstractJcrNode child = new MockAbstractJcrNode(session, name, parent);
- Segment seg = Mockito.mock(Segment.class);
- stub(seg.getName()).toReturn(new BasicName(null, name));
+ Segment seg =
session.getExecutionContext().getValueFactories().getPathFactory().createSegment(name,
index);
children.add(seg);
- stub(session.getItem(parent.getPath() + "/" + name + '[' +
index + ']')).toReturn(child);
+ // Stub the session to return this node ...
+ String absolutePath = parent.getPath() + "/" +
seg.getString(session.getExecutionContext().getNamespaceRegistry());
+ stub(session.getItem(absolutePath)).toReturn(child);
return child;
}
@@ -117,9 +116,7 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
- ExecutionContext context = Mockito.mock(ExecutionContext.class);
- stub(context.getNamespaceRegistry()).toReturn(registry);
+ ExecutionContext context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
properties = new HashSet<Property>();
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-03
22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -32,12 +32,10 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path.Segment;
import org.jboss.dna.jcr.AbstractJcrNodeTest.MockAbstractJcrNode;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -54,9 +52,7 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
- ExecutionContext context = Mockito.mock(ExecutionContext.class);
- stub(context.getNamespaceRegistry()).toReturn(registry);
+ ExecutionContext context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
node = new MockAbstractJcrNode(session, "node", null);
@@ -73,7 +69,7 @@
node.setChildren(children);
NodeIterator iter = node.getNodes();
assertThat(iter, notNullValue());
- assertThat(iter.getSize(), is(-1L));
+ assertThat(iter.getSize(), is(6L));
assertThat(iter.getPosition(), is(0L));
assertThat(iter.hasNext(), is(true));
assertThat((Node)iter.next(), is(child1));
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -131,7 +131,7 @@
while (childIterator.hasNext()) {
Location child = childIterator.next();
Name childName = child.getPath().getLastSegment().getName();
- int index = Path.NO_INDEX;
+ int index = Path.DEFAULT_INDEX;
Integer previous = childNames.put(childName, 1);
if (previous != null) {
int previousValue = previous.intValue();
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -172,8 +172,8 @@
assertThat(rule.getPathInRepository(sourcePath, pathFactory),
is(repositoryPath));
assertThatGetPathInRepositoryReturnsCorrectPathInSource("");
assertThatGetPathInRepositoryReturnsCorrectPathInSource("m/n");
- assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[0]");
- assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[0]/n/o/p");
+ assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[1]");
+ assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[1]/n/o/p");
}
protected void assertThatGetPathInRepositoryReturnsCorrectPathInSource( String
subpath ) {
@@ -199,8 +199,8 @@
assertThat(rule.getPathInSource(repositoryPath, pathFactory), is(sourcePath));
assertThatGetPathInSourceReturnsCorrectPathInRepository("");
assertThatGetPathInSourceReturnsCorrectPathInRepository("m/n");
- assertThatGetPathInSourceReturnsCorrectPathInRepository("m[0]");
- assertThatGetPathInSourceReturnsCorrectPathInRepository("m[0]/n/o/p");
+ assertThatGetPathInSourceReturnsCorrectPathInRepository("m[1]");
+ assertThatGetPathInSourceReturnsCorrectPathInRepository("m[1]/n/o/p");
}
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-03-03
22:02:41 UTC (rev 749)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-03-04
00:36:43 UTC (rev 750)
@@ -171,7 +171,7 @@
Location oldLocation = location2;
Location newLocation =
Location.create(pathFactory.create("/a/b/c/d3/e[1]"));
assertThat(oldLocation.getPath().getString(namespaces),
is("/a/b/c/e[2]"));
- assertThat(newLocation.getPath().getString(namespaces),
is("/a/b/c/d3/e[1]"));
+ assertThat(newLocation.getPath().getString(namespaces),
is("/a/b/c/d3/e")); // no SNS index
cache.addNewNode(workspaceId, location);
cache.addNewNode(workspaceId, location2);
for (Location loc : children)
@@ -296,7 +296,7 @@
Location oldLocation = location2;
Location newLocation =
Location.create(pathFactory.create("/a/b/c/d3/e[1]"));
assertThat(oldLocation.getPath().getString(namespaces),
is("/a/b/c/e[2]"));
- assertThat(newLocation.getPath().getString(namespaces),
is("/a/b/c/d3/e[1]"));
+ assertThat(newLocation.getPath().getString(namespaces),
is("/a/b/c/d3/e")); // no SNS index
cache.addNewNode(workspaceId, location);
cache.addNewNode(workspaceId, location2);
for (Location loc : children)