incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r477346 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: dtd/ java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/beanconverter/ java/org/apache/portals/graffito/jcr/persistence/beanconvert...
Date Mon, 20 Nov 2006 21:22:20 GMT
Author: clombart
Date: Mon Nov 20 13:22:18 2006
New Revision: 477346

URL: http://svn.apache.org/viewvc?view=rev&rev=477346
Log:
Review bean converter support :
* Implement GRFT-118. Now the inline is supported with a specific bean converter (InlineBeanConverterImpl). 
* review java pck

Added:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java   (contents, props changed)
      - copied, changed from r469390, incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/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   (contents, props changed)
      - copied, changed from r469390, incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/SimpleFieldsHelper.java
Removed:
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/BeanConverter.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AbstractBeanConverterImpl.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/dtd/graffito-jcr-mapping.dtd
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.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-auto.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-beandescriptor.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
    incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.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

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd Mon Nov 20 13:22:18 2006
@@ -94,7 +94,6 @@
     * autoRetrieve : If false, the bean associated to this descriptor is not retrieved when the main ojbect is retrieved
     * autoUpdate : If false, the bean associated to this descriptor is not updated when the main ojbect is updated
     * autoInsert : If false, the bean associated to this descriptor is not inserted  when the main ojbect is inserted    
-    * inline: persist/retrieve bean properties from the current node (if true).
     * converter: fully qualified name of the converter class to be used (default is ObjectConverterImpl)
     * jcrNodeType: defines the child node type, optional
     * jcrAutoCreated (boolean) default is "false"
@@ -111,7 +110,6 @@
 	autoRetrieve (true|false) "true"
 	autoUpdate (true|false) "true"
 	autoInsert (true|false) "true"	
-	inline (true | false) "false"
 	converter CDATA #IMPLIED
 	jcrNodeType CDATA #IMPLIED
     jcrAutoCreated (true | false) "false"   

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java Mon Nov 20 13:22:18 2006
@@ -17,7 +17,7 @@
 package org.apache.portals.graffito.jcr.mapper.model;
 
 
-import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter;
+import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
 import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
 
@@ -35,8 +35,7 @@
     private boolean proxy;
     private boolean autoRetrieve = true;
     private boolean autoUpdate = true;
-    private boolean autoInsert = true;
-    private boolean inline;
+    private boolean autoInsert = true;    
     private String converter;
     private BeanConverter beanConverter;
     private String jcrNodeType;
@@ -115,24 +114,6 @@
 		this.autoUpdate = autoUpdate;
 	}
 
-	/**
-     * Are the current bean properties inlined in the parent
-     * 
-     * @return <tt>true</tt> if bean's properties are inlined in the parent node
-     */
-    public boolean isInline() {
-        return this.inline;
-    }
-
-    /**
-     * Sets if the bean's properties should be inlined in the parent
-     * instead of being persisted on a subnode
-     * 
-     * @param flag <tt>true</tt> if the bean properties should be inlined
-     */
-    public void setInline(boolean flag) {
-        this.inline = flag;
-    }
 
     /**
      * Get the <code>BeanConverter</code> fully qualified name or <tt>null</tt>

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java Mon Nov 20 13:22:18 2006
@@ -354,10 +354,9 @@
      */
     public void afterPropertiesSet() {
         validateClassName();   
-        validateBeanFields();
         lookupSuperDescriptor();
         lookupInheritanceSettings();
-//        validateInheritanceSettings();
+
     }
 
 	private void validateClassName() {
@@ -368,19 +367,6 @@
 		}
 	}
 
