DNA SVN: r388 - in trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation: executor and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 12:31:28 -0400 (Wed, 06 Aug 2008)
New Revision: 388
Added:
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added a unit test class.
Added: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java (rev 0)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java 2008-08-06 16:31:28 UTC (rev 388)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.federation.executor;
+
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class FederatingCommandExecutorTest {
+
+ @Test
+ public void shouldDoSomething() {
+
+ }
+
+}
Property changes on: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r387 - in trunk/connectors/dna-connector-jbosscache/src: test/java/org/jboss/dna/connector/jbosscache and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 01:49:04 -0400 (Wed, 06 Aug 2008)
New Revision: 387
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added more unit tests.
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 05:44:32 UTC (rev 386)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 05:49:04 UTC (rev 387)
@@ -224,7 +224,7 @@
try {
lock.lock();
// Determine if this name is allowed ...
- if (sources.containsKey(name)) return false;
+ if (name != null && sources.containsKey(name)) return false;
// Remove this object under its current name
if (this.name != null) {
@@ -232,7 +232,9 @@
}
// Register this object under the new name
this.name = name;
- sources.put(this.name, this);
+ if (this.name != null) {
+ sources.put(this.name, this);
+ }
return true;
} finally {
lock.unlock();
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-06 05:44:32 UTC (rev 386)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-06 05:49:04 UTC (rev 387)
@@ -63,17 +63,16 @@
@Test
public void shouldAllowSettingName() {
- source.setName("Something");
+ assertThat(source.setName("Something"), is(true));
assertThat(source.getName(), is("Something"));
- source.setName("another name");
+ assertThat(source.setName("another name"), is(true));
assertThat(source.getName(), is("another name"));
}
@Test
- public void shouldAllowSettingNameToNull() {
- source.setName("some name");
- source.setName(null);
+ public void shouldNotAllowSettingNameToNull() {
+ assertThat(source.setName("some name"), is(true));
+ assertThat(source.setName(null), is(true));
assertThat(source.getName(), is(nullValue()));
}
-
}
15 years, 10 months
DNA SVN: r386 - in trunk/connectors/dna-connector-jbosscache/src: test/java/org/jboss/dna/connector/jbosscache and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 01:44:32 -0400 (Wed, 06 Aug 2008)
New Revision: 386
Added:
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added more unit tests.
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-06 05:43:44 UTC (rev 385)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-06 05:44:32 UTC (rev 386)
@@ -218,6 +218,8 @@
Node<Name, Object> newParent,
boolean recursive,
Name uuidProperty ) {
+ assert original != null;
+ assert newParent != null;
// Get or create the new node ...
Segment name = (Segment)original.getFqn().getLastElement();
Node<Name, Object> copy = newParent.addChild(getFullyQualifiedName(name));
Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2008-08-06 05:43:44 UTC (rev 385)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2008-08-06 05:44:32 UTC (rev 386)
@@ -22,6 +22,7 @@
package org.jboss.dna.connector.jbosscache;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.core.IsSame.sameInstance;
@@ -215,6 +216,7 @@
@Test
public void shouldGetNodeIfItExistsInCache() {
// Set up the cache with data ...
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
Name uuidProperty = connection.getUuidPropertyName(context);
Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
Path nonExistantPath = pathFactory.create("/a/d");
@@ -239,6 +241,7 @@
@Test
public void shouldThrowExceptionWithLowestExistingNodeFromGetNodeIfTheNodeDoesNotExist() {
// Set up the cache with data ...
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
Name uuidProperty = connection.getUuidPropertyName(context);
Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
Path nonExistantPath = pathFactory.create("/a/d");
@@ -262,4 +265,46 @@
}
}
+ @Test
+ public void shouldCopyNode() {
+ // Set up the cache with data ...
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ Name uuidProperty = connection.getUuidPropertyName(context);
+ Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c"),
+ pathFactory.create("/a/d")};
+ UUID[] uuids = {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ cache.put(Fqn.fromList(paths[0].getSegmentsList()), uuidProperty, uuids[0]);
+ cache.put(Fqn.fromList(paths[1].getSegmentsList()), uuidProperty, uuids[1]);
+ cache.put(Fqn.fromList(paths[2].getSegmentsList()), uuidProperty, uuids[2]);
+ cache.put(Fqn.fromList(paths[3].getSegmentsList()), uuidProperty, uuids[3]);
+ Node<Name, Object> nodeA = cache.getNode(Fqn.fromList(paths[0].getSegmentsList()));
+ Node<Name, Object> nodeB = cache.getNode(Fqn.fromList(paths[1].getSegmentsList()));
+ Node<Name, Object> nodeC = cache.getNode(Fqn.fromList(paths[2].getSegmentsList()));
+ Node<Name, Object> nodeD = cache.getNode(Fqn.fromList(paths[3].getSegmentsList()));
+ assertThat(nodeA, is(notNullValue()));
+ assertThat(nodeB, is(notNullValue()));
+ assertThat(nodeC, is(notNullValue()));
+ assertThat(nodeD, is(notNullValue()));
+ assertThat(nodeA.get(uuidProperty), is((Object)uuids[0]));
+ assertThat(nodeB.get(uuidProperty), is((Object)uuids[1]));
+ assertThat(nodeC.get(uuidProperty), is((Object)uuids[2]));
+ assertThat(nodeD.get(uuidProperty), is((Object)uuids[3]));
+ // Make sure the new nodes doesn't exist
+ Path newPathB = pathFactory.create("/a/d/b");
+ Path newPathC = pathFactory.create("/a/d/b/c");
+ Node<Name, Object> newNodeB = cache.getNode(Fqn.fromList(newPathB.getSegmentsList()));
+ Node<Name, Object> newNodeC = cache.getNode(Fqn.fromList(newPathC.getSegmentsList()));
+ assertThat(newNodeB, is(nullValue()));
+ assertThat(newNodeC, is(nullValue()));
+ // Copy node B and place under node D
+ assertThat(connection.copyNode(nodeB, nodeD, true, uuidProperty), is(2));
+ newNodeB = cache.getNode(Fqn.fromList(newPathB.getSegmentsList()));
+ newNodeC = cache.getNode(Fqn.fromList(newPathC.getSegmentsList()));
+ assertThat(newNodeB, is(notNullValue()));
+ assertThat(newNodeC, is(notNullValue()));
+ // Make sure the UUIDs are new ...
+ assertThat(newNodeB.get(uuidProperty), is(not(nodeB.get(uuidProperty))));
+ assertThat(newNodeC.get(uuidProperty), is(not(nodeC.get(uuidProperty))));
+ }
+
}
Added: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java 2008-08-06 05:44:32 UTC (rev 386)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.jbosscache;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class JBossCacheSourceTest {
+
+ private JBossCacheSource source;
+
+ @Before
+ public void beforeEach() throws Exception {
+ source = new JBossCacheSource();
+ }
+
+ @Test
+ public void shouldReturnNonNullCapabilities() {
+ assertThat(source.getCapabilities(), is(notNullValue()));
+ }
+
+ @Test
+ public void shouldSupportSameNameSiblings() {
+ assertThat(source.getCapabilities().supportsSameNameSiblings(), is(true));
+ }
+
+ @Test
+ public void shouldSupportUpdates() {
+ assertThat(source.getCapabilities().supportsUpdates(), is(true));
+ }
+
+ @Test
+ public void shouldHaveNullSourceNameUponConstruction() {
+ source = new JBossCacheSource();
+ assertThat(source.getName(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingName() {
+ source.setName("Something");
+ assertThat(source.getName(), is("Something"));
+ source.setName("another name");
+ assertThat(source.getName(), is("another name"));
+ }
+
+ @Test
+ public void shouldAllowSettingNameToNull() {
+ source.setName("some name");
+ source.setName(null);
+ assertThat(source.getName(), is(nullValue()));
+ }
+
+}
Property changes on: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r385 - trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 01:43:44 -0400 (Wed, 06 Aug 2008)
New Revision: 385
Modified:
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Added methods to test the capabilities of the FederatedRepositorySource.
Modified: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-06 05:37:35 UTC (rev 384)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-06 05:43:44 UTC (rev 385)
@@ -143,6 +143,21 @@
}
@Test
+ public void shouldReturnNonNullCapabilities() {
+ assertThat(source.getCapabilities(), is(notNullValue()));
+ }
+
+ @Test
+ public void shouldSupportSameNameSiblings() {
+ assertThat(source.getCapabilities().supportsSameNameSiblings(), is(true));
+ }
+
+ @Test
+ public void shouldSupportUpdates() {
+ assertThat(source.getCapabilities().supportsUpdates(), is(true));
+ }
+
+ @Test
public void shouldCreateConnectionsByAuthenticateUsingFederationRepository() throws Exception {
connection = source.getConnection();
assertThat(connection, is(notNullValue()));
15 years, 10 months
DNA SVN: r384 - in trunk: connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory and 3 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 01:37:35 -0400 (Wed, 06 Aug 2008)
New Revision: 384
Added:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceCapabilities.java
Modified:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Added the notion of capabilities to RepositorySource, and added to all RepositorySource implementations.
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -71,6 +71,7 @@
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories;
import org.jboss.dna.spi.graph.connection.RepositorySource;
+import org.jboss.dna.spi.graph.connection.RepositorySourceCapabilities;
import org.jboss.dna.spi.graph.connection.RepositorySourceException;
/**
@@ -955,4 +956,23 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.connection.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new Capabilities();
+ }
+
+ protected class Capabilities implements RepositorySourceCapabilities {
+ public boolean supportsSameNameSiblings() {
+ return true;
+ }
+
+ public boolean supportsUpdates() {
+ return true;
+ }
+ }
+
}
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -42,6 +42,7 @@
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.connection.AbstractRepositorySource;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositorySourceCapabilities;
import org.jboss.dna.spi.graph.connection.RepositorySourceException;
/**
@@ -260,4 +261,22 @@
return null;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.connection.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new Capabilities();
+ }
+
+ protected class Capabilities implements RepositorySourceCapabilities {
+ public boolean supportsSameNameSiblings() {
+ return true;
+ }
+
+ public boolean supportsUpdates() {
+ return true;
+ }
+ }
}
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -48,6 +48,7 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.connection.AbstractRepositorySource;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositorySourceCapabilities;
/**
* @author Randall Hauch
@@ -276,4 +277,22 @@
return null;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.connection.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new Capabilities();
+ }
+
+ protected class Capabilities implements RepositorySourceCapabilities {
+ public boolean supportsSameNameSiblings() {
+ return true;
+ }
+
+ public boolean supportsUpdates() {
+ return true;
+ }
+ }
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -65,4 +65,11 @@
*/
void setRetryLimit( int limit );
+ /**
+ * Get the capabilities for this source.
+ *
+ * @return the capabilities for this source; never null
+ */
+ RepositorySourceCapabilities getCapabilities();
+
}
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceCapabilities.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceCapabilities.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceCapabilities.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.spi.graph.connection;
+
+/**
+ * The capabilities of a {@link RepositorySource}.
+ *
+ * @author Randall Hauch
+ */
+public interface RepositorySourceCapabilities {
+
+ /**
+ * Return whether the source supports same name siblings. If not, then no two siblings may share the same name.
+ *
+ * @return true if same name siblings are supported, or false otherwise
+ */
+ boolean supportsSameNameSiblings();
+
+ /**
+ * Return whether the source supports updates.
+ *
+ * @return true if updates are supported, or false if the source only supports reads.
+ */
+ boolean supportsUpdates();
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceCapabilities.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -127,6 +127,25 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.connection.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new Capabilities();
+ }
+
+ protected class Capabilities implements RepositorySourceCapabilities {
+ public boolean supportsSameNameSiblings() {
+ return true;
+ }
+
+ public boolean supportsUpdates() {
+ return true;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.connection.AbstractRepositorySource#createConnection()
*/
@Override
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-08-06 04:59:59 UTC (rev 383)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-08-06 05:37:35 UTC (rev 384)
@@ -190,6 +190,25 @@
throw new UnsupportedOperationException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.connection.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new Capabilities();
+ }
+
+ protected class Capabilities implements RepositorySourceCapabilities {
+ public boolean supportsSameNameSiblings() {
+ return true;
+ }
+
+ public boolean supportsUpdates() {
+ return true;
+ }
+ }
+
public class Connection implements RepositoryConnection {
private final String connectionName;
15 years, 10 months
DNA SVN: r383 - in trunk/connectors/dna-connector-jbosscache: src/main/java/org/jboss/dna/connector/jbosscache and 7 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 00:59:59 -0400 (Wed, 06 Aug 2008)
New Revision: 383
Added:
trunk/connectors/dna-connector-jbosscache/src/test/java/org/
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/
trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
trunk/connectors/dna-connector-jbosscache/src/test/resources/log4j.properties
Modified:
trunk/connectors/dna-connector-jbosscache/pom.xml
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added some unit tests for JBossCacheConnection, and upgraded the version of JBoss Cache from 2.2.0CR6 to 2.2.0CR7.
Modified: trunk/connectors/dna-connector-jbosscache/pom.xml
===================================================================
--- trunk/connectors/dna-connector-jbosscache/pom.xml 2008-08-06 04:58:23 UTC (rev 382)
+++ trunk/connectors/dna-connector-jbosscache/pom.xml 2008-08-06 04:59:59 UTC (rev 383)
@@ -53,7 +53,7 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.2.0.CR6</version>
+ <version>2.2.0.CR7</version>
</dependency>
<!--
Testing (note the scope)
@@ -63,8 +63,8 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
</dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-06 04:58:23 UTC (rev 382)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-06 04:59:59 UTC (rev 383)
@@ -33,6 +33,7 @@
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.graph.PathNotFoundException;
@@ -87,13 +88,6 @@
}
/**
- * @return uuidPropertyName
- */
- public Name getUuidPropertyName() {
- return this.uuidPropertyName;
- }
-
- /**
* {@inheritDoc}
*/
public String getSourceName() {
@@ -164,15 +158,17 @@
* @param context the execution context
* @return the name, or null if the UUID should not be stored
*/
- protected Name getUuidProperty( ExecutionContext context ) {
+ protected Name getUuidPropertyName( ExecutionContext context ) {
if (!initializedUuidPropertyName) {
- this.uuidPropertyName = this.source.getUuidPropertyName(context.getValueFactories().getNameFactory());
+ NameFactory nameFactory = context.getValueFactories().getNameFactory();
+ this.uuidPropertyName = nameFactory.create(this.source.getUuidPropertyName());
initializedUuidPropertyName = true;
}
return this.uuidPropertyName;
}
protected Fqn<Path.Segment> getFullyQualifiedName( Path path ) {
+ assert path != null;
return Fqn.fromList(path.getSegmentsList());
}
@@ -183,16 +179,13 @@
* @return the relative fully-qualified name
*/
protected Fqn<Path.Segment> getFullyQualifiedName( Path.Segment pathSegment ) {
+ assert pathSegment != null;
return Fqn.fromElements(pathSegment);
}
protected Path getPath( PathFactory factory,
Fqn<Path.Segment> fqn ) {
- Path.Segment[] segments = new Path.Segment[fqn.size()];
- for (int i = 0; i != segments.length; ++i) {
- segments[i] = fqn.get(i);
- }
- return factory.create(factory.createRootPath(), segments);
+ return factory.create(factory.createRootPath(), fqn.peekElements());
}
protected Node<Name, Object> getNode( ExecutionContext context,
@@ -232,7 +225,7 @@
copy.clearData();
copy.putAll(original.getData());
if (uuidProperty != null) {
- // Generate a new UUID for the new node ...
+ // Generate a new UUID for the new node, overwriting any existing value from the original ...
copy.put(uuidProperty, generateUuid());
}
int numNodesCopied = 1;
@@ -266,7 +259,7 @@
Node<Name, Object> parentNode = getNode(parent);
Node<Name, Object> node = parentNode.addChild(childFqn);
// Add the UUID property (if required), which may be overwritten by a supplied property ...
- Name uuidPropertyName = getUuidProperty(getExecutionContext());
+ Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
if (uuidPropertyName != null) {
node.put(uuidPropertyName, generateUuid());
}
@@ -287,7 +280,7 @@
@Override
public void execute( GetChildrenCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
- Name uuidPropertyName = getUuidPropertyName();
+ Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
// Get the names of the children ...
for (Node<Name, Object> child : node.getChildren()) {
Segment segment = (Segment)child.getFqn().getLastElement();
@@ -363,7 +356,7 @@
public void execute( MoveBranchCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
boolean recursive = true;
- Name uuidProperty = getUuidProperty(getExecutionContext());
+ Name uuidProperty = getUuidPropertyName(getExecutionContext());
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
Node<Name, Object> newParent = getNode(newPath.getAncestor());
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 04:58:23 UTC (rev 382)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 04:59:59 UTC (rev 383)
@@ -46,7 +46,6 @@
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.connection.AbstractRepositorySource;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
@@ -252,18 +251,6 @@
}
/**
- * Utility method to obtain a consistent {@link Name} for the property that should store the UUID value on each node. This
- * method is properly coded so that it is threadsafe.
- *
- * @param factory the name factory; may not be null
- * @return the property name, or null if UUIDs are not to be maintained
- */
- /* package */synchronized Name getUuidPropertyName( NameFactory factory ) {
- if (this.uuidPropertyName.length() == 0) return null;
- return factory.create(this.uuidPropertyName);
- }
-
- /**
* {@inheritDoc}
*/
public Reference getReference() {
Added: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2008-08-06 04:59:59 UTC (rev 383)
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.jbosscache;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.PathNotFoundException;
+import org.jboss.dna.spi.graph.connection.BasicExecutionContext;
+import org.jboss.dna.spi.graph.connection.RepositorySourceListener;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class JBossCacheConnectionTest {
+
+ private JBossCacheConnection connection;
+ private CacheFactory<Name, Object> cacheFactory;
+ private Cache<Name, Object> cache;
+ private ExecutionContext context;
+ private PathFactory pathFactory;
+ @Mock
+ private JBossCacheSource source;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+ pathFactory = context.getValueFactories().getPathFactory();
+ cacheFactory = new DefaultCacheFactory<Name, Object>();
+ cache = cacheFactory.createCache();
+ connection = new JBossCacheConnection(source, cache);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailToInstantiateIfCacheReferenceIsNull() {
+ cache = null;
+ connection = new JBossCacheConnection(source, cache);
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailToInstantiateIfSourceReferenceIsNull() {
+ source = null;
+ connection = new JBossCacheConnection(source, cache);
+ }
+
+ @Test
+ public void shouldInstantiateWithValidSourceAndCacheReferences() {
+ assertThat(connection, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldDelegateToTheSourceForTheConnectionsSourceName() {
+ stub(source.getName()).toReturn("the source name");
+ assertThat(connection.getSourceName(), is("the source name"));
+ verify(source).getName();
+ }
+
+ @Test
+ public void shouldDelegateToTheSourceForTheConnectionsDefaultCachePolicy() {
+ CachePolicy policy = mock(CachePolicy.class);
+ stub(source.getDefaultCachePolicy()).toReturn(policy);
+ assertThat(connection.getDefaultCachePolicy(), is(sameInstance(policy)));
+ verify(source).getDefaultCachePolicy();
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Test
+ public void shouldGetTheRootFromTheCacheWhenPinged() {
+ cache = mock(Cache.class);
+ connection = new JBossCacheConnection(source, cache);
+ stub(cache.getRoot()).toReturn(null);
+ assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
+ verify(cache).getRoot();
+ }
+
+ @Test
+ public void shouldHaveNoOpListenerWhenCreated() {
+ assertThat(connection.getListener(), is(sameInstance(JBossCacheConnection.NO_OP_LISTENER)));
+ }
+
+ @Test
+ public void shouldUseNoOpListenerWhenSettingListenerToNull() {
+ connection.setListener(null);
+ assertThat(connection.getListener(), is(sameInstance(JBossCacheConnection.NO_OP_LISTENER)));
+ }
+
+ @Test
+ public void shouldSetListenerToNonNullValue() {
+ RepositorySourceListener listener = mock(RepositorySourceListener.class);
+ connection.setListener(listener);
+ assertThat(connection.getListener(), is(sameInstance(listener)));
+ connection.setListener(null);
+ assertThat(connection.getListener(), is(sameInstance(JBossCacheConnection.NO_OP_LISTENER)));
+ }
+
+ @Test
+ public void shouldGetUuidPropertyNameFromSouceAndShouldNotChangeDuringLifetimeOfConnection() {
+ stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+ Name name = connection.getUuidPropertyName(context);
+ verify(source).getUuidPropertyName();
+ assertThat(name.getLocalName(), is("uuid"));
+ assertThat(name.getNamespaceUri(), is(DnaLexicon.NAMESPACE_URI));
+ stub(source.getUuidPropertyName()).toReturn("something else");
+ for (int i = 0; i != 10; ++i) {
+ Name name2 = connection.getUuidPropertyName(context);
+ assertThat(name2, is(sameInstance(name)));
+ }
+ verifyNoMoreInteractions(source);
+ }
+
+ @Test
+ public void shouldGenerateUuid() {
+ for (int i = 0; i != 100; ++i) {
+ assertThat(connection.generateUuid(), is(notNullValue()));
+ }
+ }
+
+ @Test
+ public void shouldCreateFullyQualifiedNodeOfPathSegmentsFromPath() {
+ Path path = pathFactory.create("/a/b/c/d");
+ Fqn<Path.Segment> fqn = connection.getFullyQualifiedName(path);
+ assertThat(fqn.size(), is(4));
+ assertThat(fqn.isRoot(), is(false));
+ for (int i = 0; i != path.size(); ++i) {
+ assertThat(fqn.get(i), is(path.getSegment(i)));
+ }
+ }
+
+ @Test
+ public void shouldCreateFullyQualifiedNodeOfPathSegmentsFromRootPath() {
+ Path path = pathFactory.createRootPath();
+ Fqn<Path.Segment> fqn = connection.getFullyQualifiedName(path);
+ assertThat(fqn.size(), is(0));
+ assertThat(fqn.isRoot(), is(true));
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailToCreateFullyQualifiedNodeFromNullPath() {
+ connection.getFullyQualifiedName((Path)null);
+ }
+
+ @Test
+ public void shouldCreateFullyQualifiedNodeFromPathSegment() {
+ Path.Segment segment = pathFactory.createSegment("a");
+ Fqn<Path.Segment> fqn = connection.getFullyQualifiedName(segment);
+ assertThat(fqn.size(), is(1));
+ assertThat(fqn.isRoot(), is(false));
+ assertThat(fqn.get(0), is(segment));
+ }
+
+ @Test( expected = AssertionError.class )
+ public void shouldFailToCreateFullyQualifiedNodeFromNullPathSegment() {
+ connection.getFullyQualifiedName((Path.Segment)null);
+ }
+
+ @Test
+ public void shouldCreatePathFromFullyQualifiedNode() {
+ Path path = pathFactory.create("/a/b/c/d");
+ Fqn<Path.Segment> fqn = connection.getFullyQualifiedName(path);
+ assertThat(connection.getPath(pathFactory, fqn), is(path));
+ }
+
+ @Test
+ public void shouldCreateRootPathFromRootFullyQualifiedNode() {
+ Path path = pathFactory.createRootPath();
+ Fqn<Path.Segment> fqn = connection.getFullyQualifiedName(path);
+ assertThat(connection.getPath(pathFactory, fqn), is(path));
+ }
+
+ @Test
+ public void shouldGetNodeIfItExistsInCache() {
+ // Set up the cache with data ...
+ Name uuidProperty = connection.getUuidPropertyName(context);
+ Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
+ Path nonExistantPath = pathFactory.create("/a/d");
+ UUID[] uuids = {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ cache.put(Fqn.fromList(paths[0].getSegmentsList()), uuidProperty, uuids[0]);
+ cache.put(Fqn.fromList(paths[1].getSegmentsList()), uuidProperty, uuids[1]);
+ cache.put(Fqn.fromList(paths[2].getSegmentsList()), uuidProperty, uuids[2]);
+ Node<Name, Object> nodeA = cache.getNode(Fqn.fromList(paths[0].getSegmentsList()));
+ Node<Name, Object> nodeB = cache.getNode(Fqn.fromList(paths[1].getSegmentsList()));
+ Node<Name, Object> nodeC = cache.getNode(Fqn.fromList(paths[2].getSegmentsList()));
+ Node<Name, Object> nodeD = cache.getNode(Fqn.fromList(nonExistantPath.getSegmentsList()));
+ assertThat(nodeA, is(notNullValue()));
+ assertThat(nodeB, is(notNullValue()));
+ assertThat(nodeC, is(notNullValue()));
+ assertThat(nodeD, is(nullValue()));
+ // Test the getNode(...) method for existing nodes ...
+ assertThat(connection.getNode(context, paths[0]), is(sameInstance(nodeA)));
+ assertThat(connection.getNode(context, paths[1]), is(sameInstance(nodeB)));
+ assertThat(connection.getNode(context, paths[2]), is(sameInstance(nodeC)));
+ }
+
+ @Test
+ public void shouldThrowExceptionWithLowestExistingNodeFromGetNodeIfTheNodeDoesNotExist() {
+ // Set up the cache with data ...
+ Name uuidProperty = connection.getUuidPropertyName(context);
+ Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
+ Path nonExistantPath = pathFactory.create("/a/d");
+ UUID[] uuids = {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ cache.put(Fqn.fromList(paths[0].getSegmentsList()), uuidProperty, uuids[0]);
+ cache.put(Fqn.fromList(paths[1].getSegmentsList()), uuidProperty, uuids[1]);
+ cache.put(Fqn.fromList(paths[2].getSegmentsList()), uuidProperty, uuids[2]);
+ Node<Name, Object> nodeA = cache.getNode(Fqn.fromList(paths[0].getSegmentsList()));
+ Node<Name, Object> nodeB = cache.getNode(Fqn.fromList(paths[1].getSegmentsList()));
+ Node<Name, Object> nodeC = cache.getNode(Fqn.fromList(paths[2].getSegmentsList()));
+ Node<Name, Object> nodeD = cache.getNode(Fqn.fromList(nonExistantPath.getSegmentsList()));
+ assertThat(nodeA, is(notNullValue()));
+ assertThat(nodeB, is(notNullValue()));
+ assertThat(nodeC, is(notNullValue()));
+ assertThat(nodeD, is(nullValue()));
+ try {
+ connection.getNode(context, nonExistantPath);
+ fail();
+ } catch (PathNotFoundException e) {
+ assertThat(e.getLowestAncestorThatDoesExist(), is(paths[0]));
+ }
+ }
+
+}
Property changes on: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/connectors/dna-connector-jbosscache/src/test/resources/log4j.properties
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/resources/log4j.properties (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/test/resources/log4j.properties 2008-08-06 04:59:59 UTC (rev 383)
@@ -0,0 +1,15 @@
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Set up the default logging to be INFO level, then override specific units
+log4j.logger.org.jboss.dna=INFO
+
+# JBoss Cache logging
+log4j.logger.org.jboss.cache=WARN, stdout
+
Property changes on: trunk/connectors/dna-connector-jbosscache/src/test/resources/log4j.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r382 - in trunk: dna-spi/src/main/java/org/jboss/dna/spi/graph and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-06 00:58:23 -0400 (Wed, 06 Aug 2008)
New Revision: 382
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added new methods to the PathFactory that make it easier to create paths from segments. (Also changed the signature of one of the ArgCheck methods to use "Iterable<?>" rather than "Collection<?>".)
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-08-06 00:53:15 UTC (rev 381)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-08-06 04:58:23 UTC (rev 382)
@@ -631,7 +631,7 @@
* @param name The name of the argument
* @throws IllegalArgumentException If array is null or has null values
*/
- public static void containsNoNulls( Collection<?> argument,
+ public static void containsNoNulls( Iterable<?> argument,
String name ) {
isNotNull(argument, name);
int i = 0;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-08-06 00:53:15 UTC (rev 381)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-08-06 04:58:23 UTC (rev 382)
@@ -60,6 +60,16 @@
Path createAbsolutePath( Path.Segment... segments );
/**
+ * Create an absolute path with the supplied segments, in order. If no segments are provided, the result will be the root
+ * path.
+ *
+ * @param segments the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment is provided and if any of the supplied segments are null
+ */
+ Path createAbsolutePath( Iterable<Path.Segment> segments );
+
+ /**
* Create an empty relative path (i.e., equivalent to {@link #createRelativePath(Path.Segment...) createRelativePath}(
* {@link Path#SELF_SEGMENT})). Subsequent calls will always return the same instance.
*
@@ -87,6 +97,15 @@
Path createRelativePath( Path.Segment... segments );
/**
+ * Create a relative path with the supplied segments, in order. If no segments are provided, the result will be the root path.
+ *
+ * @param segments the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment is provided and if any of the supplied segments are null
+ */
+ Path createRelativePath( Iterable<Path.Segment> segments );
+
+ /**
* Create a path by appending the supplied relative path to the supplied parent path. The resulting path will be
* {@link Path#isAbsolute() absolute} if the supplied parent path is absolute.
*
@@ -136,6 +155,18 @@
Path.Segment... segments );
/**
+ * Create a path by appending the supplied names to the parent path. If no names are appended, the parent path is returned.
+ *
+ * @param parentPath the path that is to provide the basis for the new path
+ * @param segments the segments that are to be appended, in order, to the parent path
+ * @return the new path
+ * @throws IllegalArgumentException if the parent path reference is null, or if at least one segment name is provided and if
+ * any of the supplied segment names are null
+ */
+ Path create( Path parentPath,
+ Iterable<Path.Segment> segments );
+
+ /**
* Create a path by appending the supplied names to the parent path.
*
* @param parentPath the path that is to provide the basis for the new path
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-06 00:53:15 UTC (rev 381)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-06 04:58:23 UTC (rev 382)
@@ -53,7 +53,7 @@
public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
- protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
+ public static final Path SELF_PATH = new BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
private final List<Segment> segments;
private final boolean absolute;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-06 00:53:15 UTC (rev 381)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-06 04:58:23 UTC (rev 382)
@@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
@@ -281,6 +282,23 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#createAbsolutePath(java.lang.Iterable)
+ */
+ public Path createAbsolutePath( Iterable<Segment> segments ) {
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.ROOT;
+ return new BasicPath(segmentsList, true);
+ }
+
+ /**
* <p>
* {@inheritDoc}
* </p>
@@ -295,7 +313,7 @@
* {@inheritDoc}
*/
public Path createRelativePath( Name... segmentNames ) {
- if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+ if (segmentNames == null || segmentNames.length == 0) return BasicPath.SELF_PATH;
List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
for (Name segmentName : segmentNames) {
if (segmentName == null) {
@@ -310,7 +328,7 @@
* {@inheritDoc}
*/
public Path createRelativePath( Segment... segments ) {
- if (segments == null || segments.length == 0) return BasicPath.ROOT;
+ if (segments == null || segments.length == 0) return BasicPath.SELF_PATH;
List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
for (Segment segment : segments) {
if (segment == null) {
@@ -324,6 +342,23 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.PathFactory#createRelativePath(java.lang.Iterable)
+ */
+ public Path createRelativePath( Iterable<Segment> segments ) {
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.SELF_PATH;
+ return new BasicPath(segmentsList, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path, org.jboss.dna.spi.graph.Path)
*/
public Path create( Path parentPath,
@@ -398,6 +433,27 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path, java.lang.Iterable)
+ */
+ public Path create( Path parentPath,
+ Iterable<Segment> segments ) {
+ ArgCheck.isNotNull(parentPath, "parent path");
+
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ segmentsList.addAll(parentPath.getSegmentsList());
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.ROOT;
+ return new BasicPath(segmentsList, parentPath.isAbsolute());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path, java.lang.String)
*/
public Path create( Path parentPath,
15 years, 10 months
DNA SVN: r381 - in trunk: connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-05 20:53:15 -0400 (Tue, 05 Aug 2008)
New Revision: 381
Modified:
trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Minor changes to use the new DnaLexicon class in SPI for the DNA standard prefix and namespace URI.
Modified: trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -39,6 +39,7 @@
import javax.naming.Reference;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.ExecutionContextFactory;
import org.jboss.dna.spi.graph.connection.BasicExecutionContext;
@@ -87,7 +88,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
- context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna");
+ context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
executionContextFactoryJndiName = "context factory jndi name";
connectionFactoriesJndiName = "connection factories jndi name";
configurationSourceName = "configuration source name";
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -54,9 +54,6 @@
*/
private static final long serialVersionUID = 1L;
- public static final String DEFAULT_UUID_PROPERTY_NAMESPACE = "http://www.jboss.org/dna/connector/jbosscache";
- public static final String DEFAULT_UUID_PROPERTY_NAME = "uuid";
-
private static final ConcurrentMap<String, InMemoryRepositorySource> sources = new ConcurrentHashMap<String, InMemoryRepositorySource>();
private static final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -39,6 +39,7 @@
import org.jboss.dna.connector.federation.FederationException;
import org.jboss.dna.connector.federation.Projection;
import org.jboss.dna.repository.services.ServiceAdministrator;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
@@ -84,7 +85,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
NamespaceRegistry registry = new BasicNamespaceRegistry();
- registry.register("dna", "http://www.jboss.org/dna");
+ registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
valueFactories = new StandardValueFactories(registry);
pathFactory = valueFactories.getPathFactory();
propertyFactory = new BasicPropertyFactory(valueFactories);
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -25,6 +25,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.junit.Before;
@@ -45,9 +46,9 @@
@Before
public void beforeEach() {
- this.validNamespaceUri = "http://www.jboss.org/dna";
+ this.validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
+ this.validNamespaceUri = DnaLexicon.NAMESPACE_URI;
this.validLocalName = "localPart";
- this.validNamespacePrefix = "dna";
this.name = new BasicName(validNamespaceUri, validLocalName);
this.encoder = Path.URL_ENCODER;
this.namespaceRegistry = new BasicNamespaceRegistry();
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -24,6 +24,7 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.ValueFactory;
@@ -48,7 +49,7 @@
@Before
public void beforeEach() {
this.registry = new BasicNamespaceRegistry();
- this.registry.register("dna", "http://www.jboss.org/dna/namespace");
+ this.registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER, stringValueFactory);
this.validName = nameFactory.create("dna:something");
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-06 00:45:08 UTC (rev 380)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-08-06 00:53:15 UTC (rev 381)
@@ -32,6 +32,7 @@
import java.util.Iterator;
import java.util.List;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -59,8 +60,8 @@
@Before
public void beforeEach() {
- validNamespacePrefix = "dna";
- validNamespaceUri = "http://www.jboss.org/dna";
+ validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
+ validNamespaceUri = DnaLexicon.NAMESPACE_URI;
validSegmentNames = new Name[] {new BasicName(validNamespaceUri, "a"), new BasicName(validNamespaceUri, "b"),
new BasicName(validNamespaceUri, "c")};
validSegments = new Path.Segment[] {new BasicPathSegment(validSegmentNames[0]),
15 years, 10 months
DNA SVN: r380 - in trunk: connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge and 10 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-05 20:45:08 -0400 (Tue, 05 Aug 2008)
New Revision: 380
Added:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/UuidFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
Modified:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
trunk/connectors/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DelegatingValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepository.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
Log:
DNA-188 - Complete the federating command executor
http://jira.jboss.com/jira/browse/DNA-188
Needed to add the ability to get the identification properties (e.g., a UUID property) for each child. These properties are required when getting nodes from the original sources so that the merge logic can determine whether child nodes (from different sources) represent the same node or different nodes. These properties are also required in the Federation Connector to obtain the UUID property for each node in the integrated repository cache. The GetChildrenCommand was modified to remove most of the "setChildren(...)" methods and to instead have "addChild(Segment, Property)" methods. The existing connectors were modified to use this new capability.
To support storing UUIDs as properties, a UUID property type was added and a new UuidFactory (which extends ValueFactory<UUID>) interface was defined. Each existing factory interface (and implementation) was then modified to add a "create(UUID value)" method. All ValueFactories implementations were modified as well.
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -39,6 +39,7 @@
import org.jboss.dna.connector.federation.merge.MergeStrategy;
import org.jboss.dna.connector.federation.merge.OneContributionMergeStrategy;
import org.jboss.dna.connector.federation.merge.StandardMergeStrategy;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.DateTime;
@@ -58,7 +59,6 @@
import org.jboss.dna.spi.graph.commands.impl.BasicCreateNodeCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
-import org.jboss.dna.spi.graph.commands.impl.BasicGetPropertiesCommand;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories;
import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactory;
@@ -134,8 +134,8 @@
this.sourceProjections = sourceProjections;
this.connectionFactories = connectionFactories;
this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
- this.uuidPropertyName = context.getValueFactories().getNameFactory().create("dna:uuid");
- this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create("dna:mergePlan");
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
+ this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.MERGE_PLAN);
this.sourceNames = new HashSet<String>();
for (Projection projection : this.sourceProjections) {
this.sourceNames.add(projection.getSourceName());
@@ -143,7 +143,7 @@
if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
this.mergingStrategy = new OneContributionMergeStrategy();
} else {
- this.mergingStrategy = new StandardMergeStrategy();
+ this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.PropertyNames.UUID);
}
}
@@ -206,7 +206,9 @@
for (Property property : nodeInfo.getProperties().values()) {
command.setProperty(property);
}
- command.setChildren(nodeInfo.getChildren());
+ for (Segment child : nodeInfo.getChildren()) {
+ command.addChild(child, nodeInfo.getChildIdentityProperties(child));
+ }
}
/**
@@ -230,7 +232,9 @@
@Override
public void execute( GetChildrenCommand command ) throws RepositorySourceException, InterruptedException {
BasicGetNodeCommand nodeInfo = getNode(command.getPath());
- command.setChildren(nodeInfo.getChildren());
+ for (Segment child : nodeInfo.getChildren()) {
+ command.addChild(child, nodeInfo.getChildIdentityProperties(child));
+ }
}
/**
@@ -397,7 +401,7 @@
return mergedNode;
}
- protected MergePlan getMergePlan( BasicGetPropertiesCommand command ) {
+ protected MergePlan getMergePlan( BasicGetNodeCommand command ) {
Property mergePlanProperty = command.getProperties().get(mergePlanPropertyName);
if (mergePlanProperty == null || mergePlanProperty.isEmpty()) {
return null;
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,11 +21,10 @@
*/
package org.jboss.dna.connector.federation.executor;
-import java.util.Iterator;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.DateTime;
-import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
@@ -46,60 +45,17 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setChild(org.jboss.dna.spi.graph.Name)
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment,
+ * org.jboss.dna.spi.graph.Property[])
*/
- public void setChild( Name nameOfChild ) {
- getOriginalCommand().setChild(nameOfChild);
+ public void addChild( Segment nameOfChild,
+ Property... identityProperties ) {
+ getOriginalCommand().addChild(nameOfChild, identityProperties);
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setChildren(java.util.Iterator)
- */
- public void setChildren( Iterator<Segment> namesOfChildren ) {
- getOriginalCommand().setChildren(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setChildren(java.lang.Iterable)
- */
- public void setChildren( Iterable<Segment> namesOfChildren ) {
- getOriginalCommand().setChildren(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setChildren(org.jboss.dna.spi.graph.Path.Segment[])
- */
- public void setChildren( Segment... namesOfChildren ) {
- getOriginalCommand().setChildren(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
- */
- public void addChild( Segment nameOfChild ) {
- getOriginalCommand().addChild(nameOfChild);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
- */
- public void addChildren( Segment... namesOfChildren ) {
- getOriginalCommand().addChildren(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setNoChildren()
*/
public void setNoChildren() {
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -24,12 +24,21 @@
import java.util.List;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
/**
* @author Randall Hauch
*/
public class StandardMergeStrategy implements MergeStrategy {
+ private final String identityPropertyNameString;
+
+ public StandardMergeStrategy( String identityPropertyName ) {
+ assert identityPropertyName != null;
+ assert identityPropertyName.trim().length() != 0;
+ this.identityPropertyNameString = identityPropertyName;
+ }
+
/**
* {@inheritDoc}
*
@@ -39,5 +48,9 @@
public void merge( FederatedNode federatedNode,
List<Contribution> contributions,
ExecutionContext context ) {
+
+ // Children whose identity properties are the same will be considered to be the same node ...
+ Name identityPropertyName = context.getValueFactories().getNameFactory().create(this.identityPropertyNameString);
+ assert identityPropertyName != null;
}
}
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.connector.inmemory;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -31,6 +30,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -206,7 +206,7 @@
Path parentPath = path.getAncestor();
Node parentNode = getNode(parentPath);
Name name = path.getLastSegment().getName();
- return createNode(context, parentNode, name);
+ return createNode(context, parentNode, name, null);
}
/**
@@ -215,15 +215,18 @@
* @param context the execution context
* @param parentNode the parent node; may not be null
* @param name the name; may not be null
+ * @param uuid the UUID of the node, or null if the UUID is to be generated
* @return the new node
*/
public Node createNode( ExecutionContext context,
Node parentNode,
- Name name ) {
+ Name name,
+ UUID uuid ) {
assert context != null;
assert name != null;
if (parentNode == null) parentNode = getRoot();
- Node node = new Node(generateUuid());
+ if (uuid == null) uuid = generateUuid();
+ Node node = new Node(uuid);
nodesByUuid.put(node.getUuid(), node);
node.setParent(parentNode);
Path.Segment newName = context.getValueFactories().getPathFactory().createSegment(name);
@@ -297,7 +300,7 @@
assert original != null;
assert newParent != null;
// Get or create the new node ...
- Node copy = createNode(context, newParent, original.getName().getName());
+ Node copy = createNode(context, newParent, original.getName().getName(), null);
// Copy the properties ...
copy.getProperties().clear();
@@ -326,11 +329,18 @@
protected class Executor extends AbstractCommandExecutor {
+ private final Name uuidPropertyName;
+
protected Executor( ExecutionContext context,
String sourceName ) {
super(context, sourceName);
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
}
+ protected Property getUuidProperty( Node node ) {
+ return getExecutionContext().getPropertyFactory().create(uuidPropertyName, node.getUuid());
+ }
+
@Override
public void execute( CreateNodeCommand command ) {
Path path = command.getPath();
@@ -341,7 +351,14 @@
Path lowestExisting = getLowestExistingPath(parent);
throw new PathNotFoundException(path, lowestExisting, InMemoryConnectorI18n.nodeDoesNotExist.text(parent));
}
- Node node = createNode(getExecutionContext(), parentNode, path.getLastSegment().getName());
+ UUID uuid = null;
+ for (Property property : command.getPropertyIterator()) {
+ if (property.getName().equals(uuidPropertyName)) {
+ uuid = getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next());
+ break;
+ }
+ }
+ Node node = createNode(getExecutionContext(), parentNode, path.getLastSegment().getName(), uuid);
// Now add the properties to the supplied node ...
for (Property property : command.getPropertyIterator()) {
Name propName = property.getName();
@@ -349,7 +366,9 @@
node.getProperties().remove(propName);
continue;
}
- node.getProperties().put(propName, property);
+ if (!propName.equals(uuidPropertyName)) {
+ node.getProperties().put(propName, property);
+ }
}
assert node != null;
}
@@ -359,11 +378,10 @@
Node node = getTargetNode(command);
// Get the names of the children ...
List<Node> children = node.getChildren();
- List<Segment> childSegments = new ArrayList<Segment>(children.size());
for (Node child : children) {
- childSegments.add(child.getName());
+ Segment childName = child.getName();
+ command.addChild(childName, getUuidProperty(child));
}
- command.setChildren(childSegments);
}
@Override
@@ -372,6 +390,7 @@
for (Property property : node.getProperties().values()) {
command.setProperty(property);
}
+ command.setProperty(getUuidProperty(node));
}
@Override
@@ -384,7 +403,9 @@
node.getProperties().remove(propName);
continue;
}
- node.getProperties().put(propName, property);
+ if (!propName.equals(uuidPropertyName)) {
+ node.getProperties().put(propName, property);
+ }
}
}
Modified: trunk/connectors/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -153,21 +153,21 @@
@Test
public void shouldCreateNodesByPath() {
Name name_a = nameFactory.create("a");
- Node node_a = repository.createNode(context, repository.getRoot(), name_a);
+ Node node_a = repository.createNode(context, repository.getRoot(), name_a, null);
assertThat(node_a, is(notNullValue()));
assertThat(node_a.getParent(), is(repository.getRoot()));
assertThat(node_a.getName().getName(), is(name_a));
assertThat(node_a.getName().hasIndex(), is(false));
Name name_b = nameFactory.create("b");
- Node node_b = repository.createNode(context, node_a, name_b);
+ Node node_b = repository.createNode(context, node_a, name_b, null);
assertThat(node_b, is(notNullValue()));
assertThat(node_b.getParent(), is(node_a));
assertThat(node_b.getName().getName(), is(name_b));
assertThat(node_b.getName().hasIndex(), is(false));
Name name_c = nameFactory.create("c");
- Node node_c = repository.createNode(context, node_b, name_c);
+ Node node_c = repository.createNode(context, node_b, name_c, null);
assertThat(node_c, is(notNullValue()));
assertThat(node_c.getParent(), is(node_b));
assertThat(node_c.getName().getName(), is(name_c));
@@ -182,9 +182,9 @@
@Test
public void shouldNotFindNodesThatDoNotExist() {
- Node node_a = repository.createNode(context, repository.getRoot(), nameFactory.create("a"));
- Node node_b = repository.createNode(context, node_a, nameFactory.create("b"));
- /*Node node_c =*/repository.createNode(context, node_b, nameFactory.create("c"));
+ Node node_a = repository.createNode(context, repository.getRoot(), nameFactory.create("a"), null);
+ Node node_b = repository.createNode(context, node_a, nameFactory.create("b"), null);
+ /*Node node_c =*/repository.createNode(context, node_b, nameFactory.create("c"), null);
assertThat(repository.getNodesByUuid().size(), is(4));
assertThat(repository.getNode(pathFactory.create("/a[1]")), is(nullValue()));
@@ -194,14 +194,14 @@
@Test
public void shouldCorrectlyManageIndexesOfSiblingsWithSameNames() {
Name name_a1 = nameFactory.create("a");
- Node node_a1 = repository.createNode(context, repository.getRoot(), name_a1);
+ Node node_a1 = repository.createNode(context, repository.getRoot(), name_a1, null);
assertThat(node_a1, is(notNullValue()));
assertThat(node_a1.getParent(), is(repository.getRoot()));
assertThat(node_a1.getName().getName(), is(name_a1));
assertThat(node_a1.getName().hasIndex(), is(false));
Name name_a2 = nameFactory.create("a");
- Node node_a2 = repository.createNode(context, repository.getRoot(), name_a2);
+ Node node_a2 = repository.createNode(context, repository.getRoot(), name_a2, null);
assertThat(node_a2, is(notNullValue()));
assertThat(node_a2.getParent(), is(repository.getRoot()));
assertThat(node_a2.getName().getName(), is(name_a2));
@@ -213,7 +213,7 @@
// Add another node without the same name ...
Name name_b = nameFactory.create("b");
- Node node_b = repository.createNode(context, repository.getRoot(), name_b);
+ Node node_b = repository.createNode(context, repository.getRoot(), name_b, null);
assertThat(node_b, is(notNullValue()));
assertThat(node_b.getParent(), is(repository.getRoot()));
assertThat(node_b.getName().getName(), is(name_b));
@@ -221,7 +221,7 @@
// Add a third node with the same name ...
Name name_a3 = nameFactory.create("a");
- Node node_a3 = repository.createNode(context, repository.getRoot(), name_a3);
+ Node node_a3 = repository.createNode(context, repository.getRoot(), name_a3, null);
assertThat(node_a3, is(notNullValue()));
assertThat(node_a3.getParent(), is(repository.getRoot()));
assertThat(node_a3.getName().getName(), is(name_a3));
@@ -257,12 +257,12 @@
@Test
public void shouldMoveNodes() {
Node root = repository.getRoot();
- Node node_a = repository.createNode(context, root, nameFactory.create("a"));
- Node node_b = repository.createNode(context, node_a, nameFactory.create("b"));
- Node node_c = repository.createNode(context, node_b, nameFactory.create("c"));
- Node node_d = repository.createNode(context, root, nameFactory.create("d"));
- Node node_e = repository.createNode(context, node_d, nameFactory.create("e"));
- Node node_b2 = repository.createNode(context, node_d, nameFactory.create("b"));
+ Node node_a = repository.createNode(context, root, nameFactory.create("a"), null);
+ Node node_b = repository.createNode(context, node_a, nameFactory.create("b"), null);
+ Node node_c = repository.createNode(context, node_b, nameFactory.create("c"), null);
+ Node node_d = repository.createNode(context, root, nameFactory.create("d"), null);
+ Node node_e = repository.createNode(context, node_d, nameFactory.create("e"), null);
+ Node node_b2 = repository.createNode(context, node_d, nameFactory.create("b"), null);
assertThat(repository.getNodesByUuid().size(), is(7));
assertThat(repository.getNode(pathFactory.create("/")), is(sameInstance(repository.getRoot())));
@@ -297,12 +297,12 @@
@Test
public void shouldCopyNodes() {
Node root = repository.getRoot();
- Node node_a = repository.createNode(context, root, nameFactory.create("a"));
- Node node_b = repository.createNode(context, node_a, nameFactory.create("b"));
- Node node_c = repository.createNode(context, node_b, nameFactory.create("c"));
- Node node_d = repository.createNode(context, root, nameFactory.create("d"));
- Node node_e = repository.createNode(context, node_d, nameFactory.create("e"));
- Node node_b2 = repository.createNode(context, node_d, nameFactory.create("b"));
+ Node node_a = repository.createNode(context, root, nameFactory.create("a"), null);
+ Node node_b = repository.createNode(context, node_a, nameFactory.create("b"), null);
+ Node node_c = repository.createNode(context, node_b, nameFactory.create("c"), null);
+ Node node_d = repository.createNode(context, root, nameFactory.create("d"), null);
+ Node node_e = repository.createNode(context, node_d, nameFactory.create("e"), null);
+ Node node_b2 = repository.createNode(context, node_d, nameFactory.create("b"), null);
ValueFactory<String> stringFactory = valueFactories.getStringFactory();
Name propertyName = nameFactory.create("something");
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.connector.jbosscache;
-import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -39,6 +38,7 @@
import org.jboss.dna.spi.graph.PathNotFoundException;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.ValueFactory;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
@@ -248,11 +248,13 @@
protected class Executor extends AbstractCommandExecutor {
private final PropertyFactory propertyFactory;
+ private final ValueFactory<UUID> uuidFactory;
protected Executor( ExecutionContext context,
String sourceName ) {
super(context, sourceName);
this.propertyFactory = context.getPropertyFactory();
+ this.uuidFactory = context.getValueFactories().getUuidFactory();
}
@Override
@@ -285,12 +287,20 @@
@Override
public void execute( GetChildrenCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
+ Name uuidPropertyName = getUuidPropertyName();
// Get the names of the children ...
- List<Segment> childSegments = new ArrayList<Segment>();
for (Node<Name, Object> child : node.getChildren()) {
- childSegments.add((Segment)child.getFqn().getLastElement());
+ Segment segment = (Segment)child.getFqn().getLastElement();
+ Object uuid = node.getData().get(uuidPropertyName);
+ if (uuid == null) {
+ uuid = generateUuid();
+ node.getData().put(uuidPropertyName, uuid);
+ } else {
+ uuid = uuidFactory.create(uuid);
+ }
+ Property uuidProperty = propertyFactory.create(uuidPropertyName, uuid);
+ command.addChild(segment, uuidProperty);
}
- command.setChildren(childSegments);
}
@Override
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -43,6 +43,7 @@
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
@@ -55,11 +56,8 @@
@ThreadSafe
public class JBossCacheSource extends AbstractRepositorySource implements ObjectFactory {
- /**
- */
- private static final long serialVersionUID = 1530716494560375111L;
- public static final String DEFAULT_UUID_PROPERTY_NAMESPACE = "http://www.jboss.org/dna/connector/jbosscache";
- public static final String DEFAULT_UUID_PROPERTY_NAME = "uuid";
+ private static final long serialVersionUID = 1L;
+ public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
private static final ConcurrentMap<String, JBossCacheSource> sources = new ConcurrentHashMap<String, JBossCacheSource>();
private static final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
@@ -103,7 +101,6 @@
private CachePolicy defaultCachePolicy;
private String cacheConfigurationName;
private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
- private String uuidPropertyNamespaceUri = DEFAULT_UUID_PROPERTY_NAMESPACE;
private transient Cache<Name, Object> cache;
/**
@@ -157,20 +154,6 @@
}
/**
- * @return uuidPropertyNamespaceUri
- */
- public String getUuidPropertyNamespaceUri() {
- return this.uuidPropertyNamespaceUri;
- }
-
- /**
- * @param uuidPropertyNamespaceUri Sets uuidPropertyNamespaceUri to the specified value.
- */
- public synchronized void setUuidPropertyNamespaceUri( String uuidPropertyNamespaceUri ) {
- this.uuidPropertyNamespaceUri = uuidPropertyNamespaceUri != null ? uuidPropertyNamespaceUri.trim() : DEFAULT_UUID_PROPERTY_NAMESPACE;
- }
-
- /**
* If you use this to set a JNDI name, this source will be bound to that name using the default {@link InitialContext}. You
* can also do this manually if you have additional requirements.
*
@@ -276,8 +259,8 @@
* @return the property name, or null if UUIDs are not to be maintained
*/
/* package */synchronized Name getUuidPropertyName( NameFactory factory ) {
- if (this.uuidPropertyName.length() == 0 && this.uuidPropertyNamespaceUri.length() == 0) return null;
- return factory.create(this.uuidPropertyNamespaceUri, this.uuidPropertyName);
+ if (this.uuidPropertyName.length() == 0) return null;
+ return factory.create(this.uuidPropertyName);
}
/**
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.spi;
+
+/**
+ * @author Randall Hauch
+ */
+public class DnaLexicon {
+
+ public static final String NAMESPACE_URI = "http://www.jboss.org/dna";
+ public static final String NAMESPACE_PREFIX = "dna";
+
+ public static class PropertyNames {
+ public static final String UUID = "dna:uuid";
+ public static final String MERGE_PLAN = "dna:mergePlan";
+ }
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -28,6 +28,7 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.SpiI18n;
@@ -47,6 +48,7 @@
BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, Boolean.class),
NAME("Name", ValueComparators.NAME_COMPARATOR, Name.class),
PATH("Path", ValueComparators.PATH_COMPARATOR, Path.class),
+ UUID("UUID", ValueComparators.UUID_COMPARATOR, UUID.class),
REFERENCE("Reference", ValueComparators.REFERENCE_COMPARATOR, Reference.class),
URI("URI", ValueComparators.URI_COMPARATOR, URI.class),
OBJECT("Object", ValueComparators.OBJECT_COMPARATOR, Object.class);
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/UuidFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/UuidFactory.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/UuidFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.spi.graph;
+
+import java.util.UUID;
+
+/**
+ * A factory for creating {@link UUID UUID instances}. This interface extends the {@link ValueFactory} generic interface and adds
+ * specific methods for creating UUIDs.
+ *
+ * @author Randall Hauch
+ */
+public interface UuidFactory extends ValueFactory<UUID> {
+
+ /**
+ * Create a new random UUID.
+ *
+ * @return the new randomly generated UUID
+ */
+ UUID create();
+
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/UuidFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -28,6 +28,7 @@
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
+import java.util.UUID;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.impl.StringValueFactory;
@@ -247,6 +248,19 @@
}
};
/**
+ * A comparator of UUID values.
+ */
+ public static final Comparator<UUID> UUID_COMPARATOR = new Comparator<UUID>() {
+
+ public int compare( UUID o1,
+ UUID o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
* A comparator of reference values.
*/
public static final Comparator<Reference> REFERENCE_COMPARATOR = new Comparator<Reference>() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -26,12 +26,14 @@
/**
* The set of standard {@link ValueFactory} instances.
+ *
* @author Randall Hauch
*/
public interface ValueFactories extends Iterable<ValueFactory<?>> {
/**
* Get the value factory that creates values of the supplied {@link PropertyType type}.
+ *
* @param type the type for the values
* @return the factory; never null
* @throws IllegalArgumentException if the property type is null
@@ -40,6 +42,7 @@
/**
* Get the value factory that is best able to create values with the most natural type given by the supplied value.
+ *
* @param prototype the value that should be used to determine the best value factory
* @return the factory; never null
* @throws IllegalArgumentException if the prototype value is null
@@ -48,72 +51,91 @@
/**
* Get the value factory for {@link PropertyType#STRING string} properties.
+ *
* @return the factory; never null
*/
ValueFactory<String> getStringFactory();
/**
* Get the value factory for {@link PropertyType#BINARY binary} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Binary> getBinaryFactory();
/**
* Get the value factory for {@link PropertyType#LONG long} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Long> getLongFactory();
/**
* Get the value factory for {@link PropertyType#DOUBLE double} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Double> getDoubleFactory();
/**
* Get the value factory for {@link PropertyType#DECIMAL decimal} properties.
+ *
* @return the factory; never null
*/
ValueFactory<BigDecimal> getDecimalFactory();
/**
* Get the value factory for {@link PropertyType#DATE date} properties.
+ *
* @return the factory; never null
*/
DateTimeFactory getDateFactory();
/**
* Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Boolean> getBooleanFactory();
/**
* Get the value factory for {@link PropertyType#NAME name} properties.
+ *
* @return the factory; never null
*/
NameFactory getNameFactory();
/**
* Get the value factory for {@link PropertyType#REFERENCE reference} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Reference> getReferenceFactory();
/**
* Get the value factory for {@link PropertyType#PATH path} properties.
+ *
* @return the factory; never null
*/
PathFactory getPathFactory();
/**
* Get the value factory for {@link PropertyType#URI URI} properties.
+ *
* @return the factory; never null
*/
ValueFactory<URI> getUriFactory();
/**
+ * Get the value factory for {@link PropertyType#UUID UUID} properties.
+ *
+ * @return the factory; never null
+ */
+ UuidFactory getUuidFactory();
+
+ /**
* Get the value factory for {@link PropertyType#OBJECT object} properties.
+ *
* @return the factory; never null
*/
ValueFactory<Object> getObjectFactory();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -28,6 +28,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
@@ -187,6 +188,15 @@
T create( URI value ) throws IoException;
/**
+ * Create a value from a UUID.
+ *
+ * @param value the UUID from which the value is to be created
+ * @return the value, or null if the supplied URI is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T create( UUID value ) throws IoException;
+
+ /**
* Create a value from the binary content given by the supplied array.
*
* @param value the content to be used to create the value
@@ -218,9 +228,9 @@
int approximateLength ) throws IoException;
/**
- * Create a value from the specified information by determining which other <code>create</code> method applies and
- * delegating to that method. Note that this method only will call <code>create</code> methods that take a single parameter;
- * so this excludes {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * Create a value from the specified information by determining which other <code>create</code> method applies and delegating
+ * to that method. Note that this method only will call <code>create</code> methods that take a single parameter; so this
+ * excludes {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
*
* @param value the value
* @return the new value, or null if the supplied parameter is null
@@ -359,6 +369,15 @@
T[] create( URI[] values ) throws IoException;
/**
+ * Create an array of values from an array of UUIDs.
+ *
+ * @param values the UUIDs from which the values are to be created
+ * @return the values, or null if the supplied array is null
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ */
+ T[] create( UUID[] values ) throws IoException;
+
+ /**
* Create an array of values from the array of binary content.
*
* @param values the array of content to be used to create the values
@@ -368,9 +387,9 @@
T[] create( byte[][] values ) throws IoException;
/**
- * Create an array of values from the specified information by determining which other <code>create</code> method applies
- * for each object and then delegating to that method. Note that this method will not consider
- * {@link #create(InputStream, int)}, {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
+ * Create an array of values from the specified information by determining which other <code>create</code> method applies for
+ * each object and then delegating to that method. Note that this method will not consider {@link #create(InputStream, int)},
+ * {@link #create(Reader, int)} and {@link #create(String, TextDecoder)}.
*
* @param values the values
* @return the new value, or null if the supplied parameter is null
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,10 +21,9 @@
*/
package org.jboss.dna.spi.graph.commands;
-import java.util.Iterator;
import org.jboss.dna.spi.cache.Cacheable;
-import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
/**
* A command to get the children of a single node given its path.
@@ -34,74 +33,17 @@
public interface GetChildrenCommand extends GraphCommand, ActsOnPath, Cacheable {
/**
- * Set the children of this node using an iterator of names. Any existing child references already set on this command will be
- * replaced by those supplied to this method.
- * <p>
- * The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
- * </p>
- * <p>
- * The caller may supply a custom iterator implementation, which will be called on this same connection within the same
- * transaction when the node data is processed and consumed. This is useful, for example, if the iterator to transparently
- * page through the information without requiring all children to be pulled into memory.
- * </p>
- *
- * @param namesOfChildren the iterator over the names of children; may be null if there are no children
- */
- void setChildren( Iterator<Path.Segment> namesOfChildren );
-
- /**
- * Set the children of this node using an iterator of names. Any existing child references already set on this command will be
- * replaced by those supplied to this method.
- * <p>
- * The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
- * </p>
- * <p>
- * The caller may supply a custom {@link Iterable} implementation, which will be called on this same connection within the
- * same transaction when the node data is processed and consumed. This is useful, for example, if the iterator to
- * transparently page through the information without requiring all children to be pulled into memory.
- * </p>
- *
- * @param namesOfChildren the iterable names of children; may be null if there are no children
- */
- void setChildren( Iterable<Path.Segment> namesOfChildren );
-
- /**
- * Set the children of this node using the array of names. Any existing child references already set on this command will be
- * replaced by those supplied to this method.
- * <p>
- * The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
- * </p>
- *
- * @param namesOfChildren the names of children; may be null if there are no children
- */
- void setChildren( Path.Segment... namesOfChildren );
-
- /**
- * Set the child of this node using the supplied name. Any existing child references already set on this command will be
- * replaced by those supplied to this method. Note that a {@link Path.Segment segment} is not required in this case because
- * there is only one child and (by definition) no index.
- *
- * @param nameOfChild the name of the only child
- */
- void setChild( Name nameOfChild );
-
- /**
* Add the child to this node. This method does not affect existing children, so callers of this method should not add a child
* with the same segment as an existing child (this is not checked by this method).
*
* @param nameOfChild the name of the child; should not be the same as an existing child (not checked)
+ * @param identityProperties the property/properties that are considered identity properties (other than the name) for the
+ * child
*/
- void addChild( Path.Segment nameOfChild );
+ void addChild( Path.Segment nameOfChild,
+ Property... identityProperties );
/**
- * Adds the children to this node. This method does not affect existing children, so callers of this method should not add
- * children with the same segment as existing children (this is not checked by this method).
- *
- * @param namesOfChildren the names of the new children; these should not be the same as any other children
- */
- void addChildren( Path.Segment... namesOfChildren );
-
- /**
* Set that this node has no children. Any existing child references already set on this command will be removed.
*/
void setNoChildren();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,15 +21,16 @@
*/
package org.jboss.dna.spi.graph.commands.impl;
-import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.DateTime;
-import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
@@ -42,7 +43,8 @@
/**
*/
private static final long serialVersionUID = -8515194602506918337L;
- private List<Segment> children;
+ private final Map<Segment, Property[]> childProperties = new HashMap<Segment, Property[]>();
+ private final List<Segment> children = new LinkedList<Segment>();
private final Path path;
private CachePolicy cachePolicy;
private DateTime timeLoaded;
@@ -59,56 +61,34 @@
/**
* {@inheritDoc}
*/
- public void setChild( Name nameOfChild ) {
- children = createChildrenList(nameOfChild);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setChildren( Iterator<Segment> namesOfChildren ) {
- children = createChildrenList(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setChildren( Iterable<Segment> namesOfChildren ) {
- children = createChildrenList(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setChildren( Segment... namesOfChildren ) {
- children = createChildrenList(namesOfChildren);
- }
-
- /**
- * {@inheritDoc}
- */
public void setNoChildren() {
- children = Collections.emptyList();
+ this.children.clear();
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment,
+ * org.jboss.dna.spi.graph.Property[])
*/
- public void addChild( Segment nameOfChild ) {
- if (nameOfChild != null) this.children.add(nameOfChild);
+ public void addChild( Segment nameOfChild,
+ Property... identityProperties ) {
+ if (nameOfChild == null) return;
+ this.children.add(nameOfChild);
+ if (identityProperties != null) {
+ if (identityProperties.length == 0) identityProperties = null;
+ this.childProperties.put(nameOfChild, identityProperties);
+ }
}
/**
- * {@inheritDoc}
+ * Get the identity properties for the supplied child.
*
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
+ * @param child the name of the child
+ * @return the array of identity properties for the child, or null if there are none
*/
- public void addChildren( Segment... namesOfChildren ) {
- for (Segment nameOfChild : namesOfChildren) {
- if (nameOfChild != null) this.children.add(nameOfChild);
- }
+ public Property[] getChildIdentityProperties( Segment child ) {
+ return this.childProperties.get(child);
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -21,29 +21,24 @@
*/
package org.jboss.dna.spi.graph.commands.impl;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
-import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.GetNodeCommand;
-import org.jboss.dna.spi.graph.impl.BasicPathSegment;
/**
* @author Randall Hauch
*/
@NotThreadSafe
-public class BasicGetNodeCommand extends BasicGetPropertiesCommand implements GetNodeCommand {
+public class BasicGetNodeCommand extends BasicGetChildrenCommand implements GetNodeCommand {
- /**
- */
private static final long serialVersionUID = 5355669032301356873L;
- private List<Segment> children;
+ private final Map<Name, Property> properties = new HashMap<Name, Property>();
/**
* @param path
@@ -54,95 +49,34 @@
}
/**
- * @return children
- */
- public List<Segment> getChildren() {
- return children;
- }
-
- /**
* {@inheritDoc}
*/
- public void setChild( Name nameOfChild ) {
- if (nameOfChild == null) {
- children = Collections.emptyList();
- } else {
- children = Collections.singletonList((Segment)new BasicPathSegment(nameOfChild));
+ public void setProperty( Property property ) {
+ if (property != null) {
+ properties.put(property.getName(), property);
}
}
- /**
- * {@inheritDoc}
- */
- public void setChildren( Iterator<Segment> namesOfChildren ) {
- if (namesOfChildren == null) {
- children = Collections.emptyList();
- } else {
- children = new ArrayList<Segment>();
- while (namesOfChildren.hasNext()) {
- Segment childSegment = namesOfChildren.next();
- if (childSegment != null) children.add(childSegment);
- }
- }
+ public void setProperties( Map<Name, Property> properties ) {
+ this.properties.clear();
+ if (properties != null) this.properties.putAll(properties);
}
/**
- * {@inheritDoc}
- */
- public void setChildren( Iterable<Segment> namesOfChildren ) {
- if (namesOfChildren == null) {
- children = Collections.emptyList();
- } else {
- children = new ArrayList<Segment>();
- for (Segment childSegment : namesOfChildren) {
- if (childSegment != null) children.add(childSegment);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void setChildren( Segment... namesOfChildren ) {
- if (namesOfChildren == null || namesOfChildren.length == 0) {
- children = Collections.emptyList();
- } else {
- children = new ArrayList<Segment>();
- for (Segment childSegment : namesOfChildren) {
- if (childSegment != null) children.add(childSegment);
- }
- }
- }
-
- /**
- * {@inheritDoc}
+ * Get the property values that were added to the command
*
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
+ * @return the map of property name to values
*/
- public void addChild( Segment nameOfChild ) {
- if (nameOfChild != null) this.children.add(nameOfChild);
+ public Iterable<Property> getPropertyIterator() {
+ return this.properties.values();
}
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
- */
- public void addChildren( Segment... namesOfChildren ) {
- for (Segment nameOfChild : namesOfChildren) {
- if (nameOfChild != null) this.children.add(nameOfChild);
- }
+ public Map<Name, Property> getProperties() {
+ return this.properties;
}
/**
* {@inheritDoc}
- */
- public void setNoChildren() {
- children = Collections.emptyList();
- }
-
- /**
- * {@inheritDoc}
*
* @see java.lang.Object#toString()
*/
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactories.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -78,6 +78,8 @@
return getStringFactory();
case URI:
return getUriFactory();
+ case UUID:
+ return getUuidFactory();
}
return getObjectFactory();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,9 +27,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -327,4 +329,19 @@
return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID[])
+ */
+ public T[] create( UUID[] values ) throws IoException {
+ if (values == null) return null;
+ final int length = values.length;
+ T[] result = createEmptyArray(length);
+ for (int i = 0; i != length; ++i) {
+ result[i] = create(values[i]);
+ }
+ return result;
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,9 +27,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -175,7 +177,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Boolean create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Boolean create( byte[] value ) {
// First create a string and then create the boolean from the string value ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,9 +27,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -171,7 +173,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public BigDecimal create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public BigDecimal create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DelegatingValueFactories.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DelegatingValueFactories.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DelegatingValueFactories.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -28,6 +28,7 @@
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.ValueFactories;
import org.jboss.dna.spi.graph.ValueFactory;
@@ -91,4 +92,8 @@
return delegate.getUriFactory();
}
+ public UuidFactory getUuidFactory() {
+ return delegate.getUuidFactory();
+ }
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,9 +27,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -178,7 +180,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Double create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Double create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -29,17 +29,18 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
-import org.jboss.dna.spi.graph.IoException;
/**
* Teh standard {@link ValueFactory} for {@link PropertyType#BINARY} values.
@@ -178,7 +179,17 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Binary create( UUID value ) throws IoException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Binary create( byte[] value ) {
return new InMemoryBinary(value);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,11 +27,13 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.DateTimeFactory;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -175,7 +177,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public DateTime create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public DateTime create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,9 +27,11 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -172,7 +174,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Long create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Long create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,12 +27,14 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceException;
@@ -263,7 +265,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Name create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Name create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -27,6 +27,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -164,7 +165,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Object create( UUID value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object create( byte[] value ) {
return getBinaryValueFactory().create(value);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -29,11 +29,13 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
+import java.util.UUID;
import java.util.regex.Pattern;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -504,7 +506,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Path create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Path create( byte[] value ) {
// First attempt to create a string from the value, then a long from the string ...
return create(getStringValueFactory().create(value));
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.ValueFactory;
/**
@@ -58,6 +59,7 @@
private final PathFactory pathFactory;
private final ValueFactory<Reference> referenceFactory;
private final ValueFactory<URI> uriFactory;
+ private final UuidFactory uuidFactory;
private final ValueFactory<Object> objectFactory;
private final NamespaceRegistry namespaceRegistry;
@@ -113,6 +115,7 @@
this.pathFactory = (PathFactory)getFactory(factories, new PathValueFactory(this.decoder, this.stringFactory,
this.nameFactory));
this.referenceFactory = getFactory(factories, new UuidReferenceValueFactory(this.decoder, this.stringFactory));
+ this.uuidFactory = (UuidFactory)getFactory(factories, new UuidValueFactory(this.decoder, this.stringFactory));
this.uriFactory = getFactory(factories, new UriValueFactory(this.namespaceRegistry, this.decoder, this.stringFactory));
this.objectFactory = getFactory(factories, new ObjectValueFactory(this.decoder, this.stringFactory, this.binaryFactory));
}
@@ -222,7 +225,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactories#getUuidFactory()
*/
+ public UuidFactory getUuidFactory() {
+ return this.uuidFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ValueFactory<Object> getObjectFactory() {
return this.objectFactory;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -29,18 +29,19 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
-import org.jboss.dna.spi.graph.IoException;
/**
* The standard {@link ValueFactory} for {@link PropertyType#STRING} values.
@@ -185,7 +186,17 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public String create( UUID value ) throws IoException {
+ if (value == null) return null;
+ return value.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String create( byte[] value ) {
if (value == null) return null;
try {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -28,10 +28,12 @@
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
@@ -183,7 +185,18 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public URI create( UUID value ) throws IoException {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ UUID.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public URI create( URI value ) {
return value;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -31,6 +31,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -174,7 +175,16 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
*/
+ public Reference create( UUID value ) throws IoException {
+ return new UuidReference(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Reference create( URI value ) {
throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(),
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -0,0 +1,244 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.spi.graph.impl;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextDecoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.IoException;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.UuidFactory;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#URI} values.
+ *
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+@Immutable
+public class UuidValueFactory extends AbstractValueFactory<UUID> implements UuidFactory {
+
+ public UuidValueFactory( TextDecoder decoder,
+ ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.UUID, decoder, stringValueFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.UuidFactory#create()
+ */
+ public UUID create() {
+ return UUID.randomUUID();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( String value ) {
+ if (value == null) return null;
+ value = value.trim();
+ try {
+ return UUID.fromString(value);
+ } catch (IllegalArgumentException err) {
+ throw new IllegalArgumentException(SpiI18n.errorConvertingType.text(String.class.getSimpleName(),
+ URI.class.getSimpleName(),
+ value), err);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( String value,
+ TextDecoder decoder ) {
+ // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+ return create(getDecoder(decoder).decode(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( int value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( long value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( boolean value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( float value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( double value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( BigDecimal value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Calendar value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Date value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Date.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Name value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Path value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Reference value ) {
+ if (value instanceof UuidReference) {
+ UuidReference ref = (UuidReference)value;
+ return ref.getUuid();
+ }
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( URI value ) {
+ throw new UnsupportedOperationException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
+ Reference.class.getSimpleName(),
+ value));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.UUID)
+ */
+ public UUID create( UUID value ) throws IoException {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( byte[] value ) {
+ // First attempt to create a string from the value, then a long from the string ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( InputStream stream,
+ int approximateLength ) {
+ // First attempt to create a string from the value, then a double from the string ...
+ return create(getStringValueFactory().create(stream, approximateLength));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UUID create( Reader reader,
+ int approximateLength ) {
+ // First attempt to create a string from the value, then a double from the string ...
+ return create(getStringValueFactory().create(reader, approximateLength));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected UUID[] createEmptyArray( int length ) {
+ return new UUID[length];
+ }
+
+}
Property changes on: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepository.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepository.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -25,9 +25,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
@@ -50,6 +52,8 @@
@ThreadSafe
public class SimpleRepository {
+ public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
+
private static final ConcurrentMap<String, SimpleRepository> repositoriesByName = new ConcurrentHashMap<String, SimpleRepository>();
public static SimpleRepository get( String name ) {
@@ -64,6 +68,7 @@
private ConcurrentMap<Path, Map<Name, Property>> data = new ConcurrentHashMap<Path, Map<Name, Property>>();
private final String repositoryName;
+ private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
private boolean shutdown = false;
public SimpleRepository( String repositoryName ) {
@@ -81,6 +86,21 @@
}
/**
+ * @return uuidPropertyName
+ */
+ public String getUuidPropertyName() {
+ return uuidPropertyName;
+ }
+
+ /**
+ * @param uuidPropertyName Sets uuidPropertyName to the specified value.
+ */
+ public void setUuidPropertyName( String uuidPropertyName ) {
+ if (uuidPropertyName == null || uuidPropertyName.trim().length() == 0) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
+ this.uuidPropertyName = uuidPropertyName;
+ }
+
+ /**
* Get the current modifiable map of property data
*
* @return data
@@ -133,6 +153,10 @@
ancestorPath = ancestorPath.getAncestor();
}
data.putIfAbsent(pathObj, new HashMap<Name, Property>());
+ Name uuidName = context.getValueFactories().getNameFactory().create(this.getUuidPropertyName());
+ UUID uuid = context.getValueFactories().getUuidFactory().create();
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ data.get(pathObj).put(uuidProperty.getName(), uuidProperty);
return this;
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/SimpleRepositorySource.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -35,10 +35,11 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
-import org.jboss.dna.spi.graph.commands.CompositeCommand;
import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
+import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
/**
* A {@link RepositorySource} for a {@link SimpleRepository simple repository}.
@@ -163,61 +164,19 @@
* org.jboss.dna.spi.graph.commands.GraphCommand[])
*/
public void execute( ExecutionContext context,
- GraphCommand... commands ) throws RepositorySourceException {
+ GraphCommand... commands ) throws RepositorySourceException, InterruptedException {
assert context != null;
if (repository.isShutdown()) {
throw new RepositorySourceException(getName(), "The repository \"" + repository.getRepositoryName()
+ "\" is no longer available");
}
+ // Now execute the commands ...
+ CommandExecutor executor = new Executor(this.repository, context, this.getSourceName());
for (GraphCommand command : commands) {
- executeCommand(context, command);
+ executor.execute(command);
}
}
- protected void executeCommand( ExecutionContext context,
- GraphCommand command ) {
- if (command == null) return;
- if (command instanceof CompositeCommand) {
- CompositeCommand composite = (CompositeCommand)command;
- for (GraphCommand nestedCommand : composite) {
- executeCommand(context, nestedCommand);
- }
- }
- Map<Path, Map<Name, Property>> data = repository.getData();
- // Only commands we recognize are the following; everything else is ignored ...
- if (command instanceof GetPropertiesCommand) { // super of GetNodeCommand
- GetPropertiesCommand getProperties = (GetPropertiesCommand)command;
- Path targetPath = getProperties.getPath();
- Map<Name, Property> properties = data.get(targetPath);
- if (properties == null) {
- getProperties.setError(new InvalidPathException("Non-existant node: " + targetPath));
- return;
- }
- for (Property property : properties.values()) {
- getProperties.setProperty(property);
- }
- }
- if (command instanceof GetChildrenCommand) { // super of GetNodeCommand
- GetChildrenCommand getChildren = (GetChildrenCommand)command;
- Path targetPath = getChildren.getPath();
- if (data.get(targetPath) == null) {
- getChildren.setError(new InvalidPathException("Non-existant node: " + targetPath));
- return;
- }
- // Iterate through all of the properties, looking for any paths that are children of the path ...
- List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
- for (Path path : data.keySet()) {
- if (path.getAncestor().equals(targetPath)) {
- childSegments.add(path.getLastSegment());
- }
- }
- // This does not store children order, so sort ...
- Collections.sort(childSegments);
- getChildren.setChildren(childSegments);
- }
-
- }
-
/**
* {@inheritDoc}
*
@@ -273,4 +232,66 @@
}
+ protected class Executor extends AbstractCommandExecutor {
+ private final SimpleRepository repository;
+ private final Name uuidPropertyName;
+
+ protected Executor( SimpleRepository repository,
+ ExecutionContext context,
+ String sourceName ) {
+ super(context, sourceName);
+ this.repository = repository;
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create(this.repository.getUuidPropertyName());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.GetChildrenCommand)
+ */
+ @Override
+ public void execute( GetChildrenCommand command ) throws RepositorySourceException {
+ Path targetPath = command.getPath();
+ Map<Path, Map<Name, Property>> data = repository.getData();
+ if (data.get(targetPath) == null) {
+ command.setError(new InvalidPathException("Non-existant node: " + targetPath));
+ return;
+ }
+ // Iterate through all of the properties, looking for any paths that are children of the path ...
+ List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
+ for (Path path : data.keySet()) {
+ if (path.getAncestor().equals(targetPath)) {
+ childSegments.add(path.getLastSegment());
+ }
+ }
+ // This does not store children order, so sort ...
+ Collections.sort(childSegments);
+ for (Path.Segment childSegment : childSegments) {
+ Map<Name, Property> properties = repository.getData().get(targetPath);
+ Property uuidProperty = properties.get(uuidPropertyName);
+ command.addChild(childSegment, uuidProperty);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.GetPropertiesCommand)
+ */
+ @Override
+ public void execute( GetPropertiesCommand command ) throws RepositorySourceException {
+ Path targetPath = command.getPath();
+ Map<Name, Property> properties = repository.getData().get(targetPath);
+ if (properties == null) {
+ command.setError(new InvalidPathException("Non-existant node: " + targetPath));
+ return;
+ }
+ for (Property property : properties.values()) {
+ if (!property.getName().equals(this.uuidPropertyName)) {
+ command.setProperty(property);
+ }
+ }
+ }
+ }
+
}
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-05 21:05:45 UTC (rev 379)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -32,6 +32,7 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import java.util.UUID;
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.graph.Name;
@@ -113,6 +114,10 @@
return null;
}
+ public String create( UUID value ) {
+ return null;
+ }
+
public String create( byte[] value ) {
return null;
}
Added: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java (rev 0)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java 2008-08-06 00:45:08 UTC (rev 380)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.spi.graph.impl;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.UUID;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ * @author John Verhaeg
+ */
+public class UuidValueFactoryTest {
+
+ private UuidValueFactory factory;
+ private StringValueFactory stringFactory;
+ private UUID uuid;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ factory = new UuidValueFactory(Path.URL_DECODER, stringFactory);
+ uuid = UUID.randomUUID();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateDoubleFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test
+ public void shouldReturnUuidWhenCreatingFromUuid() {
+ assertThat(factory.create(uuid), is(sameInstance(uuid)));
+ }
+
+ @Test
+ public void shouldCreateUuidWithNoArguments() {
+ assertThat(factory.create(), is(instanceOf(UUID.class)));
+ }
+
+ @Test
+ public void shouldCreateUuidFromString() {
+ assertThat(factory.create(uuid.toString()), is(uuid));
+ }
+
+ @Test
+ public void shouldCreateUuidFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+ assertThat(factory.create(" " + uuid.toString() + " "), is(uuid));
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromIntegerValue() {
+ factory.create(1);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromLongValue() {
+ factory.create(1L);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromDoubleValue() {
+ factory.create(1.0d);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromFloatValue() {
+ factory.create(1.0f);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromCalendarValue() {
+ factory.create(Calendar.getInstance());
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromName() {
+ factory.create(mock(Name.class));
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromPath() {
+ factory.create(mock(Path.class));
+ }
+
+ @Test
+ public void shouldCreateUuidFromReference() {
+ UuidReference ref = new UuidReference(uuid);
+ assertThat(factory.create(ref), is(uuid));
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotCreateUuidFromUri() throws Exception {
+ factory.create(new URI("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateUuidFromByteArrayContainingUtf8EncodingOfStringWithUuid() throws Exception {
+ assertThat(factory.create(uuid.toString().getBytes("UTF-8")), is(uuid));
+ }
+
+ @Test
+ public void shouldCreateUuidFromInputStreamContainingUtf8EncodingOfStringWithUuid() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream(uuid.toString().getBytes("UTF-8"))), is(uuid));
+ }
+
+ @Test
+ public void shouldCreateUuidFromReaderContainingStringWithUuid() {
+ assertThat(factory.create(new StringReader(uuid.toString())), is(uuid));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotCreateUuidFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanUuid() throws Exception {
+ factory.create("something".getBytes("UTF-8"));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotCreateUuuidFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanUuuid() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotCreateUuuidFromReaderContainingStringWithContentsOtherThanUuuid() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+}
Property changes on: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/UuidValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 10 months
DNA SVN: r379 - in trunk: connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor and 9 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-08-05 17:05:45 -0400 (Tue, 05 Aug 2008)
New Revision: 379
Added:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
Removed:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/BasicFederatedNode.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
Modified:
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedCreateNodeCommand.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetPropertiesCommand.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedSetPropertiesCommand.java
trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutor.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutorTest.java
Log:
DNA-115 - Create federation service
http://jira.jboss.com/jira/browse/DNA-115
Renamed the "getEnvironment()" methods to "getExecutionContext()" to reflect the previous change in name of the ExecutionContext (was ExecutionEnvironment). Also renamed the "getProperties()" method of some of the SPI graph commands that returned an Iterator<Property> to now be "getPropertyIterator()", which is now consistent with the other graph commands. Made FederatedNode a concrete class (not an interface), moved it, and implemented additional interfaces so that it can be treated as a GetNodeCommand. Finally, made more changes to the FederationCommandExecutor implementation.
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -688,13 +688,13 @@
final String configurationSourceName = configurationProjection.getSourceName();
List<Projection> projections = Collections.singletonList(configurationProjection);
CommandExecutor executor = null;
- if (configurationProjection.getRules().size() == 1) {
+ if (configurationProjection.getRules().size() == 0) {
+ // There is no projection for the configuration repository, so just use a no-op executor
+ executor = new NoOpCommandExecutor(context, configurationSourceName);
+ } else if (configurationProjection.isSimple()) {
// There is just a single projection for the configuration repository, so just use an executor that
// translates the paths using the projection
executor = new SingleProjectionCommandExecutor(context, configurationSourceName, configurationProjection, factories);
- } else if (configurationProjection.getRules().size() == 0) {
- // There is no projection for the configuration repository, so just use a no-op executor
- executor = new NoOpCommandExecutor(context, configurationSourceName);
} else {
// The configuration repository has more than one projection, so we need to merge the results
executor = new FederatingCommandExecutor(context, configurationSourceName, projections, factories);
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -228,6 +228,7 @@
private final String sourceName;
private final List<Rule> rules;
+ private final boolean simple;
/**
* Create a new federated projection for the supplied source, using the supplied rules.
@@ -247,6 +248,7 @@
}
this.rules = Collections.unmodifiableList(rulesList);
ArgCheck.isNotEmpty(this.rules, "rules");
+ this.simple = computeSimpleProjection(this.rules);
}
/**
@@ -313,6 +315,39 @@
}
/**
+ * Determine whether this project is a simple projection that only involves for any one repository path no more than a single
+ * source path.
+ *
+ * @return true if this projection is a simple projection, or false if the projection is not simple (or it cannot be
+ * determined if it is simple)
+ */
+ public boolean isSimple() {
+ return simple;
+ }
+
+ protected boolean computeSimpleProjection( List<Rule> rules ) {
+ // Get the set of repository paths for the rules, and see if they overlap ...
+ Set<Path> repositoryPaths = new HashSet<Path>();
+ for (Rule rule : rules) {
+ if (rule instanceof PathRule) {
+ PathRule pathRule = (PathRule)rule;
+ Path repoPath = pathRule.getPathInRepository();
+ if (!repositoryPaths.isEmpty()) {
+ if (repositoryPaths.contains(repoPath)) return false;
+ for (Path path : repositoryPaths) {
+ if (path.isAtOrAbove(repoPath)) return false;
+ if (repoPath.isAtOrAbove(path)) return false;
+ }
+ }
+ repositoryPaths.add(repoPath);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* {@inheritDoc}
*
* @see java.lang.Object#hashCode()
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -29,11 +29,16 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.connector.federation.Projection;
import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
import org.jboss.dna.connector.federation.merge.MergePlan;
+import org.jboss.dna.connector.federation.merge.MergeStrategy;
+import org.jboss.dna.connector.federation.merge.OneContributionMergeStrategy;
+import org.jboss.dna.connector.federation.merge.StandardMergeStrategy;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.graph.DateTime;
@@ -51,6 +56,7 @@
import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
import org.jboss.dna.spi.graph.commands.impl.BasicCreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetPropertiesCommand;
import org.jboss.dna.spi.graph.connection.RepositoryConnection;
@@ -58,6 +64,7 @@
import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactory;
import org.jboss.dna.spi.graph.connection.RepositorySource;
import org.jboss.dna.spi.graph.connection.RepositorySourceException;
+import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
/**
* @author Randall Hauch
@@ -65,12 +72,14 @@
@NotThreadSafe
public class FederatingCommandExecutor extends AbstractCommandExecutor {
+ private final Name uuidPropertyName;
private final Name mergePlanPropertyName;
private final CachePolicy defaultCachePolicy;
private final Projection cacheProjection;
private final List<Projection> sourceProjections;
private final Set<String> sourceNames;
private final RepositoryConnectionFactories connectionFactories;
+ private final MergeStrategy mergingStrategy;
/** The set of all connections, including the cache connection */
private final Map<String, RepositoryConnection> connectionsBySourceName;
/** A direct reference to the cache connection */
@@ -125,11 +134,17 @@
this.sourceProjections = sourceProjections;
this.connectionFactories = connectionFactories;
this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
+ this.uuidPropertyName = context.getValueFactories().getNameFactory().create("dna:uuid");
this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create("dna:mergePlan");
this.sourceNames = new HashSet<String>();
for (Projection projection : this.sourceProjections) {
this.sourceNames.add(projection.getSourceName());
}
+ if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
+ this.mergingStrategy = new OneContributionMergeStrategy();
+ } else {
+ this.mergingStrategy = new StandardMergeStrategy();
+ }
}
/**
@@ -228,22 +243,52 @@
*/
protected BasicGetNodeCommand getNode( Path path ) throws RepositorySourceException, InterruptedException {
// Check the cache first ...
- final ExecutionContext context = getEnvironment();
+ final ExecutionContext context = getExecutionContext();
RepositoryConnection cacheConnection = getConnectionToCache();
BasicGetNodeCommand fromCache = new BasicGetNodeCommand(path);
cacheConnection.execute(context, fromCache);
if (fromCache.hasError()) {
if (fromCache.getError() instanceof PathNotFoundException) {
- // Start at the root and populate the cache down to this node ...
+ // The path was not found in the cache, so since we don't know whether the ancestors are federated
+ // from multiple source nodes, we need to populate the cache starting with the lowest ancestor
+ // that already exists in the cache.
+ PathNotFoundException notFound = (PathNotFoundException)fromCache.getError();
+ Path lowestExistingAncestor = notFound.getLowestAncestorThatDoesExist();
+ Path ancestor = path.getAncestor();
+
+ if (!ancestor.equals(lowestExistingAncestor)) {
+ // Create the commands that load the children (not properties) of the existing ancestor,
+ // then the children (not properties) of the child next on the desired path, etc.,
+ // down to (but excluding) the desired path.
+ LinkedList<BasicGetChildrenCommand> loadChildrenCommands = new LinkedList<BasicGetChildrenCommand>();
+ Path pathToLoad = path.getAncestor();
+ while (!pathToLoad.equals(lowestExistingAncestor)) {
+ BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathToLoad);
+ loadChildrenCommands.addFirst(command);
+ pathToLoad = pathToLoad.getAncestor();
+ }
+ // Now execute these commands (one-by-one is fine, since this is an executor) ...
+ for (BasicGetChildrenCommand command : loadChildrenCommands) {
+ execute(command);
+ }
+ }
+
+ // Load the node from the sources ...
+ FederatedNode mergedNode = loadFromSources(path);
+
+ // Place the results into the cache ...
+ updateCache(mergedNode);
+
+ // Return the results ...
+ return mergedNode;
}
+ return fromCache; // with an error
}
- if (fromCache.hasError()) return fromCache;
-
- // Look up the merge plan ...
+ // The cache had the node information, so look for the merge plan ...
MergePlan mergePlan = getMergePlan(fromCache);
- if (mergePlan != null) {
- if (isCurrent(path, mergePlan)) return fromCache;
+ assert mergePlan != null;
+ if (!isCurrent(path, mergePlan)) {
// Some of the merge plan is out of date, so we need to read the information from those regions that are expired ...
// MergePlan newMergePlan = new BasicMergePlan();
// for (Projection projection : sourceProjections) {
@@ -267,97 +312,89 @@
// }
// What about other (new) regions?
- } else {
- // At this point, there is no merge plan, so read information from the sources ...
- PathFactory pathFactory = context.getValueFactories().getPathFactory();
- DateTimeFactory timeFactory = context.getValueFactories().getDateFactory();
- List<Contribution> contributions = new LinkedList<Contribution>();
- for (Projection projection : this.sourceProjections) {
- final String source = projection.getSourceName();
- final RepositoryConnection sourceConnection = getConnection(projection);
- try {
- // Get the cached information ...
- CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
- if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
- DateTime expirationTime = null;
- if (cachePolicy != null) {
- expirationTime = timeFactory.create(getCurrentTimeInUtc(), cachePolicy.getTimeToLive());
- }
- // Get the paths-in-source where we should fetch node contributions ...
- Set<Path> pathsInSource = projection.getPathsInSource(path, pathFactory);
- if (pathsInSource.isEmpty()) {
- // The source has no contributions ...
- contributions.add(Contribution.create(source, expirationTime));
- } else {
- // There is at least one contribution ...
+ }
- // Get the contributions ...
- final int numPaths = pathsInSource.size();
- if (numPaths == 1) {
- Path pathInSource = pathsInSource.iterator().next();
- BasicGetNodeCommand fromSource = new BasicGetNodeCommand(pathInSource);
- sourceConnection.execute(getEnvironment(), fromSource);
- if (!fromSource.hasError()) {
- Collection<Property> properties = fromSource.getProperties().values();
- Collection<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- fromSource.getCachePolicy().getTimeToLive());
- Contribution contribution = Contribution.create(source,
- pathInSource,
- expTime,
- properties,
- children);
- contributions.add(contribution);
- }
- } else {
- BasicGetNodeCommand[] fromSourceCommands = new BasicGetNodeCommand[numPaths];
- int i = 0;
- for (Path pathInSource : pathsInSource) {
- fromSourceCommands[i++] = new BasicGetNodeCommand(pathInSource);
- }
- sourceConnection.execute(getEnvironment(), fromSourceCommands);
- for (BasicGetNodeCommand fromSource : fromSourceCommands) {
- if (fromSource.hasError()) continue;
- Collection<Property> properties = fromSource.getProperties().values();
- Collection<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
- fromSource.getCachePolicy().getTimeToLive());
- Contribution contribution = Contribution.create(source,
- fromSource.getPath(),
- expTime,
- properties,
- children);
- contributions.add(contribution);
- }
+ return fromCache;
+ }
+
+ /**
+ * @param path the path of the node that is to be loaded
+ * @return the federated node containing information loaded from the sources
+ * @throws InterruptedException
+ * @throws RepositorySourceException
+ */
+ protected FederatedNode loadFromSources( Path path ) throws RepositorySourceException, InterruptedException {
+ // At this point, there is no merge plan, so read information from the sources ...
+ ExecutionContext context = getExecutionContext();
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ DateTimeFactory timeFactory = context.getValueFactories().getDateFactory();
+ List<Contribution> contributions = new LinkedList<Contribution>();
+ for (Projection projection : this.sourceProjections) {
+ final String source = projection.getSourceName();
+ final RepositoryConnection sourceConnection = getConnection(projection);
+ try {
+ // Get the cached information ...
+ CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
+ if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
+ DateTime expirationTime = null;
+ if (cachePolicy != null) {
+ expirationTime = timeFactory.create(getCurrentTimeInUtc(), cachePolicy.getTimeToLive());
+ }
+ // Get the paths-in-source where we should fetch node contributions ...
+ Set<Path> pathsInSource = projection.getPathsInSource(path, pathFactory);
+ if (pathsInSource.isEmpty()) {
+ // The source has no contributions ...
+ contributions.add(Contribution.create(source, expirationTime));
+ } else {
+ // There is at least one contribution ...
+
+ // Get the contributions ...
+ final int numPaths = pathsInSource.size();
+ if (numPaths == 1) {
+ Path pathInSource = pathsInSource.iterator().next();
+ BasicGetNodeCommand fromSource = new BasicGetNodeCommand(pathInSource);
+ sourceConnection.execute(getExecutionContext(), fromSource);
+ if (!fromSource.hasError()) {
+ Collection<Property> properties = fromSource.getProperties().values();
+ Collection<Segment> children = fromSource.getChildren();
+ DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
+ fromSource.getCachePolicy().getTimeToLive());
+ Contribution contribution = Contribution.create(source, pathInSource, expTime, properties, children);
+ contributions.add(contribution);
}
+ } else {
+ BasicGetNodeCommand[] fromSourceCommands = new BasicGetNodeCommand[numPaths];
+ int i = 0;
+ for (Path pathInSource : pathsInSource) {
+ fromSourceCommands[i++] = new BasicGetNodeCommand(pathInSource);
+ }
+ sourceConnection.execute(context, fromSourceCommands);
+ for (BasicGetNodeCommand fromSource : fromSourceCommands) {
+ if (fromSource.hasError()) continue;
+ Collection<Property> properties = fromSource.getProperties().values();
+ Collection<Segment> children = fromSource.getChildren();
+ DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : timeFactory.create(getCurrentTimeInUtc(),
+ fromSource.getCachePolicy().getTimeToLive());
+ Contribution contribution = Contribution.create(source,
+ fromSource.getPath(),
+ expTime,
+ properties,
+ children);
+ contributions.add(contribution);
+ }
}
- } finally {
- sourceConnection.close();
}
+ } finally {
+ sourceConnection.close();
}
- // Merge the results into a single set of results ...
- mergePlan = MergePlan.create(contributions);
- BasicGetNodeCommand mergedNode = new BasicGetNodeCommand(null);
-
- // Place the results into the cache ...
- NodeConflictBehavior conflictBehavior = NodeConflictBehavior.UPDATE;
- BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, mergedNode.getProperties().values(),
- conflictBehavior);
- List<Segment> children = mergedNode.getChildren();
- GraphCommand[] intoCache = new GraphCommand[1 + children.size()];
- int i = 0;
- intoCache[i++] = newNode;
- List<Property> noProperties = Collections.emptyList();
- for (Segment child : mergedNode.getChildren()) {
- intoCache[i++] = new BasicCreateNodeCommand(pathFactory.create(path, child), noProperties, conflictBehavior);
- }
- cacheConnection.execute(getEnvironment(), mergedNode);
-
- // Return the results ...
- return mergedNode;
}
-
- return null;
+ // Merge the results into a single set of results ...
+ FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
+ mergingStrategy.merge(mergedNode, contributions, context);
+ if (mergedNode.getCachePolicy() == null) {
+ mergedNode.setCachePolicy(defaultCachePolicy);
+ }
+ return mergedNode;
}
protected MergePlan getMergePlan( BasicGetPropertiesCommand command ) {
@@ -369,6 +406,28 @@
return value instanceof MergePlan ? (MergePlan)value : null;
}
+ protected void updateCache( FederatedNode mergedNode ) throws RepositorySourceException, InterruptedException {
+ final ExecutionContext context = getExecutionContext();
+ final RepositoryConnection cacheConnection = getConnectionToCache();
+ final Path path = mergedNode.getPath();
+
+ NodeConflictBehavior conflictBehavior = NodeConflictBehavior.UPDATE;
+ BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, mergedNode.getProperties().values(), conflictBehavior);
+ newNode.setProperty(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+ List<Segment> children = mergedNode.getChildren();
+ GraphCommand[] intoCache = new GraphCommand[1 + children.size()];
+ int i = 0;
+ intoCache[i++] = newNode;
+ List<Property> noProperties = Collections.emptyList();
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ for (Segment child : mergedNode.getChildren()) {
+ newNode = new BasicCreateNodeCommand(pathFactory.create(path, child), noProperties, conflictBehavior);
+ // newNode.setProperty(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+ intoCache[i++] = newNode;
+ }
+ cacheConnection.execute(context, intoCache);
+ }
+
/**
* Determine if the supplied plan is considered current
*
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedCreateNodeCommand.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedCreateNodeCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedCreateNodeCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -48,10 +48,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.graph.commands.CreateNodeCommand#getProperties()
+ * @see org.jboss.dna.spi.graph.commands.CreateNodeCommand#getPropertyIterator()
*/
- public Iterable<Property> getProperties() {
- return getOriginalCommand().getProperties();
+ public Iterable<Property> getPropertyIterator() {
+ return getOriginalCommand().getPropertyIterator();
}
/**
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -23,6 +23,7 @@
import java.util.Iterator;
import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Path.Segment;
@@ -81,6 +82,24 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
+ */
+ public void addChild( Segment nameOfChild ) {
+ getOriginalCommand().addChild(nameOfChild);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
+ */
+ public void addChildren( Segment... namesOfChildren ) {
+ getOriginalCommand().addChildren(namesOfChildren);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#setNoChildren()
*/
public void setNoChildren() {
@@ -101,7 +120,7 @@
*
* @see org.jboss.dna.spi.cache.Cacheable#getTimeLoaded()
*/
- public long getTimeLoaded() {
+ public DateTime getTimeLoaded() {
return getOriginalCommand().getTimeLoaded();
}
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetPropertiesCommand.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetPropertiesCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedGetPropertiesCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -22,6 +22,7 @@
package org.jboss.dna.connector.federation.executor;
import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
@@ -55,7 +56,7 @@
*
* @see org.jboss.dna.spi.cache.Cacheable#getTimeLoaded()
*/
- public long getTimeLoaded() {
+ public DateTime getTimeLoaded() {
return getOriginalCommand().getTimeLoaded();
}
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedSetPropertiesCommand.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedSetPropertiesCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/ProjectedSetPropertiesCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -39,10 +39,10 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.spi.graph.commands.ActsOnProperties#getProperties()
+ * @see org.jboss.dna.spi.graph.commands.ActsOnProperties#getPropertyIterator()
*/
- public Iterable<Property> getProperties() {
- return getOriginalCommand().getProperties();
+ public Iterable<Property> getPropertyIterator() {
+ return getOriginalCommand().getPropertyIterator();
}
}
Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/SingleProjectionCommandExecutor.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -127,7 +127,7 @@
@Override
public void execute( GetChildrenCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedGetChildrenCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedGetChildrenCommand(command, pathInSource));
}
/**
@@ -138,7 +138,7 @@
@Override
public void execute( GetPropertiesCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedGetPropertiesCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedGetPropertiesCommand(command, pathInSource));
}
/**
@@ -149,7 +149,7 @@
@Override
public void execute( GetNodeCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedGetNodeCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedGetNodeCommand(command, pathInSource));
}
/**
@@ -160,7 +160,7 @@
@Override
public void execute( CreateNodeCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedCreateNodeCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedCreateNodeCommand(command, pathInSource));
}
/**
@@ -171,7 +171,7 @@
@Override
public void execute( SetPropertiesCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedSetPropertiesCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedSetPropertiesCommand(command, pathInSource));
}
/**
@@ -182,7 +182,7 @@
@Override
public void execute( DeleteBranchCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedDeleteBranchCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedDeleteBranchCommand(command, pathInSource));
}
/**
@@ -194,7 +194,7 @@
public void execute( MoveBranchCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
Path newPathInSource = getPathInSource(command.getNewPath());
- getConnection().execute(this.getEnvironment(), new ProjectedMoveBranchCommand(command, pathInSource, newPathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedMoveBranchCommand(command, pathInSource, newPathInSource));
}
/**
@@ -205,7 +205,7 @@
@Override
public void execute( RecordBranchCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
- getConnection().execute(this.getEnvironment(), new ProjectedRecordBranchCommand(command, pathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedRecordBranchCommand(command, pathInSource));
}
/**
@@ -217,7 +217,7 @@
public void execute( CopyBranchCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
Path newPathInSource = getPathInSource(command.getNewPath());
- getConnection().execute(this.getEnvironment(), new ProjectedCopyBranchCommand(command, pathInSource, newPathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedCopyBranchCommand(command, pathInSource, newPathInSource));
}
/**
@@ -229,7 +229,7 @@
public void execute( CopyNodeCommand command ) throws RepositorySourceException, InterruptedException {
Path pathInSource = getPathInSource(command.getPath());
Path newPathInSource = getPathInSource(command.getNewPath());
- getConnection().execute(this.getEnvironment(), new ProjectedCopyNodeCommand(command, pathInSource, newPathInSource));
+ getConnection().execute(this.getExecutionContext(), new ProjectedCopyNodeCommand(command, pathInSource, newPathInSource));
}
protected Path getPathInSource( Path pathInRepository ) {
Deleted: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/BasicFederatedNode.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/BasicFederatedNode.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/BasicFederatedNode.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -1,148 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.
- *
- * This software 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.connector.federation.merge;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Property;
-
-/**
- * @author Randall Hauch
- */
-@ThreadSafe
-public class BasicFederatedNode implements FederatedNode {
-
- private final UUID uuid;
-
- // private Name name;
-
- /**
- * Create a new federated node instance.
- *
- * @param uuid the UUID; may not be null
- */
- public BasicFederatedNode( UUID uuid ) {
- assert uuid != null;
- this.uuid = uuid;
- }
-
- /**
- * {@inheritDoc}
- */
- public UUID getUuid() {
- return uuid;
- }
-
- /**
- * {@inheritDoc}
- */
- public Name getName() {
- return null;
- }
-
- /**
- * @param name Sets name to the specified value; may not be null
- */
- public void setName( Name name ) {
- assert name != null;
- // this.name = name;
- }
-
- /**
- * {@inheritDoc}
- */
- public Set<String> getContributingSources() {
- Set<String> names = new HashSet<String>();
- return names;
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Property> getProperties() {
- // Compute merged properties ...
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public Property getProperty( Name propertyName ) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getPropertyCount() {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- */
- public Iterator<Name> getPropertyNames() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeAllProperties() {
- }
-
- /**
- * {@inheritDoc}
- */
- public void setAllProperties( Property... properties ) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void setAllProperties( Iterable<Property> properties ) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void setProperties( Property... properties ) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void setProperties( Iterable<Property> properties ) {
- }
-
- /**
- * {@inheritDoc}
- */
- public Property setPropertyIfAbsent( Property property ) {
- return null;
- }
-
-}
Deleted: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -1,140 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.
- *
- * This software 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.connector.federation.merge;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Property;
-
-/**
- * @author Randall Hauch
- */
-@ThreadSafe
-public interface FederatedNode {
- /**
- * Get the unique identifier for this federated node.
- *
- * @return the UUID; never null
- */
- UUID getUuid();
-
- /**
- * Get the name of this node.
- *
- * @return the node name; never null
- */
- Name getName();
-
- /**
- * Get the property with the given name.
- *
- * @param propertyName the property name
- * @return the property, or null if the property does not exist
- * @throws IllegalArgumentException if the name is null
- */
- Property getProperty( Name propertyName );
-
- /**
- * Get the number of properties on this node. This value is technically an estimate, as it may not exactly match the number of
- * properties returned by {@link #getProperties()} or {@link #getPropertyNames()}.
- *
- * @return the approximate number of properties.
- */
- int getPropertyCount();
-
- /**
- * Get the properties. This method returns a consistent set of properties at the moment this method is called, and is not
- * affected by additions or change to the properties. In other words, it is safe for concurrent operations and is not a
- * fail-fast iterator.
- *
- * @return the properties on this node via an immutable iterator
- */
- Iterator<Property> getProperties();
-
- /**
- * Get the names of the properties for this node. This method returns a consistent set of names at the moment this method is
- * called, and is not affected by additions or change to the properties. In other words, it is safe for concurrent operations
- * and is not a fail-fast iterator.
- *
- * @return the property names via an immutable iterator
- */
- Iterator<Name> getPropertyNames();
-
- /**
- * Set the property if it is not already set.
- *
- * @param property the property
- * @return the existing property, or null if there was no property and the supplied property was set
- * @throws IllegalArgumentException if the property is null
- */
- Property setPropertyIfAbsent( Property property );
-
- /**
- * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
- * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
- * are no properties supplied.
- *
- * @param properties the properties that should be set
- */
- void setProperties( Property... properties );
-
- /**
- * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
- * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
- * are no properties supplied.
- *
- * @param properties the properties that should be set
- */
- void setProperties( Iterable<Property> properties );
-
- /**
- * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
- * nothing if there are no properties supplied.
- *
- * @param properties the properties that should be set
- */
- void setAllProperties( Property... properties );
-
- /**
- * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
- * nothing if there are no properties supplied.
- *
- * @param properties the properties that should replace the existing properties
- */
- void setAllProperties( Iterable<Property> properties );
-
- /**
- * Remove all properties, except for the {@link #getName() name} and {@link #getUuid() identifier}.
- */
- void removeAllProperties();
-
- /**
- * Get the sources that have contributed information to this node.
- *
- * @return the names of the sources that have contributed content to this node.
- */
- Set<String> getContributingSources();
-
-}
Added: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java (rev 0)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.federation.merge;
+
+import java.util.UUID;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.NodeConflictBehavior;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
+
+/**
+ * An in-memory (and temporary) representation of a federated node and it's merged properties and children.
+ *
+ * @author Randall Hauch
+ */
+public class FederatedNode extends BasicGetNodeCommand implements CreateNodeCommand {
+
+ private static final long serialVersionUID = 1L;
+
+ private final UUID uuid;
+ private MergePlan mergePlan;
+ private NodeConflictBehavior nodeConflictBehavior = NodeConflictBehavior.UPDATE;
+
+ /**
+ * Create a federated node given the path and UUID.
+ *
+ * @param path the path of the federated node; may not be null
+ * @param uuid the UUID of the federated node; may not be null
+ */
+ public FederatedNode( Path path,
+ UUID uuid ) {
+ super(path);
+ assert uuid != null;
+ this.uuid = uuid;
+ }
+
+ /**
+ * Get the UUID for this federated node.
+ *
+ * @return the UUID; never null
+ */
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Get the merge plan for this federated node
+ *
+ * @return the merge plan, or null if there is no merge plan
+ */
+ public MergePlan getMergePlan() {
+ return mergePlan;
+ }
+
+ /**
+ * Set the merge plan for this federated node
+ *
+ * @param mergePlan the new merge plan for this federated node; may be null
+ */
+ public void setMergePlan( MergePlan mergePlan ) {
+ this.mergePlan = mergePlan;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo( CreateNodeCommand that ) {
+ if (this == that) return 0;
+ return this.getPath().compareTo(that.getPath());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return this.uuid.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof FederatedNode) {
+ FederatedNode that = (FederatedNode)obj;
+ if (this.getPath().equals(that.getPath())) return true;
+ if (this.getUuid().equals(that.getUuid())) return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getPath().toString() + " (" + this.getUuid() + ")";
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.CreateNodeCommand#getConflictBehavior()
+ */
+ public NodeConflictBehavior getConflictBehavior() {
+ return this.nodeConflictBehavior;
+ }
+
+ /**
+ * @param nodeConflictBehavior Sets nodeConflictBehavior to the specified value.
+ */
+ public void setNodeConflictBehavior( NodeConflictBehavior nodeConflictBehavior ) {
+ this.nodeConflictBehavior = nodeConflictBehavior;
+ }
+
+}
Property changes on: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/FederatedNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java (rev 0)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.federation.merge;
+
+import java.util.List;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+
+/**
+ * @author Randall Hauch
+ */
+public interface MergeStrategy {
+
+ /**
+ * Merge the contributions into a single
+ *
+ * @param federatedNode the federated node into which the contributions are to be merged; never null
+ * @param contributions the contributions to the node; never null
+ * @param context the context in which this operation is to be performed; never null
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context );
+
+}
Property changes on: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java (rev 0)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.federation.merge;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * @author Randall Hauch
+ */
+public class OneContributionMergeStrategy implements MergeStrategy {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
+ * java.util.List, org.jboss.dna.spi.ExecutionContext)
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context ) {
+ assert federatedNode != null;
+ assert contributions != null;
+ assert contributions.size() == 1;
+ Contribution contribution = contributions.get(0);
+ // Copy the children ...
+ List<Segment> children = federatedNode.getChildren();
+ children.clear();
+ Iterator<Segment> childIterator = contribution.getChildren();
+ while (childIterator.hasNext()) {
+ Segment child = childIterator.next();
+ children.add(child);
+ }
+ // Copy the properties ...
+ Map<Name, Property> properties = federatedNode.getProperties();
+ properties.clear();
+ Iterator<Property> propertyIterator = contribution.getProperties();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.next();
+ properties.put(property.getName(), property);
+ }
+ // Assign the merge plan ...
+ MergePlan mergePlan = MergePlan.create(contributions);
+ federatedNode.setMergePlan(mergePlan);
+ }
+
+}
Property changes on: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java (rev 0)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.
+ *
+ * This software 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.connector.federation.merge;
+
+import java.util.List;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.spi.ExecutionContext;
+
+/**
+ * @author Randall Hauch
+ */
+public class StandardMergeStrategy implements MergeStrategy {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
+ * java.util.List, org.jboss.dna.spi.ExecutionContext)
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context ) {
+ }
+}
Property changes on: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -341,9 +341,9 @@
Path lowestExisting = getLowestExistingPath(parent);
throw new PathNotFoundException(path, lowestExisting, InMemoryConnectorI18n.nodeDoesNotExist.text(parent));
}
- Node node = createNode(getEnvironment(), parentNode, path.getLastSegment().getName());
+ Node node = createNode(getExecutionContext(), parentNode, path.getLastSegment().getName());
// Now add the properties to the supplied node ...
- for (Property property : command.getProperties()) {
+ for (Property property : command.getPropertyIterator()) {
Name propName = property.getName();
if (property.size() == 0) {
node.getProperties().remove(propName);
@@ -378,7 +378,7 @@
public void execute( SetPropertiesCommand command ) {
Node node = getTargetNode(command);
// Now set (or remove) the properties to the supplied node ...
- for (Property property : command.getProperties()) {
+ for (Property property : command.getPropertyIterator()) {
Name propName = property.getName();
if (property.size() == 0) {
node.getProperties().remove(propName);
@@ -391,7 +391,7 @@
@Override
public void execute( DeleteBranchCommand command ) {
Node node = getTargetNode(command);
- removeNode(getEnvironment(), node);
+ removeNode(getExecutionContext(), node);
}
@Override
@@ -400,7 +400,7 @@
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
Node newParent = getNode(newPath.getAncestor());
- copyNode(getEnvironment(), node, newParent, false);
+ copyNode(getExecutionContext(), node, newParent, false);
}
@Override
@@ -409,7 +409,7 @@
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
Node newParent = getNode(newPath.getAncestor());
- copyNode(getEnvironment(), node, newParent, true);
+ copyNode(getExecutionContext(), node, newParent, true);
}
@Override
Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -264,12 +264,12 @@
Node<Name, Object> parentNode = getNode(parent);
Node<Name, Object> node = parentNode.addChild(childFqn);
// Add the UUID property (if required), which may be overwritten by a supplied property ...
- Name uuidPropertyName = getUuidProperty(getEnvironment());
+ Name uuidPropertyName = getUuidProperty(getExecutionContext());
if (uuidPropertyName != null) {
node.put(uuidPropertyName, generateUuid());
}
// Now add the properties to the supplied node ...
- for (Property property : command.getProperties()) {
+ for (Property property : command.getPropertyIterator()) {
if (property.size() == 0) continue;
Name propName = property.getName();
Object value = null;
@@ -309,7 +309,7 @@
public void execute( SetPropertiesCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
// Now set (or remove) the properties to the supplied node ...
- for (Property property : command.getProperties()) {
+ for (Property property : command.getPropertyIterator()) {
Name propName = property.getName();
if (property.size() == 0) {
node.remove(propName);
@@ -353,7 +353,7 @@
public void execute( MoveBranchCommand command ) {
Node<Name, Object> node = getNode(command.getPath());
boolean recursive = true;
- Name uuidProperty = getUuidProperty(getEnvironment());
+ Name uuidProperty = getUuidProperty(getExecutionContext());
// Look up the new parent, which must exist ...
Path newPath = command.getNewPath();
Node<Name, Object> newParent = getNode(newPath.getAncestor());
@@ -389,7 +389,7 @@
}
protected Node<Name, Object> getNode( Path path ) {
- return JBossCacheConnection.this.getNode(getEnvironment(), path);
+ return JBossCacheConnection.this.getNode(getExecutionContext(), path);
}
}
Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -206,13 +206,13 @@
// commands.
List<Projection> projections = Collections.singletonList(configurationProjection);
CommandExecutor executor = null;
- if (configurationProjection.getRules().size() == 1) {
+ if (configurationProjection.getRules().size() == 0) {
+ // There is no projection for the configuration repository, so just use a no-op executor
+ executor = new NoOpCommandExecutor(context, configurationSourceName);
+ } else if (configurationProjection.isSimple()) {
// There is just a single projection for the configuration repository, so just use an executor that
// translates the paths using the projection
executor = new SingleProjectionCommandExecutor(context, configurationSourceName, configurationProjection, sources);
- } else if (configurationProjection.getRules().size() == 0) {
- // There is no projection for the configuration repository, so just use a no-op executor
- executor = new NoOpCommandExecutor(context, configurationSourceName);
} else {
// The configuration repository has more than one projection, so we need to merge the results
executor = new FederatingCommandExecutor(context, configurationSourceName, projections, sources);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -22,18 +22,21 @@
package org.jboss.dna.spi.cache;
import java.io.Serializable;
+import org.jboss.dna.spi.graph.DateTime;
/**
* Interface defining an object that can be cached according to a {@link CachePolicy}.
+ *
* @author Randall Hauch
*/
public interface Cacheable extends Serializable {
/**
* Get the time that this node data was originally loaded.
+ *
* @return the system time (in milliseconds) that the node data was loaded
*/
- long getTimeLoaded();
+ DateTime getTimeLoaded();
/**
* Get the caching policy to be used for this object.
@@ -41,12 +44,14 @@
* Note that the values of the policy are relative to the {@link #getTimeLoaded() time the node was loaded}, so the same
* instance can be used for many nodes.
* </p>
+ *
* @return cachePolicy the caching policy, which may not be null
*/
public CachePolicy getCachePolicy();
/**
* Set the caching policy for this object.
+ *
* @param cachePolicy the caching policy to use for this object
* @throws IllegalArgumentException if the cachePolicy is null
*/
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/ActsOnProperties.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -38,6 +38,6 @@
*
* @return the properties
*/
- Iterable<Property> getProperties();
+ Iterable<Property> getPropertyIterator();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CreateNodeCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -38,7 +38,7 @@
*
* @return the property iterator; never null, but possibly empty
*/
- Iterable<Property> getProperties();
+ Iterable<Property> getPropertyIterator();
/**
* Get the desired behavior when a node at the target {@link ActsOnPath#getPath() path} already exists.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -81,11 +81,27 @@
* replaced by those supplied to this method. Note that a {@link Path.Segment segment} is not required in this case because
* there is only one child and (by definition) no index.
*
- * @param nameOfChild
+ * @param nameOfChild the name of the only child
*/
void setChild( Name nameOfChild );
/**
+ * Add the child to this node. This method does not affect existing children, so callers of this method should not add a child
+ * with the same segment as an existing child (this is not checked by this method).
+ *
+ * @param nameOfChild the name of the child; should not be the same as an existing child (not checked)
+ */
+ void addChild( Path.Segment nameOfChild );
+
+ /**
+ * Adds the children to this node. This method does not affect existing children, so callers of this method should not add
+ * children with the same segment as existing children (this is not checked by this method).
+ *
+ * @param namesOfChildren the names of the new children; these should not be the same as any other children
+ */
+ void addChildren( Path.Segment... namesOfChildren );
+
+ /**
* Set that this node has no children. Any existing child references already set on this command will be removed.
*/
void setNoChildren();
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutor.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutor.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutor.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -81,7 +81,7 @@
*
* @return the execution context; never null
*/
- public ExecutionContext getEnvironment() {
+ public ExecutionContext getExecutionContext() {
return context;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -69,7 +69,7 @@
/**
* {@inheritDoc}
*/
- public Iterable<Property> getProperties() {
+ public Iterable<Property> getPropertyIterator() {
return properties;
}
@@ -80,6 +80,18 @@
return this.conflictBehavior;
}
+ public void setProperty( Property property ) {
+ if (!properties.isEmpty()) {
+ for (Property existing : this.properties) {
+ if (existing.getName().equals(property.getName())) {
+ this.properties.remove(existing);
+ break;
+ }
+ }
+ }
+ this.properties.add(property);
+ }
+
/**
* {@inheritDoc}
*/
@@ -121,7 +133,7 @@
sb.append(" at ");
sb.append(this.getPath());
boolean firstProperty = true;
- for (Property property : this.getProperties()) {
+ for (Property property : this.getPropertyIterator()) {
if (property.isEmpty()) continue;
if (firstProperty) {
sb.append(" { ");
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -27,6 +27,7 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Path.Segment;
@@ -44,7 +45,7 @@
private List<Segment> children;
private final Path path;
private CachePolicy cachePolicy;
- private long timeLoaded;
+ private DateTime timeLoaded;
/**
* @param path the path to the node; may not be null
@@ -91,6 +92,26 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
+ */
+ public void addChild( Segment nameOfChild ) {
+ if (nameOfChild != null) this.children.add(nameOfChild);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
+ */
+ public void addChildren( Segment... namesOfChildren ) {
+ for (Segment nameOfChild : namesOfChildren) {
+ if (nameOfChild != null) this.children.add(nameOfChild);
+ }
+ }
+
+ /**
* @return children
*/
public List<Segment> getChildren() {
@@ -114,14 +135,14 @@
/**
* {@inheritDoc}
*/
- public long getTimeLoaded() {
+ public DateTime getTimeLoaded() {
return timeLoaded;
}
/**
* @param timeLoaded Sets timeLoaded to the specified value.
*/
- public void setTimeLoaded( long timeLoaded ) {
+ public void setTimeLoaded( DateTime timeLoaded ) {
this.timeLoaded = timeLoaded;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -80,7 +80,8 @@
} else {
children = new ArrayList<Segment>();
while (namesOfChildren.hasNext()) {
- children.add(namesOfChildren.next());
+ Segment childSegment = namesOfChildren.next();
+ if (childSegment != null) children.add(childSegment);
}
}
}
@@ -94,7 +95,7 @@
} else {
children = new ArrayList<Segment>();
for (Segment childSegment : namesOfChildren) {
- children.add(childSegment);
+ if (childSegment != null) children.add(childSegment);
}
}
}
@@ -108,14 +109,34 @@
} else {
children = new ArrayList<Segment>();
for (Segment childSegment : namesOfChildren) {
- children.add(childSegment);
+ if (childSegment != null) children.add(childSegment);
}
}
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChild(org.jboss.dna.spi.graph.Path.Segment)
*/
+ public void addChild( Segment nameOfChild ) {
+ if (nameOfChild != null) this.children.add(nameOfChild);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.commands.GetChildrenCommand#addChildren(org.jboss.dna.spi.graph.Path.Segment[])
+ */
+ public void addChildren( Segment... namesOfChildren ) {
+ for (Segment nameOfChild : namesOfChildren) {
+ if (nameOfChild != null) this.children.add(nameOfChild);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void setNoChildren() {
children = Collections.emptyList();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -26,6 +26,7 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Property;
@@ -43,7 +44,7 @@
private final Map<Name, Property> properties = new HashMap<Name, Property>();
private final Path path;
private CachePolicy cachePolicy;
- private long timeLoaded;
+ private DateTime timeLoaded;
/**
* @param path the path to the node; may not be null
@@ -63,6 +64,11 @@
}
}
+ public void setProperties( Map<Name, Property> properties ) {
+ this.properties.clear();
+ if (properties != null) this.properties.putAll(properties);
+ }
+
/**
* Get the property values that were added to the command
*
@@ -93,14 +99,14 @@
/**
* {@inheritDoc}
*/
- public long getTimeLoaded() {
+ public DateTime getTimeLoaded() {
return timeLoaded;
}
/**
* @param timeLoaded Sets timeLoaded to the specified value.
*/
- public void setTimeLoaded( long timeLoaded ) {
+ public void setTimeLoaded( DateTime timeLoaded ) {
this.timeLoaded = timeLoaded;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -63,7 +63,7 @@
/**
* {@inheritDoc}
*/
- public Iterable<Property> getProperties() {
+ public Iterable<Property> getPropertyIterator() {
return properties;
}
@@ -79,7 +79,7 @@
sb.append(" at ");
sb.append(this.getPath());
boolean firstProperty = true;
- for (Property property : this.getProperties()) {
+ for (Property property : this.getPropertyIterator()) {
if (property.isEmpty()) continue;
if (firstProperty) {
sb.append(" { ");
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutorTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutorTest.java 2008-08-05 18:09:39 UTC (rev 378)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/commands/executor/AbstractCommandExecutorTest.java 2008-08-05 21:05:45 UTC (rev 379)
@@ -75,7 +75,7 @@
@Test
public void shouldHaveEnvironment() {
- assertThat(executor.getEnvironment(), is(sameInstance(context)));
+ assertThat(executor.getExecutionContext(), is(sameInstance(context)));
}
@Test
15 years, 10 months