You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/04/30 14:20:42 UTC

svn commit: r770193 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java

Author: jukka
Date: Thu Apr 30 12:20:42 2009
New Revision: 770193

URL: http://svn.apache.org/viewvc?rev=770193&view=rev
Log:
JCR-1609: JSR 283: new Property Types

Initial support for Value.getDecimal()

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java?rev=770193&r1=770192&r2=770193&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java Thu Apr 30 12:20:42 2009
@@ -16,16 +16,18 @@
  */
 package org.apache.jackrabbit.value;
 
-import org.apache.jackrabbit.util.ISO8601;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
 import java.util.Calendar;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.jackrabbit.util.ISO8601;
+
 /**
  * This class is the superclass of the type-specific
  * classes implementing the <code>Value</code> interfaces.
@@ -178,6 +180,22 @@
     /**
      * {@inheritDoc}
      */
+    public BigDecimal getDecimal()
+            throws ValueFormatException, IllegalStateException,
+            RepositoryException {
+        setValueConsumed();
+
+        try {
+            // TODO: Is this the correct way to handle BigDecimal conversion
+            return new BigDecimal(getInternalString());
+        } catch (NumberFormatException e) {
+            throw new ValueFormatException("conversion to double failed", e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public InputStream getStream()
             throws IllegalStateException, RepositoryException {
         setStreamConsumed();