[dna-commits] DNA SVN: r1377 - in trunk: extensions/dna-sequencer-ddl/src/main/java/org/jboss/dna/sequencer/ddl and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue Dec 1 11:01:17 EST 2009


Author: rhauch
Date: 2009-12-01 11:01:17 -0500 (Tue, 01 Dec 2009)
New Revision: 1377

Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java
   trunk/extensions/dna-sequencer-ddl/src/main/java/org/jboss/dna/sequencer/ddl/DdlSequencer.java
Log:
Added assertion check for the GraphSequencerOutput implementation to prevent sequencers from setting property values that are Iterator<?> (which  is a common mistake if using Property objects in the sequencer and using output.setProperty(path,name,property.getValues()).)

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java	2009-12-01 15:46:19 UTC (rev 1376)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java	2009-12-01 16:01:17 UTC (rev 1377)
@@ -24,6 +24,7 @@
 package org.jboss.dna.graph.io;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 import org.jboss.dna.graph.ExecutionContext;
 import org.jboss.dna.graph.Graph;
@@ -77,6 +78,7 @@
     public void setProperty( String nodePath,
                              String propertyName,
                              Object... values ) {
+        assert valuesAreNotIterators(values);
         Path path = pathFactory.create(nodePath);
         if (paths.add(path)) {
             batch.create(path).and();
@@ -93,6 +95,7 @@
     public void setProperty( Path nodePath,
                              Name propertyName,
                              Object... values ) {
+        assert valuesAreNotIterators(values);
         if (paths.add(nodePath)) {
             batch.create(nodePath).and();
         }
@@ -118,4 +121,19 @@
         batch.execute();
     }
 
+    /**
+     * Utility method to ensure that the value objects are not {@link Iterator} instances. This may be a common mistake if the
+     * sequencer calls the {@link #setProperty(Path, Name, Object...)} or {@link #setProperty(String, String, Object...)} methods
+     * with <code>output.setProperty(path, property.getName(), property.getValues());</code>
+     * 
+     * @param values the values
+     * @return true if the values are not iterators, or false if they are
+     */
+    private final boolean valuesAreNotIterators( Object... values ) {
+        for (Object value : values) {
+            if (value instanceof Iterator<?>) return false;
+        }
+        return true;
+    }
+
 }

Modified: trunk/extensions/dna-sequencer-ddl/src/main/java/org/jboss/dna/sequencer/ddl/DdlSequencer.java
===================================================================
--- trunk/extensions/dna-sequencer-ddl/src/main/java/org/jboss/dna/sequencer/ddl/DdlSequencer.java	2009-12-01 15:46:19 UTC (rev 1376)
+++ trunk/extensions/dna-sequencer-ddl/src/main/java/org/jboss/dna/sequencer/ddl/DdlSequencer.java	2009-12-01 16:01:17 UTC (rev 1377)
@@ -120,7 +120,7 @@
         public void create( Path path,
                             List<Property> properties ) {
             for (Property property : properties) {
-                output.setProperty(path, property.getName(), property.getValues());
+                output.setProperty(path, property.getName(), property.getValuesAsArray());
             }
         }
 
@@ -133,9 +133,9 @@
         public void create( Path path,
                             Property firstProperty,
                             Property... additionalProperties ) {
-            output.setProperty(path, firstProperty.getName(), firstProperty.getValues());
+            output.setProperty(path, firstProperty.getName(), firstProperty.getValuesAsArray());
             for (Property property : additionalProperties) {
-                output.setProperty(path, property.getName(), property.getValues());
+                output.setProperty(path, property.getName(), property.getValuesAsArray());
             }
         }
 
@@ -148,7 +148,7 @@
         public void setProperties( Path path,
                                    Property... properties ) {
             for (Property property : properties) {
-                output.setProperty(path, property.getName(), property.getValues());
+                output.setProperty(path, property.getName(), property.getValuesAsArray());
             }
         }
 



More information about the dna-commits mailing list