Author: rhauch
Date: 2009-01-28 21:33:07 -0500 (Wed, 28 Jan 2009)
New Revision: 720
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
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/NamespaceRegistry.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespace.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespaceRegistry.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPath.java
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/ChildPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java
trunk/dna-graph/src/test/resources/repositoryImporterTestData1.xml
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicRequestProcessor.java
Log:
DNA-279 Various improvements to the Graph API
Made the following improvements to the Graph API:
1) added a request to verify the existance of a node (basically, this checks for existence
and fetches the actual location)
2) added a way to copy a node by specifying the path of the desired location (in addition
to the current mechanism of specifying the parent and inferring the name of the new node
from the original). This could be accomplished by adding the desired name to the
CopyBranchRequest, and then updating all of the RequestProcessor implementations to use
this optional information. This may affect a number of classes.
3) made NamespaceRegistry.Namespace extend Comparable<Namespace> so that namespaces
can be sorted naturally
4) improved the efficiency of the AbstractPath.equals(...) implementation, which is not
efficiently iterating up the Path.Segment instances.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java 2009-01-29 02:32:27
UTC (rev 719)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java 2009-01-29 02:33:07
UTC (rev 720)
@@ -32,7 +32,7 @@
public class DnaLexicon {
public static class Namespace {
- public static final String URI = "http://www.jboss.org/dna";
+ public static final String URI = "http://www.jboss.org/dna/1.0";
public static final String PREFIX = "dna";
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-01-29 02:32:27 UTC
(rev 719)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-01-29 02:33:07 UTC
(rev 720)
@@ -158,12 +158,12 @@
this.sourceName = sourceName;
this.connectionFactory = connectionFactory;
this.context = context;
- this.requestQueue = new GraphRequestQueue();
this.nextGraph = new Conjunction<Graph>() {
public Graph and() {
return Graph.this;
}
};
+ this.requestQueue = new GraphRequestQueue();
}
/**
@@ -1527,11 +1527,11 @@
return importXmlFrom(file.toURI());
}
- /*package*/Path createPath( String path ) {
+ protected Path createPath( String path ) {
return getContext().getValueFactories().getPathFactory().create(path);
}
- /*package*/void execute( Request request ) {
+ protected void execute( Request request ) {
RepositoryConnection connection =
Graph.this.getConnectionFactory().createConnection(getSourceName());
if (connection == null) {
throw new
RepositorySourceException(GraphI18n.unableToFindRepositorySourceWithName.text(getSourceName()));
@@ -1548,7 +1548,7 @@
}
}
- /*package*/List<Segment> getSegments( List<Location> locations ) {
+ protected List<Segment> getSegments( List<Location> locations ) {
List<Segment> segments = new ArrayList<Segment>(locations.size());
for (Location location : locations) {
segments.add(location.getPath().getLastSegment());
@@ -2922,59 +2922,118 @@
*/
public interface Into<Next> {
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index). If you want to control the name of the node for the
newly copied/moved node, use
+ * {@link To#to(Location)} instead.
*
- * @param to the location of the new parent
+ * @param parentLocation the location of the new parent
* @return the interface for additional requests or actions
+ * @see To#to(Location)
*/
- Next into( Location to );
+ Next into( Location parentLocation );
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index). If you want to control the name of the node for the
newly copied/moved node, use
+ * {@link To#to(String)} instead.
*
- * @param toPath the path of the new parent
+ * @param parentPath the path of the new parent
* @return the interface for additional requests or actions
+ * @see To#to(String)
*/
- Next into( String toPath );
+ Next into( String parentPath );
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index). If you want to control the name of the node for the
newly copied/moved node, use
+ * {@link To#to(Path)} instead.
*
- * @param to the path of the new parent
+ * @param parentPath the path of the new parent
* @return the interface for additional requests or actions
+ * @see To#to(Path)
*/
- Next into( Path to );
+ Next into( Path parentPath );
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index).
*
- * @param to the UUID of the new parent
+ * @param parentUuid the UUID of the new parent
* @return the interface for additional requests or actions
*/
- Next into( UUID to );
+ Next into( UUID parentUuid );
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index).
*
- * @param idProperty the property that uniquely identifies the new parent
+ * @param parentIdProperty the property that uniquely identifies the new parent
* @return the interface for additional requests or actions
*/
- Next into( Property idProperty );
+ Next into( Property parentIdProperty );
/**
- * Finish the request by specifying the new location into which the node should
be copied/moved.
+ * Finish the request by specifying the location of the parent into which the
node should be copied/moved. This operation
+ * will result in the copied/moved node having the same name as the original (but
with the appropriately-determined
+ * same-name-sibling index).
*
- * @param firstIdProperty the first property that, with the
<code>additionalIdProperties</code>, uniquely identifies the
- * new parent
- * @param additionalIdProperties the additional properties that, with the
<code>additionalIdProperties</code>, uniquely
- * identifies the new parent
+ * @param firstParentIdProperty the first property that, with the
<code>additionalIdProperties</code>, uniquely identifies
+ * the new parent
+ * @param additionalParentIdProperties the additional properties that, with the
<code>additionalIdProperties</code>,
+ * uniquely identifies the new parent
* @return the interface for additional requests or actions
*/
- Next into( Property firstIdProperty,
- Property... additionalIdProperties );
+ Next into( Property firstParentIdProperty,
+ Property... additionalParentIdProperties );
}
/**
+ * A component that defines the location to which a node should be copied or moved.
+ *
+ * @param <Next> The interface that is to be returned when this request is
completed
+ * @author Randall Hauch
+ */
+ public interface To<Next> {
+ /**
+ * Finish the request by specifying the new location where the node should be
copied/moved. Unlike
+ * {@link Into#into(Location)}, which specifies the location of the parent and
which assumes the new node should have the
+ * same name as the original, this method allows the caller to specify a new name
for the new node.
+ *
+ * @param desiredLocation the desired location for the new node, which must have
a {@link Location#getPath() path}
+ * @return the interface for additional requests or actions
+ * @see Into#into(Location)
+ */
+ Next to( Location desiredLocation );
+
+ /**
+ * Finish the request by specifying the new location where the node should be
copied/moved. Unlike
+ * {@link Into#into(String)}, which specifies the location of the parent and
which assumes the new node should have the
+ * same name as the original, this method allows the caller to specify a new name
for the new node.
+ *
+ * @param desiredPath the path for the new node
+ * @return the interface for additional requests or actions
+ * @see Into#into(String)
+ */
+ Next to( String desiredPath );
+
+ /**
+ * Finish the request by specifying the new location where the node should be
copied/moved. Unlike {@link Into#into(Path)}
+ * , which specifies the location of the parent and which assumes the new node
should have the same name as the original,
+ * this method allows the caller to specify a new name for the new node.
+ *
+ * @param desiredPath the path for the new node
+ * @return the interface for additional requests or actions
+ * @see Into#into(Path)
+ */
+ Next to( Path desiredPath );
+ }
+
+ /**
* A interface that is used to add more locations that are to be copied/moved.
*
* @param <Next> The interface that is to be returned when this request is
completed
@@ -3044,13 +3103,15 @@
}
/**
- * The interface for defining additional nodes to be copied and the parent into which
the node(s) are to be copied. where the
- * node(s) are to be moved.
+ * The interface for defining additional nodes to be copied and the locations where
the copy is to be placed. The
+ * <code>to(...)</code> methods allow you to specify the location of the
copy, including the name for the node that results
+ * from the copy. Alternatively, you can use the <code>into(...)</code>
methods to specify the parent location where the copy
+ * is to be placed, which will assume the new copy will have the same name as the
original.
*
* @param <Next> The interface that is to be returned when this request is
completed
* @author Randall Hauch
*/
- public interface Copy<Next> extends Into<Next>,
And<Copy<Next>> {
+ public interface Copy<Next> extends To<Next>, Into<Next>,
And<Copy<Next>> {
}
/**
@@ -3885,7 +3946,7 @@
*
* @author Randall Hauch
*/
- /*package*/interface RequestQueue extends Executable {
+ protected interface RequestQueue extends Executable {
Graph getGraph();
void submit( Request request );
@@ -3899,7 +3960,7 @@
* @author Randall Hauch
*/
@NotThreadSafe
- /*package*/class GraphRequestQueue implements RequestQueue {
+ protected class GraphRequestQueue implements RequestQueue {
public Graph getGraph() {
return Graph.this;
}
@@ -4598,49 +4659,75 @@
* Submit any requests to move the targets into the supplied parent location
*
* @param into the parent location
+ * @param nameForCopy the name that should be used for the copy, or null if the
name should be the same as the original
* @return this object, for method chaining
*/
- private T submit( Location into ) {
+ private T submit( Location into,
+ Name nameForCopy ) {
if (this.from.hasNext()) {
List<Request> requests = new LinkedList<Request>();
Locations locations = this.from;
while (locations.hasNext()) {
Location location = locations.getLocation();
- requests.add(new CopyBranchRequest(location, into));
+ requests.add(new CopyBranchRequest(location, into, nameForCopy));
locations = locations.next();
}
queue().submit(requests);
} else {
- queue().submit(new CopyBranchRequest(this.from.getLocation(), into));
+ queue().submit(new CopyBranchRequest(this.from.getLocation(), into,
nameForCopy));
}
return and();
}
public T into( Location into ) {
- return submit(into);
+ return submit(into, null);
}
public T into( Path into ) {
- return submit(new Location(into));
+ return submit(new Location(into), null);
}
public T into( UUID into ) {
- return submit(new Location(into));
+ return submit(new Location(into), null);
}
public T into( Property firstIdProperty,
Property... additionalIdProperties ) {
- return submit(new Location(firstIdProperty, additionalIdProperties));
+ return submit(new Location(firstIdProperty, additionalIdProperties), null);
}
public T into( Property into ) {
- return submit(new Location(into));
+ return submit(new Location(into), null);
}
public T into( String into ) {
- return submit(new Location(createPath(into)));
+ return submit(new Location(createPath(into)), null);
}
+ public T to( Location desiredLocation ) {
+ if (!desiredLocation.hasPath()) {
+ throw new
IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from,
desiredLocation));
+ }
+ Path desiredPath = desiredLocation.getPath();
+ if (desiredPath.isRoot()) {
+ throw new
IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from,
desiredLocation));
+ }
+ Path parent = desiredPath.getParent();
+ return submit(new Location(parent), desiredPath.getLastSegment().getName());
+ }
+
+ public T to( Path desiredPath ) {
+ if (desiredPath.isRoot()) {
+ throw new
IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredPath));
+ }
+ Path parent = desiredPath.getParent();
+ return submit(new Location(parent), desiredPath.getLastSegment().getName());
+ }
+
+ public T to( String desiredPath ) {
+ return to(createPath(desiredPath));
+ }
+
@Override
public Results execute() {
return queue().execute();
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-01-29 02:32:27
UTC (rev 719)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-01-29 02:33:07
UTC (rev 720)
@@ -68,8 +68,11 @@
public static I18n closingRequestProcessor;
public static I18n closedRequestProcessor;
public static I18n multipleErrorsWhileExecutingRequests;
+ public static I18n unknownTypeOfRequest;
public static I18n unableToAddMoreRequestsToAlreadyExecutedBatch;
public static I18n unableToCreateReferenceToNodeWithoutUuid;
+ public static I18n unableToCopyToLocationWithoutAPath;
+ public static I18n unableToCopyToTheRoot;
public static I18n actualLocationIsNotSameAsInputLocation;
public static I18n actualLocationIsNotChildOfInputLocation;
public static I18n actualLocationMustHavePath;
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-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -309,6 +309,7 @@
* @param context
* @param original
* @param newParent
+ * @param desiredName
* @param recursive
* @param oldToNewUuids the map of UUIDs of nodes in the new subgraph keyed by the
UUIDs of nodes in the original; may not be
* null
@@ -317,6 +318,7 @@
public InMemoryNode copyNode( ExecutionContext context,
InMemoryNode original,
InMemoryNode newParent,
+ Name desiredName,
boolean recursive,
Map<UUID, UUID> oldToNewUuids ) {
assert context != null;
@@ -325,7 +327,8 @@
assert oldToNewUuids != null;
// Get or create the new node ...
- InMemoryNode copy = createNode(context, newParent, original.getName().getName(),
null);
+ Name childName = desiredName != null ? desiredName :
original.getName().getName();
+ InMemoryNode copy = createNode(context, newParent, childName, null);
oldToNewUuids.put(original.getUuid(), copy.getUuid());
// Copy the properties ...
@@ -334,7 +337,7 @@
if (recursive) {
// Loop over each child and call this method ...
for (InMemoryNode child : original.getChildren()) {
- copyNode(context, child, copy, true, oldToNewUuids);
+ copyNode(context, child, copy, null, true, oldToNewUuids);
}
}
@@ -439,8 +442,9 @@
if (node == null) return;
// Look up the new parent, which must exist ...
Path newParentPath = request.into().getPath();
+ Name desiredName = request.desiredName();
InMemoryNode newParent = getNode(newParentPath);
- InMemoryNode newNode = copyNode(getExecutionContext(), node, newParent, true,
new HashMap<UUID, UUID>());
+ InMemoryNode newNode = copyNode(getExecutionContext(), node, newParent,
desiredName, true, new HashMap<UUID, UUID>());
Path newPath =
getExecutionContext().getValueFactories().getPathFactory().create(newParentPath,
newNode.getName());
Location oldLocation = getActualLocation(request.from().getPath(), node);
Location newLocation = new Location(newPath, newNode.getUuid());
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/NamespaceRegistry.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/NamespaceRegistry.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/NamespaceRegistry.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -119,7 +119,7 @@
* @author Randall Hauch
*/
@Immutable
- interface Namespace {
+ interface Namespace extends Comparable<Namespace> {
/**
* Get the prefix for the namespace
*
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractPath.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.NoSuchElementException;
import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.CheckArg;
@@ -53,6 +54,35 @@
public static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
+ protected static Iterator<Path.Segment> EMPTY_PATH_ITERATOR = new
Iterator<Segment>() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Segment next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+
private transient int hc = 0;
protected boolean isNormalized( List<Segment> segments ) {
@@ -471,6 +501,14 @@
}
/**
+ * Method used by {@link AbstractPath#equals(Object)} implementation to quickly get
an Iterator over the segments in the
+ * parent.
+ *
+ * @return the iterator over the segments; never null, but may not have any elements
+ */
+ protected abstract Iterator<Segment> getSegmentsOfParent();
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -478,10 +516,18 @@
if (obj == this) return true;
if (obj instanceof Path) {
Path that = (Path)obj;
+ // First check whether the paths are roots ...
+ if (this.isRoot()) return that.isRoot();
+ else if (that.isRoot()) return false;
+ // Now check the hash code and size ...
+ if (this.hashCode() != that.hashCode()) return false;
if (this.size() != that.size()) return false;
- if (this.hashCode() != that.hashCode()) return false;
- Iterator<Segment> thisIter = this.iterator();
- Iterator<Segment> thatIter = that.iterator();
+ // Check the last segments, since these will often differ anyway ...
+ if (!this.getLastSegment().equals(that.getLastSegment())) return false;
+ if (this.size() == 1) return true;
+ // Check the rest of the names ...
+ Iterator<Segment> thisIter = that instanceof AbstractPath ?
this.getSegmentsOfParent() : this.iterator();
+ Iterator<Segment> thatIter = that instanceof AbstractPath ?
((AbstractPath)that).getSegmentsOfParent() : that.iterator();
while (thisIter.hasNext()) {
Segment thisSegment = thisIter.next();
Segment thatSegment = thatIter.next();
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespace.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespace.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespace.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -80,6 +80,17 @@
/**
* {@inheritDoc}
*
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo( Namespace that ) {
+ if (that == null) return 1;
+ if (this == that) return 0;
+ return this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -101,6 +112,6 @@
*/
@Override
public String toString() {
- return prefix + ":" + namespaceUri;
+ return prefix + "=" + namespaceUri;
}
}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespaceRegistry.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespaceRegistry.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicNamespaceRegistry.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -24,9 +24,11 @@
package org.jboss.dna.graph.property.basic;
import java.text.DecimalFormat;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
@@ -252,6 +254,18 @@
return Collections.unmodifiableSet(result);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ List<Namespace> namespaces = new
ArrayList<Namespace>(getNamespaces());
+ Collections.sort(namespaces);
+ return namespaces.toString();
+ }
+
@GuardedBy( "registryLock" )
protected String generatePrefix() {
DecimalFormat formatter = new DecimalFormat(this.generatedPrefixTemplate);
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPath.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPath.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPath.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -24,6 +24,7 @@
package org.jboss.dna.graph.property.basic;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.Inflector;
@@ -87,7 +88,19 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.property.basic.AbstractPath#getSegmentsOfParent()
*/
+ @Override
+ protected Iterator<Segment> getSegmentsOfParent() {
+ int size = this.segments.size();
+ if (size == 1) return EMPTY_PATH_ITERATOR;
+ return this.segments.subList(0, size - 1).iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public List<Segment> getSegmentsList() {
return this.segments;
}
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-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -89,14 +89,14 @@
* {@inheritDoc}
*/
public boolean isParentReference() {
- return this.name.getNamespaceUri().length() == 0 &&
this.name.getLocalName().equals(Path.PARENT);
+ return this.name.getLocalName().equals(Path.PARENT) &&
this.name.getNamespaceUri().length() == 0;
}
/**
* {@inheritDoc}
*/
public boolean isSelfReference() {
- return this.name.getNamespaceUri().length() == 0 &&
this.name.getLocalName().equals(Path.SELF);
+ return this.name.getLocalName().equals(Path.SELF) &&
this.name.getNamespaceUri().length() == 0;
}
/**
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/ChildPath.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -74,6 +74,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.property.basic.AbstractPath#getSegmentsOfParent()
+ */
+ @Override
+ protected Iterator<Segment> getSegmentsOfParent() {
+ return parent.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.property.Path#getLastSegment()
*/
@Override
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/RootPath.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -73,6 +73,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.property.basic.AbstractPath#getSegmentsOfParent()
+ */
+ @Override
+ protected Iterator<Segment> getSegmentsOfParent() {
+ return EMPTY_PATH_ITERATOR;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.property.Path#getCanonicalPath()
*/
@Override
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -27,6 +27,7 @@
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.NodeConflictBehavior;
+import org.jboss.dna.graph.property.Name;
/**
* Instruction that a branch be copied from one location into another.
@@ -41,6 +42,7 @@
private final Location from;
private final Location into;
+ private final Name desiredNameForCopy;
private final NodeConflictBehavior conflictBehavior;
private Location actualOldLocation;
private Location actualNewLocation;
@@ -54,7 +56,7 @@
*/
public CopyBranchRequest( Location from,
Location into ) {
- this(from, into, DEFAULT_CONFLICT_BEHAVIOR);
+ this(from, into, null, DEFAULT_CONFLICT_BEHAVIOR);
}
/**
@@ -62,18 +64,37 @@
*
* @param from the location of the top node in the existing branch that is to be
copied
* @param into the location of the existing node into which the copy should be
placed
+ * @param nameForCopy the desired name for the node that results from the copy, or
null if the name of the original should be
+ * used
+ * @throws IllegalArgumentException if <code>from</code> or
<code>into</code> are null
+ */
+ public CopyBranchRequest( Location from,
+ Location into,
+ Name nameForCopy ) {
+ this(from, into, nameForCopy, DEFAULT_CONFLICT_BEHAVIOR);
+ }
+
+ /**
+ * Create a request to copy a branch to another.
+ *
+ * @param from the location of the top node in the existing branch that is to be
copied
+ * @param into the location of the existing node into which the copy should be
placed
+ * @param nameForCopy the desired name for the node that results from the copy, or
null if the name of the original should be
+ * used
* @param conflictBehavior the expected behavior if an equivalently-named child
already exists at the <code>into</code>
* location
* @throws IllegalArgumentException if any of the parameters are null
*/
public CopyBranchRequest( Location from,
Location into,
+ Name nameForCopy,
NodeConflictBehavior conflictBehavior ) {
CheckArg.isNotNull(from, "from");
CheckArg.isNotNull(into, "into");
CheckArg.isNotNull(conflictBehavior, "conflictBehavior");
this.from = from;
this.into = into;
+ this.desiredNameForCopy = nameForCopy;
this.conflictBehavior = conflictBehavior;
}
@@ -96,6 +117,15 @@
}
/**
+ * Get the name of the copy if it is to be different than that of the original.
+ *
+ * @return the desired name of the copy, or null if the name of the original is to be
used
+ */
+ public Name desiredName() {
+ return desiredNameForCopy;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.graph.request.Request#isReadOnly()
@@ -189,6 +219,9 @@
*/
@Override
public String toString() {
+ if (desiredNameForCopy != null) {
+ return "copy branch " + from() + " into " + into() +
" with name " + desiredNameForCopy;
+ }
return "copy branch " + from() + " into " + into();
}
}
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -0,0 +1,137 @@
+/*
+ * 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.graph.request;
+
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.GraphI18n;
+import org.jboss.dna.graph.Location;
+
+/**
+ * Instruction to verify the existance of a node at the specified location. This request
also returns the actual location.
+ *
+ * @author Randall Hauch
+ */
+public class VerifyNodeExistsRequest extends CacheableRequest {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Location at;
+ private Location actualLocation;
+
+ /**
+ * Create a request to verify the existance and location of a node at the supplied
location.
+ *
+ * @param at the location of the node to be verified
+ * @throws IllegalArgumentException if the location is null
+ */
+ public VerifyNodeExistsRequest( Location at ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.request.Request#isReadOnly()
+ */
+ @Override
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ /**
+ * Get the location defining the node that is to be read.
+ *
+ * @return the location of the node; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * Sets the actual and complete location of the node whose properties have been read.
This method must be called when
+ * processing the request, and the actual location must have a {@link
Location#getPath() path}.
+ *
+ * @param actual the actual location of the node being read, or null if the {@link
#at() current location} should be used
+ * @throws IllegalArgumentException if the actual location does not represent the
{@link Location#isSame(Location) same
+ * location} as the {@link #at() current location}, or if the actual location
does not have a path.
+ */
+ public void setActualLocationOfNode( Location actual ) {
+ if (!at.isSame(actual)) { // not same if actual is null
+ throw new
IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual,
at));
+ }
+ assert actual != null;
+ if (!actual.hasPath()) {
+ throw new
IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual));
+ }
+ this.actualLocation = actual;
+ }
+
+ /**
+ * Get the actual location of the node whose properties were read.
+ *
+ * @return the actual location, or null if the actual location was not set
+ */
+ public Location getActualLocationOfNode() {
+ return actualLocation;
+ }
+
+ /**
+ * Return whether this node is known to exist. If the request has been processed, it
will have an
+ * {@link #getActualLocationOfNode() actual location} or an {@link #getError()
error}.
+ *
+ * @return true if this node is known to exist
+ * @see #getActualLocationOfNode()
+ * @see #getError()
+ */
+ public boolean exists() {
+ return actualLocation != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ VerifyNodeExistsRequest that = (VerifyNodeExistsRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "verify node exists at " + at();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -46,6 +46,7 @@
import org.jboss.dna.graph.request.CopyBranchRequest;
import org.jboss.dna.graph.request.CreateNodeRequest;
import org.jboss.dna.graph.request.DeleteBranchRequest;
+import org.jboss.dna.graph.request.InvalidRequestException;
import org.jboss.dna.graph.request.MoveBranchRequest;
import org.jboss.dna.graph.request.ReadAllChildrenRequest;
import org.jboss.dna.graph.request.ReadAllPropertiesRequest;
@@ -58,6 +59,7 @@
import org.jboss.dna.graph.request.RenameNodeRequest;
import org.jboss.dna.graph.request.Request;
import org.jboss.dna.graph.request.UpdatePropertiesRequest;
+import org.jboss.dna.graph.request.VerifyNodeExistsRequest;
/**
* A component that is used to process and execute {@link Request}s. This class is
intended to be subclassed and methods
@@ -188,6 +190,10 @@
process((RenameNodeRequest)request);
} else if (request instanceof UpdatePropertiesRequest) {
process((UpdatePropertiesRequest)request);
+ } else if (request instanceof VerifyNodeExistsRequest) {
+ process((VerifyNodeExistsRequest)request);
+ } else {
+ processUnknownRequest(request);
}
}
@@ -223,6 +229,16 @@
}
/**
+ * Method that is called by {@link #process(Request)} when the request was found to
be of a request type that is not known by
+ * this processor. By default this method sets an {@link InvalidRequestException
invalid request error} on the request.
+ *
+ * @param request the unknown request
+ */
+ protected void processUnknownRequest( Request request ) {
+ request.setError(new
InvalidRequestException(GraphI18n.unknownTypeOfRequest.text(request.getClass().getName(),
request)));
+ }
+
+ /**
* Process a request to copy a branch into another location.
* <p>
* This method does nothing if the request is null.
@@ -469,7 +485,7 @@
* Process a request to read a single property of a node at the supplied location.
* <p>
* This method does nothing if the request is null. Unless overridden, this method
converts the request that
- * {@link ReadNodeRequest reads the node} and simply returns the one property.
+ * {@link ReadAllPropertiesRequest reads the node} and simply returns the one
property.
* </p>
*
* @param request the read request
@@ -490,6 +506,28 @@
}
/**
+ * Process a request to verify that a node exists at the supplied location.
+ * <p>
+ * This method does nothing if the request is null. Unless overridden, this method
converts the request that
+ * {@link ReadAllPropertiesRequest reads the node} and uses the result to determine
if the node exists.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public void process( VerifyNodeExistsRequest request ) {
+ if (request == null) return;
+ ReadAllPropertiesRequest readNode = new ReadAllPropertiesRequest(request.at());
+ process(readNode);
+ if (readNode.hasError()) {
+ request.setError(readNode.getError());
+ return;
+ }
+ // Set the actual location ...
+ request.setActualLocationOfNode(readNode.getActualLocationOfNode());
+ setCacheableInfo(request);
+ }
+
+ /**
* Process a request to remove the specified properties from a node.
* <p>
* This method does nothing if the request is null. Unless overridden, this method
converts this request into a
Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-01-29
02:32:27 UTC (rev 719)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-01-29
02:33:07 UTC (rev 720)
@@ -55,8 +55,11 @@
closingRequestProcessor = Closing request processor
closedRequestProcessor = Closed request processor
multipleErrorsWhileExecutingRequests = {0} of the {1} requests resulted in errors
+unknownTypeOfRequest = Unable to process requests of type "{0}" ({1})
unableToAddMoreRequestsToAlreadyExecutedBatch = Unable to add more requests to a batch of
graph requests that has already been executed
unableToCreateReferenceToNodeWithoutUuid = Unable to set a reference to node {0} since it
has no UUID
+unableToCopyToLocationWithoutAPath = Unable to copy node "{0}" to
"{1}" since the desired location has no path
+unableToCopyToTheRoot = Unable to copy node "{0}" to "{1}" since the
desired location is the root node
actualLocationIsNotSameAsInputLocation = The actual location of {0} is not the same as
the current location of {1}
actualLocationIsNotChildOfInputLocation = The actual location of {0} is not a child of
the specified location {1}
actualLocationMustHavePath = The actual location of {0} must have a path
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -99,7 +99,7 @@
"/a/b/dna:system[1]/dna:sources[1]/sourceA[1]",
"repositoryName=repositoryA",
"retryLimit=3",
- "jcr:primaryType={http://www.jboss.org/dna}xyz",
+ "jcr:primaryType={http://www.jboss.org/dna/1.0}xyz",
"dna:classname=org.jboss.dna.connector.inmemory.InMemoryRepositorySource");
assertCreateNode(iter,
"/a/b/dna:system[1]/dna:sources[1]/sourceB[1]",
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java 2009-01-29 02:32:27
UTC (rev 719)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java 2009-01-29 02:33:07
UTC (rev 720)
@@ -845,7 +845,9 @@
public void process( CopyBranchRequest request ) {
// Create a child under the new parent ...
if (request.into().hasPath()) {
- Path childPath =
context.getValueFactories().getPathFactory().create(request.into().getPath(),
"child");
+ Name childName = request.desiredName();
+ if (childName == null) childName = createName("child");
+ Path childPath =
context.getValueFactories().getPathFactory().create(request.into().getPath(), childName);
Location newChild = actualLocationOf(new Location(childPath));
// Just update the actual location
request.setActualLocations(actualLocationOf(request.from()), newChild);
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepositoryTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -329,7 +329,7 @@
assertThat(repository.getNode(pathFactory.create("/a/b")).getProperties().get(propertyName),
is(property));
- repository.copyNode(context, node_b, node_d, true, new HashMap<UUID,
UUID>());
+ repository.copyNode(context, node_b, node_d, null, true, new HashMap<UUID,
UUID>());
assertThat(repository.getNodesByUuid().size(), is(9));
assertThat(repository.getNode(pathFactory.create("/")),
is(sameInstance(repository.getRoot())));
@@ -347,6 +347,49 @@
}
@Test
+ public void shouldCopyNodesWhenDesiredNameIsSpecified() {
+ InMemoryNode root = repository.getRoot();
+ InMemoryNode node_a = repository.createNode(context, root,
nameFactory.create("a"), null);
+ InMemoryNode node_b = repository.createNode(context, node_a,
nameFactory.create("b"), null);
+ InMemoryNode node_c = repository.createNode(context, node_b,
nameFactory.create("c"), null);
+ InMemoryNode node_d = repository.createNode(context, root,
nameFactory.create("d"), null);
+ InMemoryNode node_e = repository.createNode(context, node_d,
nameFactory.create("e"), null);
+ InMemoryNode node_b2 = repository.createNode(context, node_d,
nameFactory.create("b"), null);
+
+ ValueFactory<String> stringFactory = valueFactories.getStringFactory();
+ Name propertyName = nameFactory.create("something");
+ Property property = propertyFactory.create(propertyName,
stringFactory.create("Worth the wait"));
+ node_b.getProperties().put(propertyName, property);
+
+ assertThat(repository.getNodesByUuid().size(), is(7));
+ assertThat(repository.getNode(pathFactory.create("/")),
is(sameInstance(repository.getRoot())));
+ assertThat(repository.getNode(pathFactory.create("/a")),
is(sameInstance(node_a)));
+ assertThat(repository.getNode(pathFactory.create("/a/b")),
is(sameInstance(node_b)));
+ assertThat(repository.getNode(pathFactory.create("/a/b/c")),
is(sameInstance(node_c)));
+ assertThat(repository.getNode(pathFactory.create("/d")),
is(sameInstance(node_d)));
+ assertThat(repository.getNode(pathFactory.create("/d/e")),
is(sameInstance(node_e)));
+ assertThat(repository.getNode(pathFactory.create("/d/b")),
is(sameInstance(node_b2)));
+
+
assertThat(repository.getNode(pathFactory.create("/a/b")).getProperties().get(propertyName),
is(property));
+
+ repository.copyNode(context, node_b, node_d, nameFactory.create("x"),
true, new HashMap<UUID, UUID>());
+
+ assertThat(repository.getNodesByUuid().size(), is(9));
+ assertThat(repository.getNode(pathFactory.create("/")),
is(sameInstance(repository.getRoot())));
+ assertThat(repository.getNode(pathFactory.create("/a")),
is(sameInstance(node_a)));
+ assertThat(repository.getNode(pathFactory.create("/a/b")),
is(sameInstance(node_b)));
+ assertThat(repository.getNode(pathFactory.create("/a/b/c")),
is(sameInstance(node_c)));
+ assertThat(repository.getNode(pathFactory.create("/d")),
is(sameInstance(node_d)));
+ assertThat(repository.getNode(pathFactory.create("/d/e")),
is(sameInstance(node_e)));
+ assertThat(repository.getNode(pathFactory.create("/d/b")),
is(sameInstance(node_b2)));
+ assertThat(repository.getNode(pathFactory.create("/d/x")),
is(notNullValue()));
+ assertThat(repository.getNode(pathFactory.create("/d/x/c")),
is(notNullValue()));
+
+
assertThat(repository.getNode(pathFactory.create("/a/b")).getProperties().get(propertyName),
is(property));
+
assertThat(repository.getNode(pathFactory.create("/d/x")).getProperties().get(propertyName),
is(property));
+ }
+
+ @Test
public void shouldCreateRepositoryStructure() {
repository.createNode(context, "/a").setProperty(context,
"name", "value").setProperty(context,
"desc",
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -31,8 +31,6 @@
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.basic.BasicName;
-import org.jboss.dna.graph.property.basic.BasicNamespaceRegistry;
import org.junit.Before;
import org.junit.Test;
@@ -154,7 +152,7 @@
String encodedLocalName = encoder.encode(validLocalName);
String result = name.getString(encoder);
assertThat(result, is("{" + encodedNamespaceUri + "}" +
encodedLocalName));
- assertThat(encodedNamespaceUri,
is("http%3a%2f%2fwww.jboss.org%2fdna"));
+ assertThat(encodedNamespaceUri,
is("http%3a%2f%2fwww.jboss.org%2fdna%2f1.0"));
assertThat(encodedLocalName, is("some%3aname%3awith%3acolons"));
}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathOldTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -23,11 +23,11 @@
*/
package org.jboss.dna.graph.property.basic;
-import static org.jboss.dna.graph.property.basic.IsPathContaining.hasSegments;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.graph.property.basic.IsPathContaining.hasSegments;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,14 +40,6 @@
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.BasicName;
-import org.jboss.dna.graph.property.basic.BasicNamespaceRegistry;
-import org.jboss.dna.graph.property.basic.BasicPath;
-import org.jboss.dna.graph.property.basic.BasicPathSegment;
-import org.jboss.dna.graph.property.basic.NameValueFactory;
-import org.jboss.dna.graph.property.basic.PathValueFactory;
-import org.jboss.dna.graph.property.basic.RootPath;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -708,7 +700,7 @@
public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() {
path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
assertThat(path.getString(NO_OP_ENCODER),
-
is("/{http://www.jboss.org/dna}a/{}b/{http://www.jboss.org/dna}c/../...);
+
is("/{http://www.jboss.org/dna/1.0}a/{}b/{http://www.jboss.org/dna/1...);
}
@Test
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -23,10 +23,10 @@
*/
package org.jboss.dna.graph.property.basic;
-import static org.jboss.dna.graph.property.basic.IsPathContaining.hasSegments;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.graph.property.basic.IsPathContaining.hasSegments;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collections;
@@ -39,14 +39,6 @@
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFormatException;
-import org.jboss.dna.graph.property.basic.BasicName;
-import org.jboss.dna.graph.property.basic.BasicNamespaceRegistry;
-import org.jboss.dna.graph.property.basic.BasicPath;
-import org.jboss.dna.graph.property.basic.BasicPathSegment;
-import org.jboss.dna.graph.property.basic.NameValueFactory;
-import org.jboss.dna.graph.property.basic.PathValueFactory;
-import org.jboss.dna.graph.property.basic.RootPath;
-import org.jboss.dna.graph.property.basic.StringValueFactory;
import org.junit.Before;
import org.junit.Test;
@@ -630,7 +622,7 @@
public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() {
path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
assertThat(path.getString(NO_OP_ENCODER),
-
is("/{http://www.jboss.org/dna}a/{}b/{http://www.jboss.org/dna}c/../...);
+
is("/{http://www.jboss.org/dna/1.0}a/{}b/{http://www.jboss.org/dna/1...);
}
@Test
@@ -846,12 +838,36 @@
assertThat(path.resolve(pathFactory.create("../x")),
hasSegments(pathFactory, "a", "b", "c", "d",
"e", "x"));
}
+ @Test
public void shouldResolveNonAbsolutePaths() {
path = pathFactory.create("a/b/c");
assertThat(path, hasSegments(pathFactory, "a", "b",
"c"));
}
@Test
+ public void shouldConsiderTwoEquivalentPathsEqual() {
+ Path path1 = pathFactory.create("/a/b/c");
+ Path path2 = pathFactory.create("/a/b/c");
+ assertThat(path1.equals(path2), is(true));
+ }
+
+ @Test
+ public void shouldConsiderTwoDifferentPathsNotEqual() {
+ Path path1 = pathFactory.create("/a/b/c");
+ Path path2 = pathFactory.create("/a/b/d");
+ assertThat(path1.equals(path2), is(false));
+
+ path2 = pathFactory.create("/a/b");
+ assertThat(path1.equals(path2), is(false));
+
+ path2 = pathFactory.create("/a/b/c[2]");
+ assertThat(path1.equals(path2), is(false));
+
+ path2 = pathFactory.create("/a/b/c/c");
+ assertThat(path1.equals(path2), is(false));
+ }
+
+ @Test
public void shouldConvertPathToString() {
TextEncoder encoder = new Jsr283Encoder();
TextEncoder delimEncoder = new TextEncoder() {
Modified: trunk/dna-graph/src/test/resources/repositoryImporterTestData1.xml
===================================================================
--- trunk/dna-graph/src/test/resources/repositoryImporterTestData1.xml 2009-01-29 02:32:27
UTC (rev 719)
+++ trunk/dna-graph/src/test/resources/repositoryImporterTestData1.xml 2009-01-29 02:33:07
UTC (rev 720)
@@ -24,7 +24,7 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<dna:system
xmlns:dna="http://www.jboss.org/dna"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+<dna:system
xmlns:dna="http://www.jboss.org/dna/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
<!-- Define the RepositorySource instances that will be added if not already
defined -->
<dna:sources>
<sourceA jcr:primaryType="dna:xyz"
repositoryName="repositoryA"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource"
retryLimit="3" />
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-01-29
02:33:07 UTC (rev 720)
@@ -24,7 +24,7 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<dna:system
xmlns:dna="http://www.jboss.org/dna"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+<dna:system
xmlns:dna="http://www.jboss.org/dna/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
<!-- Define the sources from which content is made available -->
<dna:sources>
<dna:source jcr:name="SourceA" dna:name="Cars"
dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource"
dna:retryLimit="3" />
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -257,7 +257,7 @@
public void process( CopyBranchRequest request ) {
Location fromLocationInSource = projectIntoSource(request.from());
Location intoLocationInSource = projectIntoSource(request.into());
- CopyBranchRequest projected = new CopyBranchRequest(fromLocationInSource,
intoLocationInSource);
+ CopyBranchRequest projected = new CopyBranchRequest(fromLocationInSource,
intoLocationInSource, request.desiredName());
getConnection().execute(this.getExecutionContext(), projected);
if (projected.hasError()) {
projectError(projected, null, request);
Modified:
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java
===================================================================
---
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -68,8 +68,8 @@
}
@Test
- public void shouldSupportUpdates() {
- assertThat(source.getCapabilities().supportsUpdates(), is(true));
+ public void shouldNotSupportUpdates() {
+ assertThat(source.getCapabilities().supportsUpdates(), is(false));
}
@Test
Modified:
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
---
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -51,7 +51,6 @@
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.PropertyFactory;
import org.jboss.dna.graph.property.ValueFactory;
-import org.jboss.dna.graph.property.Path.Segment;
import org.jboss.dna.graph.request.CopyBranchRequest;
import org.jboss.dna.graph.request.CreateNodeRequest;
import org.jboss.dna.graph.request.DeleteBranchRequest;
@@ -259,7 +258,8 @@
// Look up the new parent, which must exist ...
Path newParentPath = request.into().getPath();
Node<Name, Object> newParent = getNode(context, newParentPath);
- Path.Segment newSegment = copyNode(node, newParent, true, null, null,
getExecutionContext());
+ Name desiredName = request.desiredName();
+ Path.Segment newSegment = copyNode(node, newParent, desiredName, true,
null, null, getExecutionContext());
UUID uuid = uuidFactory.create(node.get(DnaLexicon.UUID));
Path newPath = pathFactory.create(newParentPath, newSegment);
@@ -283,7 +283,7 @@
// Look up the new parent, which must exist ...
Path newParentPath = request.into().getPath();
Node<Name, Object> newParent = getNode(context, newParentPath);
- Path.Segment newSegment = copyNode(node, newParent, recursive,
DnaLexicon.UUID, null, getExecutionContext());
+ Path.Segment newSegment = copyNode(node, newParent, null, recursive,
DnaLexicon.UUID, null, getExecutionContext());
// Now delete the old node ...
Node<Name, Object> oldParent = node.getParent();
@@ -357,6 +357,7 @@
protected Path.Segment copyNode( Node<Name, Object> original,
Node<Name, Object> newParent,
+ Name desiredName,
boolean recursive,
Name uuidProperty,
AtomicInteger count,
@@ -364,7 +365,7 @@
assert original != null;
assert newParent != null;
// Get or create the new node ...
- Segment name = (Segment)original.getFqn().getLastElement();
+ Path.Segment name = desiredName != null ?
context.getValueFactories().getPathFactory().createSegment(desiredName) :
(Path.Segment)original.getFqn().getLastElement();
// Update the children to account for same-name siblings.
// This not only updates the FQN of the child nodes, but it also sets the
property that stores the
@@ -383,7 +384,7 @@
if (recursive) {
// Loop over each child and call this method ...
for (Node<Name, Object> child : original.getChildren()) {
- copyNode(child, copy, true, uuidProperty, count, context);
+ copyNode(child, copy, null, true, uuidProperty, count, context);
}
}
return newSegment;
Modified:
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
---
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -299,7 +299,7 @@
assertThat(newNodeC, is(nullValue()));
// Copy node B and place under node D
AtomicInteger count = new AtomicInteger();
- connection.copyNode(nodeB, nodeD, true, uuidProperty, count, context);
+ connection.copyNode(nodeB, nodeD, null, true, uuidProperty, count, context);
assertThat(count.get(), is(2));
newNodeB = cache.getNode(Fqn.fromList(newPathB.getSegmentsList()));
newNodeC = cache.getNode(Fqn.fromList(newPathC.getSegmentsList()));
Modified:
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicRequestProcessor.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicRequestProcessor.java 2009-01-29
02:32:27 UTC (rev 719)
+++
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicRequestProcessor.java 2009-01-29
02:33:07 UTC (rev 720)
@@ -956,7 +956,8 @@
originalToNewUuid.put(original.getId().getChildUuidString(),
copyUuid);
// Now add the new copy of the original ...
- Name childName = fromPath.getLastSegment().getName();
+ Name childName = request.desiredName();
+ if (childName == null) childName =
fromPath.getLastSegment().getName();
actualToLocation = addNewChild(actualNewParent, copyUuid,
childName);
}