incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r448311 [17/25] - in /incubator/graffito/trunk: ./ api/ api/src/java/org/apache/portals/graffito/context/ api/src/java/org/apache/portals/graffito/exception/ api/src/java/org/apache/portals/graffito/services/core/ api/src/java/org/apache/po...
Date Wed, 20 Sep 2006 19:37:21 GMT
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java Wed Sep 20 12:37:05 2006
@@ -1,155 +1,155 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- *                     as applicable.
- *
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableArrayList;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableSet;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableVector;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/**
- * Utility class used to instantiate {@link ManageableCollection}
- *
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- *
- */
-public class ManageableCollectionUtil {
-
-    /**
-     * Instantiate a new {@link ManageableCollection}
-     * @param manageableCollectionClassName The manageable collection class name
-     * @return an emtpy created {@link ManageableCollection}
-     */
-    public static ManageableCollection getManageableCollection(String manageableCollectionClassName) {
-        try {
-            return (ManageableCollection) ReflectionUtils.newInstance(manageableCollectionClassName);
-        }
-        catch (Exception e) {
-            throw new JcrMappingException("Cannot create manageable collection : "
-                                           + manageableCollectionClassName,
-                                           e);
-        }
-    }
-
-    /**
-     * Instantiate a new {@link ManageableCollection}
-     * @param collectionClass the collection class name
-     * @return an emtpy created {@link ManageableCollection}
-     */
-
-    public static ManageableCollection getManageableCollection(Class collectionClass) {
-        try {
-
-            if (collectionClass.equals(ArrayList.class)) {
-                return new ManageableArrayList();
-            }
-
-            if (collectionClass.equals(Vector.class)) {
-                return new ManageableVector();
-            }
-
-            if (collectionClass.equals(HashSet.class)) {
-                return new ManageableSet();
-            }
-            
-            if (collectionClass.equals(Collection.class) || collectionClass.equals(List.class)) {
-                return new ManageableArrayList();
-            }
-
-            if (collectionClass.equals(Set.class)) {
-                return new ManageableSet();
-            }
-            
-            Object collection = collectionClass.newInstance();
-            if (!(collection instanceof ManageableCollection)) {
-                throw new JcrMappingException("Unsupported collection type :"
-                                               + collectionClass.getName());
-            }
-            else {
-                return (ManageableCollection) collection;
-            }
-        }
-        catch (Exception e) {
-            throw new JcrMappingException("Cannot create manageable collection", e);
-        }
-    }
-
-    /**
-     * Convert a java Collection object into a {@link ManageableCollection}.
-     * Until now, only the following class are supported :
-     * Collection, List, ArrayList, Vector
-     *
-     * If you need a Map, you have to write your own {@link ManageableCollection}.
-     * @param object the java collection or Map
-     * @return The converted {@link ManageableCollection}
-     *
-     */
-    public static ManageableCollection getManageableCollection(Object object) {
-        try {
-            if (object == null) {
-                return null;
-            }
-
-            if (object instanceof ManageableCollection) {
-                return (ManageableCollection) object;
-
-            }
-            if (object.getClass().equals(ArrayList.class)) {
-                ManageableArrayList manageableArrayList = new ManageableArrayList();
-                manageableArrayList.addAll((Collection) object);
-
-                return manageableArrayList;
-            }
-
-            if (object.getClass().equals(Vector.class)) {
-                ManageableVector manageableVector = new ManageableVector();
-                manageableVector.addAll((Collection) object);
-
-                return manageableVector;
-            }
-
-            if (object.getClass().equals(HashSet.class)) {
-                return new ManageableSet((Set) object);
-            }
-            
-            if (object.getClass().equals(Collection.class)
-                || object.getClass().equals(List.class)) {
-                ManageableArrayList manageableArrayList = new ManageableArrayList();
-                manageableArrayList.addAll((Collection) object);
-
-                return manageableArrayList;
-            }
-            if (object.getClass().equals(Set.class)) {
-                return new ManageableSet((Set) object);
-            }
-        }
-        catch (Exception e) {
-            throw new JcrMappingException("Impossible to create the manageable collection", e);
-        }
-        
-        throw new JcrMappingException("Unsupported collection type :" + object.getClass().getName());
-    }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableArrayList;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableSet;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.ManageableVector;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ * Utility class used to instantiate {@link ManageableCollection}
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ *
+ */
+public class ManageableCollectionUtil {
+
+    /**
+     * Instantiate a new {@link ManageableCollection}
+     * @param manageableCollectionClassName The manageable collection class name
+     * @return an emtpy created {@link ManageableCollection}
+     */
+    public static ManageableCollection getManageableCollection(String manageableCollectionClassName) {
+        try {
+            return (ManageableCollection) ReflectionUtils.newInstance(manageableCollectionClassName);
+        }
+        catch (Exception e) {
+            throw new JcrMappingException("Cannot create manageable collection : "
+                                           + manageableCollectionClassName,
+                                           e);
+        }
+    }
+
+    /**
+     * Instantiate a new {@link ManageableCollection}
+     * @param collectionClass the collection class name
+     * @return an emtpy created {@link ManageableCollection}
+     */
+
+    public static ManageableCollection getManageableCollection(Class collectionClass) {
+        try {
+
+            if (collectionClass.equals(ArrayList.class)) {
+                return new ManageableArrayList();
+            }
+
+            if (collectionClass.equals(Vector.class)) {
+                return new ManageableVector();
+            }
+
+            if (collectionClass.equals(HashSet.class)) {
+                return new ManageableSet();
+            }
+            
+            if (collectionClass.equals(Collection.class) || collectionClass.equals(List.class)) {
+                return new ManageableArrayList();
+            }
+
+            if (collectionClass.equals(Set.class)) {
+                return new ManageableSet();
+            }
+            
+            Object collection = collectionClass.newInstance();
+            if (!(collection instanceof ManageableCollection)) {
+                throw new JcrMappingException("Unsupported collection type :"
+                                               + collectionClass.getName());
+            }
+            else {
+                return (ManageableCollection) collection;
+            }
+        }
+        catch (Exception e) {
+            throw new JcrMappingException("Cannot create manageable collection", e);
+        }
+    }
+
+    /**
+     * Convert a java Collection object into a {@link ManageableCollection}.
+     * Until now, only the following class are supported :
+     * Collection, List, ArrayList, Vector
+     *
+     * If you need a Map, you have to write your own {@link ManageableCollection}.
+     * @param object the java collection or Map
+     * @return The converted {@link ManageableCollection}
+     *
+     */
+    public static ManageableCollection getManageableCollection(Object object) {
+        try {
+            if (object == null) {
+                return null;
+            }
+
+            if (object instanceof ManageableCollection) {
+                return (ManageableCollection) object;
+
+            }
+            if (object.getClass().equals(ArrayList.class)) {
+                ManageableArrayList manageableArrayList = new ManageableArrayList();
+                manageableArrayList.addAll((Collection) object);
+
+                return manageableArrayList;
+            }
+
+            if (object.getClass().equals(Vector.class)) {
+                ManageableVector manageableVector = new ManageableVector();
+                manageableVector.addAll((Collection) object);
+
+                return manageableVector;
+            }
+
+            if (object.getClass().equals(HashSet.class)) {
+                return new ManageableSet((Set) object);
+            }
+            
+            if (object.getClass().equals(Collection.class)
+                || object.getClass().equals(List.class)) {
+                ManageableArrayList manageableArrayList = new ManageableArrayList();
+                manageableArrayList.addAll((Collection) object);
+
+                return manageableArrayList;
+            }
+            if (object.getClass().equals(Set.class)) {
+                return new ManageableSet((Set) object);
+            }
+        }
+        catch (Exception e) {
+            throw new JcrMappingException("Impossible to create the manageable collection", e);
+        }
+        
+        throw new JcrMappingException("Unsupported collection type :" + object.getClass().getName());
+    }
+}

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ManageableCollectionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java Wed Sep 20 12:37:05 2006
@@ -1,165 +1,165 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- * 
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-import java.util.Map;
-
-import javax.jcr.ItemExistsException;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
-
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.exception.PersistenceException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/** 
- * Abstract class used for all CollectionConverter
- * 
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public abstract class AbstractCollectionConverterImpl implements CollectionConverter {
-	protected Map atomicTypeConverters;
-	protected ObjectConverter objectConverter;
-	// NOT USED
-	protected Mapper mapper;
-
-	/**
-	 * Constructor
-	 * 
-	 * @param atomicTypeConverters The atomic type converter to used
-	 * @param objectConverter The object converter to used
-	 * @param mapper The mapper to used
-	 */
-	public AbstractCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper) {
-		this.atomicTypeConverters = atomicTypeConverters;
-		this.objectConverter = objectConverter;
-		this.mapper = mapper;
-	}
-
-	protected abstract void doInsertCollection(Session session, Node parentNode, CollectionDescriptor descriptor,
-			ManageableCollection collection) throws RepositoryException;
-
-	protected abstract void doUpdateCollection(Session session, Node parentNode, CollectionDescriptor descriptor,
-			ManageableCollection collection) throws RepositoryException;
-
-	protected abstract ManageableCollection doGetCollection(Session session, Node parentNode,
-			CollectionDescriptor collectionDescriptor, Class collectionFieldClass) throws RepositoryException;
-
-	protected abstract boolean doIsNull(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
-			Class collectionFieldClass) throws RepositoryException;
-
-	/**
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#insertCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
-	 */
-	public void insertCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
-			ManageableCollection collection) {
-		try {
-			doInsertCollection(session, parentNode, collectionDescriptor, collection);
-		} catch (ItemExistsException iee) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". An item already exists.", iee);
-		} catch (PathNotFoundException pnfe) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), pnfe);
-		} catch (VersionException ve) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
-		} catch (ConstraintViolationException cve) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". Constraint violation.", cve);
-		} catch (LockException le) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked parent.", le);
-		} catch (RepositoryException re) {
-			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert collection field : "
-					+ collectionDescriptor.getFieldName() + " of class "
-					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
-		}
-	}
-
-	/**
-	 *
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#updateCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
-	 */
-	public void updateCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
-			ManageableCollection collection) {
-		try {
-
-				doUpdateCollection(session, parentNode, collectionDescriptor, collection);
-		} catch (VersionException ve) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
-		} catch (LockException le) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked node", le);
-		} catch (ConstraintViolationException cve) {
-			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
-					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " Constraint violation.", cve);
-		} catch (RepositoryException re) {
-			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert collection field : "
-					+ collectionDescriptor.getFieldName() + " of class "
-					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
-		}
-	}
-
-	/**
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#getCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, java.lang.Class)
-	 */
-	public ManageableCollection getCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
-			Class collectionFieldClass) {
-		try {
-			return doGetCollection(session, parentNode, collectionDescriptor, collectionFieldClass);
-		} catch (RepositoryException re) {
-			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot get collection field : "
-					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(), re);
-		}
-	}
-
-	/**
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#isNull(Session, Node, CollectionDescriptor, Class)
-	 */
-	public boolean isNull(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
-			Class collectionFieldClass) {
-		try {
-			return doIsNull(session, parentNode, collectionDescriptor, collectionFieldClass);
-		} catch (RepositoryException re) {
-			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot  check if the collections has elements : "
-					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(), re);
-		}
-	}
-	protected String getCollectionJcrName(CollectionDescriptor descriptor) {
-		String jcrName = descriptor.getJcrName();
-
-		if (null == jcrName) {
-			throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor : "
-					+ descriptor.getFieldName());
-		}
-
-		return jcrName;
-	}
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.Map;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/** 
+ * Abstract class used for all CollectionConverter
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public abstract class AbstractCollectionConverterImpl implements CollectionConverter {
+	protected Map atomicTypeConverters;
+	protected ObjectConverter objectConverter;
+	// NOT USED
+	protected Mapper mapper;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param atomicTypeConverters The atomic type converter to used
+	 * @param objectConverter The object converter to used
+	 * @param mapper The mapper to used
+	 */
+	public AbstractCollectionConverterImpl(Map atomicTypeConverters, ObjectConverter objectConverter, Mapper mapper) {
+		this.atomicTypeConverters = atomicTypeConverters;
+		this.objectConverter = objectConverter;
+		this.mapper = mapper;
+	}
+
+	protected abstract void doInsertCollection(Session session, Node parentNode, CollectionDescriptor descriptor,
+			ManageableCollection collection) throws RepositoryException;
+
+	protected abstract void doUpdateCollection(Session session, Node parentNode, CollectionDescriptor descriptor,
+			ManageableCollection collection) throws RepositoryException;
+
+	protected abstract ManageableCollection doGetCollection(Session session, Node parentNode,
+			CollectionDescriptor collectionDescriptor, Class collectionFieldClass) throws RepositoryException;
+
+	protected abstract boolean doIsNull(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			Class collectionFieldClass) throws RepositoryException;
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#insertCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+	 */
+	public void insertCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			ManageableCollection collection) {
+		try {
+			doInsertCollection(session, parentNode, collectionDescriptor, collection);
+		} catch (ItemExistsException iee) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". An item already exists.", iee);
+		} catch (PathNotFoundException pnfe) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), pnfe);
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + ". Constraint violation.", cve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked parent.", le);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert collection field : "
+					+ collectionDescriptor.getFieldName() + " of class "
+					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+
+	/**
+	 *
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#updateCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection)
+	 */
+	public void updateCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			ManageableCollection collection) {
+		try {
+
+				doUpdateCollection(session, parentNode, collectionDescriptor, collection);
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName(), ve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " on locked node", le);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot insert collection field : " + collectionDescriptor.getFieldName()
+					+ " of class " + collectionDescriptor.getClassDescriptor().getClassName() + " Constraint violation.", cve);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot insert collection field : "
+					+ collectionDescriptor.getFieldName() + " of class "
+					+ collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#getCollection(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor, java.lang.Class)
+	 */
+	public ManageableCollection getCollection(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			Class collectionFieldClass) {
+		try {
+			return doGetCollection(session, parentNode, collectionDescriptor, collectionFieldClass);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot get collection field : "
+					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter#isNull(Session, Node, CollectionDescriptor, Class)
+	 */
+	public boolean isNull(Session session, Node parentNode, CollectionDescriptor collectionDescriptor,
+			Class collectionFieldClass) {
+		try {
+			return doIsNull(session, parentNode, collectionDescriptor, collectionFieldClass);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot  check if the collections has elements : "
+					+ collectionDescriptor.getFieldName() + "for " + collectionDescriptor.getClassDescriptor().getClassName(), re);
+		}
+	}
+	protected String getCollectionJcrName(CollectionDescriptor descriptor) {
+		String jcrName = descriptor.getJcrName();
+
+		if (null == jcrName) {
+			throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor : "
+					+ descriptor.getFieldName());
+		}
+
+		return jcrName;
+	}
+}

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/AbstractCollectionConverterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java Wed Sep 20 12:37:05 2006
@@ -1,244 +1,244 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- *
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
-import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/**
- * Default Collection Mapping/convertion implementation.
- *
- * This collection mapping strategy maps a collection under an extra JCR node (specify by the jcrName in the CollectionDescriptor).
- * It is usefull when the node type "nt:unstructured" is applied to the collection elements. By this way, it is possible
- * to distinguish the collection elements from the other main object fields.
- *
- * If the collection element class contains an id (see the FieldDescriptor definition), this id value is used to build the collection element node.
- * Otherwise, the element node name is a simple indexed constant.
- *
- * Example - without an id attribute:
- *   /test (Main object containing the collection field )
- *     /mycollection (extra node used to store the entire collection)
- *          /collection-element (node used to store the first collection element)
- *                /item-prop
- *                ....
- *          /collection-element (node used to store the second collection element)
- *          ...
- *
- * Example - with an id attribute:
- *   /test (Main object containing the collection field )
- *     /mycollection (extra node used to store the entire collection)
- *          /aValue (id value assigned to the first element)
- *                /item-prop
- *                ....
- *          /anotherValue (id value assigned to the first element)
- *          ...
-
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class DefaultCollectionConverterImpl extends AbstractCollectionConverterImpl {
-
-    private static final String COLLECTION_ELEMENT_NAME = "collection-element";
-
-    /**
-     * Constructor
-     * @param atomicTypeConverters
-     * @param objectConverter
-     * @param mapper
-     */
-    public DefaultCollectionConverterImpl(Map atomicTypeConverters,
-                                          ObjectConverter objectConverter,
-                                          Mapper mapper) {
-        super(atomicTypeConverters, objectConverter, mapper);
-    }
-
-    /**
-     * @see AbstractCollectionConverterImpl#doInsertCollection(Session, Node, CollectionDescriptor, ManageableCollection)
-     */
-    protected void doInsertCollection(Session session,
-                                      Node parentNode,
-                                      CollectionDescriptor collectionDescriptor,
-                                      ManageableCollection collection) throws RepositoryException {
-        if (collection == null) {
-            return;
-        }
-
-        String jcrName = collectionDescriptor.getJcrName();
-
-        if (jcrName == null) {
-            throw new JcrMappingException(
-                    "The JcrName attribute is not defined for the CollectionDescriptor : "
-                    + collectionDescriptor.getFieldName() + " for the classdescriptor : " + collectionDescriptor.getClassDescriptor().getClassName());
-        }
-
-        Node collectionNode = parentNode.addNode(jcrName);
-        
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName())); 
-
-        Iterator collectionIterator = collection.getIterator();        
-        while (collectionIterator.hasNext()) {
-            Object item = collectionIterator.next();
-            String elementJcrName = null;
-
-            // If the element object has a unique id => the element jcr node name = the id value
-            if (elementClassDescriptor.hasIdField()) {
-                String idFieldName = elementClassDescriptor.getIdFieldDescriptor()
-                                                           .getFieldName();
-                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
-            }
-            else {                
-                elementJcrName = COLLECTION_ELEMENT_NAME;
-            }
-
-            objectConverter.insert(session, collectionNode, elementJcrName, item);
-        }
-    }
-
-    /**
-     *
-     * @see AbstractCollectionConverterImpl#doUpdateCollection(Session, Node, CollectionDescriptor, ManageableCollection)
-     */
-    protected void doUpdateCollection(Session session,
-                                 Node parentNode,
-                                 CollectionDescriptor collectionDescriptor,
-                                 ManageableCollection collection) throws RepositoryException {
-        
-    	    String jcrName = getCollectionJcrName(collectionDescriptor);
-        if (collection == null)
-        {
-            if (parentNode.hasNode(jcrName)) 
-            {
-                parentNode.getNode(jcrName).remove();
-            }
-            return;
-        }
-
-        
-        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));         
-        Node collectionNode = parentNode.getNode(jcrName);
-        //  If the collection elements have not an id, it is not possible to find the matching JCR nodes => delete the complete collection
-        if (!elementClassDescriptor.hasIdField()) {
-            collectionNode.remove();
-            collectionNode = parentNode.addNode(jcrName);
-        }
-
-        Iterator collectionIterator = collection.getIterator();
-
-        Map updatedItems = new HashMap();
-        while (collectionIterator.hasNext()) {
-            Object item = collectionIterator.next();
-
-            String elementJcrName = null;
-
-            if (elementClassDescriptor.hasIdField()) {
-
-                String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
-                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
-
-                // Update existing JCR Nodes
-                if (collectionNode.hasNode(elementJcrName)) {
-                    objectConverter.update(session, collectionNode, elementJcrName, item);
-                }
-                else {
-                    // Add new collection elements
-                    objectConverter.insert(session, collectionNode, elementJcrName, item);
-                }
-
-                updatedItems.put(elementJcrName, item);
-            }
-            else {
-                elementJcrName = COLLECTION_ELEMENT_NAME ;
-                objectConverter.insert(session, collectionNode, elementJcrName, item);
-            }
-        }
-
-        // Delete JCR nodes that are not present in the collection
-        if (elementClassDescriptor.hasIdField()) {
-            NodeIterator nodeIterator = collectionNode.getNodes();
-            List removeNodes = new ArrayList();
-            while (nodeIterator.hasNext()) {
-                Node child = nodeIterator.nextNode();
-                if (!updatedItems.containsKey(child.getName())) {
-                    removeNodes.add(child);
-                }
-            }
-            for(int i = 0; i < removeNodes.size(); i++) {
-                ((Node) removeNodes.get(i)).remove();
-            }
-        }
-    }
-
-    /**
-     * @see AbstractCollectionConverterImpl#doGetCollection(Session, Node, CollectionDescriptor, Class)
-     */
-    protected ManageableCollection doGetCollection(Session session,
-                                              Node parentNode,
-                                              CollectionDescriptor collectionDescriptor,
-                                              Class collectionFieldClass) throws RepositoryException {
-        String jcrName = getCollectionJcrName(collectionDescriptor);
-
-        if (parentNode == null || !parentNode.hasNode(jcrName)) {
-            return null;
-        }
-
-        ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
-        Node collectionNode = parentNode.getNode(jcrName);
-        NodeIterator children = collectionNode.getNodes();
-        Class elementClass = ReflectionUtils.forName(collectionDescriptor.getElementClassName());
-        
-        while (children.hasNext()) {
-            Node itemNode = children.nextNode();
-            Object item = objectConverter.getObject(session, itemNode.getPath());
-            collection.addObject(item);
-        }
-
-        return collection;
-    }
-    
-    /**
-     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor, Class)
-     */
-    protected boolean doIsNull(Session session,
-                                              Node parentNode,
-                                              CollectionDescriptor collectionDescriptor,
-                                              Class collectionFieldClass) throws RepositoryException {
-        String jcrName = getCollectionJcrName(collectionDescriptor);
-
-        if (parentNode == null || !parentNode.hasNode(jcrName)) {
-            return true;
-        }
-        return false;
-    }    
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ * Default Collection Mapping/convertion implementation.
+ *
+ * This collection mapping strategy maps a collection under an extra JCR node (specify by the jcrName in the CollectionDescriptor).
+ * It is usefull when the node type "nt:unstructured" is applied to the collection elements. By this way, it is possible
+ * to distinguish the collection elements from the other main object fields.
+ *
+ * If the collection element class contains an id (see the FieldDescriptor definition), this id value is used to build the collection element node.
+ * Otherwise, the element node name is a simple indexed constant.
+ *
+ * Example - without an id attribute:
+ *   /test (Main object containing the collection field )
+ *     /mycollection (extra node used to store the entire collection)
+ *          /collection-element (node used to store the first collection element)
+ *                /item-prop
+ *                ....
+ *          /collection-element (node used to store the second collection element)
+ *          ...
+ *
+ * Example - with an id attribute:
+ *   /test (Main object containing the collection field )
+ *     /mycollection (extra node used to store the entire collection)
+ *          /aValue (id value assigned to the first element)
+ *                /item-prop
+ *                ....
+ *          /anotherValue (id value assigned to the first element)
+ *          ...
+
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class DefaultCollectionConverterImpl extends AbstractCollectionConverterImpl {
+
+    private static final String COLLECTION_ELEMENT_NAME = "collection-element";
+
+    /**
+     * Constructor
+     * @param atomicTypeConverters
+     * @param objectConverter
+     * @param mapper
+     */
+    public DefaultCollectionConverterImpl(Map atomicTypeConverters,
+                                          ObjectConverter objectConverter,
+                                          Mapper mapper) {
+        super(atomicTypeConverters, objectConverter, mapper);
+    }
+
+    /**
+     * @see AbstractCollectionConverterImpl#doInsertCollection(Session, Node, CollectionDescriptor, ManageableCollection)
+     */
+    protected void doInsertCollection(Session session,
+                                      Node parentNode,
+                                      CollectionDescriptor collectionDescriptor,
+                                      ManageableCollection collection) throws RepositoryException {
+        if (collection == null) {
+            return;
+        }
+
+        String jcrName = collectionDescriptor.getJcrName();
+
+        if (jcrName == null) {
+            throw new JcrMappingException(
+                    "The JcrName attribute is not defined for the CollectionDescriptor : "
+                    + collectionDescriptor.getFieldName() + " for the classdescriptor : " + collectionDescriptor.getClassDescriptor().getClassName());
+        }
+
+        Node collectionNode = parentNode.addNode(jcrName);
+        
+        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName())); 
+
+        Iterator collectionIterator = collection.getIterator();        
+        while (collectionIterator.hasNext()) {
+            Object item = collectionIterator.next();
+            String elementJcrName = null;
+
+            // If the element object has a unique id => the element jcr node name = the id value
+            if (elementClassDescriptor.hasIdField()) {
+                String idFieldName = elementClassDescriptor.getIdFieldDescriptor()
+                                                           .getFieldName();
+                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
+            }
+            else {                
+                elementJcrName = COLLECTION_ELEMENT_NAME;
+            }
+
+            objectConverter.insert(session, collectionNode, elementJcrName, item);
+        }
+    }
+
+    /**
+     *
+     * @see AbstractCollectionConverterImpl#doUpdateCollection(Session, Node, CollectionDescriptor, ManageableCollection)
+     */
+    protected void doUpdateCollection(Session session,
+                                 Node parentNode,
+                                 CollectionDescriptor collectionDescriptor,
+                                 ManageableCollection collection) throws RepositoryException {
+        
+    	    String jcrName = getCollectionJcrName(collectionDescriptor);
+        if (collection == null)
+        {
+            if (parentNode.hasNode(jcrName)) 
+            {
+                parentNode.getNode(jcrName).remove();
+            }
+            return;
+        }
+
+        
+        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));         
+        Node collectionNode = parentNode.getNode(jcrName);
+        //  If the collection elements have not an id, it is not possible to find the matching JCR nodes => delete the complete collection
+        if (!elementClassDescriptor.hasIdField()) {
+            collectionNode.remove();
+            collectionNode = parentNode.addNode(jcrName);
+        }
+
+        Iterator collectionIterator = collection.getIterator();
+
+        Map updatedItems = new HashMap();
+        while (collectionIterator.hasNext()) {
+            Object item = collectionIterator.next();
+
+            String elementJcrName = null;
+
+            if (elementClassDescriptor.hasIdField()) {
+
+                String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
+                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
+
+                // Update existing JCR Nodes
+                if (collectionNode.hasNode(elementJcrName)) {
+                    objectConverter.update(session, collectionNode, elementJcrName, item);
+                }
+                else {
+                    // Add new collection elements
+                    objectConverter.insert(session, collectionNode, elementJcrName, item);
+                }
+
+                updatedItems.put(elementJcrName, item);
+            }
+            else {
+                elementJcrName = COLLECTION_ELEMENT_NAME ;
+                objectConverter.insert(session, collectionNode, elementJcrName, item);
+            }
+        }
+
+        // Delete JCR nodes that are not present in the collection
+        if (elementClassDescriptor.hasIdField()) {
+            NodeIterator nodeIterator = collectionNode.getNodes();
+            List removeNodes = new ArrayList();
+            while (nodeIterator.hasNext()) {
+                Node child = nodeIterator.nextNode();
+                if (!updatedItems.containsKey(child.getName())) {
+                    removeNodes.add(child);
+                }
+            }
+            for(int i = 0; i < removeNodes.size(); i++) {
+                ((Node) removeNodes.get(i)).remove();
+            }
+        }
+    }
+
+    /**
+     * @see AbstractCollectionConverterImpl#doGetCollection(Session, Node, CollectionDescriptor, Class)
+     */
+    protected ManageableCollection doGetCollection(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException {
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+        if (parentNode == null || !parentNode.hasNode(jcrName)) {
+            return null;
+        }
+
+        ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
+        Node collectionNode = parentNode.getNode(jcrName);
+        NodeIterator children = collectionNode.getNodes();
+        Class elementClass = ReflectionUtils.forName(collectionDescriptor.getElementClassName());
+        
+        while (children.hasNext()) {
+            Node itemNode = children.nextNode();
+            Object item = objectConverter.getObject(session, itemNode.getPath());
+            collection.addObject(item);
+        }
+
+        return collection;
+    }
+    
+    /**
+     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor, Class)
+     */
+    protected boolean doIsNull(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException {
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+        if (parentNode == null || !parentNode.hasNode(jcrName)) {
+            return true;
+        }
+        return false;
+    }    
 }

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java Wed Sep 20 12:37:05 2006
@@ -1,65 +1,65 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- * 
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-
-/** 
- *
- * {@link ManageableCollection} ArrayList implementation
- * 
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- * 
- */
-public class ManageableArrayList extends ArrayList implements ManageableCollection
-{
-
-	/**
-	 * 
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
-	 */
-    public void addObject(Object object)
-    {
-        this.add(object);
-     
-    }
-
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
-     */
-    public Iterator getIterator()
-    {
-        return this.iterator();
-    }
-
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
-     */
-	public int getSize()
-	{
-		
-		return this.size();
-	}
-    
-    
-
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+
+/** 
+ *
+ * {@link ManageableCollection} ArrayList implementation
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public class ManageableArrayList extends ArrayList implements ManageableCollection
+{
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
+	 */
+    public void addObject(Object object)
+    {
+        this.add(object);
+     
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
+     */
+    public Iterator getIterator()
+    {
+        return this.iterator();
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
+     */
+	public int getSize()
+	{
+		
+		return this.size();
+	}
+    
+    
+
+}

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableArrayList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableSet.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableSet.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableSet.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableSet.java Wed Sep 20 12:37:05 2006
@@ -1,42 +1,42 @@
-package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-
-
-/**
- * This class/interface 
- */
-public class ManageableSet extends HashSet implements ManageableCollection {
-    public ManageableSet() {
-    }
-    
-    public ManageableSet(Collection collection) {
-        super(collection);
-    }
-    
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
-     */
-    public void addObject(Object object) {
-        add(object);
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
-     */
-    public Iterator getIterator() {
-        return iterator();
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
-     */
-    public int getSize() {
-        return size();
-    }
-
-}
+package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+
+
+/**
+ * This class/interface 
+ */
+public class ManageableSet extends HashSet implements ManageableCollection {
+    public ManageableSet() {
+    }
+    
+    public ManageableSet(Collection collection) {
+        super(collection);
+    }
+    
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
+     */
+    public void addObject(Object object) {
+        add(object);
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
+     */
+    public Iterator getIterator() {
+        return iterator();
+    }
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
+     */
+    public int getSize() {
+        return size();
+    }
+
+}

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java Wed Sep 20 12:37:05 2006
@@ -1,62 +1,62 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- * 
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-
-/** 
- *
- * {@link ManageableCollection} Vector implementation 
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- * 
- */
-public class ManageableVector extends Vector implements ManageableCollection
-{
-
-	/**
-	 * 
-	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
-	 */
-    public void addObject(Object object)
-    {
-        this.add(object);
-    }
-
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
-     */
-    public Iterator getIterator()
-    {
-        return this.iterator();
-    }
-    
-    /**
-     * 
-     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
-     */
-	public int getSize()
-	{
-		
-		return this.size();
-	}
-    
-
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+
+/** 
+ *
+ * {@link ManageableCollection} Vector implementation 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * 
+ */
+public class ManageableVector extends Vector implements ManageableCollection
+{
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#addObject(java.lang.Object)
+	 */
+    public void addObject(Object object)
+    {
+        this.add(object);
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getIterator()
+     */
+    public Iterator getIterator()
+    {
+        return this.iterator();
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection#getSize()
+     */
+	public int getSize()
+	{
+		
+		return this.size();
+	}
+    
+
+}

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/ManageableVector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java?view=diff&rev=448311&r1=448310&r2=448311
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java Wed Sep 20 12:37:05 2006
@@ -1,179 +1,179 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- *
- * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
-
-
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.ValueFormatException;
-
-import org.apache.portals.graffito.jcr.exception.PersistenceException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
-import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
-import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
-import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
-import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
-
-/**
- * Collection Mapping/convertion implementation used for multi values properties
- *
- * This collection mapping strategy maps a collection into a JCR multi value property
- *
- * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class MultiValueCollectionConverterImpl extends AbstractCollectionConverterImpl {
-
-    /**
-     * Constructor
-     *
-     * @param atomicTypeConverters
-     * @param objectConverter
-     * @param mapper
-     */
-    public MultiValueCollectionConverterImpl(Map atomicTypeConverters,
-                                             ObjectConverter objectConverter,
-                                             Mapper mapper) {
-        super(atomicTypeConverters, objectConverter, mapper);
-    }
-
-    /**
-     *
-     * @see AbstractCollectionConverterImpl#doInsertCollection(Session, Node, CollectionDescriptor, ManageableCollection)
-     */
-    protected void doInsertCollection(Session session,
-                                      Node parentNode,
-                                      CollectionDescriptor collectionDescriptor,
-                                      ManageableCollection collection) throws RepositoryException {
-        try {
-            if (collection == null) {
-                return;
-            }
-
-            String jcrName = getCollectionJcrName(collectionDescriptor);
-            Value[] values = new Value[collection.getSize()];
-            ValueFactory valueFactory = session.getValueFactory();
-            Iterator collectionIterator = collection.getIterator();
-            for (int i = 0; i < collection.getSize(); i++) {
-                Object fieldValue = collectionIterator.next();
-                AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
-                    .get(fieldValue.getClass());
-                values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue);
-            }
-
-            parentNode.setProperty(jcrName, values);
-        }
-        catch(ValueFormatException vfe) {
-            throw new PersistenceException("Cannot insert collection field : " 
-                    + collectionDescriptor.getFieldName()
-                    + " of class "
-                    + collectionDescriptor.getClassDescriptor().getClassName(), vfe);
-        }
-    }
-
-    /**
-     *
-     * @see AbstractCollectionConverterImpl#doUpdateCollection(Session, Node, CollectionDescriptor, ManageableCollection)
-     */
-    protected void doUpdateCollection(Session session,
-                                 Node parentNode,
-                                 CollectionDescriptor collectionDescriptor,
-                                 ManageableCollection collection) throws RepositoryException {
-        String jcrName = getCollectionJcrName(collectionDescriptor);
-
-        // Delete existing values
-        if (parentNode.hasProperty(jcrName)) {
-            parentNode.setProperty(jcrName, (Value[]) null);
-        }
-
-        if (collection == null) {
-            return;
-        }
-
-
-        // Add all collection element into an Value array
-        Value[] values = new Value[collection.getSize()];
-        ValueFactory valueFactory = session.getValueFactory();
-        int i = 0; 
-        for (Iterator collectionIterator = collection.getIterator(); collectionIterator.hasNext(); i++) {
-            Object fieldValue = collectionIterator.next();
-            AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
-                .get(fieldValue.getClass());
-            values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue);
-        }
-
-        parentNode.setProperty(jcrName, values);
-    }
-
-    /**
-     * @see AbstractCollectionConverterImpl#doGetCollection(Session, Node, CollectionDescriptor, Class)
-     */
-    protected ManageableCollection doGetCollection(Session session,
-                                                   Node parentNode,
-                                                   CollectionDescriptor collectionDescriptor,
-                                                   Class collectionFieldClass) throws RepositoryException {
-        try {
-            String jcrName = getCollectionJcrName(collectionDescriptor);
-            if (!parentNode.hasProperty(jcrName)) {
-                return null;
-            }
-            Property property = parentNode.getProperty(jcrName);
-            Value[] values = property.getValues();
-
-            ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
-            String elementClassName = collectionDescriptor.getElementClassName();
-            Class elementClass = ReflectionUtils.forName(elementClassName);
-            for (int i = 0; i < values.length; i++) {
-                AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
-                    .get(elementClass);
-                collection.addObject(atomicTypeConverter.getObject(values[i]));
-            }
-
-            return collection;
-        }
-        catch(ValueFormatException vfe) {
-          throw new PersistenceException("Cannot get the collection field : "
-                  + collectionDescriptor.getFieldName()
-                  + "for class " + collectionDescriptor.getClassDescriptor().getClassName(),
-                  vfe);
-        }
-    }
-    
-    /**
-     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor, Class)
-     */
-    protected boolean doIsNull(Session session,
-                                              Node parentNode,
-                                              CollectionDescriptor collectionDescriptor,
-                                              Class collectionFieldClass) throws RepositoryException {
-        String jcrName = getCollectionJcrName(collectionDescriptor);
-
-         if (!parentNode.hasProperty(jcrName)) {
-            return true;
-        }
-        return false;
-    }     
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.portals.graffito.jcr.persistence.collectionconverter.impl;
+
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection;
+import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollectionUtil;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ * Collection Mapping/convertion implementation used for multi values properties
+ *
+ * This collection mapping strategy maps a collection into a JCR multi value property
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class MultiValueCollectionConverterImpl extends AbstractCollectionConverterImpl {
+
+    /**
+     * Constructor
+     *
+     * @param atomicTypeConverters
+     * @param objectConverter
+     * @param mapper
+     */
+    public MultiValueCollectionConverterImpl(Map atomicTypeConverters,
+                                             ObjectConverter objectConverter,
+                                             Mapper mapper) {
+        super(atomicTypeConverters, objectConverter, mapper);
+    }
+
+    /**
+     *
+     * @see AbstractCollectionConverterImpl#doInsertCollection(Session, Node, CollectionDescriptor, ManageableCollection)
+     */
+    protected void doInsertCollection(Session session,
+                                      Node parentNode,
+                                      CollectionDescriptor collectionDescriptor,
+                                      ManageableCollection collection) throws RepositoryException {
+        try {
+            if (collection == null) {
+                return;
+            }
+
+            String jcrName = getCollectionJcrName(collectionDescriptor);
+            Value[] values = new Value[collection.getSize()];
+            ValueFactory valueFactory = session.getValueFactory();
+            Iterator collectionIterator = collection.getIterator();
+            for (int i = 0; i < collection.getSize(); i++) {
+                Object fieldValue = collectionIterator.next();
+                AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
+                    .get(fieldValue.getClass());
+                values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue);
+            }
+
+            parentNode.setProperty(jcrName, values);
+        }
+        catch(ValueFormatException vfe) {
+            throw new PersistenceException("Cannot insert collection field : " 
+                    + collectionDescriptor.getFieldName()
+                    + " of class "
+                    + collectionDescriptor.getClassDescriptor().getClassName(), vfe);
+        }
+    }
+
+    /**
+     *
+     * @see AbstractCollectionConverterImpl#doUpdateCollection(Session, Node, CollectionDescriptor, ManageableCollection)
+     */
+    protected void doUpdateCollection(Session session,
+                                 Node parentNode,
+                                 CollectionDescriptor collectionDescriptor,
+                                 ManageableCollection collection) throws RepositoryException {
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+        // Delete existing values
+        if (parentNode.hasProperty(jcrName)) {
+            parentNode.setProperty(jcrName, (Value[]) null);
+        }
+
+        if (collection == null) {
+            return;
+        }
+
+
+        // Add all collection element into an Value array
+        Value[] values = new Value[collection.getSize()];
+        ValueFactory valueFactory = session.getValueFactory();
+        int i = 0; 
+        for (Iterator collectionIterator = collection.getIterator(); collectionIterator.hasNext(); i++) {
+            Object fieldValue = collectionIterator.next();
+            AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
+                .get(fieldValue.getClass());
+            values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue);
+        }
+
+        parentNode.setProperty(jcrName, values);
+    }
+
+    /**
+     * @see AbstractCollectionConverterImpl#doGetCollection(Session, Node, CollectionDescriptor, Class)
+     */
+    protected ManageableCollection doGetCollection(Session session,
+                                                   Node parentNode,
+                                                   CollectionDescriptor collectionDescriptor,
+                                                   Class collectionFieldClass) throws RepositoryException {
+        try {
+            String jcrName = getCollectionJcrName(collectionDescriptor);
+            if (!parentNode.hasProperty(jcrName)) {
+                return null;
+            }
+            Property property = parentNode.getProperty(jcrName);
+            Value[] values = property.getValues();
+
+            ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
+            String elementClassName = collectionDescriptor.getElementClassName();
+            Class elementClass = ReflectionUtils.forName(elementClassName);
+            for (int i = 0; i < values.length; i++) {
+                AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters
+                    .get(elementClass);
+                collection.addObject(atomicTypeConverter.getObject(values[i]));
+            }
+
+            return collection;
+        }
+        catch(ValueFormatException vfe) {
+          throw new PersistenceException("Cannot get the collection field : "
+                  + collectionDescriptor.getFieldName()
+                  + "for class " + collectionDescriptor.getClassDescriptor().getClassName(),
+                  vfe);
+        }
+    }
+    
+    /**
+     * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor, Class)
+     */
+    protected boolean doIsNull(Session session,
+                                              Node parentNode,
+                                              CollectionDescriptor collectionDescriptor,
+                                              Class collectionFieldClass) throws RepositoryException {
+        String jcrName = getCollectionJcrName(collectionDescriptor);
+
+         if (!parentNode.hasProperty(jcrName)) {
+            return true;
+        }
+        return false;
+    }     
 }

Propchange: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/MultiValueCollectionConverterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message