[dna-commits] DNA SVN: r176 - in branches/federation/dna-spi/src/main: java/org/jboss/dna/spi/connector and 4 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Mon May 19 12:32:40 EDT 2008


Author: rhauch
Date: 2008-05-19 12:32:40 -0400 (Mon, 19 May 2008)
New Revision: 176

Added:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
Removed:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java
Modified:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
   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/PropertyValues.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
   branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67

Updated the graph API by removing the concept of a PropertyValue and instead simply defined Property to store raw values (e.g., String, long, double, boolean, Calendar, Reference, Path, Name, URI).  Created a ValueFactory<T> interface along with a ValueFactories interface that maintains access to the different ValueFactory<T> interfaces.  These value factories can be used to create raw value instances as well as convert instances from one type to another.  Also provide a basic implementation of all these interfaces, which all should be usable in most environments (except for InMemoryBinaryValueFactory, which assumes an InMemoryBinary implementation).  The StandardValueFactories interface is a highly-flexible container for other value factories, and can easily be provided with other value factory implementations that override the default implementations.

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -41,6 +41,10 @@
     public static I18n valueJavaTypeNotCompatibleWithPropertyType;
 
     public static I18n errorConvertingBinaryValueToString;
+    public static I18n errorCreatingValue;
+    public static I18n unableToCreateValue;
+    public static I18n unableToCreatePathFromEmptyString;
+    public static I18n validPathMayNotContainEmptySegment;
 
     public static I18n pathAncestorDegreeIsInvalid;
     public static I18n pathIsAlreadyAbsolute;

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -58,6 +58,10 @@
      */
     boolean ping( long time, TimeUnit unit ) throws InterruptedException;
 
+    /**
+     * Set the listener that is to receive notifications to changes to content within this source.
+     * @param listener the new listener, or null if no component is interested in the change notifications
+     */
     void setListener( RepositorySourceListener listener );
 
     /**

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,8 @@
 
 import org.jboss.dna.spi.graph.Name;
 import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.PropertyValue;
-import org.jboss.dna.spi.graph.PropertyValueFactory;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
 
 /**
  * @author Randall Hauch
@@ -32,10 +32,10 @@
 public interface RepositorySourceEnvironment {
 
     /**
-     * Get the factory that should be used to create {@link PropertyValue property values}.
+     * Get the factories that should be used to create values for {@link Property properties}.
      * @return the property value factory; never null
      */
-    PropertyValueFactory getPropertyValueFactory();
+    ValueFactories getValueFactories();
 
     /**
      * Get the factory that should be used to create {@link Name names}.

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -23,21 +23,14 @@
 
 import java.util.Iterator;
 import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
 
 /**
  * A command to get the children of a single node.
  * @author Randall Hauch
  */
