incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r393615 [2/2] - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/mapper/impl/ java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/collectionconverter/ jav...
Date Wed, 12 Apr 2006 21:15:28 GMT
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java Wed Apr 12 14:15:26 2006
@@ -15,7 +15,6 @@
  */
 package org.apache.portals.graffito.jcr.persistence.objectconverter.impl;
 
-
 import java.util.Iterator;
 import java.util.Map;
 
@@ -29,9 +28,9 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.VersionException;
 
 import org.apache.commons.logging.Log;
@@ -50,777 +49,667 @@
 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.collectionconverter.impl.DefaultCollectionConverterImpl;
-import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
 
-import sun.reflect.misc.ReflectUtil;
-
 /**
  * Default implementation for {@link ObjectConverterImpl}
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart
+ *         Christophe </a>
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public class ObjectConverterImpl implements ObjectConverter {
-    
+
 	private final static Log log = LogFactory.getLog(ObjectConverterImpl.class);
-    
-    private static final AtomicTypeConverter NULL_CONVERTER = new NullTypeConverterImpl();
 
-    private Mapper mapper;
+	private static final AtomicTypeConverter NULL_CONVERTER = new NullTypeConverterImpl();
+
+	private Mapper mapper;
+
+	private AtomicTypeConverterProvider atomicTypeConverterProvider;
+
+	private ProxyManager proxyManager;
+
+	/**
+	 * No-arg constructor.
+	 */
+	public ObjectConverterImpl() {
+	}
+
+	/**
+	 * Constructor
+	 * 
+	 * @param mapper
+	 *            The mapper to used
+	 * @param converterProvider
+	 *            The atomic type converter provider
+	 * 
+	 */
+	public ObjectConverterImpl(Mapper mapper, AtomicTypeConverterProvider converterProvider) {
+		this.mapper = mapper;
+		this.atomicTypeConverterProvider = converterProvider;
+		this.proxyManager = new ProxyManager();
+	}
+
+	/**
+	 * Set the <code>Mapper</code> used to solve mappings.
+	 * 
+	 * @param mapper
+	 *            a <code>Mapper</code>
+	 */
+	public void setMapper(Mapper mapper) {
+		this.mapper = mapper;
+	}
+
+	/**
+	 * Sets the converter provider.
+	 * 
+	 * @param converterProvider
+	 *            an <code>AtomicTypeConverterProvider</code>
+	 */
+	public void setAtomicTypeConverterProvider(AtomicTypeConverterProvider converterProvider) {
+		this.atomicTypeConverterProvider = converterProvider;
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session,
+	 *      java.lang.Object)
+	 */
+	public void insert(Session session, Object object) {
+		String path = this.getPath(session, object);
+		try {
+			String parentPath = RepositoryUtil.getParentPath(path);
+			String nodeName = RepositoryUtil.getNodeName(path);
+			Node parentNode = (Node) session.getItem(parentPath);
+			this.insert(session, parentNode, nodeName, object);
+
+		} catch (PathNotFoundException pnfe) {
+			throw new PersistenceException("Impossible to insert the object at '" + path + "'", pnfe);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to insert the object at '" + path
+					+ "'", re);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session,
+	 *      javax.jcr.Node, java.lang.String, java.lang.Object)
+	 */
+	public void insert(Session session, Node parentNode, String nodeName, Object object) {
+		ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
+
+		String jcrNodeType = classDescriptor.getJcrNodeType();
+		if ((jcrNodeType == null) || jcrNodeType.equals("")) {
+			throw new JcrMappingException("Undefined node type for  " + parentNode);
+		}
+
+		Node objectNode = null;
+		try {
+			objectNode = parentNode.addNode(nodeName, jcrNodeType);
+
+		} catch (NoSuchNodeTypeException nsnte) {
+			throw new JcrMappingException("Unknown node type " + jcrNodeType + " for mapped class " + object.getClass(), nsnte);
+		} catch (RepositoryException re) {
+			throw new PersistenceException("Cannot create new node of type " + jcrNodeType + " from mapped class "
+					+ object.getClass(), re);
+		}
+
+		if (null != classDescriptor.getJcrMixinTypes()) {
+			String[] mixinTypes = classDescriptor.getJcrMixinTypes();
+			for (int i = 0; i < mixinTypes.length; i++) {
+				try {
+					objectNode.addMixin(mixinTypes[i].trim());
+				} catch (NoSuchNodeTypeException nsnte) {
+					throw new JcrMappingException("Unknown mixin type " + mixinTypes[i].trim() + " for mapped class "
+							+ object.getClass(), nsnte);
+				} catch (RepositoryException re) {
+					throw new PersistenceException("Cannot create new node of type " + jcrNodeType + " from mapped class "
+							+ object.getClass(), re);
+				}
+			}
+		}
+
+		storeSimpleFields(session, object, classDescriptor, objectNode);
+		insertBeanFields(session, object, classDescriptor, objectNode);
+		insertCollectionFields(session, object, classDescriptor, objectNode);
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session,
+	 *      java.lang.Object)
+	 */
+	public void update(Session session, Object object) {
+		String path = this.getPath(session, object);
+		try {
+			String parentPath = RepositoryUtil.getParentPath(path);
+			String nodeName = RepositoryUtil.getNodeName(path);
+			Node parentNode = (Node) session.getItem(parentPath);
+			this.update(session, parentNode, nodeName, object);
+		} catch (PathNotFoundException pnfe) {
+			throw new PersistenceException("Impossible to update the object at '" + path + "'", pnfe);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to update the object at '" + path
+					+ "'", re);
+		}
+	}
+
+	/**
+	 * 
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session,
+	 *      javax.jcr.Node, java.lang.String, java.lang.Object)
+	 */
+	public void update(Session session, Node parentNode, String nodeName, Object object) {
+		try {
+			ClassDescriptor classDescriptor = getClassDescriptor(ReflectionUtils.getBeanClass(object));
+			Node objectNode = parentNode.getNode(nodeName);
+
+			checkNodeType(session, classDescriptor);
+			checkCompatibleNodeTypes(session, objectNode, classDescriptor, false);
+
+			storeSimpleFields(session, object, classDescriptor, objectNode);
+			updateBeanFields(session, object, classDescriptor, objectNode);
+			updateCollectionFields(session, object, classDescriptor, objectNode);
+		} catch (PathNotFoundException pnfe) {
+			throw new PersistenceException("Impossible to update the object: " + nodeName + " at node : " + parentNode, pnfe);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to update the object: "
+					+ nodeName + " at node : " + parentNode, re);
+		}
+	}
+
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#getObject(javax.jcr.Session,
+	 *      java.lang.Class, java.lang.String)
+	 */
+	public Object getObject(Session session, Class clazz, String path) {
+		try {
+			if (!session.itemExists(path)) {
+				return null;
+			}
+
+			ClassDescriptor classDescriptor = getClassDescriptor(clazz);
+
+			checkNodeType(session, classDescriptor);
+
+			Node node = (Node) session.getItem(path);
+
+			checkCompatibleNodeTypes(session, node, classDescriptor, true);
+			Object object = null;
+			if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
+				String discriminatorProperty = classDescriptor.getDiscriminatorFieldDescriptor().getJcrName();
+
+				if (!node.hasProperty(discriminatorProperty)) {
+					throw new PersistenceException("Cannot fetch object of type '" + clazz.getName()
+							+ "' using NODETYPE_PER_HIERARCHY. Discriminator property is not present.");
+				}
+
+				String className = node.getProperty(discriminatorProperty).getValue().getString();
+				classDescriptor = getClassDescriptor(Class.forName(className));
+				object = ReflectionUtils.newInstance(className);
+			} else {
+				if (classDescriptor.usesNodeTypePerConcreteClassStrategy()) {
+					String nodeType = node.getPrimaryNodeType().getName();
+					if (!nodeType.equals(classDescriptor.getJcrNodeType())) {
+						classDescriptor = classDescriptor.getDescendantClassDescriptor(nodeType);
+					}
+				}
+				object = ReflectionUtils.newInstance(classDescriptor.getClassName());
+
+			}
+
+			retrieveSimpleFields(session, classDescriptor, node, object);
+			retrieveBeanFields(session, classDescriptor, node, path, object);
+			retrieveCollectionFields(session, classDescriptor, node, object);
+
+			return object;
+		} catch (ClassNotFoundException clnf) {
+			throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
+		} catch (PathNotFoundException pnfe) {
+			// HINT should never get here
+			throw new PersistenceException("Impossible to get the object at " + path, pnfe);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Impossible to get the object at " + path, re);
+		}
+	}
+
+	/**
+	 * Validates the node type used by the class descriptor.
+	 * 
+	 * @param session
+	 *            the current session
+	 * @param classDescriptor
+	 *            descriptor
+	 * @throws JcrMappingException
+	 *             thrown if the node type is unknown
+	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
+	 *             thrown if an error occured in the underlying repository
+	 */
+	private void checkNodeType(Session session, ClassDescriptor classDescriptor) {
+		try {
+			session.getWorkspace().getNodeTypeManager().getNodeType(classDescriptor.getJcrNodeType());
+		} catch (NoSuchNodeTypeException nsnte) {
+			throw new JcrMappingException("Mapping for class '" + classDescriptor.getClassName() + "' use unknown node type '"
+					+ classDescriptor.getJcrNodeType() + "'");
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re);
+		}
+	}
+
+	/**
+	 * Checks if the node type in the class descriptor is compatible with the
+	 * specified node node type.
+	 * 
+	 * @param session
+	 *            the current session
+	 * @param node
+	 *            node against whose node type the compatibility is checked
+	 * @param classDescriptor
+	 *            class descriptor
+	 * @param checkVersionNode
+	 *            <tt>true</tt> if the check should continue in case the
+	 *            <tt>node</tt> is a version node, <tt>false</tt> if no
+	 *            check against version node should be performed
+	 * 
+	 * @throws PersistenceException
+	 *             thrown if node types are incompatible
+	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
+	 *             thrown if an error occured in the underlying repository
+	 */
+	private void checkCompatibleNodeTypes(Session session, Node node, ClassDescriptor classDescriptor, boolean checkVersionNode) {
+		try {
+			NodeType nodeType = node.getPrimaryNodeType();
+
+			boolean compatible = checkCompatibleNodeTypes(nodeType, classDescriptor);
+
+			if (!compatible && checkVersionNode && "nt:frozenNode".equals(nodeType.getName())) {
+				NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
+				nodeType = ntMgr.getNodeType(node.getProperty("jcr:frozenPrimaryType").getString());
+
+				compatible = checkCompatibleNodeTypes(nodeType, classDescriptor);
+			}
+
+			if (!compatible) {
+				throw new PersistenceException("Cannot map object of type '" + classDescriptor.getClassName() + "'. Node type '"
+						+ node.getPrimaryNodeType().getName() + "' does not match descriptor node type '"
+						+ classDescriptor.getJcrNodeType() + "'");
+			}
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re);
+		}
+	}
+
+	/**
+	 * Node types compatibility check.
+	 * 
+	 * @param nodeType
+	 *            target node type
+	 * @param descriptor
+	 *            descriptor containing source node type
+	 * @return <tt>true</tt> if nodes are considered compatible,
+	 *         <tt>false</tt> otherwise
+	 */
+	private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor) {
+		if (nodeType.getName().equals(descriptor.getJcrNodeType())) {
+			return true;
+		}
+
+		NodeType[] superTypes = nodeType.getSupertypes();
+		for (int i = 0; i < superTypes.length; i++) {
+			if (superTypes[i].getName().equals(descriptor.getJcrNodeType())) {
+				return true;
+			}
+		}
+
+		return false;
+	}
 
