[dna-commits] DNA SVN: r218 - in branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph: commands and 3 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Mon Jun 2 12:34:48 EDT 2008


Author: rhauch
Date: 2008-06-02 12:34:47 -0400 (Mon, 02 Jun 2008)
New Revision: 218

Added:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
Modified:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
Log:
DNA-68: Create connector API
http://jira.jboss.org/jira/browse/DNA-68

Added basic property implementation.  Refactored the commands and added basic implementations.  Also included several other changes to enhance readability of the code that uses.

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java	2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -23,13 +23,13 @@
 
 import java.math.BigDecimal;
 import java.net.URI;
-import java.util.Calendar;
 import java.util.Iterator;
 import net.jcip.annotations.Immutable;
 
 /**
  * Representation of a property consisting of a name and value(s). Note that this property is immutable, meaning that the property
  * values may not be changed through this interface.
+ * 
  * @author Randall Hauch
  */
 @Immutable
@@ -37,52 +37,62 @@
 
     /**
      * Get the name of the property.
+     * 
      * @return the property name; never null
      */
     Name getName();
 
     /**
      * Get the name of the property's definition.
+     * 
      * @return the property definition's name; never null
      */
     Name getDefinitionName();
 
     /**
-     * Determine whether the property is defined to allow multiple values.
+     * Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
+     * method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
+     * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
+     * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
+     * 
+     * @return the number of actual values in this property; always non-negative
+     */
+    int size();
+
+    /**
+     * Determine whether the property currently has multiple values.
+     * 
      * @return true if the property has multiple values, or false otherwise.
      * @see #isSingle()
+     * @see #isEmpty()
      */
     boolean isMultiple();
 
     /**
-     * Determine whether the property is defined to allow a single value. This is a convenience method that is equivalent to
-     * calling <code>!isMultiple()</code>.
-     * @return true if the property has multiple values, or false otherwise.
+     * Determine whether the property currently has a single value.
+     * 
+     * @return true if the property has a single value, or false otherwise.
      * @see #isMultiple()
+     * @see #isEmpty()
      */
     boolean isSingle();
 
     /**
-     * Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
-     * method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
-     * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
-     * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
-     * @return the number of actual values in this property; always non-negative
-     */
-    int size();
-
-    /**
      * Determine whether this property has no actual values. This method may return <code>true</code> regardless of whether the
      * property allows a {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
      * <p>
      * This method is a convenience method that is equivalent to <code>size() == 0</code>.
      * </p>
-     * @return the number of actual values in this property; always non-negative
+     * 
+     * @return true if this property has no values, or false otherwise
+     * @see #isMultiple()
+     * @see #isSingle()
      */
     boolean isEmpty();
 
     /**
      * Get the type for this property.
+     * 
      * @return the property's type, which is never null
      */
     PropertyType getPropertyType();
@@ -96,12 +106,30 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the values; never null
      * @see Iterable#iterator()
+     * @see #getValuesAsArray()
      */
     Iterator<?> getValues();
 
     /**
+     * Obtain the property's values as an array of objects in their natural form, as defined by {@link #getPropertyType()}.
+     * <p>
+     * A valid array is return if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}, or a
+     * null value is returned if the property is {@link #isEmpty() empty}.
+     * </p>
+     * <p>
+     * The resulting array is a copy, guaranteeing immutability for the property.
+     * </p>
+     * 
+     * @return the array of values
+     * @see Iterable#iterator()
+     * @see #getValues()
+     */
+    Object[] getValuesAsArray();
+
+    /**
      * Obtain the property's values in their natural form, converting the values to the supplied {@link PropertyType} if it is
      * different than this property's {@link #getPropertyType() property type}. Note that it is not always possible to convert
      * between PropertyTypes.
@@ -111,6 +139,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @param type the property type defining the form of the values to be returned; if null, the
      * {@link #getPropertyType() property's type} is used
      * @return an iterator over the values; never null
@@ -126,6 +155,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the String values; never null
      */
     Iterator<String> getStringValues();
@@ -139,6 +169,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the {@link Binary} values; never null
      */
     Iterator<Binary> getBinaryValues();
@@ -152,6 +183,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the long values; never null
      */
     Iterator<Long> getLongValues();
