[dna-commits] DNA SVN: r191 - in branches/federation: dna-common/src/main/java/org/jboss/dna/common/util and 5 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri May 23 23:23:42 EDT 2008


Author: rhauch
Date: 2008-05-23 23:23:42 -0400 (Fri, 23 May 2008)
New Revision: 191

Added:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
   branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java
   branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
Modified:
   branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
   branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
   branches/federation/dna-spi/pom.xml
   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/ValueComparators.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/impl/DateValueFactory.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/LongValueFactory.java
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
   branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
   branches/federation/pom.xml
Log:
After being fed up with java.util.Date and java.util.Calendar problems and inaccuracies, I created a DateTime interface in the graph SPI to wrap Joda-Time DateTime instances and to provide a migration path to JSR-310, which will be based upon Joda-Time.

Modified: branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
===================================================================
--- branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -180,7 +180,7 @@
         }
 
         // Create the calendar object and start setting the fields ...
-        GregorianCalendar calendar = new GregorianCalendar();
+        Calendar calendar = Calendar.getInstance();
         calendar.clear();
 
         // And start setting the fields. Note that Integer.parseInt should never fail, since we're checking for null and the

Modified: branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
===================================================================
--- branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -180,4 +180,29 @@
         assertThat(DateUtil.getCalendarFromStandardString("2008-W216").get(Calendar.WEEK_OF_YEAR), is(21));
     }
 
+    @Test
+    public void shouldConvertCalendarToStringAndBackMultipleTimes() throws Exception {
+        Calendar cal1 = Calendar.getInstance();
+        String cal1Str = DateUtil.getDateAsStandardString(cal1);
+        Calendar cal2 = DateUtil.getCalendarFromStandardString(cal1Str);
+        // Force the calculation of all fields for both calendars ...
+        cal1.add(Calendar.DAY_OF_YEAR, 1);
+        cal2.add(Calendar.DAY_OF_YEAR, 1);
+        cal1.add(Calendar.DAY_OF_YEAR, -1);
+        cal2.add(Calendar.DAY_OF_YEAR, -1);
+        assertThat(cal1.getTimeInMillis(), is(cal2.getTimeInMillis()));
+        assertThat(cal1.compareTo(cal2), is(0));
+        assertThat(cal1, is(cal2));
+        String cal2Str = DateUtil.getDateAsStandardString(cal2);
+        assertThat(cal1Str, is(cal2Str));
+        Calendar cal3 = DateUtil.getCalendarFromStandardString(cal2Str);
+        cal3.add(Calendar.DAY_OF_YEAR, 1);
+        cal3.add(Calendar.DAY_OF_YEAR, -1);
+        assertThat(cal1, is(cal3));
+        assertThat(cal3, is(cal3));
+        String cal3Str = DateUtil.getDateAsStandardString(cal3);
+        assertThat(cal1Str, is(cal3Str));
+        assertThat(cal2Str, is(cal3Str));
+    }
+
 }