-    private AtomicTypeConverterProvider atomicTypeConverterProvider;
-    
-    private ProxyManager proxyManager;
-
-    /**
-     * No-arg constructor.
-     */
-    public ObjectConverterImpl() {
-    }
-
-    /**
-     * Constructor
-     *
-     * @param mapper The mapper to used
-     * @param converterProvider The atomic type converter provider
-     *
-     */
-    public ObjectConverterImpl(Mapper mapper, AtomicTypeConverterProvider converterProvider) {
-        this.mapper = mapper;
-        this.atomicTypeConverterProvider = converterProvider;
-        this.proxyManager = new ProxyManager(this);
-    }
-
-    /**
-     * Set the <code>Mapper</code> used to solve mappings.
-     * @param mapper a <code>Mapper</code>
-     */
-    public void setMapper(Mapper mapper) {
-        this.mapper = mapper;
-    }
-
-    /**
-     * Sets the converter provider.
-     *
-     * @param converterProvider an <code>AtomicTypeConverterProvider</code>
-     */
-    public void setAtomicTypeConverterProvider(AtomicTypeConverterProvider converterProvider) {
-        this.atomicTypeConverterProvider = converterProvider;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session, java.lang.Object)
-     */
-    public void insert(Session session, Object object) {
-        String path = this.getPath(session, object);
-        try {
-            String parentPath = RepositoryUtil.getParentPath(path);
-            String nodeName = RepositoryUtil.getNodeName(path);
-            Node parentNode = (Node) session.getItem(parentPath);
-            this.insert(session, parentNode, nodeName, object);
-
-        } catch (PathNotFoundException pnfe) {
-            throw new PersistenceException("Impossible to insert the object at '" + path + "'",
-                                           pnfe);
-        } catch (RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Impossible to insert the object at '" + path + "'",
-                    re);
-        }
-    }
-
-    /**
-     *
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#insert(javax.jcr.Session, javax.jcr.Node, java.lang.String, java.lang.Object)
-     */
-    public void insert(Session session, Node parentNode, String nodeName, Object object) {
-        ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
-        
-        String jcrNodeType = classDescriptor.getJcrNodeType();
-        if ((jcrNodeType == null) || jcrNodeType.equals("")) {
-            throw new JcrMappingException("Undefined node type for  " + parentNode);
-        }
-
-        Node objectNode = null;
-        try {
-            objectNode = parentNode.addNode(nodeName, jcrNodeType);
-            
-        } 
-        catch (NoSuchNodeTypeException nsnte) {
-            throw new JcrMappingException("Unknown node type " + jcrNodeType
-                                          + " for mapped class " + object.getClass(), nsnte);
-        } 
-        catch (RepositoryException re) {
-            throw new PersistenceException("Cannot create new node of type " + jcrNodeType
-                                           + " from mapped class " + object.getClass(), re);
-        }
-
-        if (null != classDescriptor.getJcrMixinTypes()) {
-            String[] mixinTypes = classDescriptor.getJcrMixinTypes();
-            for (int i = 0; i < mixinTypes.length; i++) {
-                try {
-                    objectNode.addMixin(mixinTypes[i].trim());
-                } catch (NoSuchNodeTypeException nsnte) {
-                    throw new JcrMappingException("Unknown mixin type " + mixinTypes[i].trim()
-                                                  + " for mapped class " + object.getClass(), nsnte);
-                } catch (RepositoryException re) {
-                    throw new PersistenceException("Cannot create new node of type " + jcrNodeType
-                                                   + " from mapped class " + object.getClass(), re);
-                }
-            }
-        }
-
-
-        storeSimpleFields(session, object, classDescriptor, objectNode);
-        insertBeanFields(session, object, classDescriptor, objectNode);
-        insertCollectionFields(session, object, classDescriptor, objectNode);
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session, java.lang.Object)
-     */
-    public void update(Session session, Object object) {
-        String path = this.getPath(session, object);
-        try {
-            String parentPath = RepositoryUtil.getParentPath(path);
-            String nodeName = RepositoryUtil.getNodeName(path);
-            Node parentNode = (Node) session.getItem(parentPath);
-            this.update(session, parentNode, nodeName, object);
-        }
-        catch(PathNotFoundException pnfe) {
-            throw new PersistenceException("Impossible to update the object at '"
-                    + path + "'",
-                    pnfe);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Impossible to update the object at '" + path + "'",
-                    re);
-        }
-    }
-
-    /**
-     *
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#update(javax.jcr.Session, javax.jcr.Node, java.lang.String, java.lang.Object)
-     */
-    public void update(Session session, Node parentNode, String nodeName, Object object) {
-        try {
-            ClassDescriptor classDescriptor = getClassDescriptor(ReflectionUtils.getBeanClass(object));
-            Node objectNode = parentNode.getNode(nodeName);
-
-            checkNodeType(session, classDescriptor);
-            checkCompatibleNodeTypes(session, objectNode, classDescriptor, false);
-
-            storeSimpleFields(session, object, classDescriptor, objectNode);
-            updateBeanFields(session, object, classDescriptor, objectNode);
-            updateCollectionFields(session, object, classDescriptor, objectNode);
-        }
-        catch(PathNotFoundException pnfe) {
-            throw new PersistenceException("Impossible to update the object: "
-                    + nodeName
-                    + " at node : " + parentNode, pnfe);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Impossible to update the object: " + nodeName
-                    + " at node : " + parentNode, re);
-        }
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#getObject(javax.jcr.Session, java.lang.Class, java.lang.String)
-     */
-    public Object getObject(Session session, Class clazz, String path) {
-        try {
-            if (!session.itemExists(path)) {
-                return null;
-            }
-
-            ClassDescriptor classDescriptor = getClassDescriptor(clazz);
-
-            checkNodeType(session, classDescriptor);
-
-            Node node = (Node) session.getItem(path);
-
-            checkCompatibleNodeTypes(session, node, classDescriptor, true);
-            Object object = null;
-            if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
-                String discriminatorProperty = classDescriptor.getDiscriminatorFieldDescriptor().getJcrName();
-
-                if (!node.hasProperty(discriminatorProperty)) {
-                     throw new PersistenceException("Cannot fetch object of type '"
-                        + clazz.getName()
-                        + "' using NODETYPE_PER_HIERARCHY. Discriminator property is not present.");
-                }
-                
-                String className = node.getProperty(discriminatorProperty).getValue().getString();
-                classDescriptor = getClassDescriptor(Class.forName(className));
-                object = ReflectionUtils.newInstance(className);
-            }
-            else {
-            	    if (classDescriptor.usesNodeTypePerConcreteClassStrategy())
-            	    {
-            	    	    String nodeType =  node.getPrimaryNodeType().getName();
-            	    	    if (! nodeType.equals(classDescriptor.getJcrNodeType()))
-            	    	    {
-            	    	        classDescriptor  = classDescriptor.getDescendantClassDescriptor(nodeType);
-            	    	    }
-            	    }
-                object = ReflectionUtils.newInstance(classDescriptor.getClassName());
-
-            }   
-
-            retrieveSimpleFields(session, classDescriptor, node, object);
-            retrieveBeanFields(session, classDescriptor, node, path, object);
-            retrieveCollectionFields(session, classDescriptor, node, object);
-
-            return object;
-        } 
-        catch(ClassNotFoundException clnf) {
-           	throw new PersistenceException("Impossible to instantiate the object at " + path, clnf);
-        }
-        catch(PathNotFoundException pnfe) {
-            // HINT should never get here
-            throw new PersistenceException("Impossible to get the object at " + path, pnfe);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Impossible to get the object at " + path, re);
-        }
-    }
-
-    /**
-     * Validates the node type used by the class descriptor.
-     *
-     * @param session the current session
-     * @param classDescriptor descriptor
-     * @throws JcrMappingException thrown if the node type is unknown
-     * @throws org.apache.portals.graffito.jcr.exception.RepositoryException thrown if
-     *  an error occured in the underlying repository
-     */
-    private void checkNodeType(Session session, ClassDescriptor classDescriptor) {
-        try {
-            session.getWorkspace().getNodeTypeManager().getNodeType(classDescriptor.getJcrNodeType());
-        }
-        catch(NoSuchNodeTypeException nsnte) {
-            throw new JcrMappingException("Mapping for class '"
-                + classDescriptor.getClassName()
-                + "' use unknown node type '"
-                + classDescriptor.getJcrNodeType()
-                + "'");
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re);
-        }
-    }
-
-    /**
-     * Checks if the node type in the class descriptor is compatible with the
-     * specified node node type.
-     *
-     * @param session the current session
-     * @param node node against whose node type the compatibility is checked
-     * @param classDescriptor class descriptor
-     * @param checkVersionNode <tt>true</tt> if the check should continue in case the <tt>node</tt>
-     *  is a version node, <tt>false</tt> if no check against version node should be performed
-     *
-     * @throws PersistenceException thrown if node types are incompatible
-     * @throws org.apache.portals.graffito.jcr.exception.RepositoryException thrown if an error
-     *  occured in the underlying repository
-     */
-    private void checkCompatibleNodeTypes(Session session,
-                                          Node node,
-                                          ClassDescriptor classDescriptor,
-                                          boolean checkVersionNode) {
-        try {
-            NodeType nodeType = node.getPrimaryNodeType();
-
-            boolean compatible = checkCompatibleNodeTypes(nodeType, classDescriptor);
-
-            if (!compatible && checkVersionNode && "nt:frozenNode".equals(nodeType.getName())) {
-                NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
-                nodeType = ntMgr.getNodeType(node.getProperty("jcr:frozenPrimaryType").getString());
-
-                compatible = checkCompatibleNodeTypes(nodeType, classDescriptor);
-            }
-
-            if (!compatible) {
-                throw new PersistenceException("Cannot map object of type '"
-                        + classDescriptor.getClassName()
-                        + "'. Node type '"
-                        + node.getPrimaryNodeType().getName()
-                        + "' does not match descriptor node type '"
-                        + classDescriptor.getJcrNodeType()
-                        + "'");
-            }
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re);
-        }
-    }
-
-    /**
-     * Node types compatibility check.
-     *
-     * @param nodeType target node type
-     * @param descriptor descriptor containing source node type
-     * @return <tt>true</tt> if nodes are considered compatible, <tt>false</tt> otherwise
-     */
-    private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor) {
-        if(nodeType.getName().equals(descriptor.getJcrNodeType())) {
-            return true;
-        }
-
-        NodeType[] superTypes = nodeType.getSupertypes();
-        for(int i = 0; i < superTypes.length; i++) {
-            if(superTypes[i].getName().equals(descriptor.getJcrNodeType())) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#getPath(javax.jcr.Session, java.lang.Object)
-     * @throws JcrMappingException
-     */
-    public String getPath(Session session, Object object) {
-        ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
-
-        final FieldDescriptor pathFieldDescriptor = classDescriptor.getPathFieldDescriptor();
-        if (pathFieldDescriptor == null) {
-            throw new JcrMappingException("Class of type: "
-                    + object.getClass().getName()
-                    + " has no path mapping. Maybe attribute path=\"true\" for a field element of this class in jcrmapping.xml is missing?"
-            );
-        }
-        String pathField = pathFieldDescriptor.getFieldName();
-
-        return (String) ReflectionUtils.getNestedProperty(object, pathField);
-    }
-
-    /**
-     * Retrieve simple fields (atomic fields)
-     * 
-     * @throws JcrMappingException
-     * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
-     */
-    private Object retrieveSimpleFields(Session session, 
-                                        ClassDescriptor classDescriptor, 
-                                        Node node, 
-                                        Object object) {
-       Object initializedBean = object;
-        try {
-            Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
-    
-            while (fieldDescriptorIterator.hasNext()) {
-                FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
-    
-                String fieldName = fieldDescriptor.getFieldName();
-                String propertyName = fieldDescriptor.getJcrName();
-    
-                if (fieldDescriptor.isPath()) {
-                    // 	 HINT: lazy initialize target bean - The bean can be null when it is inline
-                    if (null == initializedBean) { 
-                     initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-                   }
-                    
-                    ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());
-                 
-                }
-                else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) {                	    
-                	    
-                    if (node.hasProperty( classDescriptor.getDiscriminatorFieldDescriptor().getJcrName())) {
-                        if (null == initializedBean) {
-                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-                        }
-                        String value = node.getProperty( classDescriptor.getDiscriminatorFieldDescriptor().getJcrName()).getValue().getString();
-                        ReflectionUtils.setNestedProperty(initializedBean, fieldName, value);
-                    }
-                    else {
-                        throw new PersistenceException("Class '" + classDescriptor.getClassName() + "' have not a discriminator property.");
-                    }
-                }
-                else {
-                    if (node.hasProperty(propertyName)) {
-                        Value propValue = node.getProperty(propertyName).getValue();
-                        // 	 HINT: lazy initialize target bean - The bean can be null when it is inline
-                        if (null != propValue && null == initializedBean) { 
-                            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
-                        }
-
-                        AtomicTypeConverter converter= getAtomicTypeConverter(fieldDescriptor, 
-                                                                              initializedBean, 
-                                                                              fieldName);
-                        
-                        Object fieldValue = converter.getObject(propValue);
-                        ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
-                    }
-                    else
-                    {
-                    	     log.warn("Class '" + classDescriptor.getClassName() + "' has an unmapped property : " + propertyName);	
-                    }
-                }
-            }
-        }
-        catch(ValueFormatException vfe) {
-            throw new PersistenceException( "Cannot retrieve properties of object "
-                    + object
-                    + " from node "
-                    + node,
-                    vfe);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Cannot retrieve properties of object "
-                    + object
-                    + " from node "
-                    + node,
-                    re);
-        }
-        
-        return initializedBean;
-    }
-    
-    /**
-     * Retrieve bean fields
-     */
-    private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor,  Node node, String path, Object object) {
-        Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors()
-				.iterator();
+	/**
+	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#getPath(javax.jcr.Session,
+	 *      java.lang.Object)
+	 * @throws JcrMappingException
+	 */
+	public String getPath(Session session, Object object) {
+		ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
+
+		final FieldDescriptor pathFieldDescriptor = classDescriptor.getPathFieldDescriptor();
+		if (pathFieldDescriptor == null) {
+			throw new JcrMappingException(
+					"Class of type: "
+							+ object.getClass().getName()
+							+ " has no path mapping. Maybe attribute path=\"true\" for a field element of this class in jcrmapping.xml is missing?");
+		}
+		String pathField = pathFieldDescriptor.getFieldName();
+
+		return (String) ReflectionUtils.getNestedProperty(object, pathField);
+	}
+
+	/**
+	 * Retrieve simple fields (atomic fields)
+	 * 
+	 * @throws JcrMappingException
+	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
+	 */
+	private Object retrieveSimpleFields(Session session, ClassDescriptor classDescriptor, Node node, Object object) {
+		Object initializedBean = object;
+		try {
+			Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
+
+			while (fieldDescriptorIterator.hasNext()) {
+				FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
+
+				String fieldName = fieldDescriptor.getFieldName();
+				String propertyName = fieldDescriptor.getJcrName();
+
+				if (fieldDescriptor.isPath()) {
+					// HINT: lazy initialize target bean - The bean can be null
+					// when it is inline
+					if (null == initializedBean) {
+						initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+					}
+
+					ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());
+
+				} else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) {
+
+					if (node.hasProperty(classDescriptor.getDiscriminatorFieldDescriptor().getJcrName())) {
+						if (null == initializedBean) {
+							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+						}
+						String value = node.getProperty(classDescriptor.getDiscriminatorFieldDescriptor().getJcrName())
+								.getValue().getString();
+						ReflectionUtils.setNestedProperty(initializedBean, fieldName, value);
+					} else {
+						throw new PersistenceException("Class '" + classDescriptor.getClassName()
+								+ "' have not a discriminator property.");
+					}
+				} else {
+					if (node.hasProperty(propertyName)) {
+						Value propValue = node.getProperty(propertyName).getValue();
+						// HINT: lazy initialize target bean - The bean can be
+						// null when it is inline
+						if (null != propValue && null == initializedBean) {
+							initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
+						}
+
+						AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, initializedBean, fieldName);
+
+						Object fieldValue = converter.getObject(propValue);
+						ReflectionUtils.setNestedProperty(initializedBean, fieldName, fieldValue);
+					} else {
+						log.warn("Class '" + classDescriptor.getClassName() + "' has an unmapped property : " + propertyName);
+					}
+				}
+			}
+		} catch (ValueFormatException vfe) {
+			throw new PersistenceException("Cannot retrieve properties of object " + object + " from node " + node, vfe);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot retrieve properties of object "
+					+ object + " from node " + node, re);
+		}
+
+		return initializedBean;
+	}
+
+	/**
+	 * Retrieve bean fields
+	 */
+	private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor, Node node, String path, Object object) {
+		Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
 		while (beanDescriptorIterator.hasNext()) {
-			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator
-					.next();
+			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
 			String beanName = beanDescriptor.getFieldName();
 			Class beanClass = ReflectionUtils.getPropertyType(object, beanName);
 			Object bean = null;
 			if (beanDescriptor.isProxy()) {
-				bean = proxyManager.createBeanProxy(session, beanClass, path + "/" + beanDescriptor.getJcrName());
+				bean = proxyManager.createBeanProxy(session, this, beanClass, path + "/" + beanDescriptor.getJcrName());
 
 			} else {
 				if (beanDescriptor.isInline()) {
-					bean = this.retrieveSimpleFields(session,
-							getClassDescriptor(beanClass), node, bean);
+					bean = this.retrieveSimpleFields(session, getClassDescriptor(beanClass), node, bean);
 				} else if (null != beanDescriptor.getBeanConverter()) {
-					bean = beanDescriptor.getBeanConverter().getObject(session,
-							node, beanDescriptor, beanClass);
+					bean = beanDescriptor.getBeanConverter().getObject(session, node, beanDescriptor, beanClass);
 				} else {
-					bean = this.getObject(session, beanClass, path + "/"
-							+ beanDescriptor.getJcrName());
+					bean = this.getObject(session, beanClass, path + "/" + beanDescriptor.getJcrName());
 				}
 			}
 			ReflectionUtils.setNestedProperty(object, beanName, bean);
 		}
-    }
+	}
 