-	private void validateBeanFields()
-	{
-	         Iterator beanDescriptorIterator  =  beanDescriptors.values().iterator();
-	         while (beanDescriptorIterator.hasNext()) {
-              	        BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
-              	        if (beanDescriptor.isProxy() && beanDescriptor.isInline())
-              	        {
-              	        	     throw new JcrMappingException("Bean field can not be proxy and inline - class : " + this.className + " - bean field :" + beanDescriptor.getFieldName());	
-              	        }
-				       
-			}
-
-	}
 	
 	private void lookupSuperDescriptor() {
         if (null != superClassDescriptor) {

Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java (from r469390, incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/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=477346&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/BeanConverter.java&r1=469390&p2=incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/BeanConverter.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/BeanConverter.java Mon Nov 20 13:22:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.persistence.objectconverter;
+package org.apache.portals.graffito.jcr.persistence.beanconverter;
 
 
 import javax.jcr.Node;
@@ -24,6 +24,7 @@
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
 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;
 
 /**
  * Interface describing a custom bean converter. 
@@ -35,10 +36,11 @@
      * Insert the object.
      *
      * @param session the JCR session
-     * @param parentNode The parent node
-     * @param mapper available mappings
-     * @param beanName bean name to be inserter
-     * @param object bean
+     * @param parentNode The node which will contain the converter bean
+     * @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 
+     * @param parent the object which will contain the bean to convert 
      * 
      * @throws PersistenceException thrown in case the insert fails; marks a failure due to logic of
      *  the insert (parent node cannot be accessed, the insert fails, etc.)
@@ -47,17 +49,18 @@
      *  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, BeanDescriptor descriptor, Object object)
+    void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
 
     /**
      * Update repository from bean values.
      *
      * @param session the JCR session
-     * @param parentNode The parent node
-     * @param mapper available mappings
-     * @param beanName bean name to be updated
-     * @param object bean
+     * @param parentNode The node which will contain the converter bean
+     * @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
+     * @param parent the object which will contain the bean to convert 
      * 
      * @throws PersistenceException thrown in case the update fails; marks a failure due to logic
      *  of update (parent node cannot be accessed, the update fails, etc.)
@@ -66,7 +69,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, BeanDescriptor descriptor, Object object)
+    void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
     
     /**
@@ -74,9 +77,9 @@
      * 
      * @param session the JCR session
      * @param parentNode The parent node
-     * @param mapper available mappings
-     * @param beanName bean name to be retrieved
-     * @param beanClass class of the bean to be retrieved
+     * @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
      * 
      * @throws PersistenceException thrown in case the bean cannot be retrieved or initialized; 
      *  marks a failure due to logic of retrieval
@@ -85,7 +88,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, BeanDescriptor descriptor, Class beanClass) 
+    Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent) 
     throws PersistenceException, RepositoryException, JcrMappingException;
 
 
@@ -93,9 +96,11 @@
      * Remove the bean from the repository.
      * 
      * @param session the JCR session
-     * @param parentNode The parent node
-     * @param mapper available mappings
-     * @param beanName bean name to be retrieved
+     * @param parentNode The node which will contain the converter bean
+     * @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 
+     * @param parent the object which contains the bean to convert 
      * 
      * @throws PersistenceException thrown in case the bean cannot be removed; 
      *  marks a failure due to logic of removal
@@ -104,6 +109,6 @@
      *  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, BeanDescriptor descriptor)
+    void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object bean, ClassDescriptor parentClassDescriptor, Object parent)
     throws PersistenceException, RepositoryException, JcrMappingException;
 }

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

Added: 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=auto&rev=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/AbstractBeanConverterImpl.java Mon Nov 20 13:22:18 2006
@@ -0,0 +1,55 @@
+/*
+ * 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.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.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;
+
+public abstract class AbstractBeanConverterImpl implements BeanConverter {
+
+	protected ObjectConverter objectConverter;
+	protected Mapper mapper;
+	protected AtomicTypeConverterProvider atomicTypeConverterProvider;
+	
+	public AbstractBeanConverterImpl(Mapper mapper, ObjectConverter objectConverter, AtomicTypeConverterProvider atomicTypeConverterProvider)
+	{
+		this.mapper = mapper;
+		this.objectConverter = objectConverter;
+		this.atomicTypeConverterProvider = atomicTypeConverterProvider;
+	}
+	
+    public abstract void insert(Session session, Node parentNode, 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)
+			throws PersistenceException, RepositoryException,	JcrMappingException;
+	
+	public abstract Object getObject(Session session, Node parentNode, 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)
+	          throws PersistenceException,	RepositoryException, JcrMappingException ;
+}

Added: 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=auto&rev=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/InlineBeanConverterImpl.java Mon Nov 20 13:22:18 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.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.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;
+
+public class InlineBeanConverterImpl extends AbstractBeanConverterImpl  implements BeanConverter {
+
+	SimpleFieldsHelper simpleFieldsHelper; 
+	
+	public InlineBeanConverterImpl(Mapper mapper, ObjectConverter objectConverter, AtomicTypeConverterProvider atomicTypeConverterProvider) 
+	{
+		super(mapper, objectConverter, atomicTypeConverterProvider);
+		this.simpleFieldsHelper = new SimpleFieldsHelper(atomicTypeConverterProvider);
+	}
+
+	public void insert(Session session, Node parentNode, 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)
+			throws PersistenceException, RepositoryException, JcrMappingException {
+		simpleFieldsHelper.storeSimpleFields(session, object, beanClassDescriptor, parentNode);
+	}
+
+	public Object getObject(Session session, Node parentNode, 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)
+	          throws PersistenceException,	RepositoryException, JcrMappingException {
+				
+		simpleFieldsHelper.storeSimpleFields(session, object, beanClassDescriptor, parentNode);
+	}
+	
+	
+
+}

Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java (from r469390, 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/beanconverter/impl/ParentBeanConverterImpl.java?view=diff&rev=477346&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ParentBeanConverterImpl.java&r1=469390&p2=incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/beanconverter/impl/ParentBeanConverterImpl.java&r2=477346
==============================================================================
--- 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/beanconverter/impl/ParentBeanConverterImpl.java Mon Nov 20 13:22:18 2006
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.persistence.objectconverter.impl;
+package org.apache.portals.graffito.jcr.persistence.beanconverter.impl;
 
 import javax.jcr.Node;
 import javax.jcr.Session;
@@ -24,28 +24,30 @@
 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.model.BeanDescriptor;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+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;
 
 public class ParentBeanConverterImpl extends AbstractBeanConverterImpl  implements BeanConverter {
 
 	private final static Log log = LogFactory.getLog(ParentBeanConverterImpl.class);
 	
-	public ParentBeanConverterImpl(ObjectConverter objectConverter) 
+	public ParentBeanConverterImpl(Mapper mapper, ObjectConverter objectConverter, AtomicTypeConverterProvider atomicTypeConverterProvider) 
 	{
-		super(objectConverter);	
+		super(mapper, objectConverter, atomicTypeConverterProvider);	
 	}
 
-	public void insert(Session session, Node parentNode, BeanDescriptor descriptor, Object object)
+	public void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException, 	JcrMappingException {
 	}
 
-	public void update(Session session, Node parentNode, 	BeanDescriptor descriptor, Object object)
+	public void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 			throws PersistenceException, RepositoryException,	JcrMappingException {
 	}
 
-	public Object getObject(Session session, Node parentNode,BeanDescriptor descriptor, Class beanClass)
+	public Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent)
 			throws PersistenceException, RepositoryException,JcrMappingException {
         try {			
 			Node grandParentNode = parentNode.getParent();
@@ -61,7 +63,7 @@
 		
 	}
 
-	public void remove(Session session, Node parentNode,	BeanDescriptor descriptor)
+	public void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent)
 	          throws PersistenceException,	RepositoryException, JcrMappingException {
 
 	}

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

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=477346&r1=477345&r2=477346
==============================================================================
--- 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 Nov 20 13:22:18 2006
@@ -23,15 +23,11 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.ValueFormatException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 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;
@@ -44,14 +40,12 @@
 import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
 import org.apache.portals.graffito.jcr.persistence.PersistenceConstant;
-import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
-import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.NullTypeConverterImpl;
+import org.apache.portals.graffito.jcr.persistence.beanconverter.BeanConverter;
 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.collectionconverter.impl.DefaultCollectionConverterImpl;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 import org.apache.portals.graffito.jcr.persistence.objectconverter.ProxyManager;
 import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
@@ -67,13 +61,13 @@
 
 	private final static Log log = LogFactory.getLog(ObjectConverterImpl.class);
 
-	private static final AtomicTypeConverter NULL_CONVERTER = new NullTypeConverterImpl();
-
 	private Mapper mapper;
 
 	private AtomicTypeConverterProvider atomicTypeConverterProvider;
 
 	private ProxyManager proxyManager;
+	
+	private SimpleFieldsHelper simpleFieldsHelp;
 
 	/**
 	 * No-arg constructor.
@@ -94,6 +88,7 @@
 		this.mapper = mapper;
 		this.atomicTypeConverterProvider = converterProvider;
 		this.proxyManager = new ProxyManagerImpl();
+		this.simpleFieldsHelp = new SimpleFieldsHelper(atomicTypeConverterProvider);
 	}
 
 	/**
@@ -109,6 +104,7 @@
 		this.mapper = mapper;
 		this.atomicTypeConverterProvider = converterProvider;
 		this.proxyManager = proxyManager;
+		this.simpleFieldsHelp = new SimpleFieldsHelper(atomicTypeConverterProvider);
 	}	
 	/**
 	 * Set the <code>Mapper</code> used to solve mappings.
@@ -211,7 +207,7 @@
 					+ object.getClass(), re);
 		}
 
-		storeSimpleFields(session, object, classDescriptor, objectNode);
+		simpleFieldsHelp.storeSimpleFields(session, object, classDescriptor, objectNode);
 		insertBeanFields(session, object, classDescriptor, objectNode);
 		insertCollectionFields(session, object, classDescriptor, objectNode);
 	}
@@ -249,7 +245,7 @@
 
 			checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
 
-			storeSimpleFields(session, object, classDescriptor, objectNode);
+			simpleFieldsHelp.storeSimpleFields(session, object, classDescriptor, objectNode);
 			updateBeanFields(session, object, classDescriptor, objectNode);
 			updateCollectionFields(session, object, classDescriptor, objectNode);
 		} catch (PathNotFoundException pnfe) {
@@ -289,8 +285,7 @@
 			}
 
 			Object object = ReflectionUtils.newInstance(classDescriptor.getClassName());
-
-			retrieveSimpleFields(session, classDescriptor, node, object);
+			simpleFieldsHelp.retrieveSimpleFields(session, classDescriptor, node, object);			
 			retrieveBeanFields(session, classDescriptor, node, path, object, false);
 			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
@@ -345,7 +340,7 @@
 
 			}
 
-			retrieveSimpleFields(session, classDescriptor, node, object);
+			simpleFieldsHelp.retrieveSimpleFields(session, classDescriptor, node, object);			
 			retrieveBeanFields(session, classDescriptor, node, path, object, false);
 			retrieveCollectionFields(session, classDescriptor, node, object, false);
 
@@ -547,75 +542,6 @@
 	}
 
 	/**
-	 * 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() && classDescriptor.hasDiscriminator()) 
-					{
-						if ( ! node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) 
-						{
-							throw new PersistenceException("Class '" + classDescriptor.getClassName() + "' has not a discriminator property.");
-						}					
-					}
-					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,
@@ -641,13 +567,12 @@
 			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())) {
+			if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
 				String converterClassName = beanDescriptor.getConverter();
-				Object[] param = {this};
+				Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
+				
 				BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
-				bean = beanConverter.getObject(session, node, beanDescriptor, beanClass);
+				bean = beanConverter.getObject(session, node, mapper.getClassDescriptorByClass(beanClass), beanClass, bean);
 			} else {
 				bean = this.getObject(session, path + "/" + beanDescriptor.getJcrName());
 			}
@@ -704,13 +629,12 @@
 			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())) {
+                if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
 					String converterClassName = beanDescriptor.getConverter();
-					Object[] param = {this};
+					Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
 					BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
-					beanConverter.insert(session, objectNode, beanDescriptor, object);
+					beanConverter.insert(session, objectNode, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
+					
 				} else {
 					this.insert(session, objectNode, jcrName, bean);
 				}
@@ -736,29 +660,26 @@
 
 				// 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, mapper.getClassDescriptorByClass(beanClass), objectNode);
-					} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
+					if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) 
+					{
 						String converterClassName = beanDescriptor.getConverter();
-						Object[] param = {this};
+						Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
 						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
 								.invokeConstructor(converterClassName, param);
-						beanConverter.remove(session, objectNode, beanDescriptor);
+						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 (beanDescriptor.isInline()) {
-						this.storeSimpleFields(session, bean, mapper.getClassDescriptorByClass(bean.getClass()), objectNode);
-					} else if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
+                    if (null != beanDescriptor.getConverter() && !"".equals(beanDescriptor.getConverter())) {
 						String converterClassName = beanDescriptor.getConverter();
-						Object[] param = {this};
+						Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
 						BeanConverter beanConverter = (BeanConverter) ReflectionUtils
 								.invokeConstructor(converterClassName, param);
-						beanConverter.update(session, objectNode, beanDescriptor, bean);
+						beanConverter.update(session, objectNode, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
 					} else {
 						this.update(session, objectNode, jcrName, bean);
 					}
@@ -810,61 +731,6 @@
 		}
 	}
 
-	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;
-				}
-
-				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.getCollectionConverter();
@@ -876,45 +742,6 @@
 					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;
-		// Check if an atomic converter is assigned to the field converter
-		String atomicTypeConverterClass = fd.getConverter();
-		if (null != atomicTypeConverterClass)
-		{
-			return (AtomicTypeConverter) ReflectionUtils.newInstance(atomicTypeConverterClass);
-		}
-		else
-		{
-			// Get the default atomic converter in function of the classname
-			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) {

Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/SimpleFieldsHelper.java
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/SimpleFieldsHelper.java?view=auto&rev=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/SimpleFieldsHelper.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/SimpleFieldsHelper.java Mon Nov 20 13:22:18 2006
@@ -0,0 +1,234 @@
+/*
+ * 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.objectconverter.impl;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.PropertyDefinition;
+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.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
+import org.apache.portals.graffito.jcr.persistence.PersistenceConstant;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.NullTypeConverterImpl;
+import org.apache.portals.graffito.jcr.reflection.ReflectionUtils;
+
+/**
+ * Helper class used to map simple fields.
+ * 
+ * @author <a href="mailto:christophe.lombart@gmail.com">Lombart Christophe </a>
+ * 
+ */
+public class SimpleFieldsHelper
+{
+
+	private final static Log log = LogFactory.getLog(SimpleFieldsHelper.class);
+
+	private static final AtomicTypeConverter NULL_CONVERTER = new NullTypeConverterImpl();
+
+	private AtomicTypeConverterProvider atomicTypeConverterProvider;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param converterProvider The atomic type converter provider
+	 * 
+	 */
+	public SimpleFieldsHelper(AtomicTypeConverterProvider converterProvider) 
+	{
+		this.atomicTypeConverterProvider = converterProvider;
+	}
+
+	
+	/**
+	 * Retrieve simple fields (atomic fields)
+	 * 
+	 * @throws JcrMappingException
+	 * @throws org.apache.portals.graffito.jcr.exception.RepositoryException
+	 */
+	public 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() && classDescriptor.hasDiscriminator()) 
+					{
+						if ( ! node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) 
+						{
+							throw new PersistenceException("Class '" + classDescriptor.getClassName() + "' has not a discriminator property.");
+						}					
+					}
+					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;
+	}
+	
+	public 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;
+				}
+
+				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 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;
+		// Check if an atomic converter is assigned to the field converter
+		String atomicTypeConverterClass = fd.getConverter();
+		if (null != atomicTypeConverterClass)
+		{
+			return (AtomicTypeConverter) ReflectionUtils.newInstance(atomicTypeConverterClass);
+		}
+		else
+		{
+			// Get the default atomic converter in function of the classname
+			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;
+			}
+			
+		}
+	}
+
+}

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-auto.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-auto.xml?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-auto.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-auto.xml Mon Nov 20 13:22:18 2006
@@ -28,7 +28,7 @@
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="name" jcrName="graffito:name"  id="true" />
 		<bean-descriptor  fieldName="parentFolder"  					 