Modified: branches/federation/dna-spi/pom.xml
===================================================================
--- branches/federation/dna-spi/pom.xml	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/pom.xml	2008-05-24 03:23:42 UTC (rev 191)
@@ -31,6 +31,10 @@
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>joda-time</groupId>
+      <artifactId>joda-time</artifactId>
+    </dependency>
     <!-- 
     Testing (note the scope)
     -->

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,167 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * An immutable date-time class that represents an instance in time. This class is designed to hide the horrible implementations
+ * of the JDK date and calendar classes, which are being overhauled (and replaced) under <a
+ * href="http://jcp.org/en/jsr/detail?id=310">JSR-310</a>, which will be based upon <a
+ * href="http://joda-time.sourceforge.net/">Joda-Time</a>. This class serves as a stable migration path toward the new JSR 310
+ * classes.
+ * @author Randall Hauch
+ */
+public interface DateTime extends Comparable<DateTime>, Externalizable {
+
+    /**
+     * Get the ISO-8601 representation of this instance in time.
+     * @return the string representation; never null
+     */
+    String getString();
+
+    /**
+     * Get the number of milliseconds from 1970-01-01T00:00Z. This value is consistent with the JDK {@link java.util.Date Date}
+     * and {@link java.util.Calendar Calendar} classes.
+     * @return the number of milliseconds from 1970-01-01T00:00Z
+     */
+    long getMilliseconds();
+
+    /**
+     * Get this instance represented as a standard JDK {@link java.util.Date} instance. Note that this conversion loses the time
+     * zone information, as the standard JDK {@link java.util.Date} does not represent time zones.
+     * @return this instance in time as a JDK Date; never null
+     */
+    java.util.Date toDate();
+
+    /**
+     * Get this instance represented as a standard JDK {@link java.util.Calendar} instance, in the
+     * {@link Locale#getDefault() default locale}.
+     * @return this instance in time as a JDK Calendar; never null
+     */
+    java.util.Calendar toCalendar();
+
+    /**
+     * Get this instance represented as a standard JDK {@link java.util.Calendar} instance, in the specified {@link Locale locale}.
+     * @param locale the locale in which the Calendar instance is desired; may be null if the
+     * {@link Locale#getDefault() default locale} is to be used.
+     * @return this instance in time as a JDK Calendar; never null
+     */
+    java.util.Calendar toCalendar( Locale locale );
+
+    /**
+     * Get this instance represented as a standard JDK {@link java.util.GregorianCalendar} instance.
+     * @return this instance in time as a JDK GregorianCalendar; never null
+     */
+    java.util.GregorianCalendar toGregorianCalendar();
+
+    /**
+     * Get the era of this instance in time.
+     * @return the era
+     */
+    int getEra();
+
+    /**
+     * Get the era of this instance in time.
+     * @return the era
+     */
+    int getYear();
+
+    /**
+     * Get the era of this instance in time.
+     * @return the era
+     */
+    int getWeekyear();
+
+    /**
+     * Get the era of this instance in time.
+     * @return the era
+     */
+    int getCenturyOfEra();
+
+    /**
+     * Get the year of the era of this instance in time.
+     * @return the year of the era
+     */
+    int getYearOfEra();
+
+    /**
+     * Get the year of this century of this instance in time.
+     * @return the year of the century
+     */
+    int getYearOfCentury();
+
+    /**
+     * Get the month of the year of this instance in time.
+     * @return the month number
+     */
+    int getMonthOfYear();
+
+    /**
+     * Get the week of the weekyear of this instance in time.
+     * @return the week of the weekyear
+     */
+    int getWeekOfWeekyear();
+
+    /**
+     * Get the day of the year of this instance in time.
+     * @return the day of the year
+     */
+    int getDayOfYear();
+
+    /**
+     * Get the day of the month value of this instance in time.
+     * @return the day of the month
+     */
+    int getDayOfMonth();
+
+    /**
+     * Get the day of the week value of this instance in time.
+     * @return the day of the week
+     */
+    int getDayOfWeek();
+
+    /**
+     * Get the hour of the day of this instance in time.
+     * @return the hour of the day
+     */
+    int getHourOfDay();
+
+    /**
+     * Get the minute of this instance in time.
+     * @return the minute of the hour
+     */
+    int getMinuteOfHour();
+
+    /**
+     * Get the seconds of the minute value of this instance in time.
+     * @return the seconds of the minute
+     */
+    int getSecondOfMinute();
+
+    /**
+     * Get the milliseconds of the second value of this instance in time.
+     * @return the milliseconds
+     */
+    int getMillisOfSecond();
+}

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-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
 
 import java.math.BigDecimal;
 import java.net.URI;
-import java.util.Calendar;
 import java.util.Comparator;
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.spi.SpiI18n;
@@ -39,7 +38,7 @@
     LONG("Long", ValueComparators.LONG_COMPARATOR, Long.class),
     DOUBLE("Double", ValueComparators.DOUBLE_COMPARATOR, Double.class),
     DECIMAL("Decimal", ValueComparators.DECIMAL_COMPARATOR, BigDecimal.class),