-    /**
+	/**
 	 * Retrieve Collection fields
 	 */
-    private void retrieveCollectionFields(Session session,
-                                          ClassDescriptor classDescriptor,
-                                          Node node,
-                                          Object object)  {
-        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors()
-                                                               .iterator();
-        while (collectionDescriptorIterator.hasNext()) {
-            CollectionDescriptor collectionDescriptor = (CollectionDescriptor)
-                collectionDescriptorIterator.next();
-            CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
-            Class collectionFieldClass = ReflectionUtils.getPropertyType(object,
-                    collectionDescriptor.getFieldName());
-            ManageableCollection collection = collectionConverter.getCollection(session,
-                                                                                node,
-                                                                                collectionDescriptor,
-                                                                                collectionFieldClass);
-            ReflectionUtils.setNestedProperty(object,
-                                              collectionDescriptor.getFieldName(),
-                                              collection);
-        }
-    }
-
-    /**
-     * Insert Bean fields
-     */
-    private void insertBeanFields(Session session,
-                                  Object object,
-                                  ClassDescriptor classDescriptor,
-                                  Node objectNode) {
-        Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
-        while (beanDescriptorIterator.hasNext()) {
-            BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-            String jcrName = beanDescriptor.getJcrName();
-            Object bean = ReflectionUtils.getNestedProperty(object,
-                                                            beanDescriptor.getFieldName());
-            if (bean != null) {
-                if (beanDescriptor.isInline()) {
-                    this.storeSimpleFields(session, bean, getClassDescriptor(bean.getClass()), objectNode);
-                }
-                else if (null != beanDescriptor.getBeanConverter()) {
-                    beanDescriptor.getBeanConverter().insert(session,
-                            objectNode,
-                            beanDescriptor,
-                            object);
-                }
-                else {
-                    this.insert(session, objectNode, jcrName, bean);
-                }
-            }
-        }
-    }
-
-    /**
-     * Update Bean fields
-     */
-    private void updateBeanFields(Session session,
-                                  Object object,
-                                  ClassDescriptor classDescriptor,
-                                  Node objectNode) {
-        String jcrName = null;
-        try {
-            Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
-            while (beanDescriptorIterator.hasNext()) {
-                BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-                jcrName = beanDescriptor.getJcrName();
-                Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
-
-                // if the bean is null, remove existing node
-                if ((bean == null)) {
-                    if (beanDescriptor.isInline()) {
-                        Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
-                        this.storeSimpleFields(session, bean, getClassDescriptor(beanClass), objectNode);
-                    }
-                    else if (null != beanDescriptor.getBeanConverter()) {
-                        beanDescriptor.getBeanConverter().remove(session, objectNode, beanDescriptor);
-                    }
-                    else {
-                        if (objectNode.hasNode(jcrName)) {
-                            objectNode.getNode(jcrName).remove();
-                        }
-                    }
-                } 
-                else {
-                    if (beanDescriptor.isInline()) {
-                        this.storeSimpleFields(session, bean, getClassDescriptor(bean.getClass()), objectNode);
-                    }
-                    else if (null != beanDescriptor.getBeanConverter()) {
-                        beanDescriptor.getBeanConverter().update(session,
-                                objectNode,
-                                beanDescriptor,
-                                bean);
-                    }
-                    else {
-                        this.update(session, objectNode, jcrName, bean);
-                    }
-                }
-            }
-        } 
-        catch(VersionException ve) {
-            throw new PersistenceException("Cannot remove bean at path " + jcrName,
-                    ve);
-        }
-        catch(LockException le) {
-            throw new PersistenceException("Cannot remove bean at path " + jcrName + ". Item is locked.",
-                    le);
-        }
-        catch(ConstraintViolationException cve) {
-            throw new PersistenceException("Cannot remove bean at path " + jcrName + ". Contraint violation.",
-                    cve);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Cannot remove bean at path " + jcrName,
-                    re);
-        }
-    }
-
-    private void insertCollectionFields(Session session,
-                                        Object object,
-                                        ClassDescriptor classDescriptor,
-                                        Node objectNode) {
-        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
-        
-        while (collectionDescriptorIterator.hasNext()) {
-            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
-            CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
-            Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
-            ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
-            
-            collectionConverter.insertCollection(session,objectNode, collectionDescriptor, manageableCollection);
-        }
-    }
-
-    private void updateCollectionFields(Session session,
-                                        Object object,
-                                        ClassDescriptor classDescriptor,
-                                        Node objectNode) {
-        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
-        
-        while (collectionDescriptorIterator.hasNext()) {
-            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
-            CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
-            Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
-            ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
-            
-            collectionConverter.updateCollection(session,
-                                                 objectNode,
-                                                 collectionDescriptor,
-                                                 manageableCollection);
-        }
-    }
-
-    private void storeSimpleFields(Session session,
-                                   Object object,
-                                   ClassDescriptor classDescriptor,
-                                   Node objectNode) {
-        try {
-            ValueFactory valueFactory = session.getValueFactory();
-    
-            Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
-            while (fieldDescriptorIterator.hasNext()) {
-                FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
-
-                String fieldName = fieldDescriptor.getFieldName();
-                String jcrName = fieldDescriptor.getJcrName();
-
-
-                //Of course, Path field is not stored as property
-                if (fieldDescriptor.isPath()) {
-                    continue;
-                }
-
-                if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) {
-                     objectNode.setProperty(fieldDescriptor.getJcrName(), classDescriptor.getClassName());                     
-                    continue;
-                }
-    
-    
-                boolean protectedProperty= fieldDescriptor.isJcrProtected();
-                
-                if(objectNode.hasProperty(jcrName)) {
-                    protectedProperty= objectNode.getProperty(jcrName).getDefinition().isProtected();
-                }
-    
-                if(!protectedProperty) { // DO NOT TRY TO WRITE PROTECTED PROPERTIES
-                    Object fieldValue = ReflectionUtils.getNestedProperty(object, fieldName);
-                    AtomicTypeConverter converter= getAtomicTypeConverter(fieldDescriptor, 
-                                                                          object, 
-                                                                          fieldName); 
-                    Value value = converter.getValue(valueFactory, fieldValue);
-    
-                    // Check if the node property is "autocreated"
-                    boolean autoCreated= fieldDescriptor.isJcrAutoCreated();
-    
-                    if(objectNode.hasProperty(jcrName)) {
-                        autoCreated= objectNode.getProperty(jcrName).getDefinition().isAutoCreated();
-                    }
-                    
-                    if(!autoCreated) {
-                        // Check if mandatory property are not null
-                        checkMandatoryProperty(objectNode, fieldDescriptor, value);
-                    }
-    
-                    objectNode.setProperty(jcrName, value);
-                }
-            }
-        }
-        catch(ValueFormatException vfe) {
-            throw new PersistenceException("Cannot persist properties of object " + object
-                    + ". Value format exception.",
-                    vfe);
-        }
-        catch(VersionException ve) {
-            throw new PersistenceException("Cannot persist properties of object " + object
-                    + ". Versioning exception.",
-                    ve);
-        }
-        catch(LockException le) {
-            throw new PersistenceException("Cannot persist properties of object " + object
-                    + " on locked node.",
-                    le);
-        }
-        catch(ConstraintViolationException cve) {
-            throw new PersistenceException("Cannot persist properties of object " + object
-                    + ". Constraint violation.",
-                    cve);
-        }
-        catch(RepositoryException re) {
-            throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-                    "Cannot persist properties of object " + object,
-                    re);
-        }
-    }
-
-    private CollectionConverter getCollectionConverter(Session session, CollectionDescriptor collectionDescriptor) {
-        String className = collectionDescriptor.getCollectionConverterClassName();
-        Map atomicTypeConverters= this.atomicTypeConverterProvider.getAtomicTypeConverters();
-        if (className == null) {
-            return new DefaultCollectionConverterImpl(atomicTypeConverters, this, this.mapper);
-        } else {
-            return (CollectionConverter) ReflectionUtils.invokeConstructor(className,
-                    new Object[] {atomicTypeConverters, this, this.mapper});
-        }
-
-    }
-
-    private void checkMandatoryProperty(Node objectNode,
-                                        FieldDescriptor fieldDescriptor,
-                                        Value value) throws RepositoryException {
-        PropertyDefinition[] propertyDefinitions = objectNode.getPrimaryNodeType()
-                                                             .getDeclaredPropertyDefinitions();
-        for (int i = 0; i < propertyDefinitions.length; i++) {
-            PropertyDefinition definition = propertyDefinitions[i];
-            if (definition.getName().equals(fieldDescriptor.getJcrName())
-                && definition.isMandatory() 
-                && (definition.isAutoCreated() == false)
-                && (value == null)) 
-            {
-                throw new PersistenceException("Class of type:"
-                        + fieldDescriptor.getClassDescriptor().getClassName() 
-                        + " has property: "
-                        + fieldDescriptor.getFieldName()
-                        + " declared as JCR property: "
-                        + fieldDescriptor.getJcrName()
-                        + " This property is mandatory but property in bean has value null");
-            }
-        }
-    }
-    
-    private AtomicTypeConverter getAtomicTypeConverter(FieldDescriptor fd, 
-                                                       Object object, 
-                                                       String fieldName) {
-        Class fieldTypeClass = null;
-        if (null != fd.getFieldTypeClass()) {
-            fieldTypeClass = fd.getFieldTypeClass();
-        }
-        else if (null != object) {
-            fieldTypeClass = ReflectionUtils.getPropertyType(object, fieldName);
-        }
-
-        if (null != fieldTypeClass) {
-            return this.atomicTypeConverterProvider.getAtomicTypeConverter(fieldTypeClass);
-        }
-        else {
-            return NULL_CONVERTER;
-        }
-    }
-    
-    protected ClassDescriptor getClassDescriptor(Class beanClass) {
-        ClassDescriptor classDescriptor = mapper.getClassDescriptor(beanClass);
-        if(null == classDescriptor) {
-            throw new JcrMappingException("Class of type: " + beanClass.getName()
-                    + " is not JCR persistable. Maybe element 'class-descriptor' for this type in mapping file is missing");
-        }
-
-//        if(classDescriptor.isAbstract()) 
-//        {
-//        	      throw new PersistenceException("Cannot persist/retrieve abstract class " + beanClass.getName());
-//        }
-
-        return classDescriptor;
-    }
-    
+	private void retrieveCollectionFields(Session session, ClassDescriptor classDescriptor, Node parentNode, Object object) {
+		Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+		while (collectionDescriptorIterator.hasNext()) {
+			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+			CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
+			Class collectionFieldClass = ReflectionUtils.getPropertyType(object, collectionDescriptor.getFieldName());
+			ManageableCollection collection = null;
+			if (collectionDescriptor.isProxy()) {
+				collection = (ManageableCollection)  proxyManager.createCollectionProxy(session, collectionConverter, parentNode, collectionDescriptor,collectionFieldClass);
+
+			}
+			else 
+			{
+			     collection = collectionConverter.getCollection(session, parentNode, collectionDescriptor,	collectionFieldClass);
+			}
+			
+			ReflectionUtils.setNestedProperty(object, collectionDescriptor.getFieldName(), collection);
+		}
+	}
+
+	/**
+	 * Insert Bean fields
+	 */
+	private void insertBeanFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
+		Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+		while (beanDescriptorIterator.hasNext()) {
+			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+			String jcrName = beanDescriptor.getJcrName();
+			Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
+			if (bean != null) {
+				if (beanDescriptor.isInline()) {
+					this.storeSimpleFields(session, bean, getClassDescriptor(bean.getClass()), objectNode);
+				} else if (null != beanDescriptor.getBeanConverter()) {
+					beanDescriptor.getBeanConverter().insert(session, objectNode, beanDescriptor, object);
+				} else {
+					this.insert(session, objectNode, jcrName, bean);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Update Bean fields
+	 */
+	private void updateBeanFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
+		String jcrName = null;
+		try {
+			Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+			while (beanDescriptorIterator.hasNext()) {
+				BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+				jcrName = beanDescriptor.getJcrName();
+				Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
+
+				// if the bean is null, remove existing node
+				if ((bean == null)) {
+					if (beanDescriptor.isInline()) {
+						Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
+						this.storeSimpleFields(session, bean, getClassDescriptor(beanClass), objectNode);
+					} else if (null != beanDescriptor.getBeanConverter()) {
+						beanDescriptor.getBeanConverter().remove(session, objectNode, beanDescriptor);
+					} else {
+						if (objectNode.hasNode(jcrName)) {
+							objectNode.getNode(jcrName).remove();
+						}
+					}
+				} else {
+					if (beanDescriptor.isInline()) {
+						this.storeSimpleFields(session, bean, getClassDescriptor(bean.getClass()), objectNode);
+					} else if (null != beanDescriptor.getBeanConverter()) {
+						beanDescriptor.getBeanConverter().update(session, objectNode, beanDescriptor, bean);
+					} else {
+						this.update(session, objectNode, jcrName, bean);
+					}
+				}
+			}
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot remove bean at path " + jcrName, ve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot remove bean at path " + jcrName + ". Item is locked.", le);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot remove bean at path " + jcrName + ". Contraint violation.", cve);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot remove bean at path " + jcrName, re);
+		}
+	}
+
+	private void insertCollectionFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
+		Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+
+		while (collectionDescriptorIterator.hasNext()) {
+			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+			CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
+			Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
+			ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
+
+			collectionConverter.insertCollection(session, objectNode, collectionDescriptor, manageableCollection);
+		}
+	}
+
+	private void updateCollectionFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
+		Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+
+		while (collectionDescriptorIterator.hasNext()) {
+			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+			CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
+			Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
+			ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
+
+			collectionConverter.updateCollection(session, objectNode, collectionDescriptor, manageableCollection);
+		}
+	}
+
+	private void storeSimpleFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
+		try {
+			ValueFactory valueFactory = session.getValueFactory();
+
+			Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
+			while (fieldDescriptorIterator.hasNext()) {
+				FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
+
+				String fieldName = fieldDescriptor.getFieldName();
+				String jcrName = fieldDescriptor.getJcrName();
+
+				// Of course, Path field is not stored as property
+				if (fieldDescriptor.isPath()) {
+					continue;
+				}
+
+				if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) {
+					objectNode.setProperty(fieldDescriptor.getJcrName(), classDescriptor.getClassName());
+					continue;
+				}
+
+				boolean protectedProperty = fieldDescriptor.isJcrProtected();
+
+				if (objectNode.hasProperty(jcrName)) {
+					protectedProperty = objectNode.getProperty(jcrName).getDefinition().isProtected();
+				}
+
+				if (!protectedProperty) { // DO NOT TRY TO WRITE PROTECTED
+											// PROPERTIES
+					Object fieldValue = ReflectionUtils.getNestedProperty(object, fieldName);
+					AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, object, fieldName);
+					Value value = converter.getValue(valueFactory, fieldValue);
+
+					// Check if the node property is "autocreated"
+					boolean autoCreated = fieldDescriptor.isJcrAutoCreated();
+
+					if (objectNode.hasProperty(jcrName)) {
+						autoCreated = objectNode.getProperty(jcrName).getDefinition().isAutoCreated();
+					}
+
+					if (!autoCreated) {
+						// Check if mandatory property are not null
+						checkMandatoryProperty(objectNode, fieldDescriptor, value);
+					}
+
+					objectNode.setProperty(jcrName, value);
+				}
+			}
+		} catch (ValueFormatException vfe) {
+			throw new PersistenceException("Cannot persist properties of object " + object + ". Value format exception.", vfe);
+		} catch (VersionException ve) {
+			throw new PersistenceException("Cannot persist properties of object " + object + ". Versioning exception.", ve);
+		} catch (LockException le) {
+			throw new PersistenceException("Cannot persist properties of object " + object + " on locked node.", le);
+		} catch (ConstraintViolationException cve) {
+			throw new PersistenceException("Cannot persist properties of object " + object + ". Constraint violation.", cve);
+		} catch (RepositoryException re) {
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException("Cannot persist properties of object "
+					+ object, re);
+		}
+	}
+
+	private CollectionConverter getCollectionConverter(Session session, CollectionDescriptor collectionDescriptor) {
+		String className = collectionDescriptor.getCollectionConverterClassName();
+		Map atomicTypeConverters = this.atomicTypeConverterProvider.getAtomicTypeConverters();
+		if (className == null) {
+			return new DefaultCollectionConverterImpl(atomicTypeConverters, this, this.mapper);
+		} else {
+			return (CollectionConverter) ReflectionUtils.invokeConstructor(className, new Object[]{atomicTypeConverters, this,
+					this.mapper});
+		}
+
+	}
+
+	private void checkMandatoryProperty(Node objectNode, FieldDescriptor fieldDescriptor, Value value) throws RepositoryException {
+		PropertyDefinition[] propertyDefinitions = objectNode.getPrimaryNodeType().getDeclaredPropertyDefinitions();
+		for (int i = 0; i < propertyDefinitions.length; i++) {
+			PropertyDefinition definition = propertyDefinitions[i];
+			if (definition.getName().equals(fieldDescriptor.getJcrName()) && definition.isMandatory()
+					&& (definition.isAutoCreated() == false) && (value == null)) {
+				throw new PersistenceException("Class of type:" + fieldDescriptor.getClassDescriptor().getClassName()
+						+ " has property: " + fieldDescriptor.getFieldName() + " declared as JCR property: "
+						+ fieldDescriptor.getJcrName() + " This property is mandatory but property in bean has value null");
+			}
+		}
+	}
+
+	private AtomicTypeConverter getAtomicTypeConverter(FieldDescriptor fd, Object object, String fieldName) {
+		Class fieldTypeClass = null;
+		if (null != fd.getFieldTypeClass()) {
+			fieldTypeClass = fd.getFieldTypeClass();
+		} else if (null != object) {
+			fieldTypeClass = ReflectionUtils.getPropertyType(object, fieldName);
+		}
+
+		if (null != fieldTypeClass) {
+			return this.atomicTypeConverterProvider.getAtomicTypeConverter(fieldTypeClass);
+		} else {
+			return NULL_CONVERTER;
+		}
+	}
+
+	private ClassDescriptor getClassDescriptor(Class beanClass) {
+		ClassDescriptor classDescriptor = mapper.getClassDescriptor(beanClass);
+		if (null == classDescriptor) {
+			throw new JcrMappingException("Class of type: " + beanClass.getName()
+					+ " is not JCR persistable. Maybe element 'class-descriptor' for this type in mapping file is missing");
+		}
+
+		// if(classDescriptor.isAbstract())
+		// {
+		// throw new PersistenceException("Cannot persist/retrieve abstract
+		// class " + beanClass.getName());
+		// }
+
+		return classDescriptor;
+	}
+
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java Wed Apr 12 14:15:26 2006
@@ -16,6 +16,7 @@
 
 package org.apache.portals.graffito.jcr.persistence.objectconverter.impl;
 