-public interface GetChildrenCommand extends GetCommand {
+public interface GetChildrenCommand extends GetNodeInformationCommand {
 
     /**
-     * Get the path of the node for which the children are to be obtained.
-     * @return the node's path
-     */
-    Path getPath();
-
-    /**
      * Set the children of this node using an iterator of names. Any existing child references already set on this command will be
      * replaced by those supplied to this method.
      * <p>

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,50 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * A command to get information about a single node.
+ * @author Randall Hauch
+ */
+public interface GetNodeInformationCommand extends GetCommand {
+
+    /**
+     * Get the path of the node for which the children are to be obtained.
+     * @return the node's path
+     */
+    Path getPath();
+
+    /**
+     * Get the property with the given name. This method is useful when the source has previously saved node-specific information
+     * in properties, and that information is required to process commands. As the node may not have yet been obtained from the
+     * source, the source should not expect properties to always exist on the supplied node.
+     * @param propertyName the name of the property to retrieve
+     * @return the property with the supplied name, or null if that property is not already known to the component that created
+     * this command
+     */
+    Property getProperty( Name propertyName );
+
+}


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

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -22,27 +22,19 @@
 package org.jboss.dna.spi.connector.commands;
 
 import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PropertyValue;
 
 /**
  * A command to get the properties for a single node.
  * @author Randall Hauch
  */
-public interface GetPropertiesCommand extends GetCommand {
+public interface GetPropertiesCommand extends GetNodeInformationCommand {
 
     /**
-     * Get the path of the node for which the properties are to be obtained.
-     * @return the node's path
-     */
-    Path getPath();
-
-    /**
      * 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
      */
-    void setProperty( Name propertyName, PropertyValue... values );
+    void setProperty( Name propertyName, Object... values );
 
 }

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -59,4 +59,28 @@
      * @see #getString()
      */
     public String getString( TextEncoder encoder );
+
+    /**
+     * Get the string form of the name, using the supplied namespace registry to convert the
+     * {@link #getNamespaceUri() namespace URI} to a prefix. The {@link Path#DEFAULT_ENCODER default encoder} is used to encode
+     * characters in each of the path segments.
+     * @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
+     * {@link Name#getNamespaceUri() namespace URI}
+     * @return the encoded string
+     * @throws IllegalArgumentException if the namespace registry is null
+     * @see #getString(NamespaceRegistry,TextEncoder)
+     */
+    public String getString( NamespaceRegistry namespaceRegistry );
+
+    /**
+     * Get the encoded string form of the name, using the supplied namespace registry to convert the
+     * {@link #getNamespaceUri() namespace URI} to a prefix.
+     * @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
+     * {@link Name#getNamespaceUri() namespace URI}
+     * @param encoder the encoder to use, or null if the {@link Path#DEFAULT_ENCODER default encoder} should be used
+     * @return the encoded string
+     * @throws IllegalArgumentException if the namespace registry is null
+     * @see #getString(NamespaceRegistry)
+     */
+    public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder );
 }

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -27,29 +27,9 @@
  * A factory for creating {@link Name names}.
  * @author Randall Hauch
  */
-public interface NameFactory {
+public interface NameFactory extends ValueFactory<Name> {
 
     /**
-     * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
-     * <p>
-     * This method is equivalent to calling {@link #create(String, TextEncoder)} with a null encoder.
-     * </p>
-     * @param qualifiedName
-     * @return the new name.
-     * @throws IllegalArgumentException if the qualified name is null or invalid
-     */
-    Name create( String qualifiedName );
-
-    /**
-     * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
-     * @param qualifiedName
-     * @param encoder the encoder that should be used to decode the qualified name
-     * @return the new name
-     * @throws IllegalArgumentException if the qualified name is null or invalid
-     */
-    Name create( String qualifiedName, TextEncoder encoder );
-
-    /**
      * Create a name from the given namespace URI and local name.
      * <p>
      * This method is equivalent to calling {@link #create(String, String, TextEncoder)} with a null encoder.

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public interface NamespaceRegistry {
+
+    String getNamespaceForPrefix( String prefix );
+
+    String getPrefixForNamespaceUri( String namespaceUri );
+
+}


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

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -358,4 +358,27 @@
      */
     public String getString( TextEncoder encoder );
 
+    /**
+     * Get the string form of the path, using the supplied namespace registry to convert the names' namespace URIs to prefixes.
+     * The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each of the path segments.
+     * @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
+     * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
+     * @return the encoded string
+     * @throws IllegalArgumentException if the namespace registry is null
+     * @see #getString(NamespaceRegistry,TextEncoder)
+     */
+    public String getString( NamespaceRegistry namespaceRegistry );
+
+    /**
+     * Get the encoded string form of the path, using the supplied namespace registry to convert the names' namespace URIs to
+     * prefixes and the supplied encoder to encode characters in each of the path segments.
+     * @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
+     * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link Segment#getName() names}
+     * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default encoder} should be used
+     * @return the encoded string
+     * @throws IllegalArgumentException if the namespace registry is null
+     * @see #getString(NamespaceRegistry)
+     */
+    public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder );
+
 }

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -25,7 +25,7 @@
  * A factory for creating {@link Path paths}.
  * @author Randall Hauch
  */
-public interface PathFactory {
+public interface PathFactory extends ValueFactory<Path> {
 
     /**
      * Create an absolute path with the supplied segment names, in order. If no segments are provided, the result will be the root

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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -21,17 +21,207 @@
  */
 package org.jboss.dna.spi.graph;
 
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
 import java.util.Iterator;
 
 /**
+ * Representation of a property consisting of a name and value(s).
  * @author Randall Hauch
  */
-public interface Property extends Iterable<PropertyValue> {
+public interface Property extends Iterable<Object>, Comparable<Property> {
 
+    /**
+     * 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.
+     * @return true if the property has multiple values, or false otherwise.
+     * @see #isSingle()
+     */
     boolean isMultiple();
 
-    Iterator<PropertyValue> getValues();
+    /**
+     * 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.
+     * @see #isMultiple()
+     */
+    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
+     */
+    boolean isEmpty();
+
+    /**
+     * Get the type for this property.
+     * @return the property's type, which is never null
+     */
+    PropertyType getPropertyType();
+
+    /**
+     * Obtain the property's values in their natural form, as defined by {@link #getPropertyType()}. This is equivalent to
+     * calling {@link Iterable#iterator() iterator()}.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the values; never null
+     * @see Iterable#iterator()
+     */
+    Iterator<?> getValues();
+
+    /**
+     * 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.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </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
+     */
+    Iterator<?> getValues( PropertyType type );
+
+    /**
+     * Obtain the property's values as String objects, converting the values if the {@link #getPropertyType() property type} is
+     * not {@link PropertyType#STRING}. Note that it is always possible to convert to a String value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the String values; never null
+     */
+    Iterator<String> getStringValues();
+
+    /**
+     * Obtain the property's values as Binary objects, converting the values if the {@link #getPropertyType() property type} is
+     * not {@link PropertyType#BINARY}. Note that it is always possible to convert to a {@link Binary} value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the {@link Binary} values; never null
+     */
+    Iterator<Binary> getBinaryValues();
+
+    /**
+     * Obtain the property's values as longs, converting the values if the {@link #getPropertyType() property type} is not
+     * {@link PropertyType#LONG}. Note that it is not always possible to convert to a {@link PropertyType#LONG long} value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the long values; never null
+     */
+    Iterator<Long> getLongValues();
+
+    /**
+     * Obtain the property's values as doubles, converting the values if the {@link #getPropertyType() property type} is not
+     * {@link PropertyType#DOUBLE}. Note that it is not always possible to convert to a {@link PropertyType#DOUBLE double} value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the double values; never null
+     */
+    Iterator<Double> getDoubleValues();
+
+    /**
+     * Obtain the property's values as decimal values, converting the values if the {@link #getPropertyType() property type} is
+     * not {@link PropertyType#DECIMAL}. Note that it is not always possible to convert to a {@link PropertyType#DECIMAL decimal}
+     * value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </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
+     * {@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>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the Calendar values; never null
+     */
+    Iterator<Calendar> getDateValues();
+
+    /**
+     * Obtain the property's values as booleans, converting the values if the {@link #getPropertyType() property type} is not
+     * {@link PropertyType#BOOLEAN}. Note that it is not always possible to convert to a {@link PropertyType#BOOLEAN boolean}
+     * value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the Boolean values; never null
+     */
+    Iterator<Boolean> getBooleanValues();
+
+    /**
+     * Obtain the property's values as {@link Name names}, converting the values if the {@link #getPropertyType() property type}
+     * is not {@link PropertyType#NAME}. Note that it is not always possible to convert to a {@link PropertyType#NAME long}
+     * value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the Name values; never null
+     */
+    Iterator<Name> getNameValues();
+
+    /**
+     * Obtain the property's values as {@link Path paths}, converting the values if the {@link #getPropertyType() property type}
+     * is not {@link PropertyType#PATH}. Note that it is not always possible to convert to a {@link PropertyType#PATH path}
+     * value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the Path values; never null
+     */
+    Iterator<Path> getPathValues();
+
+    /**
+     * Obtain the property's values as references, converting the values if the {@link #getPropertyType() property type} is not
+     * {@link PropertyType#REFERENCE}. Note that it is not always possible to convert to a
+     * {@link PropertyType#REFERENCE reference} value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the Reference values; never null
+     */
+    Iterator<Reference> getReferenceValues();
+
+    /**
+     * Obtain the property's values as {@link URI URIs}, converting the values if the {@link #getPropertyType() property type} is
+     * not {@link PropertyType#URI}. Note that it is not always possible to convert to a {@link PropertyType#URI URI} value.
+     * <p>
+     * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+     * </p>
+     * @return an iterator over the URI values; never null
+     */
+    Iterator<URI> getUriValues();
+
 }

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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,8 @@
 
 import java.math.BigDecimal;
 import java.net.URI;
+import java.util.Calendar;
 import java.util.Comparator;
-import java.util.Date;
 import java.util.UUID;
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.common.util.StringUtil;
@@ -42,7 +42,7 @@
     LONG("Long", PropertyValues.LONG_COMPARATOR, Long.class),
     DOUBLE("Double", PropertyValues.DOUBLE_COMPARATOR, Double.class),
     DECIMAL("Decimal", PropertyValues.DECIMAL_COMPARATOR, BigDecimal.class),
-    DATE("Date", PropertyValues.DATE_COMPARATOR, Date.class),
+    DATE("Date", PropertyValues.DATE_COMPARATOR, Calendar.class),
     BOOLEAN("Boolean", PropertyValues.BOOLEAN_COMPARATOR, Boolean.class),
     NAME("Name", PropertyValues.NAME_COMPARATOR, Name.class),
     PATH("Path", PropertyValues.PATH_COMPARATOR, Path.class),
@@ -85,5 +85,4 @@
         }
         throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(StringUtil.readableString(value)));
     }
-
 }

Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph;
-
-import java.io.Serializable;
-
-/**
- * @author Randall Hauch
- */
-public interface PropertyValue extends Comparable<PropertyValue>, Cloneable, Serializable {
-
-    /**
-     * Determine whether the property value is null.
-     * @return true if the property value is null, or false otherwise
-     */
-    boolean isNull();
-
-    String getValueAsString();
-
-    PropertyType getPropertyType();
-
-    boolean isEquivalentTo( PropertyValue value );
-}

Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -1,68 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.net.URI;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-
-/**
- * @author Randall Hauch
- */
- at ThreadSafe
-public interface PropertyValueFactory {
-
-    PropertyValue create( String value ) throws ValueFormatException;
-
-    PropertyValue create( int value ) throws ValueFormatException;
-
-    PropertyValue create( long value ) throws ValueFormatException;
-
-    PropertyValue create( boolean value ) throws ValueFormatException;
-
-    PropertyValue create( float value ) throws ValueFormatException;
-
-    PropertyValue create( double value ) throws ValueFormatException;
-
-    PropertyValue create( Calendar value ) throws ValueFormatException;
-
-    PropertyValue create( Date value ) throws ValueFormatException;
-
-    PropertyValue create( Name value ) throws ValueFormatException;
-
-    PropertyValue create( Path value ) throws ValueFormatException;
-
-    PropertyValue create( UUID value ) throws ValueFormatException;
-
-    PropertyValue create( URI value ) throws ValueFormatException;
-
-    PropertyValue create( byte[] value ) throws ValueFormatException;
-
-    PropertyValue create( InputStream value, int approximateLength ) throws ValueFormatException;
-
-    PropertyValue create( Reader reader, int approximateLength ) throws ValueFormatException;
-
-}

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -44,6 +44,9 @@
     public static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
 
         public int compare( String o1, String o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -53,6 +56,9 @@
     public static final Comparator<Integer> INTEGER_COMPARATOR = new Comparator<Integer>() {
 
         public int compare( Integer o1, Integer o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -62,6 +68,9 @@
     public static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
 
         public int compare( Long o1, Long o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -71,6 +80,9 @@
     public static final Comparator<Float> FLOAT_COMPARATOR = new Comparator<Float>() {
 
         public int compare( Float o1, Float o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -80,6 +92,9 @@
     public static final Comparator<Double> DOUBLE_COMPARATOR = new Comparator<Double>() {
 
         public int compare( Double o1, Double o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -89,6 +104,9 @@
     public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new Comparator<BigDecimal>() {
 
         public int compare( BigDecimal o1, BigDecimal o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -164,6 +182,9 @@
     public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new Comparator<Boolean>() {
 
         public int compare( Boolean o1, Boolean o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -173,6 +194,9 @@
     public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
 
         public int compare( Date o1, Date o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -182,6 +206,9 @@
     public static final Comparator<Calendar> CALENDAR_COMPARATOR = new Comparator<Calendar>() {
 
         public int compare( Calendar o1, Calendar o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -191,6 +218,9 @@
     public static final Comparator<Name> NAME_COMPARATOR = new Comparator<Name>() {
 
         public int compare( Name o1, Name o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -200,6 +230,9 @@
     public static final Comparator<Path> PATH_COMPARATOR = new Comparator<Path>() {
 
         public int compare( Path o1, Path o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
@@ -209,15 +242,21 @@
     public static final Comparator<URI> URI_COMPARATOR = new Comparator<URI>() {
 
         public int compare( URI o1, URI o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };
     /**
      * A comparator of reference values.
      */
-    public static final Comparator<UUID> REFERENCE_COMPARATOR = new Comparator<UUID>() {
+    public static final Comparator<Reference> REFERENCE_COMPARATOR = new Comparator<Reference>() {
 
-        public int compare( UUID o1, UUID o2 ) {
+        public int compare( Reference o1, Reference o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
             return o1.compareTo(o2);
         }
     };

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,48 @@
+/*
+ * 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.io.Externalizable;
+import org.jboss.dna.common.text.TextEncoder;
+
+/**
+ * @author Randall Hauch
+ */
+public interface Reference extends Comparable<Reference>, Externalizable {
+
+    /**
+     * Get the string form of the Reference. The {@link Path#DEFAULT_ENCODER default encoder} is used to encode characters in the
+     * reference.
+     * @return the encoded string
+     * @see #getString(TextEncoder)
+     */
+    public String getString();
+
+    /**
+     * Get the encoded string form of the Reference, using the supplied encoder to encode characters in the reference.
+     * @param encoder the encoder to use, or null if the {@link Path#DEFAULT_ENCODER default encoder} should be used
+     * @return the encoded string
+     * @see #getString()
+     */
+    public String getString( TextEncoder encoder );
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,116 @@
+/*
+ * 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.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+
+/**
+ * The set of standard {@link ValueFactory} instances.
+ * @author Randall Hauch
+ */
+public interface ValueFactories extends Iterable<ValueFactory<?>> {
+
+    /**
+     * Get the value factory that creates values of the supplied {@link PropertyType type}.
+     * @param type the type for the values
+     * @return the factory; never null
+     * @throws IllegalArgumentException if the property type is null
+     */
+    ValueFactory<?> getValueFactory( PropertyType type );
+
+    /**
+     * Get the value factory that is best able to create values with the most natural type given by the supplied value.
+     * @param prototype the value that should be used to determine the best value factory
+     * @return the factory; never null
+     * @throws IllegalArgumentException if the prototype value is null
+     */
+    ValueFactory<?> getValueFactory( Object prototype );
+
+    /**
+     * Get the value factory for {@link PropertyType#STRING string} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<String> getStringFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#BINARY binary} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Binary> getBinaryFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#LONG long} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Long> getLongFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#DOUBLE double} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Double> getDoubleFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#DECIMAL decimal} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<BigDecimal> getDecimalFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#DATE date} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Calendar> getDateFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Boolean> getBooleanFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#NAME name} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Name> getNameFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#REFERENCE reference} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Reference> getReferenceFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#PATH path} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<Path> getPathFactory();
+
+    /**
+     * Get the value factory for {@link PropertyType#URI URI} properties.
+     * @return the factory; never null
+     */
+    ValueFactory<URI> getUriFactory();
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,192 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+
+/**
+ * A factory for {@link Property} values. Some of the methods may throw a {@link ValueFormatException} if the parameter supplied
+ * to the <code>create(...)</code> method cannot be converted to the {@link #getPropertyType() factory's type}.
+ * @author Randall Hauch
+ * @param <T> the type of value to create
+ */
+public interface ValueFactory<T> {
+
+    static final TextEncoder DEFAULT_ENCODER = Path.NO_OP_ENCODER;
+
+    /**
+     * Get the {@link PropertyType type} of values created by this factory.
+     * @return the value type; never null
+     */
+    PropertyType getPropertyType();
+
+    /**
+     * Create a value from a string, using no decoding.
+     * @param value the string from which the value is to be created
+     * @return the value, or null if the supplied string is null
+     * @throws ValueFormatException if the value could not be created from the supplied string
+     * @see #create(String, TextEncoder)
+     */
+    T create( String value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a string, using the supplied decoder.
+     * @param value the string from which the value is to be created
+     * @param decoder the decoder that should be used; if null, the {@link #DEFAULT_ENCODER default decoder} is used
+     * @return the value, or null if the supplied string is null
+     * @throws ValueFormatException if the value could not be created from the supplied string
+     * @see #create(String)
+     */
+    T create( String value, TextEncoder decoder ) throws ValueFormatException;
+
+    /**
+     * Create a value from an integer.
+     * @param value the integer from which the value is to be created
+     * @return the value; never null
+     * @throws ValueFormatException if the value could not be created from the supplied integer
+     */
+    T create( int value ) throws ValueFormatException;
+
+    /**
+     * Create a long from a string.
+     * @param value the string from which the long is to be created
+     * @return the value; never null
+     * @throws ValueFormatException if the value could not be created from the supplied long
+     */
+    T create( long value ) throws ValueFormatException;
+
+    /**
+     * Create a boolean from a string.
+     * @param value the boolean from which the value is to be created
+     * @return the value; never null
+     * @throws ValueFormatException if the value could not be created from the supplied boolean
+     */
+    T create( boolean value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a float.
+     * @param value the float from which the value is to be created
+     * @return the value; never null
+     * @throws ValueFormatException if the value could not be created from the supplied float
+     */
+    T create( float value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a double.
+     * @param value the double from which the value is to be created
+     * @return the value; never null
+     * @throws ValueFormatException if the value could not be created from the supplied double
+     */
+    T create( double value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a decimal.
+     * @param value the decimal from which the value is to be created
+     * @return the value, or null if the supplied decimal is null
+     * @throws ValueFormatException if the value could not be created from the supplied decimal
+     */
+    T create( BigDecimal value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a Calendar instance.
+     * @param value the Calendar instance from which the value is to be created
+     * @return the value, or null if the supplied Calendar is null
+     * @throws ValueFormatException if the value could not be created from the supplied Calendar object
+     */
+    T create( Calendar value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a date.
+     * @param value the date from which the value is to be created
+     * @return the value, or null if the supplied date is null
+     * @throws ValueFormatException if the value could not be created from the supplied date
+     */
+    T create( Date value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a name.
+     * @param value the name from which the value is to be created
+     * @return the value, or null if the supplied name is null
+     * @throws ValueFormatException if the value could not be created from the supplied name
+     */
+    T create( Name value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a path.
+     * @param value the path from which the value is to be created
+     * @return the value, or null if the supplied path is null
+     * @throws ValueFormatException if the value could not be created from the supplied path
+     */
+    T create( Path value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a reference.
+     * @param value the reference from which the value is to be created
+     * @return the value, or null if the supplied reference is null
+     * @throws ValueFormatException if the value could not be created from the supplied reference
+     */
+    T create( Reference value ) throws ValueFormatException;
+
+    /**
+     * Create a value from a URI.
+     * @param value the URI from which the value is to be created
+     * @return the value, or null if the supplied URI is null
+     * @throws ValueFormatException if the value could not be created from the supplied URI
+     */
+    T create( URI value ) throws ValueFormatException;
+
+    /**
+     * Create a value from the binary content given by the supplied array.
+     * @param value the content to be used to create the value
+     * @return the value, or null if the supplied stream is null
+     * @throws ValueFormatException if the value could not be created from the supplied byte array
+     */
+    T create( byte[] value ) throws ValueFormatException;
+
+    /**
+     * Create a value from the binary content given by the supplied stream.
+     * @param stream the stream containing the content to be used to create the value
+     * @param approximateLength the approximate length of the content (in bytes)
+     * @return the value, or null if the supplied stream is null
+     * @throws ValueFormatException if the value could not be created from the supplied stream
+     * @throws IOException if there is a problem reading the stream
+     */
+    T create( InputStream stream, int approximateLength ) throws ValueFormatException, IOException;
+
+    /**
+     * Create a value from a the binary content given by the supplied reader.
+     * @param reader the reader containing the content to be used to create the value
+     * @param approximateLength the approximate length of the content (in bytes)
+     * @return the value, or null if the supplied string is null
+     * @throws ValueFormatException if the value could not be created from the supplied reader
+     * @throws IOException if there is a problem reading the stream
+     */
+    T create( Reader reader, int approximateLength ) throws ValueFormatException, IOException;
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -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;
+
+
+/**
+ * 
+ * @author Randall Hauch
+ */
+public class Values {
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,80 @@
+/*
+ * 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 net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * Abstract {@link ValueFactory}.
+ * @author Randall Hauch
+ * @param <T> the property type
+ */
+ at Immutable
+public abstract class AbstractValueFactory<T> implements ValueFactory<T> {
+
+    private final TextEncoder encoder;
+    private final PropertyType propertyType;
+    private final ValueFactory<String> stringValueFactory;
+
+    protected AbstractValueFactory( PropertyType type, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        ArgCheck.isNotNull(type, "type");
+        this.propertyType = type;
+        this.encoder = encoder != null ? encoder : DEFAULT_ENCODER;
+        this.stringValueFactory = stringValueFactory;
+    }
+
+    /**
+     * @return stringValueFactory
+     */
+    protected ValueFactory<String> getStringValueFactory() {
+        return this.stringValueFactory;
+    }
+
+    /**
+     * Get the text encoder/decoder.
+     * @return encoder/decoder
+     */
+    public TextEncoder getEncoder() {
+        return this.encoder;
+    }
+
+    /**
+     * Utility method to obtain either the supplied encoder (if not null) or this factory's {@link #getEncoder() encoder}.
+     * @param encoder the encoder, which may be null if this factory's {@link #getEncoder() is to be used}
+     * @return the encoder; never null
+     */
+    protected TextEncoder getEncoder( TextEncoder encoder ) {
+        return encoder != null ? encoder : this.getEncoder();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PropertyType getPropertyType() {
+        return propertyType;
+    }
+
+}


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

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,10 @@
 
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.common.util.HashCode;
 import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
 import org.jboss.dna.spi.graph.Path;
 
 /**
@@ -76,6 +78,30 @@
     /**
      * {@inheritDoc}
      */
+    public String getString( NamespaceRegistry namespaceRegistry ) {
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+        if (prefix != null) {
+            return prefix + ":" + this.localName;
+        }
+        return this.localName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+        if (prefix != null) {
+            return encoder.encode(prefix) + ":" + encoder.encode(this.localName);
+        }
+        return this.localName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public int compareTo( Name that ) {
         if (that == this) return 0;
         int diff = this.getNamespaceUri().compareTo(that.getNamespaceUri());

Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph.impl;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.SpiI18n;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
-
-/**
- * @author Randall Hauch
- */
-public class BasicNameFactory implements NameFactory {
-
-    // Non-escaped pattern: (\{([^}]*)\})?(.*)
-    protected static final String QUALFIED_NAME_PATTERN_STRING = "(\\{([^}]*)\\})?(.*)";
-    protected static final Pattern QUALIFIED_NAME_PATTERN = Pattern.compile(QUALFIED_NAME_PATTERN_STRING);
-
-    /**
-     * {@inheritDoc}
-     */
-    public Name create( String qualifiedName ) {
-        return create(qualifiedName, Path.DEFAULT_ENCODER);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Name create( String qualifiedName, TextEncoder encoder ) {
-        ArgCheck.isNotNull(qualifiedName, "qualifiedName");
-        if (encoder == null) encoder = Path.DEFAULT_ENCODER;
-        String decodedQualifiedName = encoder.decode(qualifiedName.trim());
-        Matcher matcher = QUALIFIED_NAME_PATTERN.matcher(decodedQualifiedName);
-        if (!matcher.matches()) {
-            throw new IllegalArgumentException(SpiI18n.invalidQualifiedNameString.text(qualifiedName));
-        }
-        String namespaceUri = matcher.group(2);
-        String localName = matcher.group(3);
-        return new BasicName(namespaceUri, localName);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Name create( String namespaceUri, String localName ) {
-        return create(namespaceUri, localName, Path.DEFAULT_ENCODER);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Name create( String namespaceUri, String localName, TextEncoder encoder ) {
-        ArgCheck.isNotNull(localName, "localName");
-        if (encoder == null) encoder = Path.DEFAULT_ENCODER;
-        namespaceUri = namespaceUri != null ? encoder.decode(namespaceUri.trim()) : null;
-        localName = encoder.decode(localName.trim());
-        return new BasicName(namespaceUri, localName);
-    }
-
-}

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -33,6 +33,7 @@
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.spi.SpiI18n;
 import org.jboss.dna.spi.graph.InvalidPathException;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
 import org.jboss.dna.spi.graph.Path;
 import org.jboss.dna.spi.graph.PathNotFoundException;
 
@@ -190,13 +191,40 @@
      * {@inheritDoc}
      */
     public String getString() {
-        return getString(DEFAULT_ENCODER);
+        return doGetString(null, DEFAULT_ENCODER);
     }
 
     /**
      * {@inheritDoc}
      */
     public String getString( TextEncoder encoder ) {
+        return doGetString(null, encoder);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString( NamespaceRegistry namespaceRegistry ) {
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        return doGetString(namespaceRegistry, null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        return doGetString(namespaceRegistry, encoder);
+    }
+
+    /**
+     * Method that creates the string representation. This method works two different ways depending upon whether the namespace
+     * registry is provided.
+     * @param namespaceRegistry
+     * @param encoder
+     * @return
+     */
+    protected String doGetString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
         if (encoder == null) encoder = DEFAULT_ENCODER;
         if (encoder == DEFAULT_ENCODER && this.path != null) return this.path;
 
@@ -212,7 +240,11 @@
                 sb.append(DELIMITER);
             }
             assert segment != null;
-            sb.append(segment.getString(encoder));
+            if (namespaceRegistry != null) {
+                sb.append(segment.getString(encoder));
+            } else {
+                sb.append(segment.getString(encoder));
+            }
         }
         String result = sb.toString();
         // Save the result to the internal string if this the default encoder is used.
@@ -415,7 +447,6 @@
      * {@inheritDoc}
      */
     public int compareTo( Path that ) {
-        if (that == null) return 1;
         if (this == that) return 0;
         Iterator<Segment> thisIter = this.segments.iterator();
         Iterator<Segment> thatIter = that.iterator();

Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -1,167 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.Path.Segment;
-
-/**
- * @author Randall Hauch
- */
-public class BasicPathFactory implements PathFactory {
-
-    /**
-     * 
-     */
-    public BasicPathFactory() {
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path create( Name... segmentNames ) {
-        if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
-        List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
-        for (Name segmentName : segmentNames) {
-            if (segmentName == null) {
-                ArgCheck.containsNoNulls(segmentNames, "segment names");
-            }
-            segments.add(new BasicPathSegment(segmentName));
-        }
-        return new BasicPath(segments, true);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path create( Segment... segments ) {
-        if (segments == null || segments.length == 0) return BasicPath.ROOT;
-        List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
-        for (Segment segment : segments) {
-            if (segment == null) {
-                ArgCheck.containsNoNulls(segments, "segments");
-            }
-            segmentsList.add(segment);
-        }
-        return new BasicPath(segmentsList, true);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path createRelativePath( Name... segmentNames ) {
-        if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
-        List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
-        for (Name segmentName : segmentNames) {
-            if (segmentName == null) {
-                ArgCheck.containsNoNulls(segmentNames, "segment names");
-            }
-            segments.add(new BasicPathSegment(segmentName));
-        }
-        return new BasicPath(segments, false);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path createRelativePath( Segment... segments ) {
-        if (segments == null || segments.length == 0) return BasicPath.ROOT;
-        List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
-        for (Segment segment : segments) {
-            if (segment == null) {
-                ArgCheck.containsNoNulls(segments, "segments");
-            }
-            segmentsList.add(segment);
-        }
-        return new BasicPath(segmentsList, false);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path create( Path parentPath, Name segmentName, int index ) {
-        ArgCheck.isNotNull(parentPath, "parent path");
-        ArgCheck.isNotNull(segmentName, "segment name");
-        List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
-        segments.addAll(parentPath.getSegmentsList());
-        segments.add(new BasicPathSegment(segmentName, index));
-        return new BasicPath(segments, parentPath.isAbsolute());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path create( Path parentPath, Name... segmentNames ) {
-        ArgCheck.isNotNull(parentPath, "parent path");
-        if (segmentNames == null || segmentNames.length == 0) return parentPath;
-
-        List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
-        segments.addAll(parentPath.getSegmentsList());
-        for (Name segmentName : segmentNames) {
-            if (segmentName == null) {
-                ArgCheck.containsNoNulls(segmentNames, "segment names");
-            }
-            segments.add(new BasicPathSegment(segmentName));
-        }
-        return new BasicPath(segments, parentPath.isAbsolute());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Path create( Path parentPath, Segment... segments ) {
-        ArgCheck.isNotNull(parentPath, "parent path");
-        if (segments == null || segments.length == 0) return BasicPath.ROOT;
-
-        List<Segment> segmentsList = new ArrayList<Segment>(parentPath.size() + 1);
-        segmentsList.addAll(parentPath.getSegmentsList());
-        for (Segment segment : segments) {
-            if (segment == null) {
-                ArgCheck.containsNoNulls(segments, "segments");
-            }
-            segmentsList.add(segment);
-        }
-        return new BasicPath(segmentsList, parentPath.isAbsolute());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Segment createSegment( Name segmentName ) {
-        ArgCheck.isNotNull(segmentName, "segment name");
-        return new BasicPathSegment(segmentName);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Segment createSegment( Name segmentName, int index ) {
-        ArgCheck.isNotNull(segmentName, "segment name");
-        return new BasicPathSegment(segmentName, index);
-    }
-
-}

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,176 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#BOOLEAN} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class BooleanValueFactory extends AbstractValueFactory<Boolean> {
+
+    public BooleanValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.BOOLEAN, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( String value ) {
+        if (value == null) return null;
+        return Boolean.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( int value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Integer.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( long value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Long.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( boolean value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( float value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Float.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( double value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Double.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( BigDecimal value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), BigDecimal.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Calendar value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Calendar.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Date value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( byte[] value ) throws ValueFormatException {
+        // First create a string and then create the boolean from the string value ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First create a string and then create the boolean from the string value ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Boolean create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First create a string and then create the boolean from the string value ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.DateUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#DATE} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class DateValueFactory extends AbstractValueFactory<Calendar> {
+
+    public DateValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.DATE, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return DateUtil.getCalendarFromStandardString(value);
+        } catch (ParseException e) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( int value ) {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( long value ) {
+        Calendar result = Calendar.getInstance();
+        result.setTimeInMillis(value);
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( float value ) throws ValueFormatException {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( double value ) throws ValueFormatException {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( BigDecimal value ) throws ValueFormatException {
+        if (value == null) return null;
+        return create(value.longValue());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Calendar value ) throws ValueFormatException {
+        if (value == null) return null;
+        return create(value.getTimeInMillis());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Date value ) throws ValueFormatException {
+        if (value == null) return null;
+        return create(value.getTime());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#DECIMAL} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class DecimalValueFactory extends AbstractValueFactory<BigDecimal> {
+
+    public DecimalValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.DECIMAL, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return new BigDecimal(value);
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( int value ) {
+        return BigDecimal.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( long value ) {
+        return BigDecimal.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Boolean.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( float value ) {
+        return BigDecimal.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( double value ) {
+        return BigDecimal.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( BigDecimal value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Calendar value ) {
+        if (value == null) return null;
+        return create(value.getTimeInMillis());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Date value ) {
+        if (value == null) return null;
+        return create(value.getTime());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#DOUBLE} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class DoubleValueFactory extends AbstractValueFactory<Double> {
+
+    public DoubleValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.DOUBLE, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return Double.valueOf(value);
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( int value ) {
+        return Double.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( long value ) {
+        return new Double(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Double.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( float value ) {
+        return Double.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( double value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( BigDecimal value ) throws ValueFormatException {
+        if (value == null) return null;
+        double result = value.doubleValue();
+        if (result == Double.NEGATIVE_INFINITY || result == Double.POSITIVE_INFINITY) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value));
+        }
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Calendar value ) {
+        if (value == null) return null;
+        return create(value.getTimeInMillis());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Date value ) {
+        if (value == null) return null;
+        return create(value.getTime());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * Teh standard {@link ValueFactory} for {@link PropertyType#BINARY} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class InMemoryBinaryValueFactory extends AbstractValueFactory<Binary> {
+
+    private static final String CHAR_SET_NAME = "UTF-8";
+
+    public InMemoryBinaryValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.BINARY, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return create(value.getBytes(CHAR_SET_NAME));
+        } catch (UnsupportedEncodingException e) {
+            throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( String value, TextEncoder decoder ) throws ValueFormatException {
+        if (value == null) return null;
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( int value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( long value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( boolean value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( float value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( double value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( BigDecimal value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Calendar value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Date value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Name value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Path value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Reference value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( URI value ) throws ValueFormatException {
+        // Convert the value to a string, then to a binary ...
+        return create(this.getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( byte[] value ) throws ValueFormatException {
+        return new InMemoryBinary(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( InputStream stream, int approximateLength ) throws IOException {
+        if (stream == null) return null;
+        byte[] value = IoUtil.readBytes(stream);
+        return create(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Binary create( Reader reader, int approximateLength ) throws IOException {
+        if (reader == null) return null;
+        // Convert the value to a string, then to a binary ...
+        String value = IoUtil.read(reader);
+        return create(this.getStringValueFactory().create(value));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#LONG} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class LongValueFactory extends AbstractValueFactory<Long> {
+
+    public LongValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.LONG, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return Long.valueOf(value);
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( int value ) {
+        return Long.valueOf(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( long value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Long.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( float value ) throws ValueFormatException {
+        return (long)value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( double value ) throws ValueFormatException {
+        return (long)value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( BigDecimal value ) throws ValueFormatException {
+        if (value == null) return null;
+        return value.longValue();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Calendar value ) throws ValueFormatException {
+        if (value == null) return null;
+        return value.getTimeInMillis();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Date value ) throws ValueFormatException {
+        if (value == null) return null;
+        return value.getTime();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Long create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#NAME} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class NameValueFactory extends AbstractValueFactory<Name> implements NameFactory {
+
+    // Non-escaped pattern: (\{([^}]*)\})?(.*)
+    protected static final String FULLY_QUALFIED_NAME_PATTERN_STRING = "\\{([^}]*)\\}(.*)";
+    protected static final Pattern FULLY_QUALIFIED_NAME_PATTERN = Pattern.compile(FULLY_QUALFIED_NAME_PATTERN_STRING);
+
+    // Original pattern: (([^:/]*):)?(.*)
+    private static final String PREFIXED_NAME_PATTERN_STRING = "(([^:/]*):)?(.*)";
+    private static final Pattern PREFIXED_NAME_PATTERN = Pattern.compile(PREFIXED_NAME_PATTERN_STRING);
+
+    private final NamespaceRegistry namespaceRegistry;
+
+    public NameValueFactory( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.NAME, encoder, stringValueFactory);
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        this.namespaceRegistry = namespaceRegistry;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( String value ) {
+        return create(value, getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( String value, TextEncoder decoder ) throws ValueFormatException {
+        if (value == null) return null;
+        if (decoder == null) decoder = getEncoder();
+        try {
+            // First see whether the value fits the internal pattern ...
+            Matcher matcher = FULLY_QUALIFIED_NAME_PATTERN.matcher(value);
+            if (matcher.matches()) {
+                String namespaceUri = matcher.group(2);
+                String localName = matcher.group(3);
+                // Decode the parts ...
+                namespaceUri = decoder.decode(namespaceUri);
+                localName = decoder.decode(localName);
+                return new BasicName(namespaceUri, localName);
+            }
+            // Second, see whether the value fits the prefixed name pattern ...
+            matcher = PREFIXED_NAME_PATTERN.matcher(value);
+            if (matcher.matches()) {
+                String prefix = matcher.group(1);
+                String localName = matcher.group(2);
+                // Decode the parts ...
+                prefix = decoder.decode(prefix);
+                localName = decoder.decode(localName);
+                // Look for a namespace match ...
+                String namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
+                // If no namespace is found, use the prefix ...
+                if (namespaceUri == null) namespaceUri = prefix;
+                return new BasicName(namespaceUri, localName);
+            }
+        } catch (Throwable t) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), t);
+        }
+        throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( String namespaceUri, String localName ) {
+        return create(namespaceUri, localName, getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( String namespaceUri, String localName, TextEncoder decoder ) {
+        ArgCheck.isNotNull(localName, "localName");
+        if (decoder == null) decoder = getEncoder();
+        namespaceUri = namespaceUri != null ? decoder.decode(namespaceUri.trim()) : null;
+        localName = decoder.decode(localName.trim());
+        return new BasicName(namespaceUri, localName);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( int value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( long value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( float value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( double value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( BigDecimal value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Calendar value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Date value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Name value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Path value ) throws ValueFormatException {
+        if (value == null) return null;
+        if (!value.isAbsolute() && value.size() == 1) {
+            // A relative name of length 1 is converted to a name
+            return value.getSegment(0).getName();
+        }
+        throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( URI value ) throws ValueFormatException {
+        if (value == null) return null;
+        String asciiString = value.toASCIIString();
+        // Remove any leading "./" ...
+        if (asciiString.startsWith("./") && asciiString.length() > 2) {
+            asciiString = asciiString.substring(2);
+        }
+        if (asciiString.indexOf('/') == -1) {
+            return create(asciiString);
+        }
+        throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,392 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.regex.Pattern;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.jcr.InvalidPathException;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#NAME} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class PathValueFactory extends AbstractValueFactory<Path> implements PathFactory {
+
+    protected static final char DELIMITER = Path.DELIMITER;
+
+    /**
+     * Regular expression used to identify the different segments in a path, using the standard '/' delimiter. The expression is
+     * simply:
+     * 
+     * <pre>
+     * /
+     * </pre>
+     */
+    protected static final Pattern DELIMITER_PATTERN = Pattern.compile("/");
+
+    /**
+     * Regular expression used to identify the different parts of a segment. The expression is
+     * 
+     * <pre>
+     * ([&circ;*:/\[\]|]+)(:([&circ;*:/\[\]|]+))?(\[(\d+)])?
+     * </pre>
+     * 
+     * where the first part is accessed with group 1, the second part is accessed with group 3, and the index is accessed with
+     * group 5.
+     */
+    protected static final Pattern SEGMENT_PATTERN = Pattern.compile("([^:/]+)(:([^/\\[\\]]+))?(\\[(\\d+)])?");
+
+    private final ValueFactory<Name> nameValueFactory;
+
+    public PathValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory, ValueFactory<Name> nameValueFactory ) {
+        super(PropertyType.NAME, encoder, stringValueFactory);
+        ArgCheck.isNotNull(nameValueFactory, "nameValueFactory");
+        this.nameValueFactory = nameValueFactory;
+    }
+
+    /**
+     * @return nameValueFactory
+     */
+    protected ValueFactory<Name> getNameValueFactory() {
+        return this.nameValueFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( String value ) {
+        return create(value, getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( final String value, TextEncoder decoder ) throws ValueFormatException {
+        if (value == null) return null;
+        if (decoder == null) decoder = getEncoder();
+        String trimmedValue = value.trim();
+        int length = trimmedValue.length();
+        boolean absolute = false;
+        if (length == 0) {
+            throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+        }
+
+        // Remove the leading delimiter ...
+        if (trimmedValue.charAt(0) == DELIMITER) {
+            trimmedValue = length > 1 ? trimmedValue.substring(1) : "";
+            --length;
+            absolute = true;
+        }
+        // remove the trailing delimiter ...
+        if (length > 0 && trimmedValue.charAt(length - 1) == DELIMITER) {
+            trimmedValue = length > 1 ? trimmedValue.substring(0, length - 1) : "";
+            length = trimmedValue.length();
+        }
+        if (length == 0) {
+            throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+        }
+
+        // Parse the path into its segments ...
+        List<Segment> segments = new ArrayList<Segment>();
+        String[] pathSegments = DELIMITER_PATTERN.split(trimmedValue);
+        assert pathSegments.length != 0;
+        for (String segment : pathSegments) {
+            assert segment != null;
+            segment = segment.trim();
+            if (segment.length() == 0) {
+                throw new InvalidPathException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+            }
+            // Create the name and add a segment with it ...
+            Name segmentName = this.getNameValueFactory().create(segment, decoder);
+            segments.add(new BasicPathSegment(segmentName));
+        }
+
+        // Create a path constructed from the supplied segments ...
+        return new BasicPath(segments, absolute);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( int value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( long value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( float value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( double value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( BigDecimal value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Calendar value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Date value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Name value ) {
+        if (value == null) return null;
+        List<Path.Segment> segments = new ArrayList<Path.Segment>(1);
+        segments.add(new BasicPathSegment(value));
+        return new BasicPath(segments, true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Path value ) throws ValueFormatException {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Name... segmentNames ) {
+        if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+        List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
+        for (Name segmentName : segmentNames) {
+            if (segmentName == null) {
+                ArgCheck.containsNoNulls(segmentNames, "segment names");
+            }
+            segments.add(new BasicPathSegment(segmentName));
+        }
+        return new BasicPath(segments, true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Segment... segments ) {
+        if (segments == null || segments.length == 0) return BasicPath.ROOT;
+        List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
+        for (Segment segment : segments) {
+            if (segment == null) {
+                ArgCheck.containsNoNulls(segments, "segments");
+            }
+            segmentsList.add(segment);
+        }
+        return new BasicPath(segmentsList, true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path createRelativePath( Name... segmentNames ) {
+        if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+        List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
+        for (Name segmentName : segmentNames) {
+            if (segmentName == null) {
+                ArgCheck.containsNoNulls(segmentNames, "segment names");
+            }
+            segments.add(new BasicPathSegment(segmentName));
+        }
+        return new BasicPath(segments, false);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path createRelativePath( Segment... segments ) {
+        if (segments == null || segments.length == 0) return BasicPath.ROOT;
+        List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
+        for (Segment segment : segments) {
+            if (segment == null) {
+                ArgCheck.containsNoNulls(segments, "segments");
+            }
+            segmentsList.add(segment);
+        }
+        return new BasicPath(segmentsList, false);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Path parentPath, Name segmentName, int index ) {
+        ArgCheck.isNotNull(parentPath, "parent path");
+        ArgCheck.isNotNull(segmentName, "segment name");
+        List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
+        segments.addAll(parentPath.getSegmentsList());
+        segments.add(new BasicPathSegment(segmentName, index));
+        return new BasicPath(segments, parentPath.isAbsolute());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Path parentPath, Name... segmentNames ) {
+        ArgCheck.isNotNull(parentPath, "parent path");
+        if (segmentNames == null || segmentNames.length == 0) return parentPath;
+
+        List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
+        segments.addAll(parentPath.getSegmentsList());
+        for (Name segmentName : segmentNames) {
+            if (segmentName == null) {
+                ArgCheck.containsNoNulls(segmentNames, "segment names");
+            }
+            segments.add(new BasicPathSegment(segmentName));
+        }
+        return new BasicPath(segments, parentPath.isAbsolute());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Path parentPath, Segment... segments ) {
+        ArgCheck.isNotNull(parentPath, "parent path");
+        if (segments == null || segments.length == 0) return BasicPath.ROOT;
+
+        List<Segment> segmentsList = new ArrayList<Segment>(parentPath.size() + 1);
+        segmentsList.addAll(parentPath.getSegmentsList());
+        for (Segment segment : segments) {
+            if (segment == null) {
+                ArgCheck.containsNoNulls(segments, "segments");
+            }
+            segmentsList.add(segment);
+        }
+        return new BasicPath(segmentsList, parentPath.isAbsolute());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Segment createSegment( Name segmentName ) {
+        ArgCheck.isNotNull(segmentName, "segment name");
+        return new BasicPathSegment(segmentName);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Segment createSegment( Name segmentName, int index ) {
+        ArgCheck.isNotNull(segmentName, "segment name");
+        return new BasicPathSegment(segmentName, index);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( URI value ) throws ValueFormatException {
+        if (value == null) return null;
+        String asciiString = value.toASCIIString();
+        // Remove any leading "./" ...
+        if (asciiString.startsWith("./") && asciiString.length() > 2) {
+            asciiString = asciiString.substring(2);
+        }
+        if (asciiString.indexOf('/') == -1) {
+            return create(asciiString);
+        }
+        throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,232 @@
+/*
+ * 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.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.SystemFailureException;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * The standard set of {@link ValueFactory value factories}.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class StandardValueFactories implements ValueFactories {
+
+    // This class is implemented with separate members for each factory so that the typical usage is optimized.
+    private final ValueFactory<String> stringFactory;
+    private final ValueFactory<Binary> binaryFactory;
+    private final ValueFactory<Boolean> booleanFactory;
+    private final ValueFactory<Calendar> dateFactory;
+    private final ValueFactory<BigDecimal> decimalFactory;
+    private final ValueFactory<Double> doubleFactory;
+    private final ValueFactory<Long> longFactory;
+    private final ValueFactory<Name> nameFactory;
+    private final ValueFactory<Path> pathFactory;
+    private final ValueFactory<Reference> referenceFactory;
+    private final ValueFactory<URI> uriFactory;
+    private final Map<PropertyType, ValueFactory<?>> factories;
+
+    /**
+     * Create a standard set of value factories, using the {@link ValueFactory#DEFAULT_ENCODER default encoder/decoder}.
+     * @param namespaceRegistry the namespace registry
+     * @throws IllegalArgumentException if the namespace registry is null
+     */
+    public StandardValueFactories( NamespaceRegistry namespaceRegistry ) {
+        this(namespaceRegistry, null);
+    }
+
+    /**
+     * Create a standard set of value factories, using the supplied encoder/decoder.
+     * @param namespaceRegistry the namespace registry
+     * @param encoder the encoder that should be used; if null, the {@link ValueFactory#DEFAULT_ENCODER default encoder} is used.
+     * @param extraFactories any extra factories that should be used; any factory will override the standard factories based upon
+     * the {@link ValueFactory#getPropertyType() factory's property type}.
+     * @throws IllegalArgumentException if the namespace registry is null
+     */
+    public StandardValueFactories( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<?>... extraFactories ) {
+        if (encoder == null) encoder = ValueFactory.DEFAULT_ENCODER;
+        Map<PropertyType, ValueFactory<?>> factories = new HashMap<PropertyType, ValueFactory<?>>();
+
+        // Put the extra factories into the map first ...
+        for (ValueFactory<?> factory : extraFactories) {
+            if (factory == null) continue;
+            factories.put(factory.getPropertyType(), factory);
+        }
+
+        // Now assign the members, using the factories in the map or (if null) the supplied default ...
+        this.stringFactory = getFactory(factories, new StringValueFactory(encoder));
+        this.binaryFactory = getFactory(factories, new InMemoryBinaryValueFactory(encoder, this.stringFactory));
+        this.booleanFactory = getFactory(factories, new BooleanValueFactory(encoder, this.stringFactory));
+        this.dateFactory = getFactory(factories, new DateValueFactory(encoder, this.stringFactory));
+        this.decimalFactory = getFactory(factories, new DecimalValueFactory(encoder, this.stringFactory));
+        this.doubleFactory = getFactory(factories, new DoubleValueFactory(encoder, this.stringFactory));
+        this.longFactory = getFactory(factories, new LongValueFactory(encoder, this.stringFactory));
+        this.nameFactory = getFactory(factories, new NameValueFactory(namespaceRegistry, encoder, this.stringFactory));
+        this.pathFactory = getFactory(factories, new PathValueFactory(encoder, this.stringFactory, this.nameFactory));
+        this.referenceFactory = getFactory(factories, new UuidReferenceValueFactory(encoder, this.stringFactory));
+        this.uriFactory = getFactory(factories, new UriValueFactory(namespaceRegistry, encoder, this.stringFactory));
+
+        // Make sure there is a PropertyType.UNDEFINED factory ...
+        if (factories.get(PropertyType.UNDEFINED) == null) {
+            factories.put(PropertyType.UNDEFINED, this.stringFactory);
+        }
+
+        // Wrap the factories with an unmodifiable ...
+        this.factories = Collections.unmodifiableMap(factories);
+    }
+
+    @SuppressWarnings( "unchecked" )
+    private static <T> ValueFactory<T> getFactory( Map<PropertyType, ValueFactory<?>> factories, ValueFactory<T> defaultFactory ) {
+        PropertyType type = defaultFactory.getPropertyType();
+        ValueFactory<?> factory = factories.get(type);
+        if (factory == null) {
+            factory = defaultFactory;
+            factories.put(type, factory);
+        }
+        return (ValueFactory<T>)factory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Binary> getBinaryFactory() {
+        return this.binaryFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Boolean> getBooleanFactory() {
+        return this.booleanFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Calendar> getDateFactory() {
+        return this.dateFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<BigDecimal> getDecimalFactory() {
+        return this.decimalFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Double> getDoubleFactory() {
+        return this.doubleFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<?> getValueFactory( PropertyType type ) {
+        ArgCheck.isNotNull(type, "type");
+        ValueFactory<?> factory = this.factories.get(type);
+        if (factory == null) {
+            // Should never happen
+            throw new SystemFailureException("Unexpected PropertyType");
+        }
+        return factory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<?> getValueFactory( Object prototype ) {
+        ArgCheck.isNotNull(prototype, "prototype");
+        PropertyType inferredType = PropertyType.discoverType(prototype);
+        if (inferredType == null) inferredType = PropertyType.STRING;
+        return getValueFactory(inferredType);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Long> getLongFactory() {
+        return this.longFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Name> getNameFactory() {
+        return this.nameFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Path> getPathFactory() {
+        return this.pathFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<Reference> getReferenceFactory() {
+        return this.referenceFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<String> getStringFactory() {
+        return this.stringFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValueFactory<URI> getUriFactory() {
+        return this.uriFactory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<ValueFactory<?>> iterator() {
+        return this.factories.values().iterator();
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.DateUtil;
+import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#STRING} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class StringValueFactory extends AbstractValueFactory<String> {
+
+    public StringValueFactory( TextEncoder encoder ) {
+        super(PropertyType.STRING, encoder, null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected ValueFactory<String> getStringValueFactory() {
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( String value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( String value, TextEncoder decoder ) {
+        if (value == null) return value;
+        if (decoder == null) decoder = getEncoder();
+        return decoder.decode(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( int value ) {
+        return Integer.toString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( long value ) {
+        return Long.toString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( boolean value ) {
+        return Boolean.toString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( float value ) {
+        return Float.toString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( double value ) {
+        return Double.toString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( BigDecimal value ) {
+        if (value == null) return null;
+        return value.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Calendar value ) {
+        if (value == null) return null;
+        return DateUtil.getDateAsStandardString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Date value ) {
+        if (value == null) return null;
+        return DateUtil.getDateAsStandardString(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Name value ) {
+        if (value == null) return null;
+        return value.getString(getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Path value ) {
+        if (value == null) return null;
+        return value.getString(getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Reference value ) {
+        if (value == null) return null;
+        return value.getString(getEncoder());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( URI value ) {
+        if (value == null) return null;
+        return value.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( byte[] value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return new String(value, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( InputStream stream, int approximateLength ) throws IOException {
+        if (stream == null) return null;
+        byte[] value = IoUtil.readBytes(stream);
+        try {
+            return new String(value, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String create( Reader reader, int approximateLength ) throws IOException {
+        if (reader == null) return null;
+        return IoUtil.read(reader);
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#URI} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class UriValueFactory extends AbstractValueFactory<URI> {
+
+    private final NamespaceRegistry namespaceRegistry;
+
+    public UriValueFactory( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.URI, encoder, stringValueFactory);
+        ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+        this.namespaceRegistry = namespaceRegistry;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return new URI(value);
+        } catch (URISyntaxException t) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), t);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( int value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( long value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( float value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( double value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( BigDecimal value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Calendar value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Date value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Name value ) {
+        if (value == null) return null;
+        return create("./" + value.getString(this.namespaceRegistry));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Path value ) throws ValueFormatException {
+        if (value == null) return null;
+        if (value.isAbsolute()) {
+            return create("/" + value.getString(this.namespaceRegistry));
+        }
+        return create("./" + value.getString(this.namespaceRegistry));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( URI value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URI create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.jcr.Path;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Reference;
+
+/**
+ * @author Randall Hauch
+ */
+ at Immutable
+public class UuidReference implements Reference {
+
+    private UUID uuid;
+
+    public UuidReference( UUID uuid ) {
+        this.uuid = uuid;
+    }
+
+    /**
+     * @return uuid
+     */
+    public UUID getUuid() {
+        return this.uuid;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString() {
+        return this.uuid.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString( TextEncoder encoder ) {
+        if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+        return encoder.encode(getString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compareTo( Reference that ) {
+        if (this == that) return 0;
+        if (that instanceof UuidReference) {
+            return this.uuid.compareTo(((UuidReference)that).getUuid());
+        }
+        return this.getString().compareTo(that.getString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj ) {
+        if (obj == this) return true;
+        if (obj instanceof UuidReference) {
+            return this.uuid.equals(((UuidReference)obj).getUuid());
+        }
+        if (obj instanceof Reference) {
+            return this.getString().equals(((Reference)obj).getString());
+        }
+        return super.equals(obj);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return this.uuid.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void readExternal( ObjectInput in ) throws IOException {
+        long lsb = in.readLong();
+        long msb = in.readLong();
+        this.uuid = new UUID(msb, lsb);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeExternal( ObjectOutput out ) throws IOException {
+        out.writeLong(this.uuid.getLeastSignificantBits());
+        out.writeLong(this.uuid.getMostSignificantBits());
+    }
+
+}


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

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java	2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#REFERENCE} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class UuidReferenceValueFactory extends AbstractValueFactory<Reference> {
+
+    public UuidReferenceValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.REFERENCE, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            UUID uuid = UUID.fromString(value);
+            return new UuidReference(uuid);
+        } catch (IllegalArgumentException t) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), t);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( int value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( long value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( float value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( double value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( BigDecimal value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Calendar value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Date value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Reference value ) {
+        return value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Reference create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+}


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

Modified: branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
===================================================================
--- branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties	2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties	2008-05-19 16:32:40 UTC (rev 176)
@@ -3,6 +3,10 @@
 valueJavaTypeNotCompatibleWithPropertyType = Value is instance of Java type "{0}" and is not compatible with the "{1}" property type
 
 errorConvertingBinaryValueToString = Error while interpretting binary value as a UTF-8 string
+errorCreatingValue = Error creating {0} value from {1} '{2}'
+unableToCreateValue = Unable to create {0} value from {1} '{2}': undefined type conversion
+unableToCreatePathFromEmptyString = Unable to create a path from an empty string
+validPathMayNotContainEmptySegment = The path '{0}' is not valid because it contains an empty segment
 
 pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
 pathIsAlreadyAbsolute = The path {0} is already an absolute path




More information about the dna-commits mailing list