-						  converter="org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ParentBeanConverterImpl" />
+						  converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.ParentBeanConverterImpl" />
 
 	</class-descriptor>     
 

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-beandescriptor.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-beandescriptor.xml?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-beandescriptor.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-beandescriptor.xml Mon Nov 20 13:22:18 2006
@@ -7,7 +7,7 @@
 		<field-descriptor fieldName="d1" jcrName="d1" jcrType="String" jcrAutoCreated="false" jcrMandatory="false"
         jcrOnParentVersion="IGNORE" jcrProtected="false" jcrMultiple="false" />
 		
-		<bean-descriptor fieldName="b1" jcrName="b1" inline="true" />
+		<bean-descriptor fieldName="b1" jcrName="b1" converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.InlineBeanConverterImpl" />
 
 	</class-descriptor>
 	

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml
URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- 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 Mon Nov 20 13:22:18 2006
@@ -62,7 +62,7 @@
 		<field-descriptor fieldName="path" path="true" />
 		<field-descriptor fieldName="name" jcrName="graffito:name"  id="true" />
 		<bean-descriptor  fieldName="parentFolder"  					 
-						  converter="org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ParentBeanConverterImpl" />
+						  converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.ParentBeanConverterImpl" />
 
 	</class-descriptor>     
 