+import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -24,20 +25,18 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+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.collectionconverter.ManageableCollectionUtil;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 
 public class ProxyManager {
 
 	 private final static Log log = LogFactory.getLog(ProxyManager.class);
 	
-	 private ObjectConverter objectConverter;
 	 
-	 public ProxyManager(ObjectConverter objectConverter)
-	 {
-		 	this.objectConverter = objectConverter;
-	 }
-	 
-	public  Object createBeanProxy(Session session, Class beanClass, String path) 
+	public  Object createBeanProxy(Session session, ObjectConverter objectConverter,  Class beanClass, String path) 
 	{
 		
        try {
@@ -45,13 +44,24 @@
 				return null;
 			}
 		} catch (RepositoryException e) {
-			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
-					"Impossible to check,if the object exits on " + path, e);
+			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(	"Impossible to check,if the object exits on " + path, e);
 		}
-		
-		log.debug("Create proxy for " + path);
-		LazyLoader loader = new BeanLazyLoader(this.objectConverter, session, beanClass, path) ;		
+				
+		LazyLoader loader = new BeanLazyLoader(objectConverter, session, beanClass, path) ;		
 		return  Enhancer.create(beanClass, loader);
 	}
 
+	
+	public  Object createCollectionProxy(Session session, CollectionConverter collectionConverter, Node parentNode,  CollectionDescriptor collectionDescriptor, Class collectionFieldClass) 
+	{	
+		
+		if (collectionConverter.isNull(session, parentNode, collectionDescriptor, collectionFieldClass)) 	{
+			return null;
+		}
+		
+		ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);
+		
+		LazyLoader loader = new CollectionLazyLoader(collectionConverter, session, parentNode, collectionDescriptor, collectionFieldClass);
+		return  Enhancer.create(manageableCollection.getClass(), loader);
+	}	
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java Wed Apr 12 14:15:26 2006
@@ -141,7 +141,7 @@
     }
     
     public static boolean isProxy(Class beanClass)
