Author: jverhaeg(a)redhat.com
Date: 2008-08-20 11:11:57 -0400 (Wed, 20 Aug 2008)
New Revision: 451
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
Log:
DNA-197: Changed BasicPath to return null for root path's ancestor and updated
SimpleRepository to account for a path having a null parent.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-19
21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-20
15:11:57 UTC (rev 451)
@@ -83,7 +83,7 @@
* {@inheritDoc}
*/
public Path getAncestor() {
- if (this.isRoot()) return this;
+ if (this.isRoot()) return null;
if (this.segments.size() == 1) return ROOT;
return subpath(0, this.segments.size() - 1);
}
@@ -93,8 +93,8 @@
*/
public Path getAncestor( int degree ) {
ArgCheck.isNonNegative(degree, "degree");
- if (this.isRoot()) return this;
if (degree == 0) return this;
+ if (this.isRoot()) return null;
int endIndex = this.segments.size() - degree;
if (endIndex < 0) {
String msg = SpiI18n.pathAncestorDegreeIsInvalid.text(this.getString(),
Inflector.getInstance().ordinalize(degree));
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-19
21:24:05 UTC (rev 450)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java 2008-08-20
15:11:57 UTC (rev 451)
@@ -132,7 +132,9 @@
NameFactory nameFactory = context.getValueFactories().getNameFactory();
PropertyFactory propertyFactory = context.getPropertyFactory();
Path pathObj = pathFactory.create(path);
- create(context,
pathObj.getAncestor().getString(context.getNamespaceRegistry()));
+ if (!pathObj.isRoot()) {
+ create(context,
pathObj.getAncestor().getString(context.getNamespaceRegistry()));
+ }
Property property = propertyFactory.create(nameFactory.create(propertyName),
values);
Map<Name, Property> properties = new HashMap<Name, Property>();
Map<Name, Property> existingProperties = data.putIfAbsent(pathObj,
properties);
@@ -152,12 +154,11 @@
String path ) {
PathFactory pathFactory = context.getValueFactories().getPathFactory();
Path pathObj = pathFactory.create(path);
- Path ancestorPath = pathObj.getAncestor();
+ Path ancestorPath = pathObj;
while (!ancestorPath.isRoot()) {
data.putIfAbsent(ancestorPath, new HashMap<Name, Property>());
ancestorPath = ancestorPath.getAncestor();
}
- data.putIfAbsent(pathObj, new HashMap<Name, Property>());
Name uuidName =
context.getValueFactories().getNameFactory().create(this.getUuidPropertyName());
UUID uuid = context.getValueFactories().getUuidFactory().create();
Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-19
21:24:05 UTC (rev 450)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-08-20
15:11:57 UTC (rev 451)
@@ -25,6 +25,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Reference;
@@ -41,6 +42,7 @@
import org.jboss.dna.spi.graph.commands.GraphCommand;
import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
+import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
/**
* A {@link RepositorySource} for a {@link SimpleRepository simple repository}.
@@ -321,7 +323,7 @@
// Iterate through all of the properties, looking for any paths that are
children of the path ...
List<Path.Segment> childSegments = new
LinkedList<Path.Segment>();
for (Path path : data.keySet()) {
- if (path.getAncestor().equals(targetPath)) {
+ if (!path.isRoot() && path.getAncestor().equals(targetPath)) {
childSegments.add(path.getLastSegment());
}
}
@@ -330,7 +332,8 @@
for (Path.Segment childSegment : childSegments) {
Map<Name, Property> properties =
repository.getData().get(targetPath);
Property uuidProperty = properties.get(uuidPropertyName);
- command.addChild(childSegment, uuidProperty);
+ command.addChild(childSegment,
+ uuidProperty == null ? new
BasicSingleValueProperty(uuidPropertyName, UUID.randomUUID()) : uuidProperty);
}
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-19
21:24:05 UTC (rev 450)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-20
15:11:57 UTC (rev 451)
@@ -224,8 +224,8 @@
}
@Test
- public void shouldReturnRootForAncestorOfRoot() {
- assertThat(BasicPath.ROOT.getAncestor(), is(ROOT));
+ public void shouldReturnNoAncestorForRoot() {
+ assertThat(BasicPath.ROOT.getAncestor(), nullValue());
}
@Test
Show replies by date