jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r752490 - /jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java
Date Wed, 11 Mar 2009 16:10:02 GMT
Author: angela
Date: Wed Mar 11 16:10:01 2009
New Revision: 752490

URL: http://svn.apache.org/viewvc?rev=752490&view=rev
Log:
JCR-2019 spi2davex: failing value factory tests (SPI test suite)

Modified:
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java

Modified: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java?rev=752490&r1=752489&r2=752490&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java
(original)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java
Wed Mar 11 16:10:01 2009
@@ -72,7 +72,7 @@
     private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
     private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
     private static final String DEFAULT_ENCODING = "UTF-8";
-    
+
     private final NamePathResolver resolver;
     private final ValueLoader loader;
 
@@ -123,7 +123,9 @@
         try {
             switch (type) {
                 case PropertyType.BOOLEAN:
-                    return new QValueImpl(Boolean.valueOf(value));
+                    return (Boolean.valueOf(value).booleanValue()) ?
+                            QValueImpl.TRUE :
+                            QValueImpl.FALSE;
                 case PropertyType.DATE: {
                         Calendar cal = ISO8601.parse(value);
                         if (cal == null) {
@@ -144,14 +146,16 @@
                     return new QValueImpl(value, type);
                 case PropertyType.BINARY:
                     return new BinaryQValue(value.getBytes(DEFAULT_ENCODING));
-                default:
-                    throw new IllegalArgumentException("illegal type");
             }
-        } catch (NumberFormatException ex) {
+        } catch (IllegalArgumentException ex) {
+            // given String value cannot be converted to Long/Double/Path/Name
             throw new ValueFormatException(ex);
         } catch (UnsupportedEncodingException ex) {
             throw new RepositoryException(ex);
         }
+
+        // none of the legal types:
+        throw new IllegalArgumentException("illegal type");
     }
 
     /**
@@ -179,8 +183,11 @@
         return new QValueImpl(new Long(value));
     }
 
+    /**
+     * @see QValueFactory#create(boolean)
+     */
     public QValue create(boolean value) throws RepositoryException {
-        return new QValueImpl(new Boolean(value));
+        return (value) ? QValueImpl.TRUE : QValueImpl.FALSE;
     }
 
     /**
@@ -257,7 +264,10 @@
      * except for BINARY.
      * @see QValueFactoryImpl.BinaryQValue
      */
-    private class QValueImpl implements QValue, Serializable {
+    private static class QValueImpl implements QValue, Serializable {
+
+        private static final QValue TRUE = new QValueImpl(Boolean.TRUE);
+        private static final QValue FALSE = new QValueImpl(Boolean.FALSE);
 
         private final Object val;
         private final int type;
@@ -424,11 +434,7 @@
             if (val instanceof Boolean) {
                 return ((Boolean) val).booleanValue();
             } else {
-                try {
-                    return new Boolean(getString()).booleanValue();
-                } catch (NumberFormatException ex) {
-                    throw new ValueFormatException("not a long: " + getString(), ex);
-                }
+                return new Boolean(getString()).booleanValue();
             }
         }
 
@@ -439,7 +445,11 @@
             if (val instanceof Name) {
                 return (Name) val;
             } else {
-                return NAME_FACTORY.create(getString());
+                try {
+                    return NAME_FACTORY.create(getString());
+                } catch (IllegalArgumentException e) {
+                    throw new ValueFormatException("not a valid Name value: " + getString(),
e);
+                }
             }
         }
 
@@ -450,7 +460,11 @@
             if (val instanceof Path) {
                 return (Path) val;
             } else {
-                return PATH_FACTORY.create(getString());
+                try {
+                    return PATH_FACTORY.create(getString());
+                } catch (IllegalArgumentException e) {
+                    throw new ValueFormatException("not a valid Path value: " + getString(),
e);
+                }
             }
         }
 



Mime
View raw message