-    {
+    {    	        	     
          return Enhancer.isEnhanced(beanClass);	
     }
     
@@ -155,4 +155,5 @@
          }
          return beanClass;
     }
+    
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml Wed Apr 12 14:15:26 2006
@@ -40,7 +40,7 @@
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Folder" jcrNodeType="graffito:folder" 
 	                                   extends="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" >
-		<collection-descriptor fieldName="children" proxy="false" 
+		<collection-descriptor fieldName="children" proxy="true" 
 		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" 
 		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" />
 	</class-descriptor >	
@@ -53,7 +53,7 @@
 	                                   extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Content" >
 		<field-descriptor fieldName="contentType" jcrName="graffito:contenttype" />  
 		<field-descriptor fieldName="size" jcrName="graffito:size" />  	
-		<bean-descriptor fieldName="documentStream" jcrName="graffito:documentstream"  />			
+		<bean-descriptor fieldName="documentStream" jcrName="graffito:documentstream" proxy="true"  />			
 	</class-descriptor >	
 
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.DocumentStream" jcrNodeType="graffito:documentstream"  >

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml Wed Apr 12 14:15:26 2006
@@ -8,10 +8,15 @@
 		<field-descriptor fieldName="path" path="true" />
 		<bean-descriptor fieldName="proxyDetail" jcrName="proxydetail" proxy="true" jcrNodeType="nt:unstructured" />		
 		<bean-descriptor fieldName="nullDetail" jcrName="nulldetail" proxy="true" jcrNodeType="nt:unstructured" />		