@@ -165,6 +197,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the double values; never null
      */
     Iterator<Double> getDoubleValues();
@@ -179,12 +212,13 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the decimal values; never null
      */
     Iterator<BigDecimal> getDecimalValues();
 
     /**
-     * Obtain the property's values as {@link Calendar dates}, converting the values if the
+     * Obtain the property's values as {@link DateTime dates}, converting the values if the
      * {@link #getPropertyType() property type} is not {@link PropertyType#DATE}. Note that it is not always possible to convert
      * to a {@link PropertyType#DATE date} value.
      * <p>
@@ -193,9 +227,10 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
-     * @return an iterator over the Calendar values; never null
+     * 
+     * @return an iterator over the DateTime values; never null
      */
-    Iterator<Calendar> getDateValues();
+    Iterator<DateTime> getDateValues();
 
     /**
      * Obtain the property's values as booleans, converting the values if the {@link #getPropertyType() property type} is not
@@ -207,6 +242,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the Boolean values; never null
      */
     Iterator<Boolean> getBooleanValues();
@@ -221,6 +257,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the Name values; never null
      */
     Iterator<Name> getNameValues();
@@ -235,6 +272,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the Path values; never null
      */
     Iterator<Path> getPathValues();
@@ -249,6 +287,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the Reference values; never null
      */
     Iterator<Reference> getReferenceValues();
@@ -262,6 +301,7 @@
      * <p>
      * The resulting iterator is immutable, and all property values are immutable.
      * </p>
+     * 
      * @return an iterator over the URI values; never null
      */
     Iterator<URI> getUriValues();

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,37 @@
+/*
+ * 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.Iterator;
+
+/**
+ * @author Randall Hauch
+ */
+public interface PropertyFactory {
+
+    Property create( Name name, PropertyType type, Name definitionName, Object... values );
+
+    Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values );
+
+    Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values );
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java	2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -24,6 +24,7 @@
 import java.math.BigDecimal;
 import java.net.URI;
 import java.util.Comparator;
+import java.util.Iterator;
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.spi.SpiI18n;
 
@@ -68,17 +69,32 @@
         return this.comparator;
     }
 
