incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r488396 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: java/org/apache/portals/graffito/jcr/persistence/beanconverter/ java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ java/org/apache/portals/graffito/jcr/persistenc...
Date Mon, 18 Dec 2006 19:43:59 GMT
Author: clombart
Date: Mon Dec 18 11:43:58 2006
New Revision: 488396

URL: http://svn.apache.org/viewvc?view=rev&rev=488396
Log:
Review BeanConverter :
* Review method params in order to provide a complete API. 
* Fix for GRFT-122
* Code clean up - Define a DefaultBeanConverter. This simplify the code in the ObjectConverterImpl 
* Review unit test

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testdigester.xml
      - copied, changed from r477346, incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml
Removed:
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml
Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Paragraph.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java Mon Dec 18 11:43:58 2006
@@ -25,6 +25,7 @@
 import org.apache.portals.graffito.jcr.exception.RepositoryException;
 import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.persistence.beanconverter.impl.ParentBeanConverterImpl;
 
 /**
  * Interface describing a custom bean converter. 
@@ -32,11 +33,14 @@
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public interface BeanConverter {
+	
+	
     /**
      * Insert the object.
      *
      * @param session the JCR session
      * @param parentNode The node which will contain the converter bean
+     * @param beanDescriptor The bean descriptor
      * @param beanClassDescriptor the Class Descriptor associated to the bean to insert
      * @param bean the bean to convert( insert into the JCR structure)
      * @param parentClassDescriptor The Class Descriptor associated to the parent object 
@@ -49,7 +53,7 @@
      *  wrapped in PersistenceException; marks a repository failure
      * @throws JcrMappingException throws in case the mapping of the bean is not correct
      */
-    void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
+    void insert(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
 
     /**
@@ -57,6 +61,7 @@
      *
      * @param session the JCR session
      * @param parentNode The node which will contain the converter bean
+     * @param beanDescriptor The bean descriptor
      * @param beanClassDescriptor the Class Descriptor associated to the bean to update
      * @param bean the bean to convert( insert into the JCR structure)
      * @param parentClassDescriptor The Class Descriptor associated to the parent object
@@ -69,7 +74,7 @@
      *  wrapped in PersistenceException; marks a repository failure
      * @throws JcrMappingException throws in case the mapping of the bean is not correct
      */
-    void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
+    void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
     
     /**
@@ -77,6 +82,7 @@
      * 
      * @param session the JCR session
      * @param parentNode The parent node
+     * @param beanDescriptor The bean descriptor
      * @param beanClassDescriptor the Class Descriptor associated to the bean to insert
      * @param beanClass The bean Class
      * @param parent The parent which contain the bean to retrieve
@@ -88,7 +94,7 @@
      *  wrapped in PersistenceException; marks a repository failure
      * @throws JcrMappingException throws in case the mapping of the bean is not correct
      */
-    Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent) 
+    Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent) 
     throws PersistenceException, RepositoryException, JcrMappingException;
 
 
@@ -97,6 +103,7 @@
      * 
      * @param session the JCR session
      * @param parentNode The node which will contain the converter bean
+     * @param beanDescriptor The bean descriptor    
      * @param beanClassDescriptor the Class Descriptor associated to the bean to update
      * @param bean the bean to convert( insert into the JCR structure)
      * @param parentClassDescriptor The Class Descriptor associated to the parent object 
@@ -109,6 +116,28 @@
      *  wrapped in PersistenceException; marks a repository failure
      * @throws JcrMappingException throws in case the mapping of the bean is not correct
      */