-		<bean-descriptor fieldName="detail" jcrName="detail" proxy="false" jcrNodeType="nt:unstructured" />		
+		<bean-descriptor fieldName="detail" jcrName="detail" proxy="false" jcrNodeType="nt:unstructured" />		
+		
+		<collection-descriptor fieldName="proxyCollection" jcrName="proxycollection" proxy="true"
+                                                  elementClassName="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured"/>
+        <collection-descriptor fieldName="nullProxyCollection" jcrName="nullproxycollection" proxy="true"
+                                                  elementClassName="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured"/>                                                  		
 	</class-descriptor>
 
-	<class-descriptor 	className="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" 	jcrNodeType="nt:unstructured">		
+	<class-descriptor 	className="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured">		
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="field" jcrName="field" />
 	</class-descriptor>

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java Wed Apr 12 14:15:26 2006
@@ -359,9 +359,9 @@
 
 			ClassDescriptor classDescriptor = mapper.getClassDescriptor(Main.class);
 			assertNotNull("ClassDescriptor is null", classDescriptor);
-			assertTrue("Invalid proxy setting", classDescriptor.getBeanDescriptor("proxyDetail").isProxy());
-			assertFalse("Invalid proxy setting", classDescriptor.getBeanDescriptor("detail").isProxy());
-			
+			assertTrue("Invalid proxy setting for bean field proxyDetail ", classDescriptor.getBeanDescriptor("proxyDetail").isProxy());
+			assertFalse("Invalid proxy setting for bean field detail  ", classDescriptor.getBeanDescriptor("detail").isProxy());
+			assertTrue("Invalid proxy setting for collection field proxyDetail ", classDescriptor.getCollectionDescriptor("proxyCollection").isProxy());
 			
 		} catch (JcrMappingException e) {
 			e.printStackTrace();

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java Wed Apr 12 14:15:26 2006
@@ -291,5 +291,52 @@
 		assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",Folder.class));
 		
 	}
