jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r537659 - /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java
Date Sun, 13 May 2007 21:08:24 GMT
Author: clombart
Date: Sun May 13 14:08:23 2007
New Revision: 537659

URL: http://svn.apache.org/viewvc?view=rev&rev=537659
Log:
Patch apply for JCR-866

Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java?view=diff&rev=537659&r1=537658&r2=537659
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/persistence/collectionconverter/impl/ResidualPropertiesCollectionConverterImpl.java
Sun May 13 14:08:23 2007
@@ -99,9 +99,7 @@
             }
 
             ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
-            String elementClassName = collectionDescriptor.getElementClassName();
-            Class elementClass = ReflectionUtils.forName(elementClassName);
-            AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(elementClass);
+            AtomicTypeConverter atomicTypeConverter = getAtomicTypeConverter(collectionDescriptor);
 
             while (pi.hasNext()) {
                 Property prop = pi.nextProperty();
@@ -172,6 +170,8 @@
             }
         }
 
+        AtomicTypeConverter atomicTypeConverter = getAtomicTypeConverter(collectionDescriptor);
+
         try {
             Map map = (Map) collection;
             ValueFactory valueFactory = session.getValueFactory();
@@ -193,14 +193,12 @@
                     int i = 0;
                     for (Iterator vi = valueList.iterator(); vi.hasNext();) {
                         value = vi.next();
-                        AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
                         jcrValues[i++] = atomicTypeConverter.getValue(
                             valueFactory, value);
                     }
                     parentNode.setProperty(name, jcrValues);
                 } else {
                     // single value
-                    AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
                     Value jcrValue = atomicTypeConverter.getValue(valueFactory,
                         value);
                     parentNode.setProperty(name, jcrValue);
@@ -211,5 +209,31 @@
                 + collectionDescriptor.getFieldName() + " of class "
                 + collectionDescriptor.getClassDescriptor().getClassName(), vfe);
         }
+    }
+    
+    /**
+     * Returns the AtomicTypeConverter for the element class of the described
+     * collection. If no such converter can be found a PersistenceException
+     * is thrown.
+     * 
+     * @param collectionDescriptor The descriptor of the collection for whose
+     *      elements an AtomicTypeConverter is requested.
+     *      
+     * @return The AtomicTypeConverter for the elements of the collection
+     * 
+     * @throws PersistenceException if no such type converter is registered
+     */
+    private AtomicTypeConverter getAtomicTypeConverter(CollectionDescriptor collectionDescriptor)
{
+        String elementClassName = collectionDescriptor.getElementClassName();
+        Class elementClass = ReflectionUtils.forName(elementClassName);
+        AtomicTypeConverter atc = (AtomicTypeConverter) atomicTypeConverters.get(elementClass);
+        if (atc != null) {
+            return atc;
+        }
+        
+        throw new PersistenceException(
+            "Cannot get AtomicTypeConverter for element class "
+                + elementClassName + " of class "
+                + collectionDescriptor.getClassDescriptor().getClassName());
     }
 }



Mime
View raw message