incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r408736 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence: ./ impl/ objectconverter/ objectconverter/impl/
Date Mon, 22 May 2006 20:04:47 GMT
Author: clombart
Date: Mon May 22 13:04:47 2006
New Revision: 408736

URL: http://svn.apache.org/viewvc?rev=408736&view=rev
Log:
Finalise the  autoInsert, autoUpdate & autoRetrieve features.
AutoRetrieve and proxy are complementary.
Add new methods in the persistenceManager : retrieveMappedAttribute & retrieveAllMappedAttributes.
Those methods are usefull if the autoretrieve is false for one ore more object attributes.

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.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/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java?rev=408736&r1=408735&r2=408736&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
Mon May 22 13:04:47 2006
@@ -115,6 +115,23 @@
     
     
     /**
+     * Retrieve the specified attribute  for the given persistent object.
+     * this attribute is either a bean or a collection. This method is usefull if the corresponding
descriptor has an autoRetrieve="false"
+     * 
+     * @param object The persistent object
+     * @param attributeName The name of the attribute to retrieve
+     */
+    public void retrieveMappedAttribute(Object object, String attributeName);
+
+    
+    /**
+     * Retrieve all mapped  attributes for the given persistent object.
+     * @param object The persistent object
+     */
+    public void retrieveAllMappedAttributes(Object object);
+    
+    
+    /**
      * Remove an object from a JCR repository
      * @param path the object path
      * @throws PersistenceException when it is not possible to remove the object 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=408736&r1=408735&r2=408736&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
Mon May 22 13:04:47 2006
@@ -263,6 +263,22 @@
     }    
     
     /**
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#retrieveAllMappedAttributes(Object)
+     */
+    public void retrieveAllMappedAttributes(Object object) {
+		objectConverter.retrieveAllMappedAttributes(session, object);
+      
+	}
+
+    /**
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#retrieveMappedAttribute(Object,
String)
+     */    
+	public void retrieveMappedAttribute(Object object, String attributeName) {
+		objectConverter.retrieveMappedAttribute(session, object, attributeName);
+		
+	}
+
+	/**
      * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.Object)
      */
     public void insert(Object object) {

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java?rev=408736&r1=408735&r2=408736&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
Mon May 22 13:04:47 2006
@@ -72,6 +72,26 @@
      */
     public Object getObject(Session session, Class clazz, String path) throws PersistenceException;
     
+    
+    /**
+     * Retrieve the specified attribute  for the given persistent object.
+     * this attribute is either a bean or a collection. This method is usefull if the corresponding
descriptor has an autoRetrieve="false"
+     * 
+     * @param session The JCR session
+     * @param object The persistent object
+     * @param attributeName The name of the attribute to retrieve
+     */
+    public void retrieveMappedAttribute(Session session, Object object, String attributeName);
+
+    
+    /**
+     * Retrieve all mapped  attributes for the given persistent object.
+     * 
+     * @param session The JCR session     
+     * @param object The persistent object
+     */
+    public void retrieveAllMappedAttributes(Session session, Object object);
+    
 	/**
 	 * Insert the object 
 	 * 

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?rev=408736&r1=408735&r2=408736&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
Mon May 22 13:04:47 2006
@@ -144,7 +144,7 @@
 
 		String jcrNodeType = classDescriptor.getJcrNodeType();
 		if ((jcrNodeType == null) || jcrNodeType.equals("")) {
-			jcrNodeType= PersistenceConstant.NT_UNSTRUCTURED;
+			jcrNodeType = PersistenceConstant.NT_UNSTRUCTURED;
 		}
 
 		Node objectNode = null;
@@ -160,8 +160,8 @@
 
 		String[] mixinTypes = classDescriptor.getJcrMixinTypes();
 		String mixinTypeName = null;
-		try {						
-			
+		try {
+
 			// Add mixin types
 			if (null != classDescriptor.getJcrMixinTypes()) {
 				for (int i = 0; i < mixinTypes.length; i++) {
@@ -169,34 +169,31 @@
 					objectNode.addMixin(mixinTypeName);
 				}
 			}
-			
+
 			// Add mixin types defined in the associated interfaces 
-			if (! classDescriptor.hasDiscriminator() && classDescriptor.hasInterfaces())
-			{
-				Iterator  interfacesIterator = classDescriptor.getImplements().iterator();
-				while (interfacesIterator.hasNext())
-				{
-					String interfaceName = (String)  interfacesIterator.next();
-					ClassDescriptor interfaceDescriptor =  mapper.getClassDescriptorByClass(ReflectionUtils.forName(interfaceName));
+			if (!classDescriptor.hasDiscriminator() && classDescriptor.hasInterfaces()) {
+				Iterator interfacesIterator = classDescriptor.getImplements().iterator();
+				while (interfacesIterator.hasNext()) {
+					String interfaceName = (String) interfacesIterator.next();
+					ClassDescriptor interfaceDescriptor = mapper
+							.getClassDescriptorByClass(ReflectionUtils.forName(interfaceName));
 					objectNode.addMixin(interfaceDescriptor.getJcrNodeType().trim());
-				}			    
+				}
 			}
-			
+
 			// If required, add the discriminator node type 
-			if (classDescriptor.hasDiscriminator())
-			{
+			if (classDescriptor.hasDiscriminator()) {
 				mixinTypeName = PersistenceConstant.DISCRIMINATOR_NODE_TYPE;
 				objectNode.addMixin(mixinTypeName);
-				objectNode.setProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME, ReflectionUtils.getBeanClass(object).getName());
+				objectNode.setProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME, ReflectionUtils.getBeanClass(object)
+						.getName());
 			}
 		} catch (NoSuchNodeTypeException nsnte) {
-			throw new JcrMappingException(
-					"Unknown mixin type " + mixinTypeName + " for mapped class " + object.getClass(), nsnte);
+			throw new JcrMappingException("Unknown mixin type " + mixinTypeName + " 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);
@@ -233,7 +230,7 @@
 			Node objectNode = parentNode.getNode(nodeName);
 
 			checkNodeType(session, classDescriptor);
-			
+
 			checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
 
 			storeSimpleFields(session, object, classDescriptor, objectNode);
@@ -251,38 +248,35 @@
 	 * @see org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter#getObject(javax.jcr.Session,
 	 *      java.lang.Class, java.lang.String)
 	 */
-	public Object getObject(Session session,  String path) {
+	public Object getObject(Session session, String path) {
 		try {
 			if (!session.itemExists(path)) {
 				return null;
 			}
-			
-			ClassDescriptor classDescriptor =null;
+
+			ClassDescriptor classDescriptor = null;
 			Node node = (Node) session.getItem(path);
-			if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME))
-			{
+			if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) {
 				String className = node.getProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
-				classDescriptor = mapper.getClassDescriptorByClass(Class.forName(className));				
-			}
-			else
-			{
+				classDescriptor = mapper.getClassDescriptorByClass(Class.forName(className));
+			} else {
 				String nodeType = node.getPrimaryNodeType().getName();
-				if (nodeType.equals(PersistenceConstant.FROZEN_NODE_TYPE))
-				{
+				if (nodeType.equals(PersistenceConstant.FROZEN_NODE_TYPE)) {
 					nodeType = node.getProperty(PersistenceConstant.FROZEN_PRIMARY_TYPE_PROPERTY).getString();
 				}
-			    classDescriptor = mapper.getClassDescriptorByNodeType(nodeType);
+				classDescriptor = mapper.getClassDescriptorByNodeType(nodeType);
 			}
-			
+
 			if (null == classDescriptor) {
-				throw new JcrMappingException("Impossible to find the classdescriptor for " + path +
". There is no discriminator and associated  JCR node type");
+				throw new JcrMappingException("Impossible to find the classdescriptor for " + path
+						+ ". There is no discriminator and associated  JCR node type");
 			}
 
 			Object object = ReflectionUtils.newInstance(classDescriptor.getClassName());
 
 			retrieveSimpleFields(session, classDescriptor, node, object);
-			retrieveBeanFields(session, classDescriptor, node, path, object);
-			retrieveCollectionFields(session, classDescriptor, node, object);
+			retrieveBeanFields(session, classDescriptor, node, path, object, false);
+			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
 			return object;
 		} catch (ClassNotFoundException clnf) {
@@ -310,13 +304,12 @@
 			checkNodeType(session, classDescriptor);
 
 			Node node = (Node) session.getItem(path);
-            if (! classDescriptor.isInterface())
-            {
-			    checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
-            }
-            
+			if (!classDescriptor.isInterface()) {
+				checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
+			}
+
 			Object object = null;
-			if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {				
+			if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
 				if (!node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) {
 					throw new PersistenceException("Cannot fetch object of type '" + clazz.getName()
 							+ "' using NODETYPE_PER_HIERARCHY. Discriminator property is not present.");
@@ -337,8 +330,8 @@
 			}
 
 			retrieveSimpleFields(session, classDescriptor, node, object);
-			retrieveBeanFields(session, classDescriptor, node, path, object);
-			retrieveCollectionFields(session, classDescriptor, node, object);
+			retrieveBeanFields(session, classDescriptor, node, path, object, false);
+			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
 			return object;
 		} catch (ClassNotFoundException clnf) {
@@ -351,7 +344,60 @@
 		}
 	}
 
-	
+	public void retrieveAllMappedAttributes(Session session, Object object) {
+		String path = null;
+		try {
+			ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
+			String pathFieldName = classDescriptor.getPathFieldDescriptor().getFieldName();
+			path = (String) ReflectionUtils.getNestedProperty(object, pathFieldName);
+			Node node = (Node) session.getItem(path);
+			retrieveBeanFields(session, classDescriptor, node, path, object, true);
+			retrieveCollectionFields(session, classDescriptor, node, object, true);
+			
+		} catch (PathNotFoundException pnfe) {
+
+			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);
+		}
+	}
+
+	public void retrieveMappedAttribute(Session session, Object object, String attributeName)
{
+		String path = null;
+		ClassDescriptor classDescriptor = null;
+		try {
+			classDescriptor = getClassDescriptor(object.getClass());
+			String pathFieldName = classDescriptor.getPathFieldDescriptor().getFieldName();
+			path = (String) ReflectionUtils.getNestedProperty(object, pathFieldName);
+			Node node = (Node) session.getItem(path);
+			BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor(attributeName);
+			if (beanDescriptor != null)
+			{
+				this.retrieveBeanField(session, beanDescriptor, node, path, object, true);				
+			}
+			// Check if the attribute is a collection
+			else
+			{
+				CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor(attributeName);
+				if (collectionDescriptor != null)
+				{
+					this.retrieveCollectionField(session, collectionDescriptor, node, object, true);
+				}
+				else
+				{
+					throw new PersistenceException("Impossible to retrieve the mapped attribute. The attribute
'" + 
+							                                                         attributeName + "'  is not
a bean or a collection for the class : " + classDescriptor.getClassName());
+				}
+			}
+			
+		} catch (PathNotFoundException pnfe) {
+
+			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.
 	 * 
@@ -367,29 +413,23 @@
 	private void checkNodeType(Session session, ClassDescriptor classDescriptor) {
 		String jcrTypeName = null;
 		try {
-			
-			
+
 			//Don't check the primary node type for interfaces. They are only associated to mixin
node type
-			if ( classDescriptor.isInterface())
-			{
+			if (classDescriptor.isInterface()) {
 				String[] mixinTypes = classDescriptor.getJcrMixinTypes();
-				for (int i=0; i<mixinTypes.length; i++)
-				{
+				for (int i = 0; i < mixinTypes.length; i++) {
 					jcrTypeName = mixinTypes[i];
-				     session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName);
+					session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName);
 				}
-			}
-			else
-			{
+			} else {
 				jcrTypeName = classDescriptor.getJcrNodeType();
-				if(jcrTypeName != null && !  jcrTypeName.equals(""))
-				{
-				    session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName);
+				if (jcrTypeName != null && !jcrTypeName.equals("")) {
+					session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName);
 				}
 			}
 		} catch (NoSuchNodeTypeException nsnte) {
-			throw new JcrMappingException("Mapping for class '" + classDescriptor.getClassName() +
"' use unknown primary or mixin node type '"
-					+  jcrTypeName  + "'");
+			throw new JcrMappingException("Mapping for class '" + classDescriptor.getClassName()
+					+ "' use unknown primary or mixin node type '" + jcrTypeName + "'");
 		} catch (RepositoryException re) {
 			throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re);
 		}
@@ -415,7 +455,8 @@
 	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
 	 *             thrown if an error occured in the underlying repository
 	 */
-	private void checkCompatiblePrimaryNodeTypes(Session session, Node node, ClassDescriptor
classDescriptor, boolean checkVersionNode) {
+	private void checkCompatiblePrimaryNodeTypes(Session session, Node node, ClassDescriptor
classDescriptor,
+			boolean checkVersionNode) {
 		try {
 			NodeType nodeType = node.getPrimaryNodeType();
 
@@ -449,13 +490,12 @@
 	 *         <tt>false</tt> otherwise
 	 */
 	private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor)
{
-		
+
 		//return true if node type is not used
-		if (descriptor.getJcrNodeType() == null ||descriptor.getJcrNodeType().equals("") )
-		{
+		if (descriptor.getJcrNodeType() == null || descriptor.getJcrNodeType().equals("")) {
 			return true;
 		}
-		
+
 		if (nodeType.getName().equals(descriptor.getJcrNodeType())) {
 			return true;
 		}
@@ -559,65 +599,77 @@
 	/**
 	 * Retrieve bean fields
 	 */
-	private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor, Node node,
String path, Object object) {
+	private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor, Node node,
String path, Object object,
+			boolean forceToRetrieve) {
 		Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
 		while (beanDescriptorIterator.hasNext()) {
 			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-			if  (! beanDescriptor.isAutoRetrieve())
-			{
-				continue;
-			}
-			
-			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());
+			this.retrieveBeanField(session, beanDescriptor, node, path, object, forceToRetrieve);
+		}
+	}
+
+	
+	private void retrieveBeanField(Session session,BeanDescriptor beanDescriptor, Node node,
String path, Object object, boolean 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 (beanDescriptor.isInline()) {
+				bean = this.retrieveSimpleFields(session, mapper.getClassDescriptorByClass(beanClass),
node, bean);
+			} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter()))
{
+				String converterClassName = beanDescriptor.getConverter();
+				Object[] param = {this};
+				BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,
param);
+				bean = beanConverter.getObject(session, node, beanDescriptor, beanClass);
 			} else {
-				if (beanDescriptor.isInline()) {
-					bean = this.retrieveSimpleFields(session, mapper.getClassDescriptorByClass(beanClass),
node, bean);
-				} else if (null != beanDescriptor.getConverter() && ! "".equals(beanDescriptor.getConverter()))
{
-					String converterClassName =  beanDescriptor.getConverter();
-					Object[] param = {this};
-					BeanConverter beanConverter =(BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,param);
-					bean = beanConverter.getObject(session, node, beanDescriptor, beanClass);
-				} else {
-					bean = this.getObject(session,  path + "/" + beanDescriptor.getJcrName());
-				}
+				bean = this.getObject(session, path + "/" + beanDescriptor.getJcrName());
 			}
-			ReflectionUtils.setNestedProperty(object, beanName, bean);
 		}
+		ReflectionUtils.setNestedProperty(object, beanName, bean);		
 	}
-
+	
+	
+	
 	/**
 	 * Retrieve Collection fields
 	 */
-	private void retrieveCollectionFields(Session session, ClassDescriptor classDescriptor,
Node parentNode, Object object) {
+	private void retrieveCollectionFields(Session session, ClassDescriptor classDescriptor,
Node parentNode, Object object,
+			boolean forceToRetrieve) {
 		Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
 		while (collectionDescriptorIterator.hasNext()) {
 			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
-			if  (! collectionDescriptor.isAutoRetrieve())
-			{
-				continue;
-			}
-			
-			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);
+			this.retrieveCollectionField(session, collectionDescriptor, parentNode, object, forceToRetrieve);
		
 		}
 	}
 
+	private void retrieveCollectionField(Session session, CollectionDescriptor collectionDescriptor,
Node parentNode, Object object, boolean forceToRetrieve)
+	{
+		if (!collectionDescriptor.isAutoRetrieve() && !forceToRetrieve) {
+			return;
+		}
+
+		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
 	 */
@@ -625,21 +677,20 @@
 		Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
 		while (beanDescriptorIterator.hasNext()) {
 			BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-			
-			if  (! beanDescriptor.isAutoInsert())
-			{
+
+			if (!beanDescriptor.isAutoInsert()) {
 				continue;
 			}
-			
+
 			String jcrName = beanDescriptor.getJcrName();
 			Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
 			if (bean != null) {
 				if (beanDescriptor.isInline()) {
 					this.storeSimpleFields(session, bean, mapper.getClassDescriptorByClass(bean.getClass()),
objectNode);
-				} else if (null != beanDescriptor.getConverter() && ! "".equals(beanDescriptor.getConverter()))
{
-					String converterClassName =  beanDescriptor.getConverter();
+				} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter()))
{
+					String converterClassName = beanDescriptor.getConverter();
 					Object[] param = {this};
-					BeanConverter beanConverter =(BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,param);
+					BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,
param);
 					beanConverter.insert(session, objectNode, beanDescriptor, object);
 				} else {
 					this.insert(session, objectNode, jcrName, bean);
@@ -657,11 +708,10 @@
 			Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
 			while (beanDescriptorIterator.hasNext()) {
 				BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-				if  (! beanDescriptor.isAutoUpdate())
-				{
+				if (!beanDescriptor.isAutoUpdate()) {
 					continue;
 				}
-				
+
 				jcrName = beanDescriptor.getJcrName();
 				Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
 
@@ -670,10 +720,11 @@
 					if (beanDescriptor.isInline()) {
 						Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
 						this.storeSimpleFields(session, bean, mapper.getClassDescriptorByClass(beanClass),
objectNode);
-					} else if (null != beanDescriptor.getConverter() && ! "".equals(beanDescriptor.getConverter()))
{
-						String converterClassName =  beanDescriptor.getConverter();
+					} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter()))
{
+						String converterClassName = beanDescriptor.getConverter();
 						Object[] param = {this};
-						BeanConverter beanConverter =(BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,param);
+						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
+								.invokeConstructor(converterClassName, param);
 						beanConverter.remove(session, objectNode, beanDescriptor);
 					} else {
 						if (objectNode.hasNode(jcrName)) {
@@ -683,10 +734,11 @@
 				} else {
 					if (beanDescriptor.isInline()) {
 						this.storeSimpleFields(session, bean, mapper.getClassDescriptorByClass(bean.getClass()),
objectNode);
-					} else if (null != beanDescriptor.getConverter() && ! "".equals(beanDescriptor.getConverter()))
{
-						String converterClassName =  beanDescriptor.getConverter();
+					} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter()))
{
+						String converterClassName = beanDescriptor.getConverter();
 						Object[] param = {this};
-						BeanConverter beanConverter =(BeanConverter) ReflectionUtils.invokeConstructor(converterClassName,param);
+						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
+								.invokeConstructor(converterClassName, param);
 						beanConverter.update(session, objectNode, beanDescriptor, bean);
 					} else {
 						this.update(session, objectNode, jcrName, bean);
@@ -709,12 +761,11 @@
 
 		while (collectionDescriptorIterator.hasNext()) {
 			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
-			
-			if  (! collectionDescriptor.isAutoInsert())
-			{
+
+			if (!collectionDescriptor.isAutoInsert()) {
 				continue;
 			}
-			
+
 			CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
 			Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
 			ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
@@ -728,11 +779,10 @@
 
 		while (collectionDescriptorIterator.hasNext()) {
 			CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
-			if  (! collectionDescriptor.isAutoUpdate())
-			{
+			if (!collectionDescriptor.isAutoUpdate()) {
 				continue;
 			}
-			
+
 			CollectionConverter collectionConverter = this.getCollectionConverter(session, collectionDescriptor);
 			Object collection = ReflectionUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
 			ManageableCollection manageableCollection = ManageableCollectionUtil.getManageableCollection(collection);
@@ -845,6 +895,6 @@
 		}
 
 		return classDescriptor;
-	}	
-	
+	}
+
 }

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java?rev=408736&r1=408735&r2=408736&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java
Mon May 22 13:04:47 2006
@@ -46,8 +46,7 @@
 
 	public Object getObject(Session session, Node parentNode,BeanDescriptor descriptor, Class
beanClass)
 			throws PersistenceException, RepositoryException,JcrMappingException {
-        try {
-			log.debug("ParentBeanConverter  - path : " +parentNode.getPath());
+        try {			
 			Node grandParentNode = parentNode.getParent();
 			if (grandParentNode.getPath().equals("/"))
 			{



Mime
View raw message