+	  
+	public void testBeanCollection() {
+		PersistenceManager persistenceManager = this.getPersistenceManager();
+
+		//---------------------------------------------------------------------------------------------------------
+		// Insert cmsobjects
+		//---------------------------------------------------------------------------------------------------------
+		 Folder folder = new Folder();		
+	     folder.setPath("/mainfolder");
+	     folder.setName("Main folder");        
 	    
+	     for (int i=1; i<=100;i++)
+	     {
+	         Document document = new Document();	        
+	         document.setName("document" + i);
+	         document.setContentType("plain/text"); 
+	         DocumentStream documentStream = new DocumentStream();
+	         documentStream.setEncoding("utf-8");
+	         documentStream.setContent("Test Content".getBytes());
+	         document.setDocumentStream(documentStream);
+	         folder.addChild(document);
+	         
+	         Folder subFolder = new Folder();
+	         subFolder.setName("folder" + i);
+	         subFolder.addChild(document);
+	         folder.addChild(subFolder);
+	         	    	 
+	     }
+	     log.debug("Save the folder and its 200 children");   
+	     persistenceManager.insert(folder);
+	     persistenceManager.save();
+	     log.debug("End - Save the folder and its 200 children");
+
+		//---------------------------------------------------------------------------------------------------------	
+		// Retrieve Folder
+		//---------------------------------------------------------------------------------------------------------			
+		folder  = (Folder) persistenceManager.getObject(Folder.class,"/mainfolder");
+		assertNotNull("Folder is null",folder);		
+		Collection children = folder.getChildren();
+		assertEquals("Invalid number of children", children.size(), 200);
+	     for (int i=1; i<=100;i++)
+	     {
+		     assertTrue("Invalid item in the collection : " +"/mainfolder/document" + i , this.contains(children, "/mainfolder/document" + i,Document.class));
+		    assertTrue("Invalid item in the collection : " + "/mainfolder/folder" + i, this.contains(children, "/mainfolder/folder" + i, Folder.class));
+	     }
+		
+	
+	}	
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java Wed Apr 12 14:15:26 2006
@@ -16,6 +16,9 @@
  */
 package org.apache.portals.graffito.jcr.persistence.objectconverter.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -80,7 +83,6 @@
 			//---------------------------------------------------------------------------------------------------------
 			// Retrieve the main object
 			//---------------------------------------------------------------------------------------------------------						
