[dna-commits] DNA SVN: r319 - in trunk/connectors/dna-connector-jbosscache/src/main: resources/org/jboss/dna/connector/jbosscache and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Mon Jun 30 17:34:41 EDT 2008


Author: rhauch
Date: 2008-06-30 17:34:41 -0400 (Mon, 30 Jun 2008)
New Revision: 319

Modified:
   trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
   trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
Log:
Added support for composite command

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-06-30 21:33:07 UTC (rev 318)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-06-30 21:34:41 UTC (rev 319)
@@ -36,6 +36,7 @@
 import org.jboss.dna.spi.graph.Property;
 import org.jboss.dna.spi.graph.Path.Segment;
 import org.jboss.dna.spi.graph.commands.ActsOnPath;
+import org.jboss.dna.spi.graph.commands.CompositeCommand;
 import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
 import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
 import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
@@ -140,121 +141,137 @@
 
         // Now execute the commands ...
         for (GraphCommand command : commands) {
-            // This node reference is available for any command that extends ActsOnPath ...
-            Node<Name, Object> node = null;
+            executeCommand(env, command);
+        }
+    }
 
-            // First, process the commands that create a new node ...
-            if (command instanceof CreateNodeCommand) {
-                CreateNodeCommand theCommand = (CreateNodeCommand)command;
-                Path path = theCommand.getPath();
-                Path parent = path.getAncestor();
-                Fqn<Segment> childFqn = getFullyQualifiedName(path.getLastSegment());
-                // Look up the parent node, which must exist ...
-                Node<Name, Object> parentNode = getNode(env, parent);
-                node = parentNode.addChild(childFqn);
-                // Add the UUID property (if required), which may be overwritten by a supplied property ...
-                Name uuidPropertyName = getUuidProperty(env);
-                if (uuidPropertyName != null) {
-                    node.put(uuidPropertyName, generateUuid());
-                }
-                // Now add the properties to the supplied node ...
-                for (Property property : theCommand.getProperties()) {
-                    if (property.size() == 0) continue;
-                    Name propName = property.getName();
-                    Object value = null;
-                    if (property.size() == 1) {
-                        value = property.iterator().next();
-                    } else {
-                        value = property.getValuesAsArray();
-                    }
-                    node.put(propName, value);
-                }
-                assert node != null;
+    /**
+     * @param env
+     * @param command
+     */
+    protected void executeCommand( ExecutionEnvironment env,
+                                   GraphCommand command ) {
+        // This node reference is available for any command that extends ActsOnPath ...
+        Node<Name, Object> node = null;
+
+        if (command instanceof CompositeCommand) {
+            CompositeCommand theCommand = (CompositeCommand)command;
+            for (GraphCommand containedCommand : theCommand) {
+                executeCommand(env, containedCommand);
             }
+        }
 
-            // Otherwise, check whether the command is applies to a path; all the remaining commands
-            // that do so expect the node to exist ...
-            else if (command instanceof ActsOnPath) {
-                ActsOnPath theCommand = (ActsOnPath)command;
-                Path path = theCommand.getPath();
-                // Look up the node with the supplied path ...
-                node = getNode(env, path);
-                assert node != null;
+        // First, process the commands that create a new node ...
+        if (command instanceof CreateNodeCommand) {
+            CreateNodeCommand theCommand = (CreateNodeCommand)command;
+            Path path = theCommand.getPath();
+            Path parent = path.getAncestor();
+            Fqn<Segment> childFqn = getFullyQualifiedName(path.getLastSegment());
+            // Look up the parent node, which must exist ...
+            Node<Name, Object> parentNode = getNode(env, parent);
+            node = parentNode.addChild(childFqn);
+            // Add the UUID property (if required), which may be overwritten by a supplied property ...
+            Name uuidPropertyName = getUuidProperty(env);
+            if (uuidPropertyName != null) {
+                node.put(uuidPropertyName, generateUuid());
             }
-
-            if (command instanceof GetChildrenCommand) {
-                GetChildrenCommand theCommand = (GetChildrenCommand)command;
-                assert command instanceof ActsOnPath;
-                assert node != null;
-                // 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());
+            // Now add the properties to the supplied node ...
+            for (Property property : theCommand.getProperties()) {
+                if (property.size() == 0) continue;
+                Name propName = property.getName();
+                Object value = null;
+                if (property.size() == 1) {
+                    value = property.iterator().next();
+                } else {
+                    value = property.getValuesAsArray();
                 }
-                theCommand.setChildren(childSegments);
+                node.put(propName, value);
+            }
+            assert node != null;
+        }
 
+        // Otherwise, check whether the command is applies to a path; all the remaining commands
+        // that do so expect the node to exist ...
+        else if (command instanceof ActsOnPath) {
+            ActsOnPath theCommand = (ActsOnPath)command;
+            Path path = theCommand.getPath();
+            // Look up the node with the supplied path ...
+            node = getNode(env, path);
+            assert node != null;
+        }
+
+        if (command instanceof GetChildrenCommand) {
+            GetChildrenCommand theCommand = (GetChildrenCommand)command;
+            assert command instanceof ActsOnPath;
+            assert node != null;
+            // 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());
             }
-            if (command instanceof GetPropertiesCommand) {
-                GetPropertiesCommand theCommand = (GetPropertiesCommand)command;
-                assert command instanceof ActsOnPath;
-                assert node != null;
-                Map<Name, Object> dataMap = node.getData();
-                for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
-                    Name propertyName = data.getKey();
-                    Object values = data.getValue();
-                    Property property = env.getPropertyFactory().create(propertyName, values);
-                    theCommand.setProperty(property);
-                }
+            theCommand.setChildren(childSegments);
+
+        }
+        if (command instanceof GetPropertiesCommand) {
+            GetPropertiesCommand theCommand = (GetPropertiesCommand)command;
+            assert command instanceof ActsOnPath;
+            assert node != null;
+            Map<Name, Object> dataMap = node.getData();
+            for (Map.Entry<Name, Object> data : dataMap.entrySet()) {
+                Name propertyName = data.getKey();
+                Object values = data.getValue();
+                Property property = env.getPropertyFactory().create(propertyName, values);
+                theCommand.setProperty(property);
             }
-            if (command instanceof SetPropertiesCommand) {
-                SetPropertiesCommand theCommand = (SetPropertiesCommand)command;
-                assert command instanceof ActsOnPath;
-                assert node != null;
-                // Now set (or remove) the properties to the supplied node ...
-                for (Property property : theCommand.getProperties()) {
-                    Name propName = property.getName();
-                    if (property.size() == 0) {
-                        node.remove(propName);
-                        continue;
-                    }
-                    Object value = null;
-                    if (property.size() == 1) {
-                        value = property.iterator().next();
-                    } else {
-                        value = property.getValuesAsArray();
-                    }
-                    node.put(propName, value);
+        }
+        if (command instanceof SetPropertiesCommand) {
+            SetPropertiesCommand theCommand = (SetPropertiesCommand)command;
+            assert command instanceof ActsOnPath;
+            assert node != null;
+            // Now set (or remove) the properties to the supplied node ...
+            for (Property property : theCommand.getProperties()) {
+                Name propName = property.getName();
+                if (property.size() == 0) {
+                    node.remove(propName);
+                    continue;
                 }
+                Object value = null;
+                if (property.size() == 1) {
+                    value = property.iterator().next();
+                } else {
+                    value = property.getValuesAsArray();
+                }
+                node.put(propName, value);
             }
-            if (command instanceof DeleteBranchCommand) {
-                assert command instanceof ActsOnPath;
-                assert node != null;
-                node.getParent().removeChild(node.getFqn().getLastElement());
-            }
-            if (command instanceof CopyNodeCommand) {
-                CopyNodeCommand theCommand = (CopyNodeCommand)command;
-                boolean recursive = command instanceof CopyBranchCommand;
-                // Look up the new parent, which must exist ...
-                Path newPath = theCommand.getNewPath();
-                Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
-                copyNode(node, newParent, recursive, null);
-            }
-            if (command instanceof MoveBranchCommand) {
-                MoveBranchCommand theCommand = (MoveBranchCommand)command;
-                assert command instanceof ActsOnPath;
-                assert node != null;
-                boolean recursive = true;
-                Name uuidProperty = getUuidProperty(env);
-                // Look up the new parent, which must exist ...
-                Path newPath = theCommand.getNewPath();
-                Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
-                copyNode(node, newParent, recursive, uuidProperty);
-                // Now delete the old node ...
-                Node<Name, Object> oldParent = node.getParent();
-                boolean removed = oldParent.removeChild(node.getFqn().getLastElement());
-                assert removed;
-            }
         }
+        if (command instanceof DeleteBranchCommand) {
+            assert command instanceof ActsOnPath;
+            assert node != null;
+            node.getParent().removeChild(node.getFqn().getLastElement());
+        }
+        if (command instanceof CopyNodeCommand) {
+            CopyNodeCommand theCommand = (CopyNodeCommand)command;
+            boolean recursive = command instanceof CopyBranchCommand;
+            // Look up the new parent, which must exist ...
+            Path newPath = theCommand.getNewPath();
+            Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
+            copyNode(node, newParent, recursive, null);
+        }
+        if (command instanceof MoveBranchCommand) {
+            MoveBranchCommand theCommand = (MoveBranchCommand)command;
+            assert command instanceof ActsOnPath;
+            assert node != null;
+            boolean recursive = true;
+            Name uuidProperty = getUuidProperty(env);
+            // Look up the new parent, which must exist ...
+            Path newPath = theCommand.getNewPath();
+            Node<Name, Object> newParent = getNode(env, newPath.getAncestor());
+            copyNode(node, newParent, recursive, uuidProperty);
+            // Now delete the old node ...
+            Node<Name, Object> oldParent = node.getParent();
+            boolean removed = oldParent.removeChild(node.getFqn().getLastElement());
+            assert removed;
+        }
     }
 
     /**

Modified: trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties	2008-06-30 21:33:07 UTC (rev 318)
+++ trunk/connectors/dna-connector-jbosscache/src/main/resources/org/jboss/dna/connector/jbosscache/JBossCacheConnectorI18n.properties	2008-06-30 21:34:41 UTC (rev 319)
@@ -20,5 +20,5 @@
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 #
 
-connectorName = In-Memory Connector
+connectorName = JBoss Cache Connector
 nodeDoesNotExist = Could not find an existing node at {0}
\ No newline at end of file




More information about the dna-commits mailing list