-    public boolean isInstance( Object value ) {
+    public boolean isTypeFor( Object value ) {
         return this.valueClass.isInstance(value);
     }
 
+    public boolean isTypeForEach( Iterable<?> values ) {
+        for (Object value : values) {
+            if (!this.valueClass.isInstance(value)) return false;
+        }
+        return true;
+    }
+
+    public boolean isTypeForEach( Iterator<?> values ) {
+        while (values.hasNext()) {
+            Object value = values.next();
+            if (!this.valueClass.isInstance(value)) return false;
+        }
+        return true;
+    }
+
     public static PropertyType discoverType( Object value ) {
         if (value == null) {
             throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyTypeForNullValue.text());
         }
         for (PropertyType type : PropertyType.values()) {
             if (type == OBJECT) continue;
-            if (type.isInstance(value)) return type;
+            if (type.isTypeFor(value)) return type;
         }
         return OBJECT;
     }

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,31 @@
+/*
+ * 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.commands;
+
+/**
+ * Command that copies a branch from one path to another. In other words, this is a deep version of {@link CopyNodeCommand}.
+ * 
+ * @author Randall Hauch
+ */
+public interface CopyBranchCommand extends CopyNodeCommand {
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,39 @@
+/*
+ * 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.commands;
+
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * Command that makes a copy of a single node at another location.
+ * 
+ * @author Randall Hauch
+ */
+public interface CopyNodeCommand extends GraphCommand, ActsOnPath, ActsAsUpdate {
+
+    /**
+     * Get the new path to which the copy is to be made.
+     * 
+     * @return the new path; never null
+     */
+    Path getNewPath();
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/CopyNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java	2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetChildrenCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -24,9 +24,11 @@
 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;
 
 /**
  * A command to get the children of a single node given its path.
+ * 
  * @author Randall Hauch
  */
 public interface GetChildrenCommand extends GraphCommand, ActsOnPath, Cacheable {
@@ -41,9 +43,10 @@
      * 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.
      * </p>
+     * 
      * @param namesOfChildren the iterator over the names of children; may be null if there are no children
      */
-    void setChildren( Iterator<Name> namesOfChildren );
+    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
@@ -55,9 +58,10 @@
      * 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.
      * </p>
+     * 
      * @param namesOfChildren the iterable names of children; may be null if there are no children
      */
-    void setChildren( Iterable<Name> namesOfChildren );
+    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
@@ -65,13 +69,16 @@
      * <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( Name... namesOfChildren );
+    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.
+     * 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
      */
     void setChild( Name nameOfChild );

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java	2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/GetPropertiesCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -21,36 +21,48 @@
  */
 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.Property;
 
 /**
  * A command to obtain from the source the properties for a single node given its path.
+ * 
  * @author Randall Hauch
  */
 public interface GetPropertiesCommand extends GraphCommand, ActsOnPath, Cacheable {
 
     /**
-     * Set the properties. Any existing property values, if previously set, will be overwritten. If there are no property vlaues
-     * or if all of the property values are null, the property will be removed.
-     * @param properties the properties
+     * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+     * no property vlaues or if all of the property values are null, the property will be removed.
+     * <p>
+     * The implementation should be capable of accepting an array, {@link Iterator}, or {@link Iterable} as a sole single
+     * parameter, and properly extracting the values. This is so that callers that have an {@link Object} reference to an array,
+     * Iterator, or Iterable don't need to type check and cast in order to call {@link #setProperty(Name, Iterable...) the}
+     * {@link #setProperty(Name, Iterator...) appropriate} method.
+     * </p>
+     * 
+     * @param propertyName the name of the property
+     * @param values the property values
      */
-    void setProperties( Iterable<Property> properties );
+    void setProperty( Name propertyName, Object... values );
 
     /**
-     * Set the values for the property. Any existing property values, if previously set, will be overwritten. If there are no
-     * property vlaues or if all of the property values are null, the property will be removed.
-     * @param property the property
+     * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+     * no property vlaues or if all of the property values are null, the property will be removed.
+     * 
+     * @param propertyName the name of the property
+     * @param values the iterable property values
      */
-    void setProperty( Property property );
+    void setProperty( Name propertyName, Iterable<?> values );
 
     /**
      * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
      * no property vlaues or if all of the property values are null, the property will be removed.
+     * 
      * @param propertyName the name of the property
-     * @param values the property values
+     * @param values the iterator over the property values
      */
-    void setProperty( Name propertyName, Object... values );
+    void setProperty( Name propertyName, Iterator<?> values );
 
 }

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,40 @@
+/*
+ * 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.commands.impl;
+
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.CopyBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicCopyBranchCommand extends BasicCopyNodeCommand implements CopyBranchCommand {
+
+    /**
+     * @param oldPath
+     * @param newPath
+     */
+    public BasicCopyBranchCommand( Path oldPath, Path newPath ) {
+        super(oldPath, newPath);
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,63 @@
+/*
+ * 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.commands.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.CopyNodeCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicCopyNodeCommand extends BasicGraphCommand implements CopyNodeCommand {
+
+    private final Path oldPath;
+    private final Path newPath;
+
+    /**
+     * @param oldPath the path to the original; may not be null
+     * @param newPath the path to the copy; may not be null
+     */
+    public BasicCopyNodeCommand( Path oldPath, Path newPath ) {
+        super();
+        assert oldPath != null;
+        assert newPath != null;
+        this.oldPath = oldPath;
+        this.newPath = newPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return oldPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getNewPath() {
+        return newPath;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCopyNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,96 @@
+/*
+ * 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.commands.impl;
+
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicCreateNodeCommand extends BasicGraphCommand implements CreateNodeCommand {
+
+    private final Path path;
+    private final List<Property> properties;
+    private CachePolicy cachePolicy;
+    private long timeLoaded;
+
+    /**
+     * @param path the path to the node; may not be null
+     * @param properties the properties of the node; may not be null
+     */
+    public BasicCreateNodeCommand( Path path, List<Property> properties ) {
+        super();
+        assert path != null;
+        assert properties != null;
+        this.properties = properties;
+        this.path = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterable<Property> getProperties() {
+        return properties;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public CachePolicy getCachePolicy() {
+        return cachePolicy;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getTimeLoaded() {
+        return timeLoaded;
+    }
+
+    /**
+     * @param timeLoaded Sets timeLoaded to the specified value.
+     */
+    public void setTimeLoaded( long timeLoaded ) {
+        this.timeLoaded = timeLoaded;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setCachePolicy( CachePolicy cachePolicy ) {
+        this.cachePolicy = cachePolicy;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,52 @@
+/*
+ * 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.commands.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicDeleteBranchCommand extends BasicGraphCommand implements DeleteBranchCommand {
+
+    private final Path path;
+
+    /**
+     * @param path the path to the node; may not be null
+     */
+    public BasicDeleteBranchCommand( Path path ) {
+        super();
+        assert path != null;
+        this.path = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicDeleteBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,131 @@
+/*
+ * 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.commands.impl;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+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.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicGetChildrenCommand extends BasicGraphCommand implements GetChildrenCommand {
+
+    private List<Segment> children;
+    private final Path path;
+    private CachePolicy cachePolicy;
+    private long timeLoaded;
+
+    /**
+     * @param path the path to the node; may not be null
+     */
+    public BasicGetChildrenCommand( Path path ) {
+        super();
+        assert path != null;
+        this.path = path;
+    }
+
+    /**
+     * {@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();
+    }
+
+    /**
+     * @return children
+     */
+    public List<Segment> getChildren() {
+        return this.children;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public CachePolicy getCachePolicy() {
+        return cachePolicy;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getTimeLoaded() {
+        return timeLoaded;
+    }
+
+    /**
+     * @param timeLoaded Sets timeLoaded to the specified value.
+     */
+    public void setTimeLoaded( long timeLoaded ) {
+        this.timeLoaded = timeLoaded;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setCachePolicy( CachePolicy cachePolicy ) {
+        this.cachePolicy = cachePolicy;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,111 @@
+/*
+ * 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.commands.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+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
+ */
+ at NotThreadSafe
+public class BasicGetNodeCommand extends BasicGetPropertiesCommand implements GetNodeCommand {
+
+    private List<Segment> children;
+
+    /**
+     * @param path
+     */
+    public BasicGetNodeCommand( Path path ) {
+        super(path);
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setChild( Name nameOfChild ) {
+        if (nameOfChild == null) {
+            children = Collections.emptyList();
+        } else {
+            children = Collections.singletonList((Segment)new BasicPathSegment(nameOfChild));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setChildren( Iterator<Segment> namesOfChildren ) {
+        if (namesOfChildren == null) {
+            children = Collections.emptyList();
+        } else {
+            children = new ArrayList<Segment>();
+            while (namesOfChildren.hasNext()) {
+                children.add(namesOfChildren.next());
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setChildren( Iterable<Segment> namesOfChildren ) {
+        if (namesOfChildren == null) {
+            children = Collections.emptyList();
+        } else {
+            children = new ArrayList<Segment>();
+            for (Segment childSegment : namesOfChildren) {
+                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) {
+                children.add(childSegment);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setNoChildren() {
+        children = Collections.emptyList();
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,119 @@
+/*
+ * 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.commands.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+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.commands.GetPropertiesCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicGetPropertiesCommand extends BasicGraphCommand implements GetPropertiesCommand {
+
+    private final Map<Name, List<Object>> propertyValues = new HashMap<Name, List<Object>>();
+    private final Path path;
+    private CachePolicy cachePolicy;
+    private long timeLoaded;
+
+    /**
+     * @param path the path to the node; may not be null
+     */
+    public BasicGetPropertiesCommand( Path path ) {
+        super();
+        assert path != null;
+        this.path = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperty( Name propertyName, Object... values ) {
+        setProperty(propertyValues, propertyName, values);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperty( Name propertyName, Iterable<?> values ) {
+        setProperty(propertyValues, propertyName, values);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperty( Name propertyName, Iterator<?> values ) {
+        setProperty(propertyValues, propertyName, values);
+    }
+
+    /**
+     * Get the property values that were added to the command
+     * 
+     * @return the map of property name to values
+     */
+    public Map<Name, List<Object>> getPropertyValues() {
+        return this.propertyValues;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public CachePolicy getCachePolicy() {
+        return cachePolicy;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getTimeLoaded() {
+        return timeLoaded;
+    }
+
+    /**
+     * @param timeLoaded Sets timeLoaded to the specified value.
+     */
+    public void setTimeLoaded( long timeLoaded ) {
+        this.timeLoaded = timeLoaded;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setCachePolicy( CachePolicy cachePolicy ) {
+        this.cachePolicy = cachePolicy;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,163 @@
+/*
+ * 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.commands.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.impl.BasicPathSegment;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public abstract class BasicGraphCommand implements GraphCommand {
+
+    private boolean cancelled = false;
+
+    /**
+     * 
+     */
+    public BasicGraphCommand() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isCancelled() {
+        return cancelled;
+    }
+
+    /**
+     * @param cancelled Sets cancelled to the specified value.
+     */
+    public void setCancelled( boolean cancelled ) {
+        this.cancelled = cancelled;
+    }
+
+    // ----------------------------------------------------------------------------------------------------------------
+    // Utility methods used by concrete command implementations
+    // ----------------------------------------------------------------------------------------------------------------
+
+    protected List<Segment> createChildrenList( Name nameOfChild ) {
+        if (nameOfChild == null) {
+            return Collections.emptyList();
+        }
+        return Collections.singletonList((Segment)new BasicPathSegment(nameOfChild));
+    }
+
+    protected List<Segment> createChildrenList( Iterator<Segment> namesOfChildren ) {
+        if (namesOfChildren == null) {
+            return Collections.emptyList();
+        }
+        List<Segment> children = new ArrayList<Segment>();
+        while (namesOfChildren.hasNext()) {
+            children.add(namesOfChildren.next());
+        }
+        return children;
+    }
+
+    protected List<Segment> createChildrenList( Iterable<Segment> namesOfChildren ) {
+        if (namesOfChildren == null) {
+            return Collections.emptyList();
+        }
+        List<Segment> children = new ArrayList<Segment>();
+        for (Segment childSegment : namesOfChildren) {
+            children.add(childSegment);
+        }
+        return children;
+    }
+
+    protected static List<Segment> createChildrenList( Segment... namesOfChildren ) {
+        if (namesOfChildren == null || namesOfChildren.length == 0) {
+            return Collections.emptyList();
+        }
+        List<Segment> children = new ArrayList<Segment>();
+        for (Segment childSegment : namesOfChildren) {
+            children.add(childSegment);
+        }
+        return children;
+    }
+
+    protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Object... values ) {
+        if (values == null || values.length == 0) {
+            propertyValues.remove(propertyName);
+        } else {
+            List<Object> valuesList = null;
+            if (values.length == 1) {
+                Object value = values[0];
+                if (value instanceof Collection<?>) {
+                    setProperty(propertyValues, propertyName, ((Collection<?>)value).iterator());
+                    return;
+                } else if (value instanceof Iterable<?>) {
+                    setProperty(propertyValues, propertyName, (Iterable<?>)value);
+                    return;
+                } else if (value instanceof Iterator<?>) {
+                    setProperty(propertyValues, propertyName, (Iterator<?>)value);
+                    return;
+                }
+                // Otherwise, single object is just a normal value ...
+                valuesList = Collections.singletonList(value);
+            } else {
+                assert values.length > 1;
+                valuesList = new ArrayList<Object>(values.length);
+                for (Object arrayValue : values) {
+                    valuesList.add(arrayValue);
+                }
+            }
+            propertyValues.put(propertyName, valuesList);
+        }
+    }
+
+    protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Iterable<?> values ) {
+        if (values == null) {
+            propertyValues.remove(propertyName);
+        } else {
+            List<Object> valuesList = new ArrayList<Object>();
+            for (Object value : values) {
+                valuesList.add(value);
+            }
+            propertyValues.put(propertyName, valuesList);
+        }
+    }
+
+    protected static void setProperty( Map<Name, List<Object>> propertyValues, Name propertyName, Iterator<?> values ) {
+        if (values == null) {
+            propertyValues.remove(propertyName);
+        } else {
+            List<Object> valuesList = new ArrayList<Object>();
+            while (values.hasNext()) {
+                Object value = values.next();
+                valuesList.add(value);
+            }
+            propertyValues.put(propertyName, valuesList);
+        }
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGraphCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,63 @@
+/*
+ * 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.commands.impl;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.commands.MoveBranchCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicMoveBranchCommand extends BasicGraphCommand implements MoveBranchCommand {
+
+    private final Path oldPath;
+    private final Path newPath;
+
+    /**
+     * @param oldPath the path to the original; may not be null
+     * @param newPath the path to the new location; may not be null
+     */
+    public BasicMoveBranchCommand( Path oldPath, Path newPath ) {
+        super();
+        assert oldPath != null;
+        assert newPath != null;
+        this.oldPath = oldPath;
+        this.newPath = newPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return oldPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getNewPath() {
+        return newPath;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicMoveBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,96 @@
+/*
+ * 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.commands.impl;
+
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class BasicSetPropertiesCommand extends BasicGraphCommand implements SetPropertiesCommand {
+
+    private final Path path;
+    private final List<Property> properties;
+    private CachePolicy cachePolicy;
+    private long timeLoaded;
+
+    /**
+     * @param path the path to the node; may not be null
+     * @param properties the properties of the node; may not be null
+     */
+    public BasicSetPropertiesCommand( Path path, List<Property> properties ) {
+        super();
+        assert path != null;
+        assert properties != null;
+        this.properties = properties;
+        this.path = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterable<Property> getProperties() {
+        return properties;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public CachePolicy getCachePolicy() {
+        return cachePolicy;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getTimeLoaded() {
+        return timeLoaded;
+    }
+
+    /**
+     * @param timeLoaded Sets timeLoaded to the specified value.
+     */
+    public void setTimeLoaded( long timeLoaded ) {
+        this.timeLoaded = timeLoaded;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setCachePolicy( CachePolicy cachePolicy ) {
+        this.cachePolicy = cachePolicy;
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java	2008-05-30 18:57:03 UTC (rev 217)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/ExecutionEnvironment.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -23,6 +23,7 @@
 
 import org.jboss.dna.spi.graph.NamespaceRegistry;
 import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
 import org.jboss.dna.spi.graph.ValueFactories;
 
 /**
@@ -32,20 +33,30 @@
 
     /**
      * Get the factories that should be used to create values for {@link Property properties}.
+     * 
      * @return the property value factory; never null
      */
     ValueFactories getValueFactories();
 
     /**
      * Get the namespace registry for this environment.
+     * 
      * @return the namespace registry; never null
      */
     NamespaceRegistry getNamespaceRegistry();
 
     /**
      * Return the repository source against which this environment applies.
+     * 
      * @return the repository source; never null
      */
     RepositorySource getRepositorySource();
 
+    /**
+     * Get the factory for creating {@link Property} objects.
+     * 
+     * @return the property factory; never null
+     */
+    PropertyFactory getPropertyFactory();
+
 }

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,110 @@
+/*
+ * 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.util.Iterator;
+import java.util.NoSuchElementException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+ at Immutable
+public class BasicEmptyProperty extends BasicProperty {
+
+    /**
+     * @param name
+     * @param type
+     * @param definitionName
+     * @param valueFactories
+     */
+    public BasicEmptyProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
+        super(name, type, definitionName, valueFactories);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isMultiple() {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSingle() {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int size() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Object> iterator() {
+        return new EmptyIterator<Object>();
+    }
+
+    protected class EmptyIterator<T> implements Iterator<T> {
+
+        protected EmptyIterator() {
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean hasNext() {
+            return false;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public T next() {
+            throw new NoSuchElementException();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,120 @@
+/*
+ * 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.util.Iterator;
+import java.util.List;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+ at Immutable
+public class BasicMultiValueProperty extends BasicProperty {
+
+    private final List<Object> values;
+
+    /**
+     * @param name
+     * @param type
+     * @param definitionName
+     * @param valueFactories
+     * @param values
+     */
+    public BasicMultiValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, List<Object> values ) {
+        super(name, type, definitionName, valueFactories);
+        this.values = values;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        assert values.isEmpty() == false;
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isMultiple() {
+        assert values.size() > 1;
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSingle() {
+        assert values.size() == 1;
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int size() {
+        return values.size();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Object> iterator() {
+        return new ReadOnlyIterator(values.iterator());
+    }
+
+    protected class ReadOnlyIterator implements Iterator<Object> {
+
+        private final Iterator<Object> values;
+
+        protected ReadOnlyIterator( Iterator<Object> values ) {
+            assert values != null;
+            this.values = values;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean hasNext() {
+            return values.hasNext();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Object next() {
+            return values.next();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,293 @@
+/*
+ * 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.math.BigDecimal;
+import java.net.URI;
+import java.util.Iterator;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Binary;
+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.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+ at Immutable
+public abstract class BasicProperty implements Property {
+
+    private final Name name;
+    private final Name definitionName;
+    private final PropertyType type;
+    private final ValueFactories factories;
+
+    /**
+     * @param name
+     * @param type
+     * @param definitionName
+     * @param valueFactories
+     */
+    public BasicProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories ) {
+        this.name = name;
+        this.type = type;
+        this.definitionName = definitionName;
+        this.factories = valueFactories;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name getDefinitionName() {
+        return definitionName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PropertyType getPropertyType() {
+        return type;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Binary> getBinaryValues() {
+        return new ValueIterator<Binary>(factories.getBinaryFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Boolean> getBooleanValues() {
+        return new ValueIterator<Boolean>(factories.getBooleanFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<DateTime> getDateValues() {
+        return new ValueIterator<DateTime>(factories.getDateFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<BigDecimal> getDecimalValues() {
+        return new ValueIterator<BigDecimal>(factories.getDecimalFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Double> getDoubleValues() {
+        return new ValueIterator<Double>(factories.getDoubleFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Long> getLongValues() {
+        return new ValueIterator<Long>(factories.getLongFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Name> getNameValues() {
+        return new ValueIterator<Name>(factories.getNameFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Path> getPathValues() {
+        return new ValueIterator<Path>(factories.getPathFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Reference> getReferenceValues() {
+        return new ValueIterator<Reference>(factories.getReferenceFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<String> getStringValues() {
+        return new ValueIterator<String>(factories.getStringFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<URI> getUriValues() {
+        return new ValueIterator<URI>(factories.getUriFactory(), iterator());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<?> getValues() {
+        return iterator();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<?> getValues( PropertyType type ) {
+        switch (type) {
+            case BINARY:
+                return getBinaryValues();
+            case BOOLEAN:
+                return getBooleanValues();
+            case DATE:
+                return getDateValues();
+            case DECIMAL:
+                return getDecimalValues();
+            case DOUBLE:
+                return getDoubleValues();
+            case LONG:
+                return getLongValues();
+            case NAME:
+                return getNameValues();
+            case OBJECT:
+                return getValues();
+            case PATH:
+                return getPathValues();
+            case REFERENCE:
+                return getReferenceValues();
+            case STRING:
+                return getStringValues();
+            case URI:
+                return getUriValues();
+        }
+        return getValues(); // should never get here ...
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getValuesAsArray() {
+        if (size() == 0) return null;
+        Object[] results = new Object[size()];
+        Iterator<?> iter = iterator();
+        int index = 0;
+        while (iter.hasNext()) {
+            Object value = iter.next();
+            results[index++] = value;
+        }
+        return results;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compareTo( Property o ) {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj ) {
+        if (this == obj) return true;
+        if (obj instanceof Property) {
+            Property that = (Property)obj;
+            if (!this.getName().equals(that.getName())) return false;
+            if (this.getPropertyType() != that.getPropertyType()) return false;
+            if (this.size() != that.size()) return false;
+            Iterator<?> thisIter = iterator();
+            Iterator<?> thatIter = that.iterator();
+            while (thisIter.hasNext()) { // && thatIter.hasNext()
+                Object thisValue = thisIter.next();
+                Object thatValue = thatIter.next();
+                if (thisValue == null) {
+                    if (thatValue != null) return false;
+                    // else both are null
+                } else {
+                    if (!thisValue.equals(thatValue)) return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    protected class ValueIterator<T> implements Iterator<T> {
+
+        private final ValueFactory<T> factory;
+        private final Iterator<Object> values;
+
+        protected ValueIterator( ValueFactory<T> factory, Iterator<Object> values ) {
+            assert factory != null;
+            assert values != null;
+            this.factory = factory;
+            this.values = values;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean hasNext() {
+            return values.hasNext();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public T next() {
+            return factory.create(values.next());
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicProperty.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,135 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicPropertyFactory implements PropertyFactory {
+
+    private final ValueFactories factories;
+
+    /**
+     * @param valueFactories the value factories
+     * @throws IllegalArgumentException if the reference to the value factories is null
+     */
+    public BasicPropertyFactory( ValueFactories valueFactories ) {
+        ArgCheck.isNotNull(valueFactories, "value factories");
+        this.factories = valueFactories;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Property create( Name name, PropertyType type, Name definitionName, Object... values ) {
+        ArgCheck.isNotNull(name, "name");
+        ArgCheck.isNotNull(type, "type");
+        if (values == null || values.length == 0) {
+            return new BasicEmptyProperty(name, type, definitionName, this.factories);
+        }
+        final int len = values.length;
+        final ValueFactory<?> factory = factories.getValueFactory(type);
+        if (values.length == 1) {
+            Object value = values[0];
+            // Check whether the sole value was a collection ...
+            if (value instanceof Collection) {
+                // The single value is a collection, so create property with the collection's contents ...
+                return create(name, type, definitionName, (Collection<?>)value);
+            }
+            value = factory.create(values[0]);
+            return new BasicSingleValueProperty(name, type, definitionName, this.factories, value);
+        }
+        List<Object> valueList = new ArrayList<Object>(len);
+        for (int i = 0; i != len; ++i) {
+            Object value = factory.create(values[i]);
+            valueList.add(value);
+        }
+        return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings( "unchecked" )
+    public Property create( Name name, PropertyType type, Name definitionName, Iterable<?> values ) {
+        ArgCheck.isNotNull(name, "name");
+        ArgCheck.isNotNull(type, "type");
+        List<Object> valueList = null;
+        if (values instanceof Collection) {
+            Collection<Object> originalValues = (Collection<Object>)values;
+            if (originalValues.isEmpty()) {
+                return new BasicEmptyProperty(name, type, definitionName, this.factories);
+            }
+            valueList = new ArrayList<Object>(originalValues.size());
+        } else {
+            // We don't know the size
+            valueList = new ArrayList<Object>();
+        }
+        // Copy the values, ensuring that the values are the correct type ...
+        final ValueFactory<?> factory = factories.getValueFactory(type);
+        for (Object value : values) {
+            valueList.add(factory.create(value));
+        }
+        if (valueList.isEmpty()) { // may not have been a collection earlier
+            return new BasicEmptyProperty(name, type, definitionName, this.factories);
+        }
+        if (valueList.size() == 1) {
+            return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+        }
+        return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Property create( Name name, PropertyType type, Name definitionName, Iterator<?> values ) {
+        ArgCheck.isNotNull(name, "name");
+        ArgCheck.isNotNull(type, "type");
+        final List<Object> valueList = new ArrayList<Object>();
+        final ValueFactory<?> factory = factories.getValueFactory(type);
+        while (values.hasNext()) {
+            Object value = values.next();
+            value = factory.create(value);
+            valueList.add(value);
+        }
+        if (valueList.isEmpty()) {
+            return new BasicEmptyProperty(name, type, definitionName, this.factories);
+        }
+        if (valueList.size() == 1) {
+            return new BasicSingleValueProperty(name, type, definitionName, this.factories, valueList.get(0));
+        }
+        return new BasicMultiValueProperty(name, type, definitionName, this.factories, valueList);
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPropertyFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java	2008-06-02 16:34:47 UTC (rev 218)
@@ -0,0 +1,120 @@
+/*
+ * 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.util.Iterator;
+import java.util.NoSuchElementException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @author Randall Hauch
+ */
+ at Immutable
+public class BasicSingleValueProperty extends BasicProperty {
+
+    protected final Object value;
+
+    /**
+     * @param name
+     * @param type
+     * @param definitionName
+     * @param valueFactories
+     * @param value
+     */
+    public BasicSingleValueProperty( Name name, PropertyType type, Name definitionName, ValueFactories valueFactories, Object value ) {
+        super(name, type, definitionName, valueFactories);
+        this.value = value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isMultiple() {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSingle() {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int size() {
+        return 1;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Object> iterator() {
+        return new ValueIterator();
+    }
+
+    protected class ValueIterator implements Iterator<Object> {
+
+        private boolean done = false;
+
+        protected ValueIterator() {
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean hasNext() {
+            return !done;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Object next() {
+            if (!done) {
+                done = true;
+                return BasicSingleValueProperty.this.value;
+            }
+            throw new NoSuchElementException();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list