-
 			main = (Main) persistenceManager.getObject(Main.class, "/test");
 			assertNotNull("detail is null", main.getDetail());
 			assertTrue("Invalid detail bean", main.getDetail().getField().equals("FieldValue"));
@@ -129,9 +131,67 @@
 			e.printStackTrace();
 			fail();
 		}
-       
+
+		
 	}
 	
+	public void testCollectionProxy() {
+
+		try {
+			PersistenceManager persistenceManager = this.getPersistenceManager();
+
+			ArrayList  details= new ArrayList();
+			for(int i=1; i<=100;i++)
+			{
+				Detail detail = new Detail();
+				detail.setField("field" + i);				
+				details.add(detail);
+			}
+			
+			Main main = new Main();
+			main.setProxyCollection(details);
+			main.setPath("/test");							
+            persistenceManager.insert(main);
+			persistenceManager.save();
+			
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+			main = (Main) persistenceManager.getObject(Main.class, "/test");
+			assertNotNull("main is null", main);
+
+            Collection result = main.getProxyCollection();
+            assertEquals("Invalide size", result.size(), 100);
+            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());
+			
+			//---------------------------------------------------------------------------------------------------------
+			// Update  
+			//---------------------------------------------------------------------------------------------------------
+            
+            Detail detail = new Detail();
+			detail.setField("newFieldValue");			
+			result.add(detail);
+			main.setProxyCollection(result);
+			persistenceManager.update(main);
+			persistenceManager.save();
+
+			//---------------------------------------------------------------------------------------------------------
+			// Retrieve the main object
+			//---------------------------------------------------------------------------------------------------------						
+			main = (Main) persistenceManager.getObject(Main.class, "/test");
+			assertNotNull("main  is null", main);
+            assertEquals("Invalide size",main.getProxyCollection().size(), 101);
+            assertNull("nullcollectionproxy  is not null", main.getNullProxyCollection());
+            
+	
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail();
+		}
+
+		
+	}
 
 
 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java?rev=393615&r1=393614&r2=393615&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java Wed Apr 12 14:15:26 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.portals.graffito.jcr.testmodel.proxy;
 
+import java.util.Collection;
+
 public class Main 
 {
 
@@ -23,6 +25,8 @@
 	private Detail proxyDetail;
 	private Detail nullDetail; 
     private Detail detail;
+    private Collection proxyCollection;
+    private Collection nullProxyCollection;
 
      
 	public String getPath() {
@@ -56,7 +60,23 @@
 	public void setNullDetail(Detail nullDetail) {
 		this.nullDetail = nullDetail;
 	}
-     
+
+	public Collection getProxyCollection() {
+		return proxyCollection;
+	}
+
+	public void setProxyCollection(Collection proxyCollection) {
+		this.proxyCollection = proxyCollection;
+	}
+
+	public Collection getNullProxyCollection() {
+		return nullProxyCollection;
+	}
+
+	public void setNullProxyCollection(Collection nullProxyCollection) {
+		this.nullProxyCollection = nullProxyCollection;
+	}
+	
 	
      
 }



Mime
View raw message