Author: rhauch
Date: 2008-11-20 14:15:17 -0500 (Thu, 20 Nov 2008)
New Revision: 643
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/Path.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
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/connectors/SimpleRepository.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepositorySource.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
Log:
DNA-254 CreateNodeRequest does not allow passing in location of existing parent
I've changed the CreateNodeRequest to take the Location of a parent plus the Name of a
child. All the connectors have been fixed, and all unit tests pass (and I've verified
they're all still working correctly). Also, the implementation of the Graph has been
changed to use the new form, but rather than change the interface (to allow passing in the
Location of the parent), I've added new methods. This means that existing usages of
the Graph API will not break and will work as before.
NOTE that this DOES change/correct the API, and that connectors built against the 0.3
release will no longer compile and will need to be changed.
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 2008-11-19 20:26:40 UTC
(rev 642)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2008-11-20 19:15:17 UTC
(rev 643)
@@ -480,17 +480,30 @@
/**
* Begin the request to create a node located at the supplied path. This request is
submitted to the repository immediately.
+ * <p>
+ * If you have the {@link Location} of the parent (for the new node) from a previous
request, it is better and more efficient
+ * to use {@link #createUnder(Location)}. However, this method work just as well if
all you have is the {@link Path} to the
+ * parent or new node.
+ * </p>
*
* @param atPath the path to the node that is to be created.
* @return an object that may be used to start another request
*/
public Conjunction<Graph> create( String atPath ) {
- this.requestQueue.submit(new CreateNodeRequest(new
Location(createPath(atPath))));
+ Path at = createPath(atPath);
+ Path parent = at.getParent();
+ Name child = at.getLastSegment().getName();
+ this.requestQueue.submit(new CreateNodeRequest(new Location(parent), child, 0));
return nextGraph;
}
/**
* Begin the request to create a node located at the supplied path. This request is
submitted to the repository immediately.
+ * <p>
+ * If you have the {@link Location} of the parent (for the new node) from a previous
request, it is better and more efficient
+ * to use {@link #createUnder(Location)}. However, this method work just as well if
all you have is the {@link Path} to the
+ * parent or new node.
+ * </p>
*
* @param atPath the path to the node that is to be created.
* @param properties the properties for the new node
@@ -498,23 +511,39 @@
*/
public Conjunction<Graph> create( String atPath,
Property... properties ) {
- this.requestQueue.submit(new CreateNodeRequest(new Location(createPath(atPath)),
properties));
+ Path at = createPath(atPath);
+ Path parent = at.getParent();
+ Name child = at.getLastSegment().getName();
+ this.requestQueue.submit(new CreateNodeRequest(new Location(parent), child, 0,
properties));
return nextGraph;
}
/**
* Begin the request to create a node located at the supplied path. This request is
submitted to the repository immediately.
+ * <p>
+ * If you have the {@link Location} of the parent (for the new node) from a previous
request, it is better and more efficient
+ * to use {@link #createUnder(Location)}. However, this method work just as well if
all you have is the {@link Path} to the
+ * parent or new node.
+ * </p>
*
* @param at the path to the node that is to be created.
* @return an object that may be used to start another request
*/
public Conjunction<Graph> create( Path at ) {
- this.requestQueue.submit(new CreateNodeRequest(new Location(at)));
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name child = at.getLastSegment().getName();
+ this.requestQueue.submit(new CreateNodeRequest(new Location(parent), child, 0));
return nextGraph;
}
/**
* Begin the request to create a node located at the supplied path. This request is
submitted to the repository immediately.
+ * <p>
+ * If you have the {@link Location} of the parent (for the new node) from a previous
request, it is better and more efficient
+ * to use {@link #createUnder(Location)}. However, this method work just as well if
all you have is the {@link Path} to the
+ * parent or new node.
+ * </p>
*
* @param at the path to the node that is to be created.
* @param properties the properties for the new node
@@ -522,12 +551,20 @@
*/
public Conjunction<Graph> create( Path at,
Property... properties ) {
- this.requestQueue.submit(new CreateNodeRequest(new Location(at), properties));
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name child = at.getLastSegment().getName();
+ this.requestQueue.submit(new CreateNodeRequest(new Location(parent), child, 0,
properties));
return nextGraph;
}
/**
* Begin the request to create a node located at the supplied path. This request is
submitted to the repository immediately.
+ * <p>
+ * If you have the {@link Location} of the parent (for the new node) from a previous
request, it is better and more efficient
+ * to use {@link #createUnder(Location)}. However, this method work just as well if
all you have is the {@link Path} to the
+ * parent or new node.
+ * </p>
*
* @param at the path to the node that is to be created.
* @param properties the properties for the new node
@@ -535,11 +572,73 @@
*/
public Conjunction<Graph> create( Path at,
Iterable<Property> properties ) {
- this.requestQueue.submit(new CreateNodeRequest(new Location(at), properties));
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name child = at.getLastSegment().getName();
+ this.requestQueue.submit(new CreateNodeRequest(new Location(parent), child, 0,
properties));
return nextGraph;
}
/**
+ * Begin the request to create a node under the existing parent node at the supplied
location. Use this method if you are
+ * creating a node when you have the {@link Location} of a parent from a previous
request.
+ * <p>
+ * Like all other methods on the {@link Graph}, the copy request will be performed
immediately when the <code>node(...)</code>
+ * method is called on the returned object
+ * </p>
+ *
+ * @param parent the location of the parent
+ * @return the object used to start creating a node
+ */
+ public CreateNode<Conjunction<Graph>> createUnder( final Location parent
) {
+ final NameFactory nameFactory =
getContext().getValueFactories().getNameFactory();
+ CheckArg.isNotNull(parent, "parent");
+ return new CreateNode<Conjunction<Graph>>() {
+ public Conjunction<Graph> node( String name,
+ Property... properties ) {
+ return node(name, -1, properties);
+ }
+
+ public Conjunction<Graph> node( String name,
+ Iterator<Property> properties ) {
+ return node(name, -1, properties);
+ }
+
+ public Conjunction<Graph> node( String name,
+ Iterable<Property> properties ) {
+ return node(name, -1, properties);
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Conjunction<Graph> node( String name,
+ int desiredIndexInParent,
+ Property... properties ) {
+ Name child = nameFactory.create(name);
+ requestQueue.submit(new CreateNodeRequest(parent, child,
desiredIndexInParent, properties));
+ return nextGraph;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Conjunction<Graph> node( String name,
+ int desiredIndexInParent,
+ Iterator<Property> properties ) {
+ Name child = nameFactory.create(name);
+ requestQueue.submit(new CreateNodeRequest(parent, child,
desiredIndexInParent, properties));
+ return nextGraph;
+ }
+
+ @SuppressWarnings( "synthetic-access" )
+ public Conjunction<Graph> node( String name,
+ int desiredIndexInParent,
+ Iterable<Property> properties ) {
+ Name child = nameFactory.create(name);
+ requestQueue.submit(new CreateNodeRequest(parent, child,
desiredIndexInParent, properties));
+ return nextGraph;
+ }
+ };
+ }
+
+ /**
* Set the properties on a node.
*
* @param properties the properties to set
@@ -1515,7 +1614,10 @@
*/
public Create<BatchConjunction> create( String atPath ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(createPath(atPath)));
+ Path at = createPath(atPath);
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0);
}
/**
@@ -1533,7 +1635,10 @@
public Create<BatchConjunction> create( String atPath,
Property property ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(createPath(atPath))).with(property);
+ Path at = createPath(atPath);
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0).with(property);
}
/**
@@ -1553,8 +1658,11 @@
Property firstProperty,
Property... additionalProperties ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(createPath(atPath))).with(firstProperty,
-
additionalProperties);
+ Path at = createPath(atPath);
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0).with(firstProperty,
+
additionalProperties);
}
/**
@@ -1570,7 +1678,10 @@
*/
public Create<BatchConjunction> create( Path at ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(at));
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0);
}
/**
@@ -1588,8 +1699,11 @@
public Create<BatchConjunction> create( Path at,
Iterable<Property> properties ) {
assertNotExecuted();
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
CreateAction<BatchConjunction> action = new
CreateAction<BatchConjunction>(nextRequests, requestQueue,
-
new Location(at));
+
new Location(parent), name, 0);
for (Property property : properties) {
action.and(property);
}
@@ -1611,7 +1725,10 @@
public Create<BatchConjunction> create( Path at,
Property property ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(at)).with(property);
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0).with(property);
}
/**
@@ -1631,11 +1748,26 @@
Property firstProperty,
Property... additionalProperties ) {
assertNotExecuted();
- return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(at)).with(firstProperty,
-
additionalProperties);
+ CheckArg.isNotNull(at, "at");
+ Path parent = at.getParent();
+ Name name = at.getLastSegment().getName();
+ return new CreateAction<BatchConjunction>(nextRequests, requestQueue,
new Location(parent), name, 0).with(firstProperty,
+
additionalProperties);
}
/**
+ * Begin the request to create a node under the existing parent node at the
supplied location. This request is submitted
+ * to the repository after the returned components are completed.
+ *
+ * @param parent the location of the parent
+ * @return the object used to start creating a node
+ */
+ public CreateNodeNamed<BatchConjunction> createUnder( Location parent ) {
+ CheckArg.isNotNull(parent, "parent");
+ return new CreateNodeNamedAction<BatchConjunction>(nextRequests,
requestQueue, parent);
+ }
+
+ /**
* Set the properties on a node.
*
* @param properties the properties to set
@@ -2482,6 +2614,106 @@
}
/**
+ * A component that defines a node that is to be created.
+ *
+ * @param <Next> The interface that is to be returned to complete the create
request
+ * @author Randall Hauch
+ */
+ public interface CreateNode<Next> {
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ Property... properties );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ Iterator<Property> properties );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ Iterable<Property> properties );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param sameNameSiblingIndex the desired same-name-sibling index
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ int sameNameSiblingIndex,
+ Property... properties );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param sameNameSiblingIndex the desired same-name-sibling index
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ int sameNameSiblingIndex,
+ Iterator<Property> properties );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param sameNameSiblingIndex the desired same-name-sibling index
+ * @param properties the properties for the new node
+ * @return the next component for making additional requests.
+ */
+ Next node( String nodeName,
+ int sameNameSiblingIndex,
+ Iterable<Property> properties );
+ }
+
+ /**
+ * A component that defines a node that is to be created.
+ *
+ * @param <Next> The interface that is to be returned to complete the create
request
+ * @author Randall Hauch
+ */
+ public interface CreateNodeNamed<Next> {
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @return the interface used to complete the request
+ */
+ CreateAction<Next> nodeNamed( String nodeName );
+
+ /**
+ * Specify the name of the node that is to be created.
+ *
+ * @param nodeName the name of the new node
+ * @param sameNameSiblingIndex the desired same-name-sibling index
+ * @return the interface used to complete the request
+ */
+ CreateAction<Next> nodeNamed( String nodeName,
+ int sameNameSiblingIndex );
+ }
+
+ /**
* A component that defines the location into which a node should be copied or
moved.
*
* @param <Next> The interface that is to be returned when this request is
completed
@@ -3114,6 +3346,10 @@
return this.queue;
}
+ /*package*/T afterConjunction() {
+ return this.afterConjunction;
+ }
+
public T and() {
return this.afterConjunction;
}
@@ -3319,14 +3555,20 @@
@NotThreadSafe
static class CreateAction<T> extends AbstractAction<T> implements
Create<T> {
- private final Location at;
+ private final Location parent;
+ private final Name childName;
+ private final int desiredIndex;
private final List<Property> properties = new
LinkedList<Property>();
/*package*/CreateAction( T afterConjunction,
RequestQueue queue,
- Location at ) {
+ Location parent,
+ Name childName,
+ int desiredIndex ) {
super(afterConjunction, queue);
- this.at = at;
+ this.parent = parent;
+ this.childName = childName;
+ this.desiredIndex = desiredIndex;
}
public Create<T> and( UUID uuid ) {
@@ -3391,7 +3633,7 @@
@Override
public T and() {
- this.queue().submit(new CreateNodeRequest(this.at, this.properties));
+ this.queue().submit(new CreateNodeRequest(parent, childName, desiredIndex,
this.properties));
return super.and();
}
@@ -3401,4 +3643,31 @@
}
}
+ @NotThreadSafe
+ static class CreateNodeNamedAction<T> extends AbstractAction<T>
implements CreateNodeNamed<T> {
+ private final Location parent;
+
+ /*package*/CreateNodeNamedAction( T afterConjunction,
+ RequestQueue queue,
+ Location parent ) {
+ super(afterConjunction, queue);
+ this.parent = parent;
+ }
+
+ public CreateAction<T> nodeNamed( String name ) {
+ ExecutionContext context = queue().getGraph().getContext();
+ NameFactory factory = context.getValueFactories().getNameFactory();
+ Name nameObj = factory.create(name);
+ return new CreateAction<T>(afterConjunction(), queue(), parent,
nameObj, 0);
+ }
+
+ public CreateAction<T> nodeNamed( String name,
+ int desiredIndex ) {
+ ExecutionContext context = queue().getGraph().getContext();
+ NameFactory factory = context.getValueFactories().getNameFactory();
+ Name nameObj = factory.create(name);
+ if (desiredIndex < 0) desiredIndex = 0;
+ return new CreateAction<T>(afterConjunction(), queue(), parent,
nameObj, desiredIndex);
+ }
+ }
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/Path.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/Path.java 2008-11-19
20:26:40 UTC (rev 642)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/Path.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -157,7 +157,7 @@
public Name getName();
/**
- * Get the index for this segment, which will be {@link Path#NO_INDEX 0} if this
segment has no specific index.
+ * Get the index for this segment, which will be {@link Path#NO_INDEX -1} if this
segment has no specific index.
*
* @return the index
*/
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -7,7 +7,7 @@
* This is free software; you can redistribute it and/or modify it
* 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.
+ * the License, or (under your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -31,10 +31,11 @@
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.NodeConflictBehavior;
+import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Property;
/**
- * Instruction to create the node at the specified location. This command will create the
node and set the initial properties.
+ * Instruction to create the node under the specified location. This command will create
the node and set the initial properties.
*
* @author Randall Hauch
*/
@@ -44,107 +45,132 @@
public static final NodeConflictBehavior DEFAULT_CONFLICT_BEHAVIOR =
NodeConflictBehavior.APPEND;
- private final Location at;
+ private final Location under;
+ private final Name childName;
+ private final Integer desiredIndex;
private final List<Property> properties;
private final NodeConflictBehavior conflictBehavior;
private Location actualLocation;
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @throws IllegalArgumentException if the location is null or has no {@link
Location#getPath() path}
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @throws IllegalArgumentException if the location or the child name is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
Property... properties ) {
- this(at, DEFAULT_CONFLICT_BEHAVIOR, properties);
+ this(parentLocation, childName, desiredIndexInParent, DEFAULT_CONFLICT_BEHAVIOR,
properties);
}
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @throws IllegalArgumentException if the location is null or has no {@link
Location#getPath() path}
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @throws IllegalArgumentException if the location or the child name is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
Iterable<Property> properties ) {
- this(at, DEFAULT_CONFLICT_BEHAVIOR, properties);
+ this(parentLocation, childName, desiredIndexInParent, DEFAULT_CONFLICT_BEHAVIOR,
properties);
}
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @throws IllegalArgumentException if the location is null or has no {@link
Location#getPath() path}
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @throws IllegalArgumentException if the location or the child name is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
Iterator<Property> properties ) {
- this(at, DEFAULT_CONFLICT_BEHAVIOR, properties);
+ this(parentLocation, childName, desiredIndexInParent, DEFAULT_CONFLICT_BEHAVIOR,
properties);
}
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @param conflictBehavior the expected behavior if an equivalently-named child
already exists at the <code>into</code>
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @param conflictBehavior the expected behavior if an equivalently-named child
already exists under the <code>into</code>
* location
- * @throws IllegalArgumentException if the location or the conflict behavior is null,
or if the location does not have a
- * {@link Location#getPath() path}
+ * @throws IllegalArgumentException if the location, the child name, or the conflict
behavior is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
NodeConflictBehavior conflictBehavior,
Property... properties ) {
- CheckArg.isNotNull(at, "at");
+ CheckArg.isNotNull(parentLocation, "parentLocation");
CheckArg.isNotNull(conflictBehavior, "conflictBehavior");
- CheckArg.isNotNull(at.getPath(), "at.getPath()");
- this.at = at;
+ CheckArg.isNotNull(childName, "childName");
+ this.under = parentLocation;
+ this.childName = childName;
+ this.desiredIndex = desiredIndexInParent < 1 ? null : new
Integer(desiredIndexInParent);
this.conflictBehavior = conflictBehavior;
- int number = properties.length + (at.hasIdProperties() ?
at.getIdProperties().size() : 0);
+ int number = properties.length + (under.hasIdProperties() ?
under.getIdProperties().size() : 0);
List<Property> props = new ArrayList<Property>(number);
for (Property property : properties) {
if (property != null) props.add(property);
}
- // Add in the location properties ...
- if (at.hasIdProperties()) {
- for (Property property : at.getIdProperties()) {
- if (property != null) props.add(property);
- }
- }
this.properties = Collections.unmodifiableList(props);
}
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @param conflictBehavior the expected behavior if an equivalently-named child
already exists at the <code>into</code>
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @param conflictBehavior the expected behavior if an equivalently-named child
already exists under the <code>into</code>
* location
- * @throws IllegalArgumentException if the location or the conflict behavior is null
+ * @throws IllegalArgumentException if the location, the child name, or the conflict
behavior is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
NodeConflictBehavior conflictBehavior,
Iterable<Property> properties ) {
- CheckArg.isNotNull(at, "at");
+ CheckArg.isNotNull(parentLocation, "parentLocation");
CheckArg.isNotNull(conflictBehavior, "conflictBehavior");
- this.at = at;
+ CheckArg.isNotNull(childName, "childName");
+ this.under = parentLocation;
+ this.childName = childName;
+ this.desiredIndex = desiredIndexInParent < 1 ? null : new
Integer(desiredIndexInParent);
this.conflictBehavior = conflictBehavior;
List<Property> props = new LinkedList<Property>();
for (Property property : properties) {
if (property != null) props.add(property);
}
// Add in the location properties ...
- if (at.hasIdProperties()) {
- for (Property property : at.getIdProperties()) {
+ if (under.hasIdProperties()) {
+ for (Property property : under.getIdProperties()) {
if (property != null) props.add(property);
}
}
@@ -152,21 +178,29 @@
}
/**
- * Create a request to create a node with the given properties at the supplied
location.
+ * Create a request to create a node with the given properties under the supplied
location.
*
- * @param at the location of the node to be read
- * @param properties the properties of the new node, which should not include the
location's
- * {@link Location#getIdProperties() identification properties}
- * @param conflictBehavior the expected behavior if an equivalently-named child
already exists at the <code>into</code>
+ * @param parentLocation the location of the existing parent node, under which the
new child should be created
+ * @param childName the name of the new child to create under the existing parent
+ * @param desiredIndexInParent the desired index in the parent under which the new
child should be created, or 0 if the child
+ * is to be appended under the end of the existing children
+ * @param properties the properties of the new node, which should include any {@link
Location#getIdProperties() identification
+ * properties} for the new node
+ * @param conflictBehavior the expected behavior if an equivalently-named child
already exists under the <code>into</code>
* location
- * @throws IllegalArgumentException if the location or the conflict behavior is null
+ * @throws IllegalArgumentException if the location, the child name, or the conflict
behavior is null
*/
- public CreateNodeRequest( Location at,
+ public CreateNodeRequest( Location parentLocation,
+ Name childName,
+ int desiredIndexInParent,
NodeConflictBehavior conflictBehavior,
Iterator<Property> properties ) {
- CheckArg.isNotNull(at, "at");
+ CheckArg.isNotNull(parentLocation, "parentLocation");
CheckArg.isNotNull(conflictBehavior, "conflictBehavior");
- this.at = at;
+ CheckArg.isNotNull(childName, "childName");
+ this.under = parentLocation;
+ this.childName = childName;
+ this.desiredIndex = desiredIndexInParent < 1 ? null : new
Integer(desiredIndexInParent);
this.conflictBehavior = conflictBehavior;
List<Property> props = new LinkedList<Property>();
while (properties.hasNext()) {
@@ -174,8 +208,8 @@
if (property != null) props.add(property);
}
// Add in the location properties ...
- if (at.hasIdProperties()) {
- for (Property property : at.getIdProperties()) {
+ if (under.hasIdProperties()) {
+ for (Property property : under.getIdProperties()) {
if (property != null) props.add(property);
}
}
@@ -183,15 +217,34 @@
}
/**
- * Get the location defining the node that is to be created.
+ * Get the location defining the parent of the new node that is to be created.
*
- * @return the location of the node; never null
+ * @return the location of the parent node; never null
*/
- public Location at() {
- return at;
+ public Location under() {
+ return under;
}
/**
+ * Get the name for the new child.
+ *
+ * @return the child's name; never null
+ */
+ public Name named() {
+ return childName;
+ }
+
+ /**
+ * Get the desired index (always positive) in the parent for the new child, or null
if the new child should be appended under
+ * the end of the existing children.
+ *
+ * @return the desired index, or null if there is no desired index
+ */
+ public Integer desiredIndex() {
+ return desiredIndex;
+ }
+
+ /**
* {@inheritDoc}
*
* @see java.lang.Iterable#iterator()
@@ -201,7 +254,7 @@
}
/**
- * Get the properties for the node. If the node's {@link #at() location} has
identification properties, the resulting
+ * Get the properties for the node. If the node's {@link #under() location} has
identification properties, the resulting
* properties will include the {@link Location#getIdProperties() identification
properties}.
*
* @return the collection of properties; never null
@@ -211,7 +264,8 @@
}
/**
- * Get the expected behavior when copying the branch and the {@link #at()
destination} already has a node with the same name.
+ * Get the expected behavior when copying the branch and the {@link #under()
destination} already has a node with the same
+ * name.
*
* @return the behavior specification
*/
@@ -233,18 +287,23 @@
* Sets the actual and complete location of the node being created. 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 created, or null if the {@link
#at() current location} should be used
+ * @param actual the actual location of the node being created, or null if the {@link
#under() 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.
+ * location} as the {@link #under() current location}, or if the actual
location does not have a path.
*/
public void setActualLocationOfNode( Location actual ) {
- if (!at.isSame(actual, false)) { // not same if actual is null
- throw new
IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual,
at));
+ CheckArg.isNotNull(actual, "actual");
+ if (!under.isSame(actual, false)) { // not same if actual is null
}
assert actual != null;
if (!actual.hasPath()) {
throw new
IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual));
}
+ assert actual.hasPath();
+ if (under.hasPath() &&
!under.getPath().equals(actual.getPath().getParent())) {
+ throw new
IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual,
under));
+ }
this.actualLocation = actual;
}
@@ -266,7 +325,7 @@
public boolean equals( Object obj ) {
if (this.getClass().isInstance(obj)) {
CreateNodeRequest that = (CreateNodeRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.under().equals(that.under())) return false;
if (!this.conflictBehavior().equals(that.conflictBehavior())) return false;
if (!this.properties().equals(that.properties())) return false;
return true;
@@ -281,7 +340,7 @@
*/
@Override
public String toString() {
- return "create node at " + at() + " with properties " +
properties();
+ return "create node \"" + childName + "\" under " +
under() + " with properties " + properties();
}
}
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 2008-11-19
20:26:40 UTC (rev 642)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -114,7 +114,9 @@
assertThat(nextCommand, is(instanceOf(CreateNodeRequest.class)));
CreateNodeRequest createNode = (CreateNodeRequest)nextCommand;
Path expectedPath = context.getValueFactories().getPathFactory().create(path);
- assertThat(createNode.at().getPath(), is(expectedPath));
+ Path parentPath = createNode.under().getPath();
+ assertThat(parentPath, is(expectedPath.getParent()));
+ assertThat(createNode.named(), is(expectedPath.getLastSegment().getName()));
Map<Name, Property> propertiesByName = new HashMap<Name,
Property>();
for (Property prop : createNode.properties()) {
propertiesByName.put(prop.getName(), prop);
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 2008-11-19 20:26:40
UTC (rev 642)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java 2008-11-20 19:15:17
UTC (rev 643)
@@ -160,9 +160,12 @@
assertThat(executedRequests.poll(), is((Request)new DeleteBranchRequest(at)));
}
- protected void assertNextRequestIsCreate( Location at,
+ protected void assertNextRequestIsCreate( Location parent,
+ String child,
+ int desiredIndex,
Property... properties ) {
- assertThat(executedRequests.poll(), is((Request)new CreateNodeRequest(at,
properties)));
+ Name name = context.getValueFactories().getNameFactory().create(child);
+ assertThat(executedRequests.poll(), is((Request)new CreateNodeRequest(parent,
name, desiredIndex, properties)));
}
protected void assertNextRequestReadProperties( Location at,
@@ -307,32 +310,32 @@
public void shouldCreateNode() {
graph.create(validPath);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath));
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c",
0);
assertNoMoreRequests();
graph.create(validPath, validIdProperty1);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath), validIdProperty1);
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c", 0,
validIdProperty1);
assertNoMoreRequests();
graph.create(validPath, validIdProperty1, validIdProperty2);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath), validIdProperty1,
validIdProperty2);
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c", 0,
validIdProperty1, validIdProperty2);
assertNoMoreRequests();
graph.create(validPathString);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath));
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c",
0);
assertNoMoreRequests();
graph.create(validPathString, validIdProperty1);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath), validIdProperty1);
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c", 0,
validIdProperty1);
assertNoMoreRequests();
graph.create(validPathString, validIdProperty1, validIdProperty2);
assertThat(numberOfExecutions, is(1));
- assertNextRequestIsCreate(new Location(validPath), validIdProperty1,
validIdProperty2);
+ assertNextRequestIsCreate(new Location(validPath.getParent()), "c", 0,
validIdProperty1, validIdProperty2);
assertNoMoreRequests();
}
@@ -775,8 +778,11 @@
@Override
public void process( CreateNodeRequest request ) {
- // Just update the actual location
- request.setActualLocationOfNode(actualLocationOf(request.at()));
+ // Just update the actual location ...
+ Location parent = actualLocationOf(request.under()); // just make sure it has
a path ...
+ Name name = request.named();
+ Path childPath =
context.getValueFactories().getPathFactory().create(parent.getPath(), name);
+ request.setActualLocationOfNode(new Location(childPath));
}
@Override
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -209,6 +209,18 @@
return this;
}
+ public List<Path> getChildren( ExecutionContext context,
+ Path path ) {
+ List<Path> children = new LinkedList<Path>();
+ for (Path nodePath : data.keySet()) {
+ if (nodePath.isRoot()) continue;
+ if (nodePath.getParent().equals(path)) {
+ children.add(nodePath);
+ }
+ }
+ return children;
+ }
+
/**
* @param data new new map of property data
*/
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepositorySource.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepositorySource.java 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepositorySource.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -290,20 +290,54 @@
@Override
public void process( CreateNodeRequest request ) {
- Path targetPath = request.at().getPath();
+ Path parentPath = request.under().getPath();
ExecutionContext context = getExecutionContext();
- repository.create(context,
targetPath.getString(context.getNamespaceRegistry()));
- Map<Name, Property> properties =
repository.getData().get(targetPath);
+ Path targetPath =
context.getValueFactories().getPathFactory().create(parentPath, request.named());
+ final Name childName = request.named();
+ Map<Name, Property> properties = null;
+ // Create the path for the new node, but we need to look for existing
SNS ...
+ switch (request.conflictBehavior()) {
+ case DO_NOT_REPLACE:
+ case APPEND:
+ // Need to look for existing SNS ...
+ int lastSns = 0;
+ for (Path child : repository.getChildren(context,
parentPath)) {
+ Path.Segment segment = child.getLastSegment();
+ if (segment.getName().equals(childName)) {
+ if (segment.hasIndex()) lastSns =
segment.getIndex();
+ else ++lastSns;
+ }
+ targetPath =
context.getValueFactories().getPathFactory().create(parentPath,
+
request.named(),
+
++lastSns);
+ }
+ repository.create(context,
targetPath.getString(context.getNamespaceRegistry()));
+ break;
+ case REPLACE:
+ // Remove any existing node with the desired target path ...
+ repository.delete(context,
targetPath.getString(context.getNamespaceRegistry()));
+ repository.create(context,
targetPath.getString(context.getNamespaceRegistry()));
+ break;
+ case UPDATE:
+ // Get the existing properties (if there are any) and merge
new properties,
+ // using the desired target path ...
+ properties = repository.getData().get(targetPath);
+ if (properties == null) {
+ repository.create(context,
targetPath.getString(context.getNamespaceRegistry()));
+ }
+ break;
+ }
+ if (properties == null) properties =
repository.getData().get(targetPath);
assert properties != null;
// Set the UUID if the request has one ...
- Property uuidProperty = request.at().getIdProperty(DnaLexicon.UUID);
+ Property uuidProperty =
request.under().getIdProperty(DnaLexicon.UUID);
if (uuidProperty != null) {
properties.put(uuidProperty.getName(), uuidProperty);
- request.setActualLocationOfNode(request.at());
} else {
uuidProperty = properties.get(DnaLexicon.UUID);
-
request.setActualLocationOfNode(request.at().with(uuidProperty));
}
+ Location actual = new Location(targetPath, uuidProperty);
+ request.setActualLocationOfNode(actual);
for (Property property : request.properties()) {
if (property != null) properties.put(property.getName(),
property);
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java 2008-11-19
20:26:40 UTC (rev 642)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -399,7 +399,9 @@
}
// Now get the next request and compare the expected and actual ...
CreateNodeRequest request = requests.remove();
- assertThat(request.at().getPath(), is(expectedPath));
+ Path parentPath = request.under().getPath();
+ assertThat(parentPath, is(expectedPath.getParent()));
+ assertThat(request.named(), is(expectedPath.getLastSegment().getName()));
for (Property actual : request.properties()) {
Property expected = expectedProperties.remove(actual.getName());
assertThat("unexpected property: " + actual, expected,
is(notNullValue()));
@@ -434,18 +436,23 @@
public void create( Path path,
List<Property> properties ) {
- requests.add(new CreateNodeRequest(new Location(path), properties));
+ assert path != null;
+ Path parent = path.getParent();
+ Name child = path.getLastSegment().getName();
+ requests.add(new CreateNodeRequest(new Location(parent), child, 0,
properties));
}
public void create( final Path path,
final Property firstProperty,
final Property... additionalProperties ) {
- Location location = new Location(path);
+ Path parent = path.getParent();
+ Name child = path.getLastSegment().getName();
+ Location location = new Location(parent);
if (firstProperty == null) {
- requests.add(new CreateNodeRequest(location));
+ requests.add(new CreateNodeRequest(location, child, 0));
} else {
if (additionalProperties == null || additionalProperties.length == 0) {
- requests.add(new CreateNodeRequest(location, firstProperty));
+ requests.add(new CreateNodeRequest(location, child, 0,
firstProperty));
} else {
Iterator<Property> iter = new Iterator<Property>() {
private int index = -1;
@@ -466,7 +473,7 @@
throw new UnsupportedOperationException();
}
};
- requests.add(new CreateNodeRequest(location, iter));
+ requests.add(new CreateNodeRequest(location, child, 0, iter));
}
}
}
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -47,12 +47,14 @@
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.NodeConflictBehavior;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connectors.RepositoryConnection;
import org.jboss.dna.graph.connectors.RepositoryConnectionFactory;
import org.jboss.dna.graph.connectors.RepositorySource;
import org.jboss.dna.graph.connectors.RepositorySourceException;
import org.jboss.dna.graph.properties.DateTime;
+import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
import org.jboss.dna.graph.properties.PathNotFoundException;
@@ -640,12 +642,23 @@
protected void updateCache( FederatedNode mergedNode ) throws
RepositorySourceException {
final ExecutionContext context = getExecutionContext();
final RepositoryConnection cacheConnection = getConnectionToCache();
- final Location path = mergedNode.at();
+ final Location location = mergedNode.at();
+ final Path path = location.getPath();
+ assert path != null;
+ List<Request> requests = new ArrayList<Request>();
+ Name childName = null;
+ if (!path.isRoot()) {
+ // This is not the root node, so we need to create the node ...
+ final Location parentLocation = new Location(path.getParent());
+ childName = path.getLastSegment().getName();
+ requests.add(new CreateNodeRequest(parentLocation, childName, 0,
NodeConflictBehavior.REPLACE,
+ mergedNode.getProperties()));
+ }
- List<Request> requests = new ArrayList<Request>();
- requests.add(new CreateNodeRequest(path, mergedNode.getProperties()));
+ // Now create all of the children that this federated node knows of ...
for (Location child : mergedNode.getChildren()) {
- requests.add(new CreateNodeRequest(child));
+ childName = child.getPath().getLastSegment().getName();
+ requests.add(new CreateNodeRequest(location, childName, 0,
NodeConflictBehavior.APPEND));
}
cacheConnection.execute(context, CompositeRequest.with(requests));
}
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 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -32,6 +32,7 @@
import org.jboss.dna.graph.connectors.RepositorySource;
import org.jboss.dna.graph.connectors.RepositorySourceException;
import org.jboss.dna.graph.properties.DateTime;
+import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
import org.jboss.dna.graph.properties.PathNotFoundException;
@@ -186,11 +187,14 @@
*/
@Override
public void process( CreateNodeRequest request ) {
- Location locationInSource = projectIntoSource(request.at());
- CreateNodeRequest projected = new CreateNodeRequest(locationInSource,
request.properties());
+ Location locationInSource = projectIntoSource(request.under());
+ Name child = request.named();
+ Integer desiredIndex = request.desiredIndex();
+ int index = desiredIndex != null ? desiredIndex.intValue() : 0;
+ CreateNodeRequest projected = new CreateNodeRequest(locationInSource, child,
index, request.properties());
getConnection().execute(this.getExecutionContext(), projected);
if (projected.hasError()) {
- projectError(projected, request.at(), request);
+ projectError(projected, request.under(), request);
return;
}
}
Modified:
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
---
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -382,30 +382,26 @@
@Override
public void process( CreateNodeRequest request ) {
- Path path = request.at().getPath();
- CheckArg.isNotNull(path, "request.at().getPath()");
+ Path parent = request.under().getPath();
+ CheckArg.isNotNull(parent, "request.under().getPath()");
Node node = null;
- if (!path.isRoot()) {
- Path parent = path.getParent();
- // Look up the parent node, which must exist ...
- Node parentNode = getNode(parent);
- if (parentNode == null) {
- Path lowestExisting = getLowestExistingPath(parent);
- throw new PathNotFoundException(request.at(), lowestExisting,
-
InMemoryConnectorI18n.nodeDoesNotExist.text(parent));
+ // Look up the parent node, which must exist ...
+ Node parentNode = getNode(parent);
+ if (parentNode == null) {
+ Path lowestExisting = getLowestExistingPath(parent);
+ throw new PathNotFoundException(request.under(), lowestExisting,
+
InMemoryConnectorI18n.nodeDoesNotExist.text(parent));
+ }
+ UUID uuid = null;
+ for (Property property : request.properties()) {
+ if (property.getName().equals(DnaLexicon.UUID)) {
+ uuid =
getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next());
+ break;
}
- UUID uuid = null;
- for (Property property : request.properties()) {
- if (property.getName().equals(DnaLexicon.UUID)) {
- uuid =
getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next());
- break;
- }
- }
- node = createNode(getExecutionContext(), parentNode,
path.getLastSegment().getName(), uuid);
- path =
getExecutionContext().getValueFactories().getPathFactory().create(parent,
node.getName());
- } else {
- node = getRoot();
}
+ node = createNode(getExecutionContext(), parentNode, request.named(), uuid);
+ assert node != null;
+ Path path =
getExecutionContext().getValueFactories().getPathFactory().create(parent,
node.getName());
// Now add the properties to the supplied node ...
for (Property property : request.properties()) {
Name propName = property.getName();
@@ -417,7 +413,6 @@
node.getProperties().put(propName, property);
}
}
- assert node != null;
request.setActualLocationOfNode(new Location(path, node.getUuid()));
}
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 2008-11-19
20:26:40 UTC (rev 642)
+++
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-11-20
19:15:17 UTC (rev 643)
@@ -195,18 +195,14 @@
@Override
public void process( CreateNodeRequest request ) {
- Path path = request.at().getPath();
- Path parent = path.getParent();
+ Path parent = request.under().getPath();
// Look up the parent node, which must exist ...
Node<Name, Object> parentNode = getNode(context, parent);
// 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
// the array of Path.Segment for the children (since the cache
doesn't maintain order).
- Path.Segment newSegment = updateChildList(parentNode,
-
path.getLastSegment().getName(),
- getExecutionContext(),
- true);
+ Path.Segment newSegment = updateChildList(parentNode, request.named(),
getExecutionContext(), true);
Node<Name, Object> node =
parentNode.addChild(Fqn.fromElements(newSegment));
assert checkChildren(parentNode);