jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r896113 [2/3] - in /jackrabbit/commons/jcr-rmi/trunk: ./ src/main/java/org/apache/jackrabbit/rmi/client/ src/main/java/org/apache/jackrabbit/rmi/observation/ src/main/java/org/apache/jackrabbit/rmi/server/ src/main/java/org/apache/jackrabbi...
Date Tue, 05 Jan 2010 16:18:17 GMT
Added: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BaseValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BaseValue.java?rev=896113&view=auto
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BaseValue.java (added)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BaseValue.java Tue Jan  5 16:18:16 2010
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.value;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.FilterInputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
+import javax.jcr.Binary;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+/**
+ * Abstract base class for {@link Value} implementations. This class
+ * implements all {@link Value} methods except <code>getString</code> and
+ * <code>getType</code>.
+ * <p>
+ * Most of the default value getters always throw {@link ValueFormatException}s
+ * and expect type-specific subclasses to override that behaviour with the
+ * appropriate value conversions.
+ * <p>
+ * The {@link #getBinary()} method is implemented based on the abstract
+ * {@link #getString()} method, but subclasses can override that default
+ * implementation.
+ * <p>
+ * The {@link #getStream()} method uses {@link #getBinary()} to implement
+ * the deprecated JCR 1.0 behaviour. This method must not be overridden.
+ */
+abstract class BaseValue implements Value, Serializable {
+
+    /**
+     * Serial version UID
+     */
+    private static final long serialVersionUID = -1989277354799918598L;
+
+    /**
+     * The stream instance returned by {@link #getStream()}. Note that
+     * the stream is not included when serializing the value.
+     */
+    private transient InputStream stream = null;
+
+    /**
+     * Returns the stream representation of this value. This method implements
+     * the deprecated JCR 1.0 behaviour of always returning the same stream
+     * instance. The stream is retrieved from a {@link Binary} instance
+     * returned by {@link #getBinary()}.
+     *
+     * @return stream representation of this value
+     * @throws RepositoryException if the stream can not be created
+     */
+    public synchronized final InputStream getStream()
+            throws RepositoryException {
+        if (stream == null) {
+            final Binary binary = getBinary();
+            try {
+                stream = new FilterInputStream(binary.getStream()) {
+                    @Override
+                    public void close() throws IOException {
+                        super.close();
+                        binary.dispose();
+                    }
+                };
+            } finally {
+                // Proper cleanup also when binary.getStream() fails
+                if (stream == null) {
+                    binary.dispose();
+                }
+            }
+        }
+        return stream;
+    }
+
+    /**
+     * Returns the binary representation of this value. The default
+     * implementation uses the UTF-8 serialization of the string returned
+     * by {@link #getString()}. Subclasses 
+     */
+    public Binary getBinary() throws RepositoryException {
+        try {
+            final byte[] value = getString().getBytes("UTF-8");
+            return new Binary() {
+                public int read(byte[] b, long position) {
+                    if (position >= value.length) {
+                        return -1;
+                    } else {
+                        int p = (int) position;
+                        int n = Math.min(b.length, value.length - p);
+                        System.arraycopy(value, p, b, 0, n);
+                        return n;
+                    }
+                }
+                public InputStream getStream() {
+                    return new ByteArrayInputStream(value);
+                }
+                public long getSize() {
+                    return value.length;
+                }
+                public void dispose() {
+                }
+            };
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException("UTF-8 is not supported", e);
+        }
+    }
+
+    /**
+     * Always throws a <code>ValueFormatException</code>. Implementations should
+     * overwrite if conversion to boolean is supported.
+     *
+     * @return nothing
+     * @throws ValueFormatException If the value cannot be converted to a
+     *      boolean.
+     */
+    public boolean getBoolean() throws ValueFormatException {
+        throw getValueFormatException(PropertyType.TYPENAME_BOOLEAN);
+    }
+
+    /**
+     * Always throws a <code>ValueFormatException</code>. Implementations should
+     * overwrite if conversion to <code>Calender</code> is supported.
+     *
+     * @return nothing
+     * @throws ValueFormatException If the value cannot be converted to a
+     *      <code>Calendar</code> instance.
+     */
+    public Calendar getDate() throws ValueFormatException {
+        throw getValueFormatException(PropertyType.TYPENAME_DATE);
+    }
+
+    /**
+     * Always throws a <code>ValueFormatException</code>. Implementations should
+     * overwrite if conversion to a {@link BigDecimal} is supported.
+     *
+     * @return nothing
+     * @throws ValueFormatException If the value cannot be converted to a
+     *      {@link BigDecimal}.
+     */
+    public BigDecimal getDecimal() throws RepositoryException {
+        throw getValueFormatException(PropertyType.TYPENAME_DECIMAL);
+    }
+
+    /**
+     * Always throws a <code>ValueFormatException</code>. Implementations should
+     * overwrite if conversion to double is supported.
+     *
+     * @return nothing
+     * @throws ValueFormatException If the value cannot be converted to a
+     *      double.
+     */
+    public double getDouble() throws ValueFormatException {
+        throw getValueFormatException(PropertyType.TYPENAME_DOUBLE);
+    }
+
+    /**
+     * Always throws a <code>ValueFormatException</code>. Implementations should
+     * overwrite if conversion to long is supported.
+     *
+     * @return nothing
+     * @throws ValueFormatException If the value cannot be converted to a
+     *      long.
+     */
+    public long getLong() throws ValueFormatException {
+        throw getValueFormatException(PropertyType.TYPENAME_LONG);
+    }
+
+    /**
+     * Returns a <code>ValueFormatException</code> with a message indicating
+     * what kind of type conversion is not supported.
+     *
+     * @return nothing
+     * @param destType The name of the value type to which this value cannot
+     *      be converted.
+     */
+    protected ValueFormatException getValueFormatException(String destType) {
+        return new ValueFormatException(
+                "Cannot convert value \"" + this + "\" of type "
+                + PropertyType.nameFromValue(getType()) + " to " + destType);
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    /**
+     * Compares values as defined in the JCR specification.
+     *
+     * @param object value for comparison
+     * @return <code>true</code> if the values are equal,
+     *         <code>false</code> otherwise
+     * @see <a href="https://issues.apache.org/jira/browse/JCRRMI-16">JCRRMI-16</a>
+     */
+    public boolean equals(Object object) {
+        try {
+            return (object instanceof Value)
+                && getType() == ((Value) object).getType()
+                && getString().equals(((Value) object).getString());
+        } catch (RepositoryException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns a hash code that's in line with how the {@link #equals(Object)}
+     * method is implemented.
+     *
+     * @return hash code of this value
+     */
+    public int hashCode() {
+        try {
+            return getType() + getString().hashCode();
+        } catch (RepositoryException e) {
+            return getType();
+        }
+    }
+
+    /**
+     * Returns a string representation of this value.
+     *
+     * @return value string
+     */
+    public String toString() {
+        try {
+            return getString();
+        } catch (RepositoryException e) {
+            return PropertyType.nameFromValue(getType());
+        }
+    }
+
+}

Propchange: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BaseValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BinaryValue.java Tue Jan  5 16:18:16 2010
@@ -17,106 +17,62 @@
 package org.apache.jackrabbit.rmi.value;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.OutputStream;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
 import java.util.Calendar;
 
+import javax.jcr.Binary;
 import javax.jcr.PropertyType;
-import javax.jcr.ValueFormatException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 
 /**
- * The <code>BinaryValue</code> class implements the committed value state for
- * Binary values as a part of the State design pattern (Gof) used by this
- * package.
- * <p>
- * NOTE: This class forwards the <code>InputStream</code> from which it was
- * created through the {@link #getStream()} method but does not close the
- * stream. It is the sole responsibility of the user of this value to close the
- * stream if not needed anymore to prevent memory loss.
- * <p>
- * This class implements {@link #readObject(ObjectInputStream)} and
- * {@link #writeObject(ObjectOutputStream)} methods to (de-)serialize the
- * data.
- *
- * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
+ * Binary value.
  */
-public class BinaryValue implements Serializable, StatefulValue {
-
-    /** The serial version UID */
-    private static final long serialVersionUID = -2410070522924274051L;
-
-    /** The <code>InputStream</code> providing the value */
-    private InputStream stream;
+public class BinaryValue implements Value, Serializable {
 
     /**
-     * Creates an instance on the given <code>InputStream</code>. This exact
-     * stream will be provided by the {@link #getStream()}, thus care must be
-     * taken to not inadvertendly read or close the stream.
-     *
-     * @param stream The <code>InputStream</code> providing the value.
+     * Serial version UID.
      */
-    protected BinaryValue(InputStream stream) {
-        this.stream = stream;
-    }
+    private static final long serialVersionUID = -2837970977514458618L;
+
+    private final byte[] data;
 
     /**
-     * Creates an instance providing the UTF-8 representation of the given
-     * string value.
-     *
-     * @param value The string whose UTF-8 representation is provided as the
-     *      value of this instance.
-     *
-     * @throws ValueFormatException If the platform does not support UTF-8
-     *      encoding (which is unlikely as UTF-8 is required to be available
-     *      on all platforms).
+     * The stream instance returned by {@link #getStream()}. Note that
+     * the stream is not included when serializing the value.
      */
-    protected BinaryValue(String value) throws ValueFormatException {
-        this(toStream(value));
-    }
+    private transient InputStream stream = null;
 
     /**
-     * Helper method to convert a string value into an <code>InputStream</code>
-     * from which the UTF-8 representation can be read.
+     * Creates a binary value from the given stream. The stream is closed.
      *
-     * @param value The string value to be made available through a stream.
-     *
-     * @return The <code>InputStream</code> from which the UTF-8 representation
-     *      of the <code>value</code> may be read.
-     *
-     * @throws ValueFormatException If the platform does not support UTF-8
-     *      encoding (which is unlikely as UTF-8 is required to be available
-     *      on all platforms).
+     * @param stream The <code>InputStream</code> providing the value.
+     * @throws IOException if the stream can not be read
      */
-    protected static InputStream toStream(String value)
-            throws ValueFormatException {
+    protected BinaryValue(InputStream stream) throws IOException {
         try {
-            return new ByteArrayInputStream(value.getBytes("UTF-8"));
-        } catch (UnsupportedEncodingException e) {
-            throw new ValueFormatException("Invalid string value encoding", e);
+            byte[] buffer = new byte[100 * 1024];
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            int n = stream.read(buffer);
+            while (n != -1) {
+                output.write(buffer, 0, n);
+                n = stream.read(buffer);
+            }
+            this.data = output.toByteArray();
+        } finally {
+            stream.close();
         }
     }
 
     /**
-     * Returns the <code>InputStream</code> from which this instance has been
-     * created.
-     *
-     * @return value stream
-     */
-    public InputStream getStream() {
-        return stream;
-    }
-
-    /**
-     * Returns <code>PropertyType.BINARY</code>.
+     * Returns {@link PropertyType#BINARY}.
      *
      * @return property type
      */
@@ -124,130 +80,61 @@
         return PropertyType.BINARY;
     }
 
-    /**
-     * Always throws <code>IllegalStateException</code> because only an
-     * <code>InputStream</code> is available from this implementation.
-     *
-     * @return nothing
-     * @throws IllegalStateException as defined above.
-     */
-    public String getString() throws IllegalStateException {
-        throw new IllegalStateException("Stream already retrieved");
+    public Binary getBinary() {
+        return new Binary() {
+            public int read(byte[] b, long position) {
+                if (position < 0 || position >= data.length) {
+                    return -1;
+                } else {
+                    int n = Math.min(b.length, data.length - (int) position);
+                    System.arraycopy(data, (int) position, b, 0, n);
+                    return n;
+                }
+            }
+            public InputStream getStream() {
+                return new ByteArrayInputStream(data);
+            }
+            public long getSize() {
+                return data.length;
+            }
+            public void dispose() {
+            }
+        };
     }
 
-    /**
-     * Always throws <code>IllegalStateException</code> because only an
-     * <code>InputStream</code> is available from this implementation.
-     *
-     * @return nothing
-     * @throws IllegalStateException as defined above.
-     */
-    public long getLong() throws IllegalStateException {
-        throw new IllegalStateException("Stream already retrieved");
+    public String getString() throws RepositoryException {
+        try {
+            return new String(data, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException("UTF-8 is not supported", e);
+        }
     }
 
-    /**
-     * Always throws <code>IllegalStateException</code> because only an
-     * <code>InputStream</code> is available from this implementation.
-     *
-     * @return nothing
-     * @throws IllegalStateException as defined above.
-     */
-    public double getDouble() throws IllegalStateException {
-        throw new IllegalStateException("Stream already retrieved");
+    public synchronized InputStream getStream() {
+        if (stream == null) {
+            stream = new ByteArrayInputStream(data);
+        }
+        return stream;
     }
 
-    /**
-     * Always throws <code>IllegalStateException</code> because only an
-     * <code>InputStream</code> is available from this implementation.
-     *
-     * @return nothing
-     * @throws IllegalStateException as defined above.
-     */
-    public Calendar getDate() throws IllegalStateException {
-        throw new IllegalStateException("Stream already retrieved");
+    public boolean getBoolean() throws RepositoryException {
+        return new StringValue(getString()).getBoolean();
     }
 
-    /**
-     * Always throws <code>IllegalStateException</code> because only an
-     * <code>InputStream</code> is available from this implementation.
-     *
-     * @return nothing
-     * @throws IllegalStateException as defined above.
-     */
-    public boolean getBoolean() throws IllegalStateException {
-        throw new IllegalStateException("Stream already retrieved");
+    public Calendar getDate() throws RepositoryException {
+        return new StringValue(getString()).getDate();
     }
 
-    /**
-     * Writes the contents of the underlying stream to the
-     * <code>ObjectOutputStream</code>.
-     *
-     * @param out The <code>ObjectOutputStream</code> to where the binary
-     *      data is copied.
-     * @throws IOException If an error occurs writing the binary data.
-     */
-    private void writeObject(ObjectOutputStream out) throws IOException {
-        byte[] buffer = new byte[4096];
-        int bytes = 0;
-        while ((bytes = stream.read(buffer)) >= 0) {
-            // Write a segment of the input stream
-            if (bytes > 0) {
-                // just to ensure that no 0 is written
-                out.writeInt(bytes);
-                out.write(buffer, 0, bytes);
-            }
-        }
-        // Write the end of stream marker
-        out.writeInt(0);
-        // close stream
-        stream.close();
+    public BigDecimal getDecimal() throws RepositoryException {
+        return new StringValue(getString()).getDecimal();
     }
 
-    /**
-     * Reads the binary data from the <code>ObjectInputStream</code> into
-     * a temporary file that is used to back up the binary stream contents
-     * of the constructed value instance. The temporary file gets deleted
-     * when the binary stream is closed or garbage collected.
-     *
-     * @param in The <code>ObjectInputStream</code> from where to get the
-     *      binary data.
-     * @throws IOException If an error occurs reading the binary data.
-     */
-    private void readObject(ObjectInputStream in) throws IOException {
-        final File file = File.createTempFile("jcr-value", "bin");
-
-        OutputStream out = new FileOutputStream(file);
-        byte[] buffer = new byte[4096];
-        for (int bytes = in.readInt(); bytes > 0; bytes = in.readInt()) {
-            if (buffer.length < bytes) {
-                buffer = new byte[bytes];
-            }
-            in.readFully(buffer, 0, bytes);
-            out.write(buffer, 0, bytes);
-        }
-        out.close();
-
-        stream = new FileInputStream(file) {
-
-            private boolean closed = false;
-
-            public void close() throws IOException {
-                super.close();
-                closed = true;
-                file.delete();
-            }
+    public double getDouble() throws RepositoryException {
+        return new StringValue(getString()).getDouble();
+    }
 
-            protected void finalize() throws IOException {
-                try {
-                    if (!closed) {
-                        file.delete();
-                    }
-                } finally {
-                    super.finalize();
-                }
-            }
-        };
+    public long getLong() throws RepositoryException {
+        return new StringValue(getString()).getLong();
     }
 
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BooleanValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BooleanValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BooleanValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/BooleanValue.java Tue Jan  5 16:18:16 2010
@@ -16,55 +16,32 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
-
 import javax.jcr.PropertyType;
 
 /**
- * The <code>BooleanValue</code> class implements the committed value state for
- * Boolean values as a part of the State design pattern (Gof) used by this
- * package.
- *
- * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
+ * Boolean value.
  */
-public class BooleanValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
-
-    /** The serial version UID */
-    private static final long serialVersionUID = 8212168298890947089L;
-
-    /** The boolean value */
-    private final boolean value;
+class BooleanValue extends BaseValue {
 
     /**
-     * Creates an instance for the given boolean <code>value</code>.
+     * Serial version UID
      */
-    protected BooleanValue(boolean value) {
-        this.value = value;
-    }
+    private static final long serialVersionUID = 5266937874230536517L;
 
     /**
-     * Creates an instance for the given string representation of a boolean.
-     * <p>
-     * Calls {@link #toBoolean(String)} to convert the string to a boolean.
+     * The boolean value
      */
-    protected BooleanValue(String value) {
-        this(toBoolean(value));
-    }
+    private final boolean value;
 
     /**
-     * Returns the boolean value represented by the string <code>value</code>.
-     * <p>
-     * This implementation uses the <code>Boolean.valueOf(String)</code> method
-     * to convert the string to a boolean.
+     * Creates an instance for the given boolean value.
      */
-    protected static boolean toBoolean(String value) {
-        return Boolean.valueOf(value).booleanValue();
+    public BooleanValue(boolean value) {
+        this.value = value;
     }
 
     /**
-     * Returns <code>PropertyType.BOOLEAN</code>.
+     * Returns {@link PropertyType#BOOLEAN}.
      */
     public int getType() {
         return PropertyType.BOOLEAN;
@@ -78,10 +55,10 @@
     }
 
     /**
-     * Returns the boolean as a string converted by the
-     * <code>Boolean.toString(boolean)</code>.
+     * The boolean is converted using {@link Boolean#toString()}.
      */
     public String getString() {
         return Boolean.toString(value);
     }
+
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DateValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DateValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DateValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DateValue.java Tue Jan  5 16:18:16 2010
@@ -16,38 +16,32 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
-import java.text.DecimalFormat;
 import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
 
 import javax.jcr.PropertyType;
 import javax.jcr.ValueFormatException;
 
 /**
- * The <code>DateValue</code> class implements the committed value state for
- * Date values as a part of the State design pattern (Gof) used by this
- * package.
- *
- * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
+ * Date value.
  */
-public class DateValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+class DateValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = 7158448867450810873L;
+    /**
+     * Serial version UID
+     */
+    private static final long serialVersionUID = -2382837055824423966L;
 
-    /** The <code>Calendar</code> value */
+    /**
+     * The date value
+     */
     private final Calendar value;
 
     /**
-     * Creates an instance for the given <code>Calendar</code> <code>value</code>.
+     * Creates an instance for the given date value.
      *
-     * @param value the calendar for this value.
+     * @param value the date value
      */
-    protected DateValue(Calendar value) {
+    public DateValue(Calendar value) {
         this.value = value;
     }
 
@@ -71,15 +65,16 @@
     }
 
     /**
-     * Returns <code>PropertyType.DATE</code>.
+     * Returns {@link PropertyType#DATE}.
      */
     public int getType() {
         return PropertyType.DATE;
     }
 
     /**
-     * Returns the time represented by this instance as the number of
-     * milliseconds since the epoch (1.1.1970, 0:00, UTC).
+     * The date is converted to the number of milliseconds since
+     * 00:00 (UTC) 1 January 1970 (1970-01-01T00:00:00.000Z). If this number
+     * is out-of-range for a double, a ValueFormatException is thrown.
      */
     public double getDouble() {
         return value.getTimeInMillis();
@@ -94,8 +89,9 @@
     }
 
     /**
-     * Returns the time represented by this instance as the number of
-     * milliseconds since the epoch (1.1.1970, 0:00, UTC).
+     * The date is converted to the number of milliseconds since
+     * 00:00 (UTC) 1 January 1970 (1970-01-01T00:00:00.000Z). If this number
+     * is out-of-range for a long, a ValueFormatException is thrown.
      */
     public long getLong() {
         return value.getTimeInMillis();
@@ -109,261 +105,5 @@
     public Calendar getDate() {
         return (Calendar) value.clone();
     }
-}
-
-/**
- * Note: this class was copied from <code>org.apache.jackrabbit.util.ISO8601</code>
- *       for now we try to avoid dependencies on other libs can jcr.
- *
- * The <code>ISO8601</code> utility class provides helper methods
- * to deal with date/time formatting using a specific ISO8601-compliant
- * format (see <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a>).
- * <p/>
- * The currently supported format is:
- * <pre>
- *   &plusmn;YYYY-MM-DDThh:mm:ss.SSSTZD
- * </pre>
- * where:
- * <pre>
- *   &plusmn;YYYY = four-digit year with optional sign where values <= 0 are
- *           denoting years BCE and values > 0 are denoting years CE,
- *           e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE,
- *           0001 denotes the year 1 CE, and so on...
- *   MM    = two-digit month (01=January, etc.)
- *   DD    = two-digit day of month (01 through 31)
- *   hh    = two digits of hour (00 through 23) (am/pm NOT allowed)
- *   mm    = two digits of minute (00 through 59)
- *   ss    = two digits of second (00 through 59)
- *   SSS   = three digits of milliseconds (000 through 999)
- *   TZD   = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC
- *           in the form of +hh:mm or -hh:mm
- * </pre>
- */
-final class ISO8601 {
-    /**
-     * misc. numeric formats used in formatting
-     */
-    private static final DecimalFormat XX_FORMAT = new DecimalFormat("00");
-    private static final DecimalFormat XXX_FORMAT = new DecimalFormat("000");
-    private static final DecimalFormat XXXX_FORMAT = new DecimalFormat("0000");
-
-    /**
-     * Parses an ISO8601-compliant date/time string.
-     *
-     * @param text the date/time string to be parsed
-     * @return a <code>Calendar</code>, or <code>null</code> if the input could
-     *         not be parsed
-     * @throws IllegalArgumentException if a <code>null</code> argument is passed
-     */
-    public static Calendar parse(String text) {
-        if (text == null) {
-            throw new IllegalArgumentException("argument can not be null");
-        }
-
-        // check optional leading sign
-        char sign;
-        int start;
-        if (text.startsWith("-")) {
-            sign = '-';
-            start = 1;
-        } else if (text.startsWith("+")) {
-            sign = '+';
-            start = 1;
-        } else {
-            sign = '+'; // no sign specified, implied '+'
-            start = 0;
-        }
-
-        /**
-         * the expected format of the remainder of the string is:
-         * YYYY-MM-DDThh:mm:ss.SSSTZD
-         *
-         * note that we cannot use java.text.SimpleDateFormat for
-         * parsing because it can't handle years <= 0 and TZD's
-         */
-
-        int year, month, day, hour, min, sec, ms;
-        String tzID;
-        try {
-            // year (YYYY)
-            year = Integer.parseInt(text.substring(start, start + 4));
-            start += 4;
-            // delimiter '-'
-            if (text.charAt(start) != '-') {
-                return null;
-            }
-            start++;
-            // month (MM)
-            month = Integer.parseInt(text.substring(start, start + 2));
-            start += 2;
-            // delimiter '-'
-            if (text.charAt(start) != '-') {
-                return null;
-            }
-            start++;
-            // day (DD)
-            day = Integer.parseInt(text.substring(start, start + 2));
-            start += 2;
-            // delimiter 'T'
-            if (text.charAt(start) != 'T') {
-                return null;
-            }
-            start++;
-            // hour (hh)
-            hour = Integer.parseInt(text.substring(start, start + 2));
-            start += 2;
-            // delimiter ':'
-            if (text.charAt(start) != ':') {
-                return null;
-            }
-            start++;
-            // minute (mm)
-            min = Integer.parseInt(text.substring(start, start + 2));
-            start += 2;
-            // delimiter ':'
-            if (text.charAt(start) != ':') {
-                return null;
-            }
-            start++;
-            // second (ss)
-            sec = Integer.parseInt(text.substring(start, start + 2));
-            start += 2;
-            // delimiter '.'
-            if (text.charAt(start) != '.') {
-                return null;
-            }
-            start++;
-            // millisecond (SSS)
-            ms = Integer.parseInt(text.substring(start, start + 3));
-            start += 3;
-            // time zone designator (Z or +00:00 or -00:00)
-            if (text.charAt(start) == '+' || text.charAt(start) == '-') {
-                // offset to UTC specified in the format +00:00/-00:00
-                tzID = "GMT" + text.substring(start);
-            } else if (text.substring(start).equals("Z")) {
-                tzID = "GMT";
-            } else {
-                // invalid time zone designator
-                return null;
-            }
-        } catch (IndexOutOfBoundsException e) {
-            return null;
-        } catch (NumberFormatException e) {
-            return null;
-        }
-
-        TimeZone tz = TimeZone.getTimeZone(tzID);
-        // verify id of returned time zone (getTimeZone defaults to "GMT")
-        if (!tz.getID().equals(tzID)) {
-            // invalid time zone
-            return null;
-        }
-
-        // initialize Calendar object
-        Calendar cal = Calendar.getInstance(tz);
-        cal.setLenient(false);
-        // year and era
-        if (sign == '-' || year == 0) {
-            // not CE, need to set era (BCE) and adjust year
-            cal.set(Calendar.YEAR, year + 1);
-            cal.set(Calendar.ERA, GregorianCalendar.BC);
-        } else {
-            cal.set(Calendar.YEAR, year);
-            cal.set(Calendar.ERA, GregorianCalendar.AD);
-        }
-        // month (0-based!)
-        cal.set(Calendar.MONTH, month - 1);
-        // day of month
-        cal.set(Calendar.DAY_OF_MONTH, day);
-        // hour
-        cal.set(Calendar.HOUR_OF_DAY, hour);
-        // minute
-        cal.set(Calendar.MINUTE, min);
-        // second
-        cal.set(Calendar.SECOND, sec);
-        // millisecond
-        cal.set(Calendar.MILLISECOND, ms);
-
-        try {
-            /**
-             * the following call will trigger an IllegalArgumentException
-             * if any of the set values are illegal or out of range
-             */
-            cal.getTime();
-        } catch (IllegalArgumentException e) {
-            return null;
-        }
-
-        return cal;
-    }
-
-    /**
-     * Formats a <code>Calendar</code> value into an ISO8601-compliant
-     * date/time string.
-     *
-     * @param cal the time value to be formatted into a date/time string.
-     * @return the formatted date/time string.
-     * @throws IllegalArgumentException if a <code>null</code> argument is passed
-     */
-    public static String format(Calendar cal) {
-        if (cal == null) {
-            throw new IllegalArgumentException("argument can not be null");
-        }
 
-        // determine era and adjust year if necessary
-        int year = cal.get(Calendar.YEAR);
-        if (cal.isSet(Calendar.ERA)
-                && cal.get(Calendar.ERA) == GregorianCalendar.BC) {
-            /**
-             * calculate year using astronomical system:
-             * year n BCE => astronomical year -n + 1
-             */
-            year = 0 - year + 1;
-        }
-
-        /**
-         * the format of the date/time string is:
-         * YYYY-MM-DDThh:mm:ss.SSSTZD
-         *
-         * note that we cannot use java.text.SimpleDateFormat for
-         * formatting because it can't handle years <= 0 and TZD's
-         */
-        StringBuffer buf = new StringBuffer();
-        // year ([-]YYYY)
-        buf.append(XXXX_FORMAT.format(year));
-        buf.append('-');
-        // month (MM)
-        buf.append(XX_FORMAT.format(cal.get(Calendar.MONTH) + 1));
-        buf.append('-');
-        // day (DD)
-        buf.append(XX_FORMAT.format(cal.get(Calendar.DAY_OF_MONTH)));
-        buf.append('T');
-        // hour (hh)
-        buf.append(XX_FORMAT.format(cal.get(Calendar.HOUR_OF_DAY)));
-        buf.append(':');
-        // minute (mm)
-        buf.append(XX_FORMAT.format(cal.get(Calendar.MINUTE)));
-        buf.append(':');
-        // second (ss)
-        buf.append(XX_FORMAT.format(cal.get(Calendar.SECOND)));
-        buf.append('.');
-        // millisecond (SSS)
-        buf.append(XXX_FORMAT.format(cal.get(Calendar.MILLISECOND)));
-        // time zone designator (Z or +00:00 or -00:00)
-        TimeZone tz = cal.getTimeZone();
-        // determine offset of timezone from UTC (incl. daylight saving)
-        int offset = tz.getOffset(cal.getTimeInMillis());
-        if (offset != 0) {
-            int hours = Math.abs((offset / (60 * 1000)) / 60);
-            int minutes = Math.abs((offset / (60 * 1000)) % 60);
-            buf.append(offset < 0 ? '-' : '+');
-            buf.append(XX_FORMAT.format(hours));
-            buf.append(':');
-            buf.append(XX_FORMAT.format(minutes));
-        } else {
-            buf.append('Z');
-        }
-        return buf.toString();
-    }
 }
-

Added: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DecimalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DecimalValue.java?rev=896113&view=auto
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DecimalValue.java (added)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DecimalValue.java Tue Jan  5 16:18:16 2010
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.value;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+
+/**
+ * Decimal value.
+ */
+class DecimalValue extends BaseValue {
+
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 2077767642124007133L;
+
+    /**
+     * The decimal value.
+     */
+    private final BigDecimal value;
+
+    /**
+     * Creates an instance for the given decimal value.
+     */
+    public DecimalValue(BigDecimal value) {
+        this.value = value;
+    }
+
+    /**
+     * Returns {@link PropertyType#DECIMAL}.
+     */
+    public int getType() {
+        return PropertyType.DECIMAL;
+    }
+
+    /**
+     * The decimal is converted to a long and interpreted as the number of
+     * milliseconds since 00:00 (UTC) 1 January 1970 (1970-01-01T00:00:00.000Z).
+     * If the resulting value is out of range for a date,
+     * a ValueFormatException is thrown.
+     */
+    public Calendar getDate() throws ValueFormatException {
+        Calendar date = Calendar.getInstance();
+        date.setTimeInMillis(getLong());
+        return date;
+    }
+
+    /**
+     * The decimal is converted using {@link BigDecimal#longValue()}.
+     */
+    public long getLong() {
+        return value.longValue();
+    }
+
+    /**
+     * The decimal is converted using {@link BigDecimal#toString()}.
+     */
+    public String getString() {
+        return value.toString();
+    }
+
+    /**
+     * The decimal is converted using {@link BigDecimal#doubleValue()}.
+     */
+    public double getDouble() {
+        return value.doubleValue();
+    }
+
+}

Propchange: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DecimalValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DoubleValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DoubleValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DoubleValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/DoubleValue.java Tue Jan  5 16:18:16 2010
@@ -16,65 +16,35 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
 import java.util.Calendar;
 
 import javax.jcr.PropertyType;
 import javax.jcr.ValueFormatException;
 
 /**
- * The <code>DoubleValue</code> class implements the committed value state for
- * Double values as a part of the State design pattern (Gof) used by this
- * package.
- *
- * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
+ * Double value.
  */
-public class DoubleValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
-
-    /** The serial version UID */
-    private static final long serialVersionUID = 1008752925622023274L;
-
-    /** The double value */
-    private final double value;
+class DoubleValue extends BaseValue {
 
     /**
-     * Creates an instance for the given double <code>value</code>.
+     * Serial version UID.
      */
-    protected DoubleValue(double value) {
-        this.value = value;
-    }
+    private static final long serialVersionUID = -2767063038068929611L;
 
     /**
-     * Creates an instance for the given string representation of a double.
-     * <p>
-     * This implementation uses the <code>Double.valueOf(String)</code> method
-     * to convert the string to a double.
-     *
-     * @throws ValueFormatException if the string <code>value</code> cannot be
-     *      parsed to double.
+     * The double value.
      */
-    protected DoubleValue(String value) throws ValueFormatException {
-        this(toDouble(value));
-    }
+    private final double value;
 
     /**
-     * Returns the double value represented by the string <code>value</code>.
-     *
-     * @throws ValueFormatException if the string <code>value</code> cannot be
-     *      parsed to double.
+     * Creates an instance for the given double value.
      */
-    protected static double toDouble(String value) throws ValueFormatException {
-        try {
-            return Double.valueOf(value).doubleValue();
-        } catch (NumberFormatException e) {
-            throw new ValueFormatException(e);
-        }
+    public DoubleValue(double value) {
+        this.value = value;
     }
 
     /**
-     * Returns <code>PropertyType.DOUBLE</code>.
+     * Returns {@link PropertyType#DOUBLE}.
      */
     public int getType() {
         return PropertyType.DOUBLE;
@@ -111,4 +81,5 @@
     public long getLong() {
         return (long) value;
     }
+
 }

Added: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ISO8601.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ISO8601.java?rev=896113&view=auto
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ISO8601.java (added)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ISO8601.java Tue Jan  5 16:18:16 2010
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.value;
+
+import java.text.DecimalFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+/**
+ * Note: this class was copied from <code>org.apache.jackrabbit.util.ISO8601</code>
+ *       for now we try to avoid dependencies on other libs can jcr.
+ *
+ * The <code>ISO8601</code> utility class provides helper methods
+ * to deal with date/time formatting using a specific ISO8601-compliant
+ * format (see <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a>).
+ * <p/>
+ * The currently supported format is:
+ * <pre>
+ *   &plusmn;YYYY-MM-DDThh:mm:ss.SSSTZD
+ * </pre>
+ * where:
+ * <pre>
+ *   &plusmn;YYYY = four-digit year with optional sign where values <= 0 are
+ *           denoting years BCE and values > 0 are denoting years CE,
+ *           e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE,
+ *           0001 denotes the year 1 CE, and so on...
+ *   MM    = two-digit month (01=January, etc.)
+ *   DD    = two-digit day of month (01 through 31)
+ *   hh    = two digits of hour (00 through 23) (am/pm NOT allowed)
+ *   mm    = two digits of minute (00 through 59)
+ *   ss    = two digits of second (00 through 59)
+ *   SSS   = three digits of milliseconds (000 through 999)
+ *   TZD   = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC
+ *           in the form of +hh:mm or -hh:mm
+ * </pre>
+ */
+final class ISO8601 {
+
+    /**
+     * misc. numeric formats used in formatting
+     */
+    private static final DecimalFormat XX_FORMAT = new DecimalFormat("00");
+    private static final DecimalFormat XXX_FORMAT = new DecimalFormat("000");
+    private static final DecimalFormat XXXX_FORMAT = new DecimalFormat("0000");
+
+    /**
+     * Parses an ISO8601-compliant date/time string.
+     *
+     * @param text the date/time string to be parsed
+     * @return a <code>Calendar</code>, or <code>null</code> if the input could
+     *         not be parsed
+     * @throws IllegalArgumentException if a <code>null</code> argument is passed
+     */
+    public static Calendar parse(String text) {
+        if (text == null) {
+            throw new IllegalArgumentException("argument can not be null");
+        }
+
+        // check optional leading sign
+        char sign;
+        int start;
+        if (text.startsWith("-")) {
+            sign = '-';
+            start = 1;
+        } else if (text.startsWith("+")) {
+            sign = '+';
+            start = 1;
+        } else {
+            sign = '+'; // no sign specified, implied '+'
+            start = 0;
+        }
+
+        /**
+         * the expected format of the remainder of the string is:
+         * YYYY-MM-DDThh:mm:ss.SSSTZD
+         *
+         * note that we cannot use java.text.SimpleDateFormat for
+         * parsing because it can't handle years <= 0 and TZD's
+         */
+
+        int year, month, day, hour, min, sec, ms;
+        String tzID;
+        try {
+            // year (YYYY)
+            year = Integer.parseInt(text.substring(start, start + 4));
+            start += 4;
+            // delimiter '-'
+            if (text.charAt(start) != '-') {
+                return null;
+            }
+            start++;
+            // month (MM)
+            month = Integer.parseInt(text.substring(start, start + 2));
+            start += 2;
+            // delimiter '-'
+            if (text.charAt(start) != '-') {
+                return null;
+            }
+            start++;
+            // day (DD)
+            day = Integer.parseInt(text.substring(start, start + 2));
+            start += 2;
+            // delimiter 'T'
+            if (text.charAt(start) != 'T') {
+                return null;
+            }
+            start++;
+            // hour (hh)
+            hour = Integer.parseInt(text.substring(start, start + 2));
+            start += 2;
+            // delimiter ':'
+            if (text.charAt(start) != ':') {
+                return null;
+            }
+            start++;
+            // minute (mm)
+            min = Integer.parseInt(text.substring(start, start + 2));
+            start += 2;
+            // delimiter ':'
+            if (text.charAt(start) != ':') {
+                return null;
+            }
+            start++;
+            // second (ss)
+            sec = Integer.parseInt(text.substring(start, start + 2));
+            start += 2;
+            // delimiter '.'
+            if (text.charAt(start) != '.') {
+                return null;
+            }
+            start++;
+            // millisecond (SSS)
+            ms = Integer.parseInt(text.substring(start, start + 3));
+            start += 3;
+            // time zone designator (Z or +00:00 or -00:00)
+            if (text.charAt(start) == '+' || text.charAt(start) == '-') {
+                // offset to UTC specified in the format +00:00/-00:00
+                tzID = "GMT" + text.substring(start);
+            } else if (text.substring(start).equals("Z")) {
+                tzID = "GMT";
+            } else {
+                // invalid time zone designator
+                return null;
+            }
+        } catch (IndexOutOfBoundsException e) {
+            return null;
+        } catch (NumberFormatException e) {
+            return null;
+        }
+
+        TimeZone tz = TimeZone.getTimeZone(tzID);
+        // verify id of returned time zone (getTimeZone defaults to "GMT")
+        if (!tz.getID().equals(tzID)) {
+            // invalid time zone
+            return null;
+        }
+
+        // initialize Calendar object
+        Calendar cal = Calendar.getInstance(tz);
+        cal.setLenient(false);
+        // year and era
+        if (sign == '-' || year == 0) {
+            // not CE, need to set era (BCE) and adjust year
+            cal.set(Calendar.YEAR, year + 1);
+            cal.set(Calendar.ERA, GregorianCalendar.BC);
+        } else {
+            cal.set(Calendar.YEAR, year);
+            cal.set(Calendar.ERA, GregorianCalendar.AD);
+        }
+        // month (0-based!)
+        cal.set(Calendar.MONTH, month - 1);
+        // day of month
+        cal.set(Calendar.DAY_OF_MONTH, day);
+        // hour
+        cal.set(Calendar.HOUR_OF_DAY, hour);
+        // minute
+        cal.set(Calendar.MINUTE, min);
+        // second
+        cal.set(Calendar.SECOND, sec);
+        // millisecond
+        cal.set(Calendar.MILLISECOND, ms);
+
+        try {
+            /**
+             * the following call will trigger an IllegalArgumentException
+             * if any of the set values are illegal or out of range
+             */
+            cal.getTime();
+        } catch (IllegalArgumentException e) {
+            return null;
+        }
+
+        return cal;
+    }
+
+    /**
+     * Formats a <code>Calendar</code> value into an ISO8601-compliant
+     * date/time string.
+     *
+     * @param cal the time value to be formatted into a date/time string.
+     * @return the formatted date/time string.
+     * @throws IllegalArgumentException if a <code>null</code> argument is passed
+     */
+    public static String format(Calendar cal) {
+        if (cal == null) {
+            throw new IllegalArgumentException("argument can not be null");
+        }
+
+        // determine era and adjust year if necessary
+        int year = cal.get(Calendar.YEAR);
+        if (cal.isSet(Calendar.ERA)
+                && cal.get(Calendar.ERA) == GregorianCalendar.BC) {
+            /**
+             * calculate year using astronomical system:
+             * year n BCE => astronomical year -n + 1
+             */
+            year = 0 - year + 1;
+        }
+
+        /**
+         * the format of the date/time string is:
+         * YYYY-MM-DDThh:mm:ss.SSSTZD
+         *
+         * note that we cannot use java.text.SimpleDateFormat for
+         * formatting because it can't handle years <= 0 and TZD's
+         */
+        StringBuffer buf = new StringBuffer();
+        // year ([-]YYYY)
+        buf.append(XXXX_FORMAT.format(year));
+        buf.append('-');
+        // month (MM)
+        buf.append(XX_FORMAT.format(cal.get(Calendar.MONTH) + 1));
+        buf.append('-');
+        // day (DD)
+        buf.append(XX_FORMAT.format(cal.get(Calendar.DAY_OF_MONTH)));
+        buf.append('T');
+        // hour (hh)
+        buf.append(XX_FORMAT.format(cal.get(Calendar.HOUR_OF_DAY)));
+        buf.append(':');
+        // minute (mm)
+        buf.append(XX_FORMAT.format(cal.get(Calendar.MINUTE)));
+        buf.append(':');
+        // second (ss)
+        buf.append(XX_FORMAT.format(cal.get(Calendar.SECOND)));
+        buf.append('.');
+        // millisecond (SSS)
+        buf.append(XXX_FORMAT.format(cal.get(Calendar.MILLISECOND)));
+        // time zone designator (Z or +00:00 or -00:00)
+        TimeZone tz = cal.getTimeZone();
+        // determine offset of timezone from UTC (incl. daylight saving)
+        int offset = tz.getOffset(cal.getTimeInMillis());
+        if (offset != 0) {
+            int hours = Math.abs((offset / (60 * 1000)) / 60);
+            int minutes = Math.abs((offset / (60 * 1000)) % 60);
+            buf.append(offset < 0 ? '-' : '+');
+            buf.append(XX_FORMAT.format(hours));
+            buf.append(':');
+            buf.append(XX_FORMAT.format(minutes));
+        } else {
+            buf.append('Z');
+        }
+        return buf.toString();
+    }
+
+}

Propchange: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ISO8601.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/LongValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/LongValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/LongValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/LongValue.java Tue Jan  5 16:18:16 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
 import java.util.Calendar;
 
 import javax.jcr.PropertyType;
@@ -28,13 +27,13 @@
  * package.
  *
  * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
  */
-public class LongValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+public class LongValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = 2115837525193497922L;
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = -5983072186237752887L;
 
     /** The long value */
     private final long value;
@@ -111,4 +110,5 @@
     public double getDouble() {
         return value;
     }
+
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/NameValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/NameValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/NameValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/NameValue.java Tue Jan  5 16:18:16 2010
@@ -16,26 +16,22 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
-
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
 
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.NameFormat;
-
 /**
  * The <code>NameValue</code> class implements the committed value state for
  * Name values as a part of the State design pattern (Gof) used by this package.
  *
  * @since 0.16.4.1
  */
-public class NameValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+public class NameValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = -2165655071495230179L;
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 4598175360244278453L;
 
     /** The name value. */
     private final String value;
@@ -44,27 +40,8 @@
      * Creates an instance for the given name <code>value</code>.
      */
     protected NameValue(String value) throws ValueFormatException {
-        this.value = toName(value);
-    }
-
-    /**
-     * Checks whether the string value adheres to the name syntax.
-     *
-     * @param value The string to check for synthactical compliance with a
-     *      name value.
-     *
-     * @return The input value.
-     *
-     * @throws ValueFormatException if the string <code>value</code> is not a
-     *      synthactically correct name.
-     */
-    protected static String toName(String value) throws ValueFormatException {
-        try {
-            NameFormat.checkFormat(value);
-            return value;
-        } catch (IllegalNameException e) {
-            throw new ValueFormatException("Invalid name: " + value, e);
-        }
+        // TODO: Check name format
+        this.value = value;
     }
 
     /**
@@ -77,7 +54,7 @@
     /**
      * Returns the string representation of the Name value.
      */
-    public String getString() throws ValueFormatException, RepositoryException {
+    public String getString() throws RepositoryException {
         return value;
     }
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/PathValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/PathValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/PathValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/PathValue.java Tue Jan  5 16:18:16 2010
@@ -16,26 +16,22 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
-
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
 
-import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.PathFormat;
-
 /**
  * The <code>PathValue</code> class implements the committed value state for
  * Path values as a part of the State design pattern (Gof) used by this package.
  *
  * @since 0.16.4.1
  */
-public class PathValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+public class PathValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = 961536566073928748L;
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 6233090249008329224L;
 
     /** The path value. */
     private final String value;
@@ -44,27 +40,8 @@
      * Creates an instance for the given path <code>value</code>.
      */
     protected PathValue(String value) throws ValueFormatException {
-        this.value = toPath(value);
-    }
-
-    /**
-     * Checks whether the string value adheres to the path syntax.
-     *
-     * @param value The string to check for synthactical compliance with a
-     *      path value.
-     *
-     * @return The input value.
-     *
-     * @throws ValueFormatException if the string <code>value</code> is not a
-     *      synthactically correct path.
-     */
-    protected static String toPath(String value) throws ValueFormatException {
-        try {
-            PathFormat.checkFormat(value);
-            return value;
-        } catch (MalformedPathException e) {
-            throw new ValueFormatException("Invalid path: " + value, e);
-        }
+        // TODO: Check path format
+        this.value = value;
     }
 
     /**

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ReferenceValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ReferenceValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ReferenceValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/ReferenceValue.java Tue Jan  5 16:18:16 2010
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
-
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
@@ -29,11 +27,12 @@
  *
  * @since 0.16.4.1
  */
-public class ReferenceValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+public class ReferenceValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = -3160494922729580458L;
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 5245358709465803351L;
 
     /** The reference value */
     private final String value;
@@ -42,23 +41,8 @@
      * Creates an instance for the given reference <code>value</code>.
      */
     protected ReferenceValue(String value) throws ValueFormatException {
-        this.value = toReference(value);
-    }
-
-    /**
-     * Checks whether the string value adheres to the reference syntax.
-     *
-     * @param value The string to check for synthactical compliance with a
-     *      reference value.
-     *
-     * @return The input value.
-     *
-     * @throws ValueFormatException if the string <code>value</code> is not a
-     *      synthactically correct reference.
-     */
-    protected static String toReference(String value) throws ValueFormatException {
         // TODO: check syntax
-        return value;
+        this.value = value;
     }
 
     /**

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/SerialValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/SerialValueFactory.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/SerialValueFactory.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/SerialValueFactory.java Tue Jan  5 16:18:16 2010
@@ -16,11 +16,15 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
 
+import javax.jcr.Binary;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -68,17 +72,19 @@
      *
      * @param values the values to be decorated
      * @return array of decorated values
+     * @throws RepositoryException if the values can not be serialized
      */
-    public static Value[] makeSerialValueArray(Value[] values) {
-        List serials = new ArrayList();
+    public static Value[] makeSerialValueArray(Value[] values)
+            throws RepositoryException {
+        List<Value> serials = new ArrayList<Value>();
         if (values != null) {
-            for (int i = 0; i < values.length; i++) {
-                if (values[i] != null) {
-                    serials.add(makeSerialValue(values[i]));
+            for (Value value : values) {
+                if (value != null) {
+                    serials.add(makeSerialValue(value));
                 }
             }
         }
-        return (Value[]) serials.toArray(new Value[serials.size()]);
+        return serials.toArray(new Value[serials.size()]);
     }
 
     /**
@@ -88,15 +94,15 @@
      *
      * @param value the value to be decorated, or <code>null</code>
      * @return the decorated value, or <code>null</code>
+     * @throws RepositoryException if the value can not be serialized
      */
-    public static Value makeSerialValue(Value value) {
+    public static Value makeSerialValue(Value value) throws RepositoryException {
         // if the value is null or already serializable, just return it
-        if (value == null || value instanceof SerialValue) {
+        if (value == null || value instanceof Serializable) {
             return value;
+        } else {
+            return INSTANCE.createValue(value);
         }
-
-        // convert to a general vaule
-        return new SerialValue(new StatefulValueAdapter(value));
     }
 
     /**
@@ -110,15 +116,15 @@
      * @return array of string values
      */
     public static Value[] makeSerialValueArray(String[] values) {
-        List serials = new ArrayList();
+        List<Value> serials = new ArrayList<Value>();
         if (values != null) {
-            for (int i = 0; i < values.length; i++) {
-                if (values[i] != null) {
-                    serials.add(INSTANCE.createValue(values[i]));
+            for (String value : values) {
+                if (value != null) {
+                    serials.add(INSTANCE.createValue(value));
                 }
             }
         }
-        return (Value[]) serials.toArray(new Value[serials.size()]);
+        return serials.toArray(new Value[serials.size()]);
     }
 
     /**
@@ -129,71 +135,92 @@
     }
 
     /** {@inheritDoc} */
-    public final Value createValue(String value) {
-        return new SerialValue(createStringValue(value));
+    public Value createValue(String value) {
+        return new StringValue(value);
     }
 
     /** {@inheritDoc} */
-    public final Value createValue(String value, int type) throws ValueFormatException {
-        StatefulValue intValue;
-        switch (type) {
-            case PropertyType.BINARY:
-                intValue = createBinaryValue(value);
-                break;
-            case PropertyType.BOOLEAN:
-                intValue = createBooleanValue(value);
-                break;
-            case PropertyType.DATE:
-                intValue = createDateValue(value);
-                break;
-            case PropertyType.DOUBLE:
-                intValue = createDoubleValue(value);
-                break;
-            case PropertyType.LONG:
-                intValue = createLongValue(value);
-                break;
-            case PropertyType.NAME:
-                intValue = createNameValue(value);
-                break;
-            case PropertyType.PATH:
-                intValue = createPathValue(value);
-                break;
-            case PropertyType.REFERENCE:
-                intValue = createReferenceValue(value);
-                break;
-            case PropertyType.STRING:
-                intValue = createStringValue(value);
-                break;
-            default:
-                throw new ValueFormatException("Unknown type " + type);
+    public final Value createValue(String value, int type)
+            throws ValueFormatException {
+        try {
+            return createValue(new StringValue(value), type);
+        } catch (ValueFormatException e) {
+            throw e;
+        } catch (RepositoryException e) {
+            throw new ValueFormatException(
+                    "Unexpected error when creating value: " + value, e);
         }
+    }
 
-        return new SerialValue(intValue);
+    private Value createValue(Value value) throws RepositoryException {
+        return createValue(value, value.getType());
+    }
+
+    private Value createValue(Value value, int type)
+            throws RepositoryException {
+        switch (type) {
+        case PropertyType.BINARY:
+            Binary binary = value.getBinary();
+            try {
+                return new BinaryValue(binary.getStream());
+            } catch (IOException e) {
+                throw new RepositoryException("Unable to read binary value");
+            } finally {
+                binary.dispose();
+            }
+        case PropertyType.BOOLEAN:
+            return new BooleanValue(value.getBoolean());
+        case PropertyType.DATE:
+            return new DateValue(value.getDate());
+        case PropertyType.DOUBLE:
+            return new DoubleValue(value.getDouble());
+        case PropertyType.LONG:
+            return new LongValue(value.getLong());
+        case PropertyType.NAME:
+            return new NameValue(value.getString());
+        case PropertyType.PATH:
+            return new PathValue(value.getString());
+        case PropertyType.REFERENCE:
+            return new ReferenceValue(value.getString());
+        case PropertyType.STRING:
+            return new StringValue(value.getString());
+        default:
+            throw new ValueFormatException("Unknown value type " + type);
+        }
     }
 
     /** {@inheritDoc} */
     public final Value createValue(long value) {
-        return new SerialValue(createLongValue(value));
+        return new LongValue(value);
     }
 
     /** {@inheritDoc} */
     public final Value createValue(double value) {
-        return new SerialValue(createDoubleValue(value));
+        return new DoubleValue(value);
     }
 
     /** {@inheritDoc} */
     public final Value createValue(boolean value) {
-        return new SerialValue(createBooleanValue(value));
+        return new BooleanValue(value);
+    }
+
+    /** {@inheritDoc} */
+    public Value createValue(BigDecimal value) {
+        return null;
     }
 
     /** {@inheritDoc} */
     public final Value createValue(Calendar value) {
-        return new SerialValue(createDateValue(value));
+        return new DateValue(value);
     }
 
     /** {@inheritDoc} */
     public final Value createValue(InputStream value) {
-        return new SerialValue(createBinaryValue(value));
+        try {
+            return new BinaryValue(value);
+        } catch (IOException e) {
+            throw new RuntimeException("Unable to create binary value", e);
+        }
     }
 
     /** {@inheritDoc} */
@@ -203,220 +230,20 @@
 
     //---------- API to overwrite to use extended classes ----------------------
 
-    /**
-     * Creates an instance of the {@link StringValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link StringValue#StringValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string making up the value itself.
-     */
-    protected StringValue createStringValue(String value) {
-        return new StringValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link NameValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link NameValue#NameValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string making up the value itself.
-     *
-     * @throws ValueFormatException if the string is not a synthactically
-     *      correct JCR name.
-     */
-    protected NameValue createNameValue(String value)
-            throws ValueFormatException {
-        return new NameValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link PathValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link PathValue#PathValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string making up the value itself.
-     *
-     * @throws ValueFormatException if the string is not a synthactically
-     *      correct JCR path.
-     */
-    protected PathValue createPathValue(String value)
-            throws ValueFormatException {
-        return new PathValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link ReferenceValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link ReferenceValue#ReferenceValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string making up the value itself.
-     *
-     * @throws ValueFormatException if the string is not a synthactically
-     *      correct JCR reference.
-     */
-    protected ReferenceValue createReferenceValue(String value)
-            throws ValueFormatException {
-        return new ReferenceValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link LongValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link LongValue#LongValue(long)}
-     * with the long <code>value</code>.
-     *
-     * @param value The long making up the value itself.
-     */
-    protected LongValue createLongValue(long value) {
-        return new LongValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link LongValue} class or an extension
-     * thereof from the string representation of the <code>long</code> number.
-     * <p>
-     * This implementation just calls {@link LongValue#LongValue(String)} with
-     * the string <code>value</code>.
-     *
-     * @param value The string representation of the <code>long</code> number
-     *      making up the value itself.
-     *
-     * @throws ValueFormatException if the string cannot be converted to a
-     *      long number.
-     */
-    protected LongValue createLongValue(String value) throws ValueFormatException {
-        return new LongValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link DoubleValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link DoubleValue#DoubleValue(double)}
-     * with the double <code>value</code>.
-     *
-     * @param value The double making up the value itself.
-     */
-    protected DoubleValue createDoubleValue(double value) {
-        return new DoubleValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link DoubleValue} class or an extension
-     * thereof from the string representation of the <code>double</code> number.
-     * <p>
-     * This implementation just calls {@link DoubleValue#DoubleValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string representation of the <code>long</code> number
-     *      making up the value itself.
-     *
-     * @throws ValueFormatException if the string cannot be converted to a
-     *      double number.
-     */
-    protected DoubleValue createDoubleValue(String value) throws ValueFormatException {
-        return new DoubleValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link DateValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link DateValue#DateValue(Calendar)}
-     * with the <code>Calendar</code> <code>value</code>.
-     *
-     * @param value The <code>Calendar</code> making up the value itself.
-     */
-    protected DateValue createDateValue(Calendar value) {
-        return new DateValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link DateValue} class or an extension
-     * thereof from the string representation of <code>Calendar</code>
-     * instance formatted as specified in the JCR specification.
-     * <p>
-     * This implementation just calls {@link DateValue#DateValue(String)} with
-     * the string <code>value</code>.
-     *
-     * @param value The string representation of the <code>Calendar</code>
-     *      instance making up the value itself.
-     *
-     * @throws ValueFormatException if the string cannot be converted to a
-     *      <code>Calendar</code> instance.
-     */
-    protected DateValue createDateValue(String value) throws ValueFormatException {
-        return new DateValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link BooleanValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link BooleanValue#BooleanValue(boolean)}
-     * with the boolean <code>value</code>.
-     *
-     * @param value The boolean making up the value itself.
-     */
-    protected BooleanValue createBooleanValue(boolean value) {
-        return new BooleanValue(value);
+    public Binary createBinary(InputStream stream) throws RepositoryException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
-    /**
-     * Creates an instance of the {@link BooleanValue} class or an extension
-     * thereof from the string representation of the <code>boolean</code>.
-     * <p>
-     * This implementation just calls {@link BooleanValue#BooleanValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string representation of the <code>boolean</code>
-     *      making up the value itself.
-     *
-     * @throws ValueFormatException if the string cannot be converted to a
-     *      long number.
-     */
-    protected BooleanValue createBooleanValue(String value) {
-        return new BooleanValue(value);
-    }
-
-    /**
-     * Creates an instance of the {@link BinaryValue} class or an extension
-     * thereof.
-     * <p>
-     * This implementation just calls {@link BinaryValue#BinaryValue(InputStream)}
-     * with the <code>InputStream</code> <code>value</code>.
-     *
-     * @param value The <code>InputStream</code> making up the value itself.
-     */
-    protected BinaryValue createBinaryValue(InputStream value) {
-        return new BinaryValue(value);
+    public Value createValue(Binary value) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
-    /**
-     * Creates an instance of the {@link BinaryValue} class or an extension
-     * thereof from the string whose UTF-8 representation is used as the
-     * binary data.
-     * <p>
-     * This implementation just calls {@link BinaryValue#BinaryValue(String)}
-     * with the string <code>value</code>.
-     *
-     * @param value The string whose UTF-8 representation is making up the value
-     *      itself.
-     *
-     * @throws ValueFormatException if the UTF-8 representation of the string
-     *      cannot be created.
-     */
-    protected BinaryValue createBinaryValue(String value) throws ValueFormatException {
-        return new BinaryValue(value);
+    public Value createValue(Node value, boolean weak)
+            throws RepositoryException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/StringValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/StringValue.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/StringValue.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/main/java/org/apache/jackrabbit/rmi/value/StringValue.java Tue Jan  5 16:18:16 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.rmi.value;
 
-import java.io.Serializable;
 import java.util.Calendar;
 
 import javax.jcr.PropertyType;
@@ -28,13 +27,13 @@
  * package.
  *
  * @since 0.16.4.1
- * @see org.apache.jackrabbit.rmi.value.SerialValue
  */
-public class StringValue extends BaseNonStreamValue
-        implements Serializable, StatefulValue {
+public class StringValue extends BaseValue {
 
-    /** The serial version UID */
-    private static final long serialVersionUID = -6456025645604163205L;
+    /**
+     * Serial version UID.
+     */
+    private static final long serialVersionUID = 220963478492833703L;
 
     /** The string value */
     private final String value;
@@ -61,23 +60,25 @@
     }
 
     /**
-     * Returns the string value parsed to a long calling the
-     * <code>Long.valueOf(String)</code> method.
-     *
-     * @throws ValueFormatException if the string cannot be parsed to long.
+     * The string is converted using {@link Long#valueOf(String)}.
      */
     public long getLong() throws ValueFormatException {
-        return LongValue.toLong(value);
+        try {
+            return Long.valueOf(value);
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException("Not a long value: " + value, e);
+        }
     }
 
     /**
-     * Returns the string value parsed to a double calling the
-     * <code>Double.valueOf(String)</code> method.
-     *
-     * @throws ValueFormatException if the string cannot be parsed to double.
+     * The string is converted using {@link Double#valueOf(String)}.
      */
     public double getDouble() throws ValueFormatException {
-        return DoubleValue.toDouble(value);
+        try {
+            return Double.valueOf(value);
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException("Not a double value: " + value, e);
+        }
     }
 
     /**
@@ -98,10 +99,10 @@
     }
 
     /**
-     * Returns the string value parsed to a boolean calling the
-     * <code>Boolean.valueOf(String)</code> method.
+     * The string is converted using {@link Boolean#valueOf(String)}.
      */
     public boolean getBoolean() {
-        return BooleanValue.toBoolean(value);
+        return Boolean.valueOf(value);
     }
+
 }

Modified: jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/ConformanceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/ConformanceTest.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/ConformanceTest.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/ConformanceTest.java Tue Jan  5 16:18:16 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.rmi;
 
+import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.jackrabbit.test.JCRTestSuite;
@@ -23,7 +24,7 @@
 /**
  * JCR API conformance test suite.
  */
-public class ConformanceTest {
+public class ConformanceTest extends TestCase {
 
     public static TestSuite suite() {
         return new JCRTestSuite();

Modified: jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java?rev=896113&r1=896112&r2=896113&view=diff
==============================================================================
--- jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java (original)
+++ jackrabbit/commons/jcr-rmi/trunk/src/test/java/org/apache/jackrabbit/rmi/RepositoryStubImpl.java Tue Jan  5 16:18:16 2010
@@ -16,14 +16,24 @@
  */
 package org.apache.jackrabbit.rmi;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.rmi.server.RemoteObject;
 import java.util.Properties;
 
 import javax.jcr.Repository;
 
-import org.apache.jackrabbit.test.RepositoryStub;
+import org.apache.jackrabbit.core.JackrabbitRepositoryStub;
+import org.apache.jackrabbit.rmi.client.LocalAdapterFactory;
+import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory;
+import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitServerAdapterFactory;
+import org.apache.jackrabbit.rmi.remote.RemoteRepository;
+import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory;
 import org.apache.jackrabbit.test.RepositoryStubException;
 
-public class RepositoryStubImpl extends RepositoryStub {
+public class RepositoryStubImpl extends JackrabbitRepositoryStub {
 
     public RepositoryStubImpl(Properties env) {
         super(env);
@@ -31,7 +41,25 @@
 
     @Override
     public Repository getRepository() throws RepositoryStubException {
-        return RepositoryServer.getRepositoryClient();
+        try {
+            Repository repository = super.getRepository();
+
+            RemoteAdapterFactory raf = new JackrabbitServerAdapterFactory();
+            RemoteRepository remote = raf.getRemoteRepository(repository);
+
+            // Make sure that the remote reference survives serialization
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(buffer);
+            oos.writeObject(RemoteObject.toStub(remote));
+            oos.close();
+
+            ObjectInputStream ois = new ObjectInputStream(
+                    new ByteArrayInputStream(buffer.toByteArray()));
+            LocalAdapterFactory laf = new JackrabbitClientAdapterFactory();
+            return laf.getRepository((RemoteRepository) ois.readObject());
+        } catch (Exception e) {
+            throw new RepositoryStubException(e.getMessage());
+        }
     }
 
 }



Mime
View raw message