Modified: 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-testmappings.xml?view=diff&rev=477346&r1=477345&r2=477346
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-testmappings.xml Mon Nov 20 13:22:18 2006
@@ -27,7 +27,7 @@
 		<bean-descriptor fieldName="b" 
 						 jcrName="b" 
 						 proxy="false" 
-						 inline="true"
+						 converter="org.apache.portals.graffito.jcr.persistence.beanconverter.impl.InlineBeanConverterImpl"
 						 jcrNodeType="nt:unstructured"
         				 jcrAutoCreated="false" 
         				 jcrMandatory="false" 

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=477346&r1=477345&r2=477346
==============================================================================
--- 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 Nov 20 13:22:18 2006
@@ -85,9 +85,8 @@
 
 			BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
 			assertNotNull("BeanDescriptor is null", beanDescriptor);
-			assertTrue("Invalid jcrName for field b", beanDescriptor	.getJcrName().equals("b"));
-			assertEquals("Invalid bean-descriptor inline", true, beanDescriptor.isInline());
-			assertNull("Invalid bean default converter", beanDescriptor.getConverter());
+			assertTrue("Invalid jcrName for field b", beanDescriptor	.getJcrName().equals("b"));			
+			assertNotNull("Invalid bean default converter", beanDescriptor.getConverter());
 			
 
 			CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor("collection");

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=477346&r1=477345&r2=477346
==============================================================================
--- 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 Nov 20 13:22:18 2006
@@ -80,7 +80,6 @@
     }
     
     public void testInlined() throws Exception {
-        System.out.println("inlined");
         
         B expB = new B();
         expB.setB1("b1value");

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=477346&r1=477345&r2=477346
==============================================================================
--- 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 Nov 20 13:22:18 2006
@@ -24,17 +24,19 @@
 import javax.jcr.Session;
 
 import org.apache.portals.graffito.jcr.exception.PersistenceException;
-import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+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.persistence.objectconverter.impl.AbstractBeanConverterImpl;
 import org.apache.portals.graffito.jcr.testmodel.B;
 
 public class FakeBeanConverter extends AbstractBeanConverterImpl {
 
     private static  List log = new ArrayList();
     
-    public FakeBeanConverter(ObjectConverter objectConverter) {
-		super(objectConverter);
+    public FakeBeanConverter(Mapper mapper, ObjectConverter objectConverter, AtomicTypeConverterProvider atomicTypeConverterProvider) {
+		super(mapper, objectConverter, atomicTypeConverterProvider);
 		 
 		 
 	}
@@ -44,9 +46,9 @@
     }
         
     /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#insert(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
+     * @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, BeanDescriptor descriptor, Object object) throws PersistenceException {
+    public void insert(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
         try {
             log.add("insert at path " + parentNode.getPath());
             
@@ -57,9 +59,9 @@
     } 
 
     /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#update(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Object)
+     * @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, BeanDescriptor descriptor, Object object) throws PersistenceException {
+    public void update(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
         try {
             log.add("update at path " + parentNode.getPath());
         }
@@ -69,9 +71,9 @@
     }
 
     /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#getObject(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String, java.lang.Class)
+     * @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, BeanDescriptor descriptor, Class beanClass) throws PersistenceException {
+    public Object getObject(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Class beanClass, Object parent) throws PersistenceException {
         try {
             log.add("get from path " + parentNode.getPath());
         }
@@ -84,9 +86,9 @@
     }
 
     /**
-     * @see org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter#remove(javax.jcr.Session, javax.jcr.Node, org.apache.portals.graffito.jcr.mapper.Mapper, java.lang.String)
+     * @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, BeanDescriptor descriptor) throws PersistenceException {
+    public void remove(Session session, Node parentNode, ClassDescriptor beanClassDescriptor, Object object, ClassDescriptor parentClassDescriptor, Object parent) throws PersistenceException {
         try {
             log.add("remove from path " + parentNode.getPath());
         }



Mime
View raw message