[dna-commits] DNA SVN: r404 - in trunk: connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge and 8 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri Aug 8 16:43:42 EDT 2008


Author: rhauch
Date: 2008-08-08 16:43:42 -0400 (Fri, 08 Aug 2008)
New Revision: 404

Added:
   trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.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/merge/StandardMergeStrategy.java
   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/InMemoryRepository.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/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
   trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
   trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.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-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83

Added logic to handle same-name siblings.  Also changed the structure of the "Lexicon" classes to be more easily used.

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -133,8 +133,8 @@
         this.sourceProjections = sourceProjections;
         this.connectionFactory = connectionFactory;
         this.connectionsBySourceName = new HashMap<String, RepositoryConnection>();
-        this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
-        this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.MERGE_PLAN);
+        this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.UUID);
+        this.mergePlanPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.MERGE_PLAN);
         this.sourceNames = new HashSet<String>();
         for (Projection projection : this.sourceProjections) {
             this.sourceNames.add(projection.getSourceName());
@@ -142,7 +142,7 @@
         if (this.sourceProjections.size() == 1 && this.sourceProjections.get(0).isSimple()) {
             this.mergingStrategy = new OneContributionMergeStrategy();
         } else {
-            this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.PropertyNames.UUID);
+            this.mergingStrategy = new StandardMergeStrategy(DnaLexicon.UUID);
         }
     }
 

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/StandardMergeStrategy.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -31,12 +31,11 @@
  */
 public class StandardMergeStrategy implements MergeStrategy {
 
-    private final String identityPropertyNameString;
+    private final Name identityPropertyName;
 
-    public StandardMergeStrategy( String identityPropertyName ) {
+    public StandardMergeStrategy( Name identityPropertyName ) {
         assert identityPropertyName != null;
-        assert identityPropertyName.trim().length() != 0;
-        this.identityPropertyNameString = identityPropertyName;
+        this.identityPropertyName = identityPropertyName;
     }
 
     /**
@@ -50,7 +49,6 @@
                        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-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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -90,7 +90,7 @@
     public void beforeEach() throws Exception {
         MockitoAnnotations.initMocks(this);
         context = new BasicExecutionContext();
-        context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+        context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
         executionContextFactoryJndiName = "context factory jndi name";
         repositoryConnectionFactoryJndiName = "repository connection factory jndi name";
         configurationSourceName = "configuration source name";

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -334,7 +334,7 @@
         protected Executor( ExecutionContext context,
                             String sourceName ) {
             super(context, sourceName);
-            this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.PropertyNames.UUID);
+            this.uuidPropertyName = context.getValueFactories().getNameFactory().create(DnaLexicon.UUID);
         }
 
         protected Property getUuidProperty( Node node ) {

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -24,6 +24,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 import javax.transaction.xa.XAResource;
@@ -73,7 +74,6 @@
         }
     };
 
-    private boolean initializedUuidPropertyName = false;
     private Name uuidPropertyName;
     private final JBossCacheSource source;
     private final Cache<Name, Object> cache;
@@ -166,10 +166,9 @@
      * @return the name, or null if the UUID should not be stored
      */
     protected Name getUuidPropertyName( ExecutionContext context ) {
-        if (!initializedUuidPropertyName) {
+        if (uuidPropertyName == null) {
             NameFactory nameFactory = context.getValueFactories().getNameFactory();
-            this.uuidPropertyName = nameFactory.create(this.source.getUuidPropertyName());
-            initializedUuidPropertyName = true;
+            uuidPropertyName = nameFactory.create(this.source.getUuidPropertyName());
         }
         return this.uuidPropertyName;
     }
@@ -247,6 +246,127 @@
         return numNodesCopied;
     }
 
+    /**
+     * Update (or create) the array of {@link Path.Segment path segments} for the children of the supplied node. This array
+     * maintains the ordered list of children (since the {@link Cache} does not maintain the order). Invoking this method will
+     * change any existing children that a {@link Path.Segment#getName() name part} that matches the supplied
+     * <code>changedName</code> to have the appropriate {@link Path.Segment#getIndex() same-name sibling index}.
+     * 
+     * @param parent the parent node; may not be null
+     * @param changedName the name that should be compared to the existing node siblings to determine whether the same-name
+     *        sibling indexes should be updated; may not be null
+     * @param context the execution context; may not be null
+     */
+    @SuppressWarnings( "unchecked" )
+    protected void updateChildList( Node<Name, Object> parent,
+                                    Name changedName,
+                                    ExecutionContext context ) {
+        assert parent != null;
+        assert changedName != null;
+        assert context != null;
+        Set<Node<Name, Object>> children = parent.getChildren();
+        final int numChildren = children.size();
+        if (numChildren == 0) return;
+        // Go through the children, looking for any children with the same name as the 'changedName'
+        List<ChildInfo> childrenWithChangedName = new LinkedList<ChildInfo>();
+        Path.Segment[] childSegments = new Path.Segment[children.size()];
+        int index = 0;
+        for (Node<Name, Object> child : children) {
+            Path.Segment childSegment = (Path.Segment)child.getFqn().getLastElement();
+            Name childName = childSegment.getName();
+            if (childName.equals(changedName)) {
+                ChildInfo info = new ChildInfo(child.getFqn(), index);
+                childrenWithChangedName.add(info);
+            }
+            childSegments[index++] = childSegment;
+        }
+        // Go through the children with the same name as the 'changedName', making sure their indexes are correct ...
+        assert childrenWithChangedName.isEmpty() == false;
+        if (childrenWithChangedName.size() == 1) {
+            // The child should have no indexes ...
+            ChildInfo child = childrenWithChangedName.get(0);
+            Fqn<Path.Segment> fqn = child.getFqn();
+            Path.Segment segment = fqn.getLastElement();
+            if (segment.hasIndex()) {
+                // Determine the new name and index ...
+                Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(changedName);
+                // Replace the child with the correct FQN ...
+                changeNodeName(parent, fqn, newSegment, context);
+                // Change the segment in the child list ...
+                childSegments[child.getChildIndex()] = newSegment;
+            }
+        } else {
+            // There is more than one child with the same name ...
+            int i = 0;
+            for (ChildInfo child : childrenWithChangedName) {
+                Fqn<Path.Segment> fqn = child.getFqn();
+                Path.Segment childSegment = fqn.getLastElement();
+                if (childSegment.getIndex() != i) {
+                    // Determine the new name and index ...
+                    Path.Segment newSegment = context.getValueFactories().getPathFactory().createSegment(changedName, i);
+                    // Replace the child with the correct FQN ...
+                    changeNodeName(parent, fqn, newSegment, context);
+                    // Change the segment in the child list ...
+                    childSegments[child.getChildIndex()] = newSegment;
+                }
+                ++i;
+            }
+        }
+        // Record the list of children as a property on the parent ...
+        // (Do this last, as it doesn't need to be done if there's an exception in the above logic)
+        parent.put(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST, childSegments); // replaces any existing value
+    }
+
+    /**
+     * Utility class used by the {@link JBossCacheConnection#updateChildList(Node, Name, ExecutionContext)} method.
+     * 
+     * @author Randall Hauch
+     */
+    private static class ChildInfo {
+        private final Fqn<Path.Segment> fqn;
+        private final int childIndex;
+
+        protected ChildInfo( Fqn<Path.Segment> fqn,
+                             int childIndex ) {
+            assert fqn != null;
+            this.fqn = fqn;
+            this.childIndex = childIndex;
+        }
+
+        public int getChildIndex() {
+            return childIndex;
+        }
+
+        public Fqn<Path.Segment> getFqn() {
+            return fqn;
+        }
+    }
+
+    /**
+     * Changes the name of the node in the cache (but does not update the list of child segments stored on the parent).
+     * 
+     * @param parent
+     * @param existing
+     * @param newSegment
+     * @param context
+     */
+    protected void changeNodeName( Node<Name, Object> parent,
+                                   Fqn<Path.Segment> existing,
+                                   Path.Segment newSegment,
+                                   ExecutionContext context ) {
+        assert parent != null;
+        assert existing != null;
+        assert newSegment != null;
+        assert context != null;
+        parent.removeChild(existing);
+        List<Path.Segment> elements = existing.peekElements();
+        assert elements.size() > 0;
+        elements.set(elements.size() - 1, newSegment);
+        existing = Fqn.fromList(elements);
+        parent.addChild(existing);
+
+    }
+
     protected class Executor extends AbstractCommandExecutor {
 
         private final PropertyFactory propertyFactory;
@@ -267,6 +387,12 @@
             // Look up the parent node, which must exist ...
             Node<Name, Object> parentNode = getNode(parent);
             Node<Name, Object> node = parentNode.addChild(childFqn);
+
+            // Update the children to account for same-name siblings.
+            // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+            // the array of Path.Segment for the children (since the cache doesn't maintain order).
+            updateChildList(parentNode, path.getLastSegment().getName(), getExecutionContext());
+
             // Add the UUID property (if required), which may be overwritten by a supplied property ...
             Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
             if (uuidPropertyName != null) {
@@ -286,22 +412,29 @@
             }
         }
 
+        @SuppressWarnings( "unchecked" )
         @Override
         public void execute( GetChildrenCommand command ) {
             Node<Name, Object> node = getNode(command.getPath());
             Name uuidPropertyName = getUuidPropertyName(getExecutionContext());
-            // Get the names of the children ...
-            for (Node<Name, Object> child : node.getChildren()) {
-                Segment segment = (Segment)child.getFqn().getLastElement();
-                Object uuid = node.getData().get(uuidPropertyName);
+            List<Path.Segment> segments = node.getFqn().peekElements();
+            segments.add(null);
+            // Get the names of the children, using the child list ...
+            Path.Segment[] childList = (Path.Segment[])node.get(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST);
+            for (Path.Segment child : childList) {
+                // We have the child segment, but we need the UUID property ...
+                segments.set(segments.size() - 1, child); // each iteration sets this last list element ...
+                Fqn<Path.Segment> fqn = Fqn.fromList(segments);
+                Node<Name, Object> childNode = node.getChild(fqn);
+                Object uuid = childNode.getData().get(uuidPropertyName);
                 if (uuid == null) {
                     uuid = generateUuid();
-                    node.getData().put(uuidPropertyName, uuid);
+                    childNode.getData().put(uuidPropertyName, uuid);
                 } else {
                     uuid = uuidFactory.create(uuid);
                 }
                 Property uuidProperty = propertyFactory.create(uuidPropertyName, uuid);
-                command.addChild(segment, uuidProperty);
+                command.addChild(child, uuidProperty);
             }
         }
 
@@ -311,6 +444,8 @@
             Map<Name, Object> dataMap = node.getData();
             for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
                 Name propertyName = data.getKey();
+                // Don't allow the child list property to be accessed
+                if (propertyName.equals(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST)) continue;
                 Object values = data.getValue();
                 Property property = propertyFactory.create(propertyName, values);
                 command.setProperty(property);
@@ -323,6 +458,8 @@
             // Now set (or remove) the properties to the supplied node ...
             for (Property property : command.getPropertyIterator()) {
                 Name propName = property.getName();
+                // Don't allow the child list property to be removed or changed
+                if (propName.equals(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST)) continue;
                 if (property.size() == 0) {
                     node.remove(propName);
                     continue;
@@ -350,6 +487,10 @@
             Path newPath = command.getNewPath();
             Node<Name, Object> newParent = getNode(newPath.getAncestor());
             copyNode(node, newParent, false, null);
+            // Update the children to account for same-name siblings.
+            // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+            // the array of Path.Segment for the children (since the cache doesn't maintain order).
+            updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
         }
 
         @Override
@@ -359,6 +500,10 @@
             Path newPath = command.getNewPath();
             Node<Name, Object> newParent = getNode(newPath.getAncestor());
             copyNode(node, newParent, true, null);
+            // Update the children to account for same-name siblings.
+            // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+            // the array of Path.Segment for the children (since the cache doesn't maintain order).
+            updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
         }
 
         @Override
@@ -370,6 +515,10 @@
             Path newPath = command.getNewPath();
             Node<Name, Object> newParent = getNode(newPath.getAncestor());
             copyNode(node, newParent, recursive, uuidProperty);
+            // Update the children to account for same-name siblings.
+            // This not only updates the FQN of the child nodes, but it also sets the property that stores the
+            // the array of Path.Segment for the children (since the cache doesn't maintain order).
+            updateChildList(newParent, newPath.getLastSegment().getName(), getExecutionContext());
             // Now delete the old node ...
             Node<Name, Object> oldParent = node.getParent();
             boolean removed = oldParent.removeChild(node.getFqn().getLastElement());

Added: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java	                        (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -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.connector.jbosscache;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
+/**
+ * The namespace and property names used within a {@link JBossCacheSource} to store internal information.
+ * 
+ * @author Randall Hauch
+ */
+public class JBossCacheLexicon {
+
+    public static class Namespace {
+        public static final String URI = "http://www.jboss.org/dna/connector/jbosscache";
+        public static final String PREFIX = "dnajbcc";
+    }
+
+    public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI, "orderedChildNames");
+
+}


Property changes on: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheLexicon.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -78,7 +78,7 @@
      * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
      */
     public static final int DEFAULT_RETRY_LIMIT = 0;
-    public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
+    public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.UUID.getString();
 
     protected static final String ROOT_NODE_UUID = "rootNodeUuid";
     protected static final String SOURCE_NAME = "sourceName";

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-07 22:37:39 UTC (rev 403)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -70,7 +70,7 @@
     public void beforeEach() throws Exception {
         MockitoAnnotations.initMocks(this);
         context = new BasicExecutionContext();
-        context.getNamespaceRegistry().register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+        context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
         pathFactory = context.getValueFactories().getPathFactory();
         cacheFactory = new DefaultCacheFactory<Name, Object>();
         cache = cacheFactory.createCache();
@@ -141,11 +141,11 @@
 
     @Test
     public void shouldGetUuidPropertyNameFromSouceAndShouldNotChangeDuringLifetimeOfConnection() {
-        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
         Name name = connection.getUuidPropertyName(context);
         verify(source).getUuidPropertyName();
         assertThat(name.getLocalName(), is("uuid"));
-        assertThat(name.getNamespaceUri(), is(DnaLexicon.NAMESPACE_URI));
+        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);
@@ -216,7 +216,7 @@
     @Test
     public void shouldGetNodeIfItExistsInCache() {
         // Set up the cache with data ...
-        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
         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");
@@ -241,7 +241,7 @@
     @Test
     public void shouldThrowExceptionWithLowestExistingNodeFromGetNodeIfTheNodeDoesNotExist() {
         // Set up the cache with data ...
-        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
         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");
@@ -268,7 +268,7 @@
     @Test
     public void shouldCopyNode() {
         // Set up the cache with data ...
-        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.UUID.getString(context.getNamespaceRegistry()));
         Name uuidProperty = connection.getUuidPropertyName(context);
         Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c"),
             pathFactory.create("/a/d")};

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-07 22:37:39 UTC (rev 403)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -87,7 +87,7 @@
     public void beforeEach() throws Exception {
         MockitoAnnotations.initMocks(this);
         NamespaceRegistry registry = new BasicNamespaceRegistry();
-        registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+        registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
         valueFactories = new StandardValueFactories(registry);
         pathFactory = valueFactories.getPathFactory();
         propertyFactory = new BasicPropertyFactory(valueFactories);

Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java	2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/DnaLexicon.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -21,16 +21,19 @@
  */
 package org.jboss.dna.spi;
 
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.impl.BasicName;
+
 /**
  * @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 Namespace {
+        public static final String URI = "http://www.jboss.org/dna";
+        public static final String PREFIX = "dna";
+    }
 
-    public static class PropertyNames {
-        public static final String UUID = "dna:uuid";
-        public static final String MERGE_PLAN = "dna:mergePlan";
-    }
+    public static final Name UUID = new BasicName(Namespace.URI, "uuid");
+    public static final Name MERGE_PLAN = new BasicName(Namespace.URI, "mergePlan");
 }

Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java	2008-08-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepository.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -52,7 +52,7 @@
 @ThreadSafe
 public class SimpleRepository {
 
-    public static final String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.PropertyNames.UUID;
+    public static final Name DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.UUID;
 
     private static final ConcurrentMap<String, SimpleRepository> repositoriesByName = new ConcurrentHashMap<String, SimpleRepository>();
 
@@ -68,7 +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 Name uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
     private boolean shutdown = false;
 
     public SimpleRepository( String repositoryName ) {
@@ -88,15 +88,15 @@
     /**
      * @return uuidPropertyName
      */
-    public String getUuidPropertyName() {
+    public Name 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;
+    public void setUuidPropertyName( Name uuidPropertyName ) {
+        if (uuidPropertyName == null) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
         this.uuidPropertyName = uuidPropertyName;
     }
 

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-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -46,8 +46,8 @@
 
     @Before
     public void beforeEach() {
-        this.validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
-        this.validNamespaceUri = DnaLexicon.NAMESPACE_URI;
+        this.validNamespacePrefix = DnaLexicon.Namespace.PREFIX;
+        this.validNamespaceUri = DnaLexicon.Namespace.URI;
         this.validLocalName = "localPart";
         this.name = new BasicName(validNamespaceUri, validLocalName);
         this.encoder = Path.URL_ENCODER;

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-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -49,7 +49,7 @@
     @Before
     public void beforeEach() {
         this.registry = new BasicNamespaceRegistry();
-        this.registry.register(DnaLexicon.NAMESPACE_PREFIX, DnaLexicon.NAMESPACE_URI);
+        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-07 22:37:39 UTC (rev 403)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java	2008-08-08 20:43:42 UTC (rev 404)
@@ -60,8 +60,8 @@
 
     @Before
     public void beforeEach() {
-        validNamespacePrefix = DnaLexicon.NAMESPACE_PREFIX;
-        validNamespaceUri = DnaLexicon.NAMESPACE_URI;
+        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]),




More information about the dna-commits mailing list