[dna-commits] DNA SVN: r808 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Mon Apr 6 11:55:23 EDT 2009


Author: rhauch
Date: 2009-04-06 11:55:23 -0400 (Mon, 06 Apr 2009)
New Revision: 808

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
DNA-344 JcrSession.getValueFactory.create(String, int) Does Not Fail Fast as per Specification

Applied patch to correct the behavior.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java	2009-04-06 14:37:57 UTC (rev 807)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java	2009-04-06 15:55:23 UTC (rev 808)
@@ -44,6 +44,7 @@
 import javax.jcr.SimpleCredentials;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
 import javax.jcr.Workspace;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
@@ -451,8 +452,10 @@
         return new ValueFactory() {
 
             public Value createValue( String value,
-                                      int propertyType ) {
-                return new JcrValue(valueFactories, sessionCache, propertyType, value);
+                                      int propertyType ) 
+                throws ValueFormatException
+            {
+                return new JcrValue(valueFactories, sessionCache, propertyType, convertValueToType(value, propertyType));
             }
 
             public Value createValue( Node value ) throws RepositoryException {
@@ -485,6 +488,79 @@
             public Value createValue( String value ) {
                 return new JcrValue(valueFactories, sessionCache, PropertyType.STRING, value);
             }
+            
+            Object convertValueToType(Object value, int toType) throws ValueFormatException { 
+                switch (toType) {
+                    case PropertyType.BOOLEAN:
+                        try {
+                            return valueFactories.getBooleanFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+
+                    case PropertyType.DATE:
+                        try {
+                            return valueFactories.getDateFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+
+                    case PropertyType.NAME:
+                        try {
+                            return valueFactories.getNameFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+
+                    case PropertyType.PATH:
+                        try {
+                            return valueFactories.getPathFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+
+                    case PropertyType.REFERENCE:
+                        try {
+                            return valueFactories.getReferenceFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+                    case PropertyType.DOUBLE:
+                        try {
+                            return valueFactories.getDoubleFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+                    case PropertyType.LONG:
+                        try {
+                            return valueFactories.getLongFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+
+                        // Anything can be converted to these types
+                    case PropertyType.BINARY:
+                        try {
+                            return valueFactories.getBinaryFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+                    case PropertyType.STRING:
+                        try {
+                            return valueFactories.getStringFactory().create(value);
+                        } catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
+                            throw new ValueFormatException(vfe);
+                        }
+                    case PropertyType.UNDEFINED:
+                        return value;
+
+                    default:
+                        assert false : "Unexpected JCR property type " + toType;
+                        // This should still throw an exception even if assertions are turned off
+                        throw new IllegalStateException("Invalid property type " + toType);
+                }
+            }
+
         };
     }
 

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-04-06 14:37:57 UTC (rev 807)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-04-06 15:55:23 UTC (rev 808)
@@ -40,11 +40,13 @@
 import org.apache.jackrabbit.test.api.NamespaceRegistryTest;
 import org.apache.jackrabbit.test.api.PropertyTest;
 import org.apache.jackrabbit.test.api.RepositoryLoginTest;
+import org.apache.jackrabbit.test.api.SessionUUIDTest;
 import org.apache.jackrabbit.test.api.SetValueBooleanTest;
 import org.apache.jackrabbit.test.api.SetValueDateTest;
 import org.apache.jackrabbit.test.api.SetValueDoubleTest;
 import org.apache.jackrabbit.test.api.SetValueLongTest;
 import org.apache.jackrabbit.test.api.SetValueReferenceTest;
+import org.apache.jackrabbit.test.api.ValueFactoryTest;
 import org.jboss.dna.graph.DnaLexicon;
 import org.jboss.dna.graph.ExecutionContext;
 import org.jboss.dna.graph.Graph;
@@ -156,7 +158,7 @@
             addTestSuite(NamespaceRegistryTest.class);
             // addTestSuite(ReferencesTest.class);
             // addTestSuite(SessionTest.class);
-            // addTestSuite(SessionUUIDTest.class);
+            addTestSuite(SessionUUIDTest.class);
             // addTestSuite(NodeTest.class);
             // addTestSuite(NodeUUIDTest.class);
             // addTestSuite(NodeOrderableChildNodesTest.class);
@@ -216,8 +218,8 @@
             //
             // addTestSuite(DocumentViewImportTest.class);
             // addTestSuite(SerializationTest.class);
-            //
-            // addTestSuite(ValueFactoryTest.class);
+
+            addTestSuite(ValueFactoryTest.class);
         }
     }
 
@@ -337,6 +339,18 @@
         /**
          * {@inheritDoc}
          * 
+         * @see org.apache.jackrabbit.test.RepositoryStub#getReadOnlyCredentials()
+         */
+        @Override
+        public Credentials getReadWriteCredentials() {
+            // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
+            // SimpleCredentials.
+            return credentials;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
          * @see org.apache.jackrabbit.test.RepositoryStub#getRepository()
          */
         @Override




More information about the dna-commits mailing list