-    DATE("Date", ValueComparators.CALENDAR_COMPARATOR, Calendar.class),
+    DATE("Date", ValueComparators.DATE_TIME_COMPARATOR, DateTime.class),
     BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, Boolean.class),
     NAME("Name", ValueComparators.NAME_COMPARATOR, Name.class),
     PATH("Path", ValueComparators.PATH_COMPARATOR, Path.class),

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -163,6 +163,18 @@
         }
     };
     /**
+     * A comparator of date-time instances.
+     */
+    public static final Comparator<DateTime> DATE_TIME_COMPARATOR = new Comparator<DateTime>() {
+
+        public int compare( DateTime o1, DateTime o2 ) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return -1;
+            if (o2 == null) return 1;
+            return o1.compareTo(o2);
+        }
+    };
+    /**
      * A comparator of date values.
      */
     public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {

Modified: 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	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
 
 import java.math.BigDecimal;
 import java.net.URI;
-import java.util.Calendar;
 
 /**
  * The set of standard {@link ValueFactory} instances.
@@ -81,7 +80,7 @@
      * Get the value factory for {@link PropertyType#DATE date} properties.
      * @return the factory; never null
      */
-    ValueFactory<Calendar> getDateFactory();
+    ValueFactory<DateTime> getDateFactory();
 
     /**
      * Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.

Modified: 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	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -26,13 +26,12 @@
 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.DateTime;
 import org.jboss.dna.spi.graph.Name;
 import org.jboss.dna.spi.graph.Path;
 import org.jboss.dna.spi.graph.PropertyType;
@@ -45,7 +44,7 @@
  * @author Randall Hauch
  */
 @Immutable
-public class DateValueFactory extends AbstractValueFactory<Calendar> {
+public class DateValueFactory extends AbstractValueFactory<DateTime> {
 
     public DateValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
         super(PropertyType.DATE, encoder, stringValueFactory);
@@ -54,11 +53,11 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( String value ) throws ValueFormatException {
+    public DateTime create( String value ) throws ValueFormatException {
         if (value == null) return null;
         try {
-            return DateUtil.getCalendarFromStandardString(value);
-        } catch (ParseException e) {
+            return new JodaDateTime(value.trim());
+        } catch (IllegalArgumentException e) {
             throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
         }
     }
@@ -66,7 +65,7 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( String value, TextEncoder decoder ) {
+    public DateTime 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));
     }
@@ -74,44 +73,42 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( int value ) {
+    public DateTime create( int value ) {
         return create((long)value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( long value ) {
-        Calendar result = Calendar.getInstance();
-        result.setTimeInMillis(value);
-        return result;
+    public DateTime create( long value ) {
+        return new JodaDateTime(value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( boolean value ) throws ValueFormatException {
+    public DateTime 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 {
+    public DateTime create( float value ) throws ValueFormatException {
         return create((long)value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( double value ) throws ValueFormatException {
+    public DateTime create( double value ) throws ValueFormatException {
         return create((long)value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( BigDecimal value ) throws ValueFormatException {
+    public DateTime create( BigDecimal value ) throws ValueFormatException {
         if (value == null) return null;
         return create(value.longValue());
     }
@@ -119,51 +116,51 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( Calendar value ) throws ValueFormatException {
+    public DateTime create( Calendar value ) throws ValueFormatException {
         if (value == null) return null;
-        return create(value.getTimeInMillis());
+        return new JodaDateTime(value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( Date value ) throws ValueFormatException {
+    public DateTime create( Date value ) throws ValueFormatException {
         if (value == null) return null;
-        return create(value.getTime());
+        return new JodaDateTime(value);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Calendar create( Name value ) throws ValueFormatException {
+    public DateTime 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 {
+    public DateTime 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 {
+    public DateTime 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 {
+    public DateTime 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 {
+    public DateTime 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));
     }
@@ -171,7 +168,7 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+    public DateTime 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));
     }
@@ -179,7 +176,7 @@
     /**
      * {@inheritDoc}
      */
-    public Calendar create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+    public DateTime 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));
     }

Modified: 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	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -55,7 +55,7 @@
     public Double create( String value ) throws ValueFormatException {
         if (value == null) return null;
         try {
-            return Double.valueOf(value);
+            return Double.valueOf(value.trim());
         } catch (NumberFormatException e) {
             throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
         }

Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,291 @@
+/*
+ * 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.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import net.jcip.annotations.Immutable;
+import org.joda.time.Chronology;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
+/**
+ * Implementation of DateTime based upon the Joda-Time library.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
+
+    private DateTime instance;
+    private transient String formattedString;
+
+    public JodaDateTime( String iso8601 ) {
+        this.instance = new DateTime(iso8601);
+    }
+
+    public JodaDateTime( long milliseconds ) {
+        this.instance = new DateTime(milliseconds);
+    }
+
+    public JodaDateTime( long milliseconds, Chronology chronology ) {
+        this.instance = new DateTime(milliseconds, chronology);
+    }
+
+    public JodaDateTime( DateTimeZone dateTimeZone ) {
+        this.instance = new DateTime(dateTimeZone);
+    }
+
+    public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond ) {
+        this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond);
+    }
+
+    public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, Chronology chronology ) {
+        this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, chronology);
+    }
+
+    public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, DateTimeZone dateTimeZone ) {
+        this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, dateTimeZone);
+    }
+
+    public JodaDateTime( java.util.Date jdkDate ) {
+        this.instance = new DateTime(jdkDate);
+    }
+
+    public JodaDateTime( java.util.Calendar jdkCalendar ) {
+        this.instance = new DateTime(jdkCalendar);
+    }
+
+    public JodaDateTime( DateTime dateTime ) {
+        this.instance = dateTime; // it's immutable, so just hold onto the supplied instance
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getCenturyOfEra() {
+        return this.instance.getCenturyOfEra();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getDayOfMonth() {
+        return this.instance.getDayOfMonth();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getDayOfWeek() {
+        return this.instance.getDayOfWeek();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getDayOfYear() {
+        return this.instance.getDayOfYear();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getEra() {
+        return this.instance.getEra();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getHourOfDay() {
+        return this.instance.getHourOfDay();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMillisOfSecond() {
+        return this.instance.getMillisOfSecond();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getMilliseconds() {
+        return this.instance.getMillis();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMinuteOfHour() {
+        return this.instance.getMinuteOfHour();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMonthOfYear() {
+        return this.instance.getMonthOfYear();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getSecondOfMinute() {
+        return this.instance.getSecondOfMinute();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getString() {
+        if (this.formattedString == null) {
+            // This is transient and can be done multiple times by concurrent threads (without locking),
+            // since the object is immutable
+            this.formattedString = this.instance.toString(org.joda.time.format.ISODateTimeFormat.dateTime());
+        }
+        return this.formattedString;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getWeekOfWeekyear() {
+        return this.instance.getWeekOfWeekyear();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getWeekyear() {
+        return this.instance.getWeekyear();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getYear() {
+        return this.instance.getYear();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getYearOfCentury() {
+        return this.instance.getYearOfCentury();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getYearOfEra() {
+        return this.instance.getYearOfEra();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar toCalendar() {
+        return toCalendar(null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Calendar toCalendar( Locale locale ) {
+        return this.instance.toCalendar(locale);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Date toDate() {
+        return this.instance.toDate();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public GregorianCalendar toGregorianCalendar() {
+        return this.instance.toGregorianCalendar();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compareTo( org.jboss.dna.spi.graph.DateTime that ) {
+        return this.instance.compareTo(that);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return this.instance.hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj ) {
+        if (obj == this) return true;
+        if (obj instanceof JodaDateTime) {
+            JodaDateTime that = (JodaDateTime)obj;
+            return this.instance.equals(that.instance);
+        }
+        if (obj instanceof DateTime) {
+            return this.instance.equals(obj);
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return getString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void readExternal( ObjectInput in ) throws IOException {
+        this.instance = new DateTime(in.readUTF());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeExternal( ObjectOutput out ) throws IOException {
+        out.writeUTF(this.getString());
+    }
+
+}

Modified: 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	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -55,7 +55,7 @@
     public Long create( String value ) throws ValueFormatException {
         if (value == null) return null;
         try {
-            return Long.valueOf(value);
+            return Long.valueOf(value.trim());
         } catch (NumberFormatException e) {
             throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
         }

Modified: 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	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
 
 import java.math.BigDecimal;
 import java.net.URI;
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -32,6 +31,7 @@
 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.DateTime;
 import org.jboss.dna.spi.graph.NameFactory;
 import org.jboss.dna.spi.graph.NamespaceRegistry;
 import org.jboss.dna.spi.graph.PathFactory;
@@ -51,7 +51,7 @@
     private final ValueFactory<String> stringFactory;
     private final ValueFactory<Binary> binaryFactory;
     private final ValueFactory<Boolean> booleanFactory;
-    private final ValueFactory<Calendar> dateFactory;
+    private final ValueFactory<DateTime> dateFactory;
     private final ValueFactory<BigDecimal> decimalFactory;
     private final ValueFactory<Double> doubleFactory;
     private final ValueFactory<Long> longFactory;
@@ -161,7 +161,7 @@
     /**
      * {@inheritDoc}
      */
-    public ValueFactory<Calendar> getDateFactory() {
+    public ValueFactory<DateTime> getDateFactory() {
         return this.dateFactory;
     }
 

Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java	                        (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -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 static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class DateValueFactoryTest {
+
+    public static final DateTime TODAY;
+    public static final DateTime LAST_YEAR;
+
+    static {
+        org.joda.time.DateTime now = new org.joda.time.DateTime();
+        TODAY = new JodaDateTime(now);
+        LAST_YEAR = new JodaDateTime(now.minusYears(1));
+    }
+
+    private DateValueFactory factory;
+    private StringValueFactory stringFactory;
+    private Mockery context;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        TextEncoder encoder = Path.URL_ENCODER;
+        stringFactory = new StringValueFactory(encoder);
+        factory = new DateValueFactory(encoder, stringFactory);
+        context = new Mockery();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromBoolean() {
+        factory.create(true);
+    }
+
+    @Test
+    public void shouldCreateDateFromString() {
+        assertThat(factory.create(TODAY.getString()), is(TODAY));
+        assertThat(factory.create(LAST_YEAR.getString()), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+        assertThat(factory.create("  " + TODAY.getString() + "  "), is(TODAY));
+        assertThat(factory.create("  " + LAST_YEAR.getString() + "  "), is(LAST_YEAR));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromStringThatIsNotInTheStandardFormat() {
+        factory.create("something");
+    }
+
+    @Test
+    public void shouldNotCreateDateFromIntegerValue() {
+        assertThat(factory.create(10000), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromLongValue() {
+        assertThat(factory.create(10000l), is((DateTime)new JodaDateTime(10000l)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromFloatValue() {
+        assertThat(factory.create(10000.12345f), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromDoubleValue() {
+        assertThat(factory.create(10000.12345d), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldCreateDateFromBigDecimal() {
+        assertThat(factory.create(new BigDecimal(10000)), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldCreateDateFromDate() {
+        Calendar value = Calendar.getInstance();
+        assertThat(factory.create(value.getTime()), is((DateTime)new JodaDateTime(value.getTime())));
+    }
+
+    @Test
+    public void shouldCreateDateFromCalendar() {
+        Calendar value = Calendar.getInstance();
+        value.setTimeInMillis(10000);
+        assertThat(factory.create(value), is((DateTime)new JodaDateTime(value)));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromName() {
+        factory.create(context.mock(Name.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromPath() {
+        factory.create(context.mock(Path.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromReference() {
+        factory.create(context.mock(Reference.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromUri() throws Exception {
+        factory.create(new URI("http://www.jboss.org"));
+    }
+
+    @Test
+    public void shouldCreateDateFromByteArrayContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(TODAY.getString().getBytes("UTF-8")), is(TODAY));
+        assertThat(factory.create(LAST_YEAR.getString().getBytes("UTF-8")), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromInputStreamContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(new ByteArrayInputStream(TODAY.getString().getBytes("UTF-8"))), is(TODAY));
+        assertThat(factory.create(new ByteArrayInputStream(LAST_YEAR.getString().getBytes("UTF-8"))), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromReaderContainingStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(new StringReader(TODAY.getString())), is(TODAY));
+        assertThat(factory.create(new StringReader(LAST_YEAR.getString())), is(LAST_YEAR));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromByteArrayContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create("something".getBytes("UTF-8"));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromInputStreamContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromReaderContainingStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+}

Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -24,6 +24,7 @@
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 import java.io.ByteArrayInputStream;
+import java.io.StringReader;
 import java.math.BigDecimal;
 import java.net.URI;
 import java.util.Calendar;
@@ -152,10 +153,10 @@
 
     @Test
     public void shouldCreateDoubleFromReaderContainingStringWithDouble() throws Exception {
-        assertThat(factory.create(new ByteArrayInputStream("0.1".getBytes("UTF-8"))), is(0.1d));
-        assertThat(factory.create(new ByteArrayInputStream("1".getBytes("UTF-8"))), is(1.0d));
-        assertThat(factory.create(new ByteArrayInputStream("-1.03".getBytes("UTF-8"))), is(-1.03));
-        assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044.d));
+        assertThat(factory.create(new StringReader("0.1")), is(0.1d));
+        assertThat(factory.create(new StringReader("1")), is(1.0d));
+        assertThat(factory.create(new StringReader("-1.03")), is(-1.03));
+        assertThat(factory.create(new StringReader("1003044")), is(1003044.d));
     }
 
     @Test( expected = ValueFormatException.class )

Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java	                        (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java	2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,178 @@
+/*
+ * 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 static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class LongValueFactoryTest {
+
+    private LongValueFactory factory;
+    private StringValueFactory stringFactory;
+    private Mockery context;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        TextEncoder encoder = Path.URL_ENCODER;
+        stringFactory = new StringValueFactory(encoder);
+        factory = new LongValueFactory(encoder, stringFactory);
+        context = new Mockery();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDoubleFromBooleanValue() {
+        factory.create(true);
+    }
+
+    @Test
+    public void shouldCreateLongFromString() {
+        assertThat(factory.create("1"), is(Long.valueOf(1)));
+        assertThat(factory.create("-10"), is(Long.valueOf(-10)));
+        assertThat(factory.create("100000101"), is(Long.valueOf(100000101)));
+    }
+
+    @Test
+    public void shouldCreateLongFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+        assertThat(factory.create("  1  "), is(Long.valueOf(1)));
+        assertThat(factory.create("  -10  "), is(Long.valueOf(-10)));
+        assertThat(factory.create("  100000101  "), is(Long.valueOf(100000101)));
+    }
+
+    @Test
+    public void shouldNotCreateLongFromIntegerValue() {
+        assertThat(factory.create(1), is(1l));
+    }
+
+    @Test
+    public void shouldNotCreateLongFromLongValue() {
+        assertThat(factory.create(1l), is(1l));
+    }
+
+    @Test
+    public void shouldNotCreateLongFromFloatValue() {
+        assertThat(factory.create(1.0f), is(1l));
+        assertThat(factory.create(1.023f), is(1l));
+        assertThat(factory.create(1.923f), is(1l));
+    }
+
+    @Test
+    public void shouldNotCreateLongFromDoubleValue() {
+        assertThat(factory.create(1.0122d), is(1l));
+    }
+
+    @Test
+    public void shouldCreateLongFromBigDecimal() {
+        BigDecimal value = new BigDecimal(100);
+        assertThat(factory.create(value), is(value.longValue()));
+    }
+
+    @Test
+    public void shouldCreateLongFromDate() {
+        Date value = new Date();
+        assertThat(factory.create(value), is(Long.valueOf(value.getTime())));
+    }
+
+    @Test
+    public void shouldCreateLongFromCalendar() {
+        Calendar value = Calendar.getInstance();
+        assertThat(factory.create(value), is(Long.valueOf(value.getTimeInMillis())));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromName() {
+        factory.create(context.mock(Name.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromPath() {
+        factory.create(context.mock(Path.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromReference() {
+        factory.create(context.mock(Reference.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromUri() throws Exception {
+        factory.create(new URI("http://www.jboss.org"));
+    }
+
+    @Test
+    public void shouldCreateLongFromByteArrayContainingUtf8EncodingOfStringWithLong() throws Exception {
+        assertThat(factory.create("0".getBytes("UTF-8")), is(0l));
+        assertThat(factory.create("10".getBytes("UTF-8")), is(10l));
+        assertThat(factory.create("-103".getBytes("UTF-8")), is(-103l));
+        assertThat(factory.create("1003044".getBytes("UTF-8")), is(1003044l));
+    }
+
+    @Test
+    public void shouldCreateLongFromInputStreamContainingUtf8EncodingOfStringWithLong() throws Exception {
+        assertThat(factory.create(new ByteArrayInputStream("0".getBytes("UTF-8"))), is(0l));
+        assertThat(factory.create(new ByteArrayInputStream("10".getBytes("UTF-8"))), is(10l));
+        assertThat(factory.create(new ByteArrayInputStream("-103".getBytes("UTF-8"))), is(-103l));
+        assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044l));
+    }
+
+    @Test
+    public void shouldCreateLongFromReaderContainingStringWithLong() throws Exception {
+        assertThat(factory.create(new StringReader("0")), is(0l));
+        assertThat(factory.create(new StringReader("10")), is(10l));
+        assertThat(factory.create(new StringReader("-103")), is(-103l));
+        assertThat(factory.create(new StringReader("1003044")), is(1003044l));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
+        factory.create("something".getBytes("UTF-8"));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateLongFromReaderContainingStringWithContentsOtherThanLong() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+}

Modified: branches/federation/pom.xml
===================================================================
--- branches/federation/pom.xml	2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/pom.xml	2008-05-24 03:23:42 UTC (rev 191)
@@ -274,6 +274,14 @@
 				<version>${dna-version}</version>
 			</dependency>
 			<!-- 
+		    Time and Date
+		    -->
+			<dependency>
+				<groupId>joda-time</groupId>
+				<artifactId>joda-time</artifactId>
+				<version>1.4</version>
+			</dependency>
+			<!-- 
 		    Rules
 		    -->
 			<dependency>




More information about the dna-commits mailing list