-    void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
+    void remove(Session session, Node parentNode,  BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
+    
+    /**
+     * Get the bean path. 
+     * 
+     * When the bean is mapped to a subnode, the bean path is the parent node path + the jcrname of the current bean.
+     * Sometime a BeanConverter can be used to access to a bean which is not mapped to a subnode. In this case, 
+     * another implementation can be provided in this method getPath. {@link  ParentBeanConverterImpl} is a good example.
+     * 
+     * @param session the JCR session 
+     * @param beanDescriptor The descriptor of the bean to convert
+     * @param parentNode the node which contain this bean (its corresponfing subnode)
+     * @return the bean path
+     * 
+     * @throws RepositoryException thrown in case the underlying repository has thrown a
+     *  <code>javax.jcr.RepositoryException</code> that is not possible to be handled or
+     *  wrapped in PersistenceException; marks a repository failure
+     * 
+     */
+    String getPath(Session session, BeanDescriptor beanDescriptor, Node parentNode)
+    throws PersistenceException;
+    
+
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java Mon Dec 18 11:43:58 2006
@@ -23,11 +23,18 @@
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.exception.RepositoryException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
 import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
-
+/**
+ * 
+ * Abstract Bean Converter Class
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ *
+ */
 public abstract class AbstractBeanConverterImpl implements BeanConverter {
 
 	protected ObjectConverter objectConverter;
@@ -40,16 +47,42 @@
 		this.objectConverter = objectConverter;
 		this.atomicTypeConverterProvider = atomicTypeConverterProvider;
 	}
-	
-    public abstract void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+
+	/**
+	 * 
+	 * Default implementation for many BeanConverter. This method can be overridden in specific BeanConverter
+	 * 
+	 */
+    public String getPath(Session session, BeanDescriptor beanDescriptor, Node parentNode)
+           throws PersistenceException
+    {		
+		 try 
+		 {
+			String path = "";
+			if (parentNode != null)
+		    {				
+				 path +=  parentNode.getPath();
+			}
+		    return path + "/"  + beanDescriptor.getJcrName();
+
+		} 
+		catch (javax.jcr.RepositoryException e) 
+		{
+			throw new RepositoryException(e);
+		}
+	}
+
+
+
+	public abstract void insert(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException, 	JcrMappingException;
 
-	public abstract  void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public abstract  void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException,	JcrMappingException;
 	
-	public abstract Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
+	public abstract Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
 			throws PersistenceException, RepositoryException,JcrMappingException ;
 
-	public abstract void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor,  Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public abstract void remove(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor,  Object object, ClassDescriptor parentClassDescriptor, Object parent)
 	          throws PersistenceException,	RepositoryException, JcrMappingException ;
 }

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/DefaultBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/DefaultBeanConverterImpl.java?view=auto&rev=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/DefaultBeanConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/DefaultBeanConverterImpl.java Mon Dec 18 11:43:58 2006
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.beanconverter.impl;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.exception.RepositoryException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
+import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+/**
+ * 
+ * Default Bean Converter
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ *
+ */
+public class DefaultBeanConverterImpl extends AbstractBeanConverterImpl  implements BeanConverter {
+
+	private final static Log log = LogFactory.getLog(DefaultBeanConverterImpl.class);
+	
+	public DefaultBeanConverterImpl(Mapper mapper, ObjectConverter objectConverter, AtomicTypeConverterProvider atomicTypeConverterProvider) 
+	{
+		super(mapper, objectConverter, atomicTypeConverterProvider);	
+	}
+
+	public void insert(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+			throws PersistenceException, RepositoryException, 	JcrMappingException 
+	{
+		objectConverter.insert(session, parentNode, beanDescriptor.getJcrName(), object);
+	}
+
+	public void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+			throws PersistenceException, RepositoryException,	JcrMappingException 
+	{
+		objectConverter.update(session, parentNode, beanDescriptor.getJcrName(), object);
+	}
+
+	public Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
+			throws PersistenceException, RepositoryException,JcrMappingException 
+	{
+        return objectConverter.getObject(session, beanClass, this.getPath(session, beanDescriptor, parentNode));
+		
+	}
+
+	public void remove(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	          throws PersistenceException,	RepositoryException, JcrMappingException 
+	{
+		try {
+			if (parentNode.hasNode(beanDescriptor.getJcrName())) 
+			{
+				parentNode.getNode(beanDescriptor.getJcrName()).remove();
+			}
+
+		} catch (javax.jcr.RepositoryException e) {
+			
+			throw new RepositoryException(e);
+		}
+		
+	}
+	
+
+}

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java Mon Dec 18 11:43:58 2006
@@ -23,12 +23,20 @@
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.exception.RepositoryException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
 import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.SimpleFieldsHelper;
-
+/**
+ * 
+ * Bean converter used to map some node properties into one nested bean field.
+ * The corresponding bean field is not associated to a subnode.
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ *
+ */
 public class InlineBeanConverterImpl extends AbstractBeanConverterImpl  implements BeanConverter {
 
 	SimpleFieldsHelper simpleFieldsHelper; 
@@ -39,25 +47,25 @@
 		this.simpleFieldsHelper = new SimpleFieldsHelper(atomicTypeConverterProvider);
 	}
 
-	public void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void insert(Session session, Node parentNode,  BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException, 	JcrMappingException {
 		
 		simpleFieldsHelper.storeSimpleFields(session, object, beanClassDescriptor, parentNode);
 	}
 
-	public void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void update(Session session, Node parentNode,  BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException, JcrMappingException {
 		simpleFieldsHelper.storeSimpleFields(session, object, beanClassDescriptor, parentNode);
 	}
 
-	public Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object bean)
+	public Object getObject(Session session, Node parentNode,  BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object bean)
 			throws PersistenceException, RepositoryException,JcrMappingException {
 		
 		return simpleFieldsHelper.retrieveSimpleFields(session, beanClassDescriptor, parentNode, bean);
  
 	}
 
-	public void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void remove(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 	          throws PersistenceException,	RepositoryException, JcrMappingException {
 				
 		simpleFieldsHelper.storeSimpleFields(session, object, beanClassDescriptor, parentNode);

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java Mon Dec 18 11:43:58 2006
@@ -25,11 +25,19 @@
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 import org.apache.portals.graffito.jcr.exception.RepositoryException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
 import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
-
+/**
+ * 
+ * Bean converter used to access to the parent object.
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ *
+ */
 public class ParentBeanConverterImpl extends AbstractBeanConverterImpl  implements BeanConverter {
 
 	private final static Log log = LogFactory.getLog(ParentBeanConverterImpl.class);
@@ -39,17 +47,18 @@
 		super(mapper, objectConverter, atomicTypeConverterProvider);	
 	}
 
-	public void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void insert(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException, 	JcrMappingException {
 	}
 
-	public void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException,	JcrMappingException {
 	}
 
-	public Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
+	public Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
 			throws PersistenceException, RepositoryException,JcrMappingException {
-        try {			
+        try 
+        {			
 			Node grandParentNode = parentNode.getParent();
 			if (grandParentNode.getPath().equals("/"))
 			{
@@ -57,15 +66,43 @@
 			}
 			return objectConverter.getObject(session, grandParentNode.getPath());
 			
-		} catch (javax.jcr.RepositoryException e) {
+		} 
+        catch (javax.jcr.RepositoryException e) 
+		{
 			throw new RepositoryException(e);
 		} 
 		
 	}
 
-	public void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	public void remove(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 	          throws PersistenceException,	RepositoryException, JcrMappingException {
 
 	}
+	
+	/**
+	 * 
+	 * Default implementation for many BeanConverter. This method can be overridden in specific BeanConverter
+	 * 
+	 */
+    public String getPath(Session session, BeanDescriptor beanDescriptor, Node parentNode)
+                throws PersistenceException
+    {		
+		 try 
+		 {
+			if (parentNode != null)
+		    {
+				
+				 return parentNode.getParent().getPath();
+			}
+			else
+			{
+			    return null; 
+			}
+		} 
+		catch (javax.jcr.RepositoryException e) 
+		{
+			throw new RepositoryException(e);
+		}
+	}	
 
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java Mon Dec 18 11:43:58 2006
@@ -46,6 +46,6 @@
 
 	public Object loadObject() 
 	{				
-		return objectConverter.getObject(session, path);		
+		return objectConverter.getObject(session, beanClass, path);		
 	}
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- 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 Mon Dec 18 11:43:58 2006
@@ -59,6 +59,8 @@
  */
 public class ObjectConverterImpl implements ObjectConverter {
 
+	private static final String DEFAULT_BEAN_CONVERTER = "org.apache.portals.graffito.jcr.persistence.beanconverter.impl.DefaultBeanConverterImpl";
+
 	private final static Log log = LogFactory.getLog(ObjectConverterImpl.class);
 
 	private Mapper mapper;
@@ -556,27 +558,36 @@
 	
 	private void retrieveBeanField(Session session,BeanDescriptor beanDescriptor, Node node, String path, Object object, boolean forceToRetrieve )
 	{
-		if (!beanDescriptor.isAutoRetrieve() && !forceToRetrieve) {
+		if (!beanDescriptor.isAutoRetrieve() && !forceToRetrieve) 
+		{
 			return;
 		}
 
 		String beanName = beanDescriptor.getFieldName();
 		Class beanClass = ReflectionUtils.getPropertyType(object, beanName);
 		Object bean = null;
-		if (beanDescriptor.isProxy()) {
-			bean = proxyManager.createBeanProxy(session, this, beanClass, path + "/" + beanDescriptor.getJcrName());
-
-		} else {
-			if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
-				String converterClassName = beanDescriptor.getConverter();
-				Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
-				
-				BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
-				bean = beanConverter.getObject(session, node, mapper.getClassDescriptorByClass(beanClass), beanClass, bean);
-			} else {
-				bean = this.getObject(session, path + "/" + beanDescriptor.getJcrName());
-			}
+		
+		String converterClassName = null;		
+		if (null == beanDescriptor.getConverter() || "".equals(beanDescriptor.getConverter())) 
+		{
+			converterClassName = DEFAULT_BEAN_CONVERTER;
+		}
+		else
+		{
+			converterClassName = beanDescriptor.getConverter();
 		}
+					
+		Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};			
+		BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
+		if (beanDescriptor.isProxy()) 
+		{
+			bean = proxyManager.createBeanProxy(session, this, beanClass, beanConverter.getPath(session, beanDescriptor, node));
+		} 
+		else
+		{
+			bean = beanConverter.getObject(session, node, beanDescriptor,  mapper.getClassDescriptorByClass(beanClass), beanClass, bean);
+		}			
+			
 		ReflectionUtils.setNestedProperty(object, beanName, bean);		
 	}
 	
@@ -628,16 +639,22 @@
 
 			String jcrName = beanDescriptor.getJcrName();
 			Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
-			if (bean != null) {
-                if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
-					String converterClassName = beanDescriptor.getConverter();
-					Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
-					BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
-					beanConverter.insert(session, objectNode, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
-					
-				} else {
-					this.insert(session, objectNode, jcrName, bean);
+			if (bean != null) 
+			{
+				String converterClassName = null;
+				
+				if (null == beanDescriptor.getConverter() || "".equals(beanDescriptor.getConverter())) 
+				{
+					converterClassName = DEFAULT_BEAN_CONVERTER;
+				}
+				else
+				{
+					converterClassName = beanDescriptor.getConverter();
 				}
+                
+				Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
+				BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
+				beanConverter.insert(session, objectNode, beanDescriptor, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
 			}
 		}
 	}
@@ -647,52 +664,41 @@
 	 */
 	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();
-				if (!beanDescriptor.isAutoUpdate()) {
-					continue;
-				}
-
-				jcrName = beanDescriptor.getJcrName();
-				Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
-
-				// if the bean is null, remove existing node
-				if ((bean == null)) {
-					if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) 
-					{
-						String converterClassName = beanDescriptor.getConverter();
-						Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
-						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
-								.invokeConstructor(converterClassName, param);
-						Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
-						beanConverter.remove(session, objectNode, mapper.getClassDescriptorByClass(beanClass), bean, classDescriptor, object);
-					} else {
-						if (objectNode.hasNode(jcrName)) {
-							objectNode.getNode(jcrName).remove();
-						}
-					}
-				} else {
-                    if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
-						String converterClassName = beanDescriptor.getConverter();
-						Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
-						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
-								.invokeConstructor(converterClassName, param);
-						beanConverter.update(session, objectNode, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
-					} else {
-						this.update(session, objectNode, jcrName, bean);
-					}
-				}
+		Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+		while (beanDescriptorIterator.hasNext()) 
+		{
+			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+			if (!beanDescriptor.isAutoUpdate()) {
+				continue;
 			}
-		} 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);
+
+			jcrName = beanDescriptor.getJcrName();
+			Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
+			
+			String converterClassName = null;
+			if (null == beanDescriptor.getConverter() || "".equals(beanDescriptor.getConverter())) 
+			{
+				converterClassName = DEFAULT_BEAN_CONVERTER;
+			} 
+			else 
+			{
+				converterClassName = beanDescriptor.getConverter();
+			}
+			
+			Object[] param = {this.mapper, this, this.atomicTypeConverterProvider };
+			BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
+			Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
+			// if the bean is null, remove existing node
+			if ((bean == null)) 
+			{
+				
+				beanConverter.remove(session, objectNode, beanDescriptor, mapper.getClassDescriptorByClass(beanClass), bean, classDescriptor, object);
+
+			} else 
+			{
+				beanConverter.update(session, objectNode, beanDescriptor, mapper.getClassDescriptorByClass(beanClass), bean, classDescriptor, object);
+			}
+
 		}
 	}
 

Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testdigester.xml (from r477346, incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml)
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testdigester.xml?view=diff&rev=488396&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml&r1=477346&p2=incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testdigester.xml&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testdigester.xml Mon Dec 18 11:43:58 2006
@@ -2,8 +2,8 @@
 
 <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "./src/dtd/graffito-jcr-mapping.dtd">
 <graffito-jcr>
-    
-  
+
+
 
 	<!--
 		The following classes are used to test object associations
@@ -13,8 +13,7 @@
 	-->
 	<class-descriptor
 		className="org.apache.portals.graffito.jcr.testmodel.A"
-		jcrNodeType="nt:unstructured"
-		jcrMixinTypes="mixin:a,mixin:b">
+		jcrNodeType="nt:unstructured" jcrMixinTypes="mixin:a,mixin:b">
 		<!-- Field-descriptor is used to map simple attributes to jcr property -->
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="a1" jcrName="a1" />
@@ -24,77 +23,71 @@
 			* The definition of the associated class has to be defined in this mapping file 
 			* proxy="true" => use lazy laoding for this attribute b when retrieving A
 		-->
-		<bean-descriptor fieldName="b" 
-						 jcrName="b" 
-						 proxy="false" 
-						 converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.InlineBeanConverterImpl"
-						 jcrNodeType="nt:unstructured"
-        				 jcrAutoCreated="false" 
-        				 jcrMandatory="false" 
-        				 jcrOnParentVersion="IGNORE"
-        				 jcrProtected="false" 
-        				 jcrSameNameSiblings="false" />
+		<bean-descriptor fieldName="b" jcrName="b" proxy="false"
+			converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.InlineBeanConverterImpl"
+			jcrNodeType="nt:unstructured" jcrAutoCreated="false"
+			jcrMandatory="false" jcrOnParentVersion="IGNORE" jcrProtected="false"
+			jcrSameNameSiblings="false" />
 
 		<!-- 
 			Use the default collection mapping stategy and the default collection type (can be a Vector, an ArrayList, a Collection or a List) 
 			The default collection mapping strategy map a collection under an extra JCR node (specify by the jcrName).
 			
 		-->
-		<collection-descriptor fieldName="collection" jcrName="collection" proxy="false"
-        elementClassName="org.apache.portals.graffito.jcr.testmodel.C" jcrNodeType="graffito:C"
-        jcrAutoCreated="false" jcrMandatory="false" jcrOnParentVersion="IGNORE"
-        jcrProtected="false" jcrSameNameSiblings="false"/>
-        
-		<collection-descriptor fieldName="emptyCollection" jcrName="emptyCollection" proxy="false"
-        elementClassName="org.apache.portals.graffito.jcr.testmodel.C" />
-		
+		<collection-descriptor fieldName="collection"
+			jcrName="collection" proxy="false"
+			elementClassName="org.apache.portals.graffito.jcr.testmodel.C"
+			jcrNodeType="graffito:C" jcrAutoCreated="false" jcrMandatory="false"
+			jcrOnParentVersion="IGNORE" jcrProtected="false"
+			jcrSameNameSiblings="false" />
+
+		<collection-descriptor fieldName="emptyCollection"
+			jcrName="emptyCollection" proxy="false"
+			elementClassName="org.apache.portals.graffito.jcr.testmodel.C" />
+
 	</class-descriptor>
 
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.B"  jcrNodeType="nt:unstructured" jcrSuperTypes="nt:base">
+	<class-descriptor
+		className="org.apache.portals.graffito.jcr.testmodel.B"
+		jcrNodeType="nt:unstructured" jcrSuperTypes="nt:base">
 		<!-- Field-descriptor is used to map simple attributes to jcr property -->
 
-		<field-descriptor fieldName="b1" jcrName="b1" jcrType="String" jcrAutoCreated="false" jcrMandatory="false"
-        jcrOnParentVersion="IGNORE" jcrProtected="false" jcrMultiple="false" />
-		
-        <field-descriptor fieldName="b2" jcrName="b2" jcrType="String" jcrAutoCreated="true" jcrMandatory="true"
-        jcrOnParentVersion="COPY" jcrProtected="true" jcrMultiple="true" />
+		<field-descriptor fieldName="b1" jcrName="b1" jcrType="String"
+			jcrAutoCreated="false" jcrMandatory="false"
+			jcrOnParentVersion="IGNORE" jcrProtected="false" jcrMultiple="false" />
+
+		<field-descriptor fieldName="b2" jcrName="b2" jcrType="String"
+			jcrAutoCreated="true" jcrMandatory="true" jcrOnParentVersion="COPY"
+			jcrProtected="true" jcrMultiple="true" />
 
 	</class-descriptor>
 
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.C" jcrNodeType="graffito:C" discriminator="false">
+	<class-descriptor
+		className="org.apache.portals.graffito.jcr.testmodel.C"
+		jcrNodeType="graffito:C" discriminator="false">
 		<!-- Field-descriptor is used to map simple attributes to jcr property -->
-		<field-descriptor fieldName="id" jcrName="graffito:id" 	id="true" />
+		<field-descriptor fieldName="id" jcrName="graffito:id"
+			id="true" />
 		<field-descriptor fieldName="name" jcrName="graffito:name" />
 	</class-descriptor>
 
 
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="graffito:page" discriminator="false">
-		<field-descriptor fieldName="path" path="true" />
-		<field-descriptor fieldName="title" jcrName="graffito:title" />
-		<collection-descriptor fieldName="paragraphs" proxy="false" 
-		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.Paragraph" 
-		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" />
-	</class-descriptor>
-
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph" discriminator="false">
-		<field-descriptor fieldName="path" path="true" />
-		<field-descriptor fieldName="text" jcrName="graffito:text"/>
-	</class-descriptor>
-
-
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Main" jcrNodeType="nt:unstructured">
+	<class-descriptor
+		className="org.apache.portals.graffito.jcr.testmodel.hashmap.Main"
+		jcrNodeType="nt:unstructured">
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="text" jcrName="text" />
-		<collection-descriptor fieldName="elements" proxy="false" 
-		                       elementClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.Element" 
-		                       collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" 
-		                       collectionClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.HashMapElement" />
-		                       
+		<collection-descriptor fieldName="elements" proxy="false"
+			elementClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.Element"
+			collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl"
+			collectionClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.HashMapElement" />
+
 	</class-descriptor>
 
-	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element" jcrNodeType="graffito:element" discriminator="false">
-		<field-descriptor fieldName="id" jcrName="graffito:id"  />
+	<class-descriptor
+		className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element"
+		jcrNodeType="graffito:element" discriminator="false">
+		<field-descriptor fieldName="id" jcrName="graffito:id" />
 		<field-descriptor fieldName="text" jcrName="graffito:text" />
 	</class-descriptor>
 </graffito-jcr>
- 
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml Mon Dec 18 11:43:58 2006
@@ -71,6 +71,7 @@
 	<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph" discriminator="false" >
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="text" jcrName="graffito:text"/>
+    	<bean-descriptor fieldName="page" jcrName="page" proxy="true" converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.ParentBeanConverterImpl" />		
 	</class-descriptor>
 
 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- 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 Mon Dec 18 11:43:58 2006
@@ -69,7 +69,7 @@
 		try {
 
 			Mapper mapper = new DigesterMapperImpl(
-					"./src/test-config/jcrmapping-testmappings.xml");
+					"./src/test-config/jcrmapping-testdigester.xml");
 					
 			assertNotNull("Mapper is null", mapper);
 
@@ -105,7 +105,8 @@
 	public void testDiscriminatorSetting() {
 		try {
 
-			Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping-testmappings.xml");
+			Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping-testdigester.xml");
+
 			assertNotNull("Mapper is null", mapper);
 
 			ClassDescriptor classDescriptor = mapper.getClassDescriptorByNodeType("graffito:C");
@@ -124,8 +125,7 @@
 	 */
 	public void testMapperOptionalProperties() {
 		try {
-			Mapper mapper = new DigesterMapperImpl(
-					"./src/test-config/jcrmapping.xml");
+			Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping.xml");
 			assertNotNull("Mapper is null", mapper);
 
 			ClassDescriptor classDescriptor = mapper

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanDescriptorTest.java Mon Dec 18 11:43:58 2006
@@ -18,6 +18,9 @@
 
 
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.Test;
@@ -25,13 +28,15 @@
 
 import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
 import org.apache.portals.graffito.jcr.TestBase;
-import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
 import org.apache.portals.graffito.jcr.testmodel.B;
 import org.apache.portals.graffito.jcr.testmodel.D;
 import org.apache.portals.graffito.jcr.testmodel.DFull;
 import org.apache.portals.graffito.jcr.testmodel.E;
+import org.apache.portals.graffito.jcr.testmodel.Page;
+import org.apache.portals.graffito.jcr.testmodel.Paragraph;
 
 /**
  * ObjectConverter test for bean-descriptor with inner bean inlined and inner bean with
@@ -73,10 +78,12 @@
     }
 
     private void clean() throws Exception {
-        if(getSession().itemExists("/someD")) {
+        if(getSession().itemExists("/someD")) 
+        {
             getSession().getItem("/someD").remove();
             getSession().save();
         }
+
     }
     
     public void testInlined() throws Exception {
@@ -187,6 +194,59 @@
         assertEquals("remove from path /someD", messages.get(4));
         assertEquals("get from path /someD", messages.get(5));
 
+    }
+    
+    public void testParentBeanConverter() throws Exception
+    {
+        try
+        {
+        	PersistenceManager persistenceManager = getPersistenceManager();
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+
+            Page page = new Page();
+            page.setPath("/test");
+            page.setTitle("Page Title");
+            
+            Collection paragraphs = new ArrayList();
+            
+            paragraphs.add(new Paragraph("Para 1"));
+            paragraphs.add(new Paragraph("Para 2"));
+            paragraphs.add(new Paragraph("Para 3"));
+            page.setParagraphs(paragraphs);
+            
+            persistenceManager.insert(page);
+            persistenceManager.save();
+            
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            page = (Page) persistenceManager.getObject("/test");
+            paragraphs = page.getParagraphs();
+            for (Iterator iter = paragraphs.iterator(); iter.hasNext();) {
+				Paragraph paragraph = (Paragraph) iter.next();
+				System.out.println("Paragraph path : " + paragraph.getPath());				
+			}
+            Paragraph p1 = (Paragraph) persistenceManager.getObject(Paragraph.class, "/test/collection-element[2]");
+            Page paraPage = p1.getPage();
+            assertNotNull("Parent page is null", paraPage);
+            assertTrue("Invalid parent page", paraPage.getPath().equals("/test"));
+            
+            // --------------------------------------------------------------------------------
+            // Remove the object
+            // --------------------------------------------------------------------------------           
+            persistenceManager.remove("/test");
+            persistenceManager.save();
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+    	
     }
     
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/beanconverter/FakeBeanConverter.java Mon Dec 18 11:43:58 2006
@@ -20,18 +20,21 @@
 import java.util.List;
 
 import javax.jcr.Node;
-import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
+import org.apache.portals.graffito.jcr.exception.RepositoryException;
+
 import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
 import org.apache.portals.graffito.jcr.persistence.beanconverter.impl.AbstractBeanConverterImpl;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.testmodel.B;
 
-public class FakeBeanConverter extends AbstractBeanConverterImpl {
+public class FakeBeanConverter extends AbstractBeanConverterImpl implements BeanConverter {
 
     private static  List log = new ArrayList();
     
@@ -48,12 +51,13 @@
     /**
      * @see org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter#insert(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
      */
-    public void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
+	public void insert(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	throws PersistenceException, RepositoryException, 	JcrMappingException {
         try {
             log.add("insert at path " + parentNode.getPath());
             
         }
-        catch(RepositoryException re) {
+        catch(javax.jcr.RepositoryException re) {
             throw new PersistenceException(re);
         }
     } 
@@ -61,11 +65,12 @@
     /**
      * @see org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter#update(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
      */
-    public void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
+	public void update(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+	throws PersistenceException, RepositoryException,	JcrMappingException {
         try {
             log.add("update at path " + parentNode.getPath());
         }
-        catch(RepositoryException re) {
+        catch(javax.jcr.RepositoryException re) {
             throw new PersistenceException(re);
         }
     }
@@ -73,11 +78,12 @@
     /**
      * @see org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter#getObject(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Class)
      */
-    public Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent) throws PersistenceException {
+    public Object getObject(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
+	throws PersistenceException, RepositoryException,JcrMappingException {
         try {
             log.add("get from path " + parentNode.getPath());
         }
-        catch(RepositoryException re) {
+        catch(javax.jcr.RepositoryException re) {
             throw new PersistenceException(re);
         }
         // The B object is not important for the unit test. 
@@ -88,11 +94,13 @@
     /**
      * @see org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter#remove(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String)
      */
-    public void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
+	public void remove(Session session, Node parentNode, BeanDescriptor beanDescriptor, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
+    throws PersistenceException,	RepositoryException, JcrMappingException {
+
         try {
             log.add("remove from path " + parentNode.getPath());
         }
-        catch(RepositoryException re) {
+        catch(javax.jcr.RepositoryException re) {
             throw new PersistenceException(re);
         }
     }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Paragraph.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Paragraph.java?view=diff&rev=488396&r1=488395&r2=488396
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Paragraph.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/Paragraph.java Mon Dec 18 11:43:58 2006
@@ -25,8 +25,8 @@
 {
     private String path;
 	private String text;
-
-
+    // Simple reference to the page containing this pararaph - cannot be updated
+	private Page page; 
 	
     public String getPath() 
     {
@@ -63,5 +63,17 @@
     {
         this.text = text;
     }
+
+	public Page getPage() 
+	{
+		return page;
+	}
+
+	public void setPage(Page page) {
+		this.page = page;
+	}
+
+	
+    
     
 }



Mime
View raw message