You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2005/09/05 19:22:47 UTC

svn commit: r278817 - in /incubator/graffito/trunk/jcr-mapping/src: conf/ conf/convertertest/ conf/repository-test/ conf/repository-test/meta/ conf/repository-test/namespaces/ conf/repository-test/nodetypes/ dtd/ java/org/apache/portals/graffito/jcr/co...

Author: clombart
Date: Mon Sep  5 12:22:30 2005
New Revision: 278817

URL: http://svn.apache.org/viewcvs?rev=278817&view=rev
Log:
Refactor the current code:
* Drop the old converter classes
* Add the AtomicTypeConverter
* Add the ObjectConverter
* Review the PersistenceManager implementation
* Review tests

Added:
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rep.properties
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rootUUID
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/ns_reg.properties
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/
    incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/custom_nodetypes.xml
    incubator/graffito/trunk/jcr-mapping/src/dtd/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/CollectionFieldStrategy.java
      - copied, changed from r263842, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
Removed:
    incubator/graffito/trunk/jcr-mapping/src/conf/convertertest/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/converter/impl/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/
Modified:
    incubator/graffito/trunk/jcr-mapping/src/conf/repository.xml
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java
    incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java

Added: incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rep.properties
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rep.properties?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rep.properties (added)
+++ incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rep.properties Mon Sep  5 12:22:30 2005
@@ -0,0 +1,18 @@
+#Mon Sep 05 21:15:37 CEST 2005
+option.versioning.supported=true
+jcr.repository.version=1.0-dev
+jcr.repository.name=Jackrabbit
+option.observation.supported=true
+option.locking.supported=true
+option.transactions.supported=true
+jcr.repository.stats.nodes.count=12
+jcr.specification.name=Content Repository API for Java(TM) Technology Specification
+level.2.supported=true
+option.query.sql.supported=true
+level.1.supported=true
+jcr.repository.stats.properties.count=206
+jcr.repository.vendor=Apache Software Foundation
+jcr.specification.version=1.0
+query.xpath.doc.order=true
+query.xpath.pos.index=true
+jcr.repository.vendor.url=http\://www.apache.org/

Added: incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rootUUID
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rootUUID?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rootUUID (added)
+++ incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/meta/rootUUID Mon Sep  5 12:22:30 2005
@@ -0,0 +1 @@
+cafebabe-cafe-babe-cafe-babecafebabe
\ No newline at end of file

Added: incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/ns_reg.properties
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/ns_reg.properties?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/ns_reg.properties (added)
+++ incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/namespaces/ns_reg.properties Mon Sep  5 12:22:30 2005
@@ -0,0 +1,11 @@
+#Thu Sep 01 10:14:30 CEST 2005
+xs=http\://www.w3.org/2001/XMLSchema
+graffito=http\://incubator.apache.org/graffito
+xml=http\://www.w3.org/XML/1998/namespace
+jcr=http\://www.jcp.org/jcr/1.0
+nt=http\://www.jcp.org/jcr/nt/1.0
+fn=http\://www.w3.org/2004/10/xpath-functions
+rep=internal
+sv=http\://www.jcp.org/jcr/sv/1.0
+mix=http\://www.jcp.org/jcr/mix/1.0
+=

Added: incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/custom_nodetypes.xml?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/custom_nodetypes.xml (added)
+++ incubator/graffito/trunk/jcr-mapping/src/conf/repository-test/nodetypes/custom_nodetypes.xml Mon Sep  5 12:22:30 2005
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ -->
+<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:test="http://www.apache.org/jackrabbit/test" 
+	       xmlns:mix="http://www.jcp.org/jcr/mix/1.0"   xmlns:graffito="http://incubator.apache.org/graffito">
+  <nodeType name="graffito:C" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mix:versionable</supertype>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false" />
+    <propertyDefinition name="graffito:id" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />
+	<propertyDefinition name="graffito:name" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />
+
+  </nodeType>
+</nodeTypes>
+

Modified: incubator/graffito/trunk/jcr-mapping/src/conf/repository.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/conf/repository.xml?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/conf/repository.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/conf/repository.xml Mon Sep  5 12:22:30 2005
@@ -131,7 +131,7 @@
         (e.g. registered namespaces, custom node types, etc.)
     -->
     <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-        <param name="path" value="${rep.home}/repository"/>
+        <param name="path" value="${rep.home}/../../src/conf/repository-test"/>
     </FileSystem>
 
     <!--

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverter.java Mon Sep  5 12:22:30 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+/**
+ * Implementations of this class can create additional atomic types. They act
+ * as flyweights. They not only avoid overhead of instance creation but especially
+ * unnecessary conversions. They should be reused in the application domain
+ * model as much as possible. 
+ * These additional types can be registered with the AtomicTypeConverterFactory.
+ * 
+ * The returning objects of the java read methods as defined in the mapping model
+ * are converted with the getJcrValueFromJavaObject method to JCR-Values and stored
+ * in the repository.
+ * 
+ * @ToDo: Explain the general relationship to the mapping specified
+ * in the JavaToJcrMapping.xml file. Maybe also the role in the 
+ * persistance manager.
+ * @ToDo: Should we specify the converter in the mapping xml-file
+ * instead of using reflection on the objects to store (see
+ * ObjectToItemConverter)?
+ * @ToDo: Integrate "null" value handling.
+ */
+public abstract class AtomicTypeConverter {
+
+
+	private ValueFactory valueFactory;
+
+	public abstract String getPropertyType();
+	
+	public abstract Class[] getJavaTypes();
+	
+	Class[] getAndCheckJavaTypes(){
+	    Class[] javaTypes = getJavaTypes();
+	    if (javaTypes==null || javaTypes.length==0) throw new RuntimeException("An AtomicTypeConverter has to return an array of at least one java type in the getJavaTypes() method. It is not allowed to return null or an empty array.");
+	    return javaTypes;
+	}
+	
+	/**
+	 * The mapping framework ensures, that only objects of the types returned by getJavaTypes
+	 * are forwarded to this method. A type check is not needed. 
+	 * @param propValue
+	 * @return
+	 */
+	public abstract Value getJcrValueFromJavaObject(Object propValue);	
+
+	public abstract Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException;
+	
+	void setValueFactory(ValueFactory aValueFactory){
+		this.valueFactory = aValueFactory;
+	}
+
+	public ValueFactory getValueFactory(){
+		return this.valueFactory;
+	}
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/atomictypeconverter/AtomicTypeConverterFactory.java Mon Sep  5 12:22:30 2005
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.atomictypeconverter;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+
+
+
+/**
+ * According to the Flyweight pattern you can register new atomic types (flyweights)
+ * in this factory. 
+ * They not only avoid overhead of instance creation but especially
+ * unnecessary conversions. They should be reused in the application domain
+ * model as much as possible. 
+ * 
+ * @ToDo:Methods using these types can be specified in the JavaToJcrMapping
+ * XML file. 
+ * @ToDo: The types itself should also be specified in the XML file.
+ * 
+ */
+public class AtomicTypeConverterFactory {
+	private AtomicTypeConverter stringTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_STRING;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			return this.getValueFactory().createValue((String) propValue);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			return node.getProperty(jcrPropName).getString();
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={String.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter binaryTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_BINARY;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			return this.getValueFactory().createValue((InputStream) propValue);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			return node.getProperty(jcrPropName).getStream();
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={InputStream.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter intTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_LONG;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			long value = ((Integer) propValue).intValue();
+			return this.getValueFactory().createValue(value);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			int beanPropValue = (int) node.getProperty(jcrPropName).getLong();
+			return new Integer(beanPropValue);
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={Integer.class, int.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter longTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_LONG;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			long value = ((Long) propValue).longValue();
+			return this.getValueFactory().createValue(value);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			long beanPropValue = node.getProperty(jcrPropName).getLong();
+			return new Long(beanPropValue);
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={Long.class, long.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter doubleTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_DOUBLE;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			double value = ((Double) propValue).doubleValue();
+			return this.getValueFactory().createValue(value);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			double beanPropValue = node.getProperty(jcrPropName).getDouble();
+			return new Double(beanPropValue);
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={Double.class, double.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter calendarTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_DATE;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			return this.getValueFactory().createValue((Calendar) propValue);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			return node.getProperty(jcrPropName).getDate();
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={Calendar.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter utilDateTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_DATE;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTime((java.util.Date)propValue);
+			return this.getValueFactory().createValue(calendar);
+		}
+
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			Calendar calendar =  node.getProperty(jcrPropName).getDate();
+			Date date = calendar.getTime();
+			return date;
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={java.util.Date.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter booleanTypeConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_BOOLEAN;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			boolean value = ((Boolean) propValue).booleanValue();
+			return this.getValueFactory().createValue(value);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			boolean aBoolean= node.getProperty(jcrPropName).getBoolean();
+			return new Boolean(aBoolean);
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={Boolean.class, boolean.class}; 
+            return javaTypes;
+        }
+	};
+	private AtomicTypeConverter byteArrayConverter = new AtomicTypeConverter(){
+		public String getPropertyType(){
+			return PropertyType.TYPENAME_STRING;
+		}
+		public Value getJcrValueFromJavaObject(Object propValue){
+			if (propValue==null) return null;
+			String value = new String((byte[]) propValue);
+			return getValueFactory().createValue(value);
+		}
+		public Object getJavaObjectFromJcr(Node node, String jcrPropName) throws ValueFormatException, PathNotFoundException, RepositoryException{
+			String aString= node.getProperty(jcrPropName).getString();
+			return aString;
+		}
+        public Class[] getJavaTypes() {
+            Class[] javaTypes ={byte[].class}; 
+            return javaTypes;
+        }
+	};
+	
+	
+	private Map typeConverterMap = new HashMap();
+	
+	private static AtomicTypeConverterFactory thisInstance;
+
+	private ValueFactory valueFactory;
+
+	private AtomicTypeConverterFactory(ValueFactory aValueFactory){
+		this.valueFactory=aValueFactory; //it's needed for the registration
+		this.registerTypeConverter(stringTypeConverter);
+		this.registerTypeConverter(binaryTypeConverter);
+		this.registerTypeConverter(longTypeConverter);
+		this.registerTypeConverter(intTypeConverter);
+		this.registerTypeConverter(doubleTypeConverter);
+		this.registerTypeConverter(booleanTypeConverter);
+		this.registerTypeConverter(calendarTypeConverter);
+		this.registerTypeConverter(utilDateTypeConverter);
+		this.registerTypeConverter(byteArrayConverter);
+	}
+
+	public void registerTypeConverter(AtomicTypeConverter converter){
+	    Class[] javaTypes = converter.getAndCheckJavaTypes();
+	    for (int i=0; i<converter.getJavaTypes().length; i++){
+	        if (this.typeConverterMap.containsKey(javaTypes[i])){
+	            throw new RuntimeException("The java type '"+javaTypes[i]+"' has already been registered.");
+	        }else {
+	            this.typeConverterMap.put(javaTypes[i],converter);
+	        }
+			converter.setValueFactory(this.valueFactory);
+	    }
+	}
+	
+	public AtomicTypeConverter getJCRTypeConverter(Class javaType){
+	    if(!this.typeConverterMap.containsKey(javaType)){
+            throw new RuntimeException("The java type '"+javaType+"' is not registered.");	        
+	    }
+		return (AtomicTypeConverter) this.typeConverterMap.get(javaType);
+	}
+	
+	/**
+	 * @param session
+	 * @return
+	 * @throws UnsupportedRepositoryOperationException - if writing to the repository is not supported.
+	 * @throws RepositoryException - if another error occurs.
+	 */
+	public static AtomicTypeConverterFactory getInstance(ValueFactory aValueFactory) throws UnsupportedRepositoryOperationException, RepositoryException{
+		if (AtomicTypeConverterFactory.thisInstance==null){
+			AtomicTypeConverterFactory.thisInstance=new AtomicTypeConverterFactory(aValueFactory);
+		}
+		return AtomicTypeConverterFactory.thisInstance;
+	}
+	
+	public boolean isTypeRegistered(Class type){
+		return this.typeConverterMap.containsKey(type);
+	}
+	
+	public String getJCRPropertyType(Class javaType){
+		AtomicTypeConverter typeConverter = (AtomicTypeConverter) this.typeConverterMap.get(javaType);
+		return typeConverter.getPropertyType();
+	}
+}

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Mon Sep  5 12:22:30 2005
@@ -23,11 +23,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.portals.graffito.jcr.converter.Converter;
-import org.apache.portals.graffito.jcr.converter.ConverterManager;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
 import org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterFactory;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
 
 /** Interface that specifies howto interact with a jcr repository (JCR broker).
  * 
@@ -42,10 +43,7 @@
      */
     private final static Log log = LogFactory.getLog(PersistenceManagerImpl.class);    
     
-    /** Converter manager needed for graffito managed content objects.
-     */
-    private ConverterManager converterManager;
-    
+   
     /** Jackrabbit jcr repository.
      */
     private Repository repository;
@@ -53,11 +51,27 @@
     /** Jackrabbit jcr session.
      */
     private Session session;
+       
 
     /** Custom node type creator dependency needed during repository setup.
      */
     private CustomNodeTypeCreator jcrCustomNodeTypeCreator;
+    
+    /**
+     * The Mapper component
+     */
+    private Mapper mapper; 
 
+    /**
+     * The Atomic Type Converter Factory
+     */
+    private AtomicTypeConverterFactory atomicTypeConverterFactory;
+    
+    /**
+     * Object Converter
+     */
+    private ObjectConverter objectConverter;
+    
     /** Graffito namespace prefix constant.
      */
     private static final String GRAFFITO_NAMESPACE_PREFIX   = "graffito";
@@ -69,18 +83,28 @@
     /**
      * Contructor for setting up a session to interact with a jcr repository. 
      * 
-     * @param converterManager The converter manager
-     * @param repository The Repository
+     * @param mapper the Mapper component
+     * @param repository The JCR repository reference
      * @param session The JCR Session
      * @param jcrCustomNodeTypeCreator Custom node type creator
+     * @throws JcrMappingException when it is impossible to create the PersistenceManager
      */
-    public PersistenceManagerImpl(ConverterManager converterManager, Repository repository,
-            Session session, CustomNodeTypeCreator jcrCustomNodeTypeCreator)
+    public PersistenceManagerImpl(Mapper mapper, Repository repository, Session session, CustomNodeTypeCreator jcrCustomNodeTypeCreator) throws JcrMappingException
     {
-        this.converterManager = converterManager;
+       try
+       {
+        this.mapper = mapper;
         this.repository = repository;
         this.session = session;
+        this.atomicTypeConverterFactory = AtomicTypeConverterFactory.getInstance(session.getValueFactory());
+        this.objectConverter = new ObjectConverter(mapper, atomicTypeConverterFactory);
         this.jcrCustomNodeTypeCreator = jcrCustomNodeTypeCreator;
+        
+       }
+       catch(Exception e)
+       {
+           throw new JcrMappingException("Impossible to create the persistenceManager", e);
+       }
     }
     
     /**
@@ -113,10 +137,10 @@
                 log.info("Jcr repository setup successfull.");
             }
             
-            if (getJcrCustomNodeTypeCreator().createInitialJcrCustomNodeTypes())
-            {
-                log.info("Jcr custom node type creation successful.");
-            }
+//            if (getJcrCustomNodeTypeCreator().createInitialJcrCustomNodeTypes())
+//            {
+//                log.info("Jcr custom node type creation successful.");
+//            }
         }
         catch (Exception e)
         {
@@ -163,15 +187,16 @@
             if (!session.itemExists(path))
             {
                 return null;
-            }
+            }                      
+
         }
-        catch (RepositoryException re)
+        catch (Exception e)
         {
-            throw new JcrMappingException(re.getMessage());
-        }
+            throw new JcrMappingException("Impossible to get the object at " + path, e);
+        }    
         
-        Converter converter = converterManager.getConverter(pojoClass);
-        return converter.getObject(session, pojoClass, path);
+        return objectConverter.getObject(session, pojoClass, path);
+                
     }
     
     /**
@@ -192,8 +217,9 @@
             throw new JcrMappingException(re.getMessage());
         }
         
-        Converter converter = converterManager.getConverter(object.getClass());
-        converter.insert(session, path, object);
+        
+        objectConverter.insert(session, path, object);
+        
     }
 
     /**
@@ -214,8 +240,7 @@
             throw new JcrMappingException(re.getMessage());
         }
         
-        Converter converter = converterManager.getConverter(object.getClass());
-        converter.update(session, path, object);
+        objectConverter.update(session, path, object);  
     }
         
     /**
@@ -271,5 +296,6 @@
     {
         this.jcrCustomNodeTypeCreator = object;
     }
+    
   
 }

Copied: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/CollectionFieldStrategy.java (from r263842, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/CollectionFieldStrategy.java?p2=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/CollectionFieldStrategy.java&p1=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java&r1=263842&r2=278817&rev=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/CollectionFieldStrategy.java Mon Sep  5 12:22:30 2005
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.converter.generic.collection;
+package org.apache.portals.graffito.jcr.persistence.objectconverter;
 
 
 import java.util.Collection;

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java?rev=278817&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/ObjectConverter.java Mon Sep  5 12:22:30 2005
@@ -0,0 +1,417 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.persistence.objectconverter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
+import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterFactory;
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+
+/**
+ * Convert any kind of bean by using the xml mapping file
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class ObjectConverter
+{
+    private Mapper mapper;
+    private AtomicTypeConverterFactory atomicTypeConverterFactory;
+
+    public ObjectConverter(Mapper mapper, AtomicTypeConverterFactory atomicTypeConverterFactory)
+    {
+        this.mapper = mapper;
+        this.atomicTypeConverterFactory = atomicTypeConverterFactory;
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#insert(javax.jcr.Session, java.lang.String, java.lang.Object)
+     */
+    public void insert(Session session, String path, Object object) throws JcrMappingException
+    {
+        try
+        {
+            String parentPath = RepositoryUtil.getParentPath(path);
+            String nodeName = RepositoryUtil.getNodeName(path);
+            Node parentNode = (Node) session.getItem(parentPath);
+            this.insertNode(session, parentNode, nodeName, object);            
+            parentNode.save();
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#update(javax.jcr.Session, java.lang.String, java.lang.Object)
+     */
+    public void update(Session session, String path, Object object) throws JcrMappingException
+    {
+        try
+        {
+            String parentPath = RepositoryUtil.getParentPath(path);
+            String nodeName = RepositoryUtil.getNodeName(path);
+            Node parentNode = (Node) session.getItem(parentPath);
+            this.updateNode(session, parentNode, nodeName, object);
+            parentNode.save();
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the object at " + path, e);
+        }
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session, java.lang.Class, java.lang.String)
+     */
+    public Object getObject(Session session, Class clazz, String path) throws JcrMappingException
+    {
+
+        try
+        {
+            ClassDescriptor classDescriptor = mapper.getClassDescriptor(clazz);
+
+            Node node = (Node) session.getItem(path);
+            Object object = clazz.newInstance();
+
+            retrieveSimpleFields(classDescriptor, node, object);
+            retrieveBeanFields(session, path, classDescriptor, object);
+            retrieveCollectionFields(session, classDescriptor, node, object);
+            
+            return object;
+
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to get the object at " + path, e);
+        }
+    }
+
+    /**
+     * @param classDescriptor
+     * @param node
+     * @param object
+     * @throws PathNotFoundException
+     * @throws RepositoryException
+     * @throws ValueFormatException
+     * @throws JcrMappingException
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     * @throws NoSuchMethodException
+     */
+    private void retrieveSimpleFields(ClassDescriptor classDescriptor, Node node, Object object) throws PathNotFoundException, RepositoryException, ValueFormatException, JcrMappingException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
+    {
+        Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
+        
+        while (fieldDescriptorIterator.hasNext())
+        {
+            FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
+            String fieldName = fieldDescriptor.getFieldName();
+            String propertyName = fieldDescriptor.getJcrName();
+            
+            AtomicTypeConverter converter = atomicTypeConverterFactory.getJCRTypeConverter(PropertyUtils.getPropertyType(object, fieldName));
+            Object fieldValue = converter.getJavaObjectFromJcr(node, propertyName);
+            
+            PropertyUtils.setNestedProperty(object, fieldName, fieldValue);
+        }        
+    }    
+    
+    
+    /**
+     * @param session
+     * @param path
+     * @param classDescriptor
+     * @param object
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     * @throws NoSuchMethodException
+     * @throws JcrMappingException
+     */
+    private void retrieveBeanFields(Session session, String path, ClassDescriptor classDescriptor, Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, JcrMappingException
+    {
+        Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+        while (beanDescriptorIterator.hasNext())
+        {
+            BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+            String beanName = beanDescriptor.getFieldName();
+            Class beanClass = PropertyUtils.getPropertyDescriptor(object, beanName).getPropertyType();
+            Object bean = this.getObject(session, beanClass, path + "/" + beanDescriptor.getJcrName());
+            PropertyUtils.setNestedProperty(object, beanName, bean);
+        }
+    }
+
+    
+    /**
+     * @param session
+     * @param classDescriptor
+     * @param node
+     * @param object
+     * @throws PathNotFoundException
+     * @throws RepositoryException
+     * @throws JcrMappingException
+     * @throws ClassNotFoundException
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     * @throws NoSuchMethodException
+     */
+    private void retrieveCollectionFields(Session session, ClassDescriptor classDescriptor, Node node, Object object) throws PathNotFoundException, RepositoryException, JcrMappingException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
+    {
+        Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+        while(collectionDescriptorIterator.hasNext())
+        {
+            CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+            String jcrName = collectionDescriptor.getJcrName();
+            String fieldName = collectionDescriptor.getFieldName();
+            
+            Node collectionNode = node.getNode(jcrName);
+            NodeIterator children = collectionNode.getNodes();
+            
+            //TODO : support other collection type and Map ? 
+            Collection collection = new ArrayList();
+            while (children.hasNext())
+            {
+                Node itemNode = children.nextNode();
+                Object item = this.getObject(session, Class.forName(collectionDescriptor.getClassName()), itemNode.getPath());
+                collection.add(item);                    
+            }
+            
+            PropertyUtils.setNestedProperty(object, fieldName, collection);
+        }
+    }
+
+    private void insertNode(Session session, Node parentNode, String nodeName, Object object) throws JcrMappingException
+    {
+        try
+        {
+            ClassDescriptor classDescriptor = mapper.getClassDescriptor(object.getClass());
+            String jcrNodeType = classDescriptor.getJcrNodeType();
+            if (jcrNodeType == null || jcrNodeType.equals(""))
+            {
+                throw new JcrMappingException("Undefined node type for  " + parentNode);
+            }
+
+            Node objectNode = null;
+            objectNode = parentNode.addNode(nodeName, jcrNodeType);
+
+            storeSimpleFields(object, classDescriptor, objectNode);
+            insertBeanFields(session, object, classDescriptor, objectNode);            
+            insertCollectionFields(session, object, classDescriptor, objectNode);
+            
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to add the node : " + parentNode);
+        }
+
+    }
+
+    private void updateNode(Session session, Node parentNode, String nodeName, Object object) throws JcrMappingException
+    {
+        try
+        {
+            ClassDescriptor classDescriptor = mapper.getClassDescriptor(object.getClass());
+            String jcrNodeType = classDescriptor.getJcrNodeType();
+            if (jcrNodeType == null || jcrNodeType.equals(""))
+            {
+                throw new JcrMappingException("Undefined node type for  " + parentNode);
+            }
+
+            Node objectNode = null;
+            objectNode = parentNode.getNode(nodeName);
+
+            storeSimpleFields(object, classDescriptor, objectNode);
+            updateBeanFields(session, object, classDescriptor, objectNode);            
+            updateCollectionFields(session, object, classDescriptor, objectNode);
+            
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to add the node : " + parentNode);
+        }
+
+    }    
+    private void insertBeanFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) throws JcrMappingException
+    {
+        try
+        {
+            Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+            while (beanDescriptorIterator.hasNext())
+            {
+                BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+                String jcrName = beanDescriptor.getJcrName();
+                Object bean = PropertyUtils.getNestedProperty(object, beanDescriptor.getFieldName());
+                this.insertNode(session, objectNode, jcrName, bean);
+
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the bean fields", e);
+        }
+        
+    }
+    
+    private void updateBeanFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) throws JcrMappingException
+    {
+        try
+        {
+            Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
+            while (beanDescriptorIterator.hasNext())
+            {
+                BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
+                String jcrName = beanDescriptor.getJcrName();
+                Object bean = PropertyUtils.getNestedProperty(object, beanDescriptor.getFieldName());
+                this.updateNode(session, objectNode, jcrName, bean);
+
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the bean fields", e);
+        }
+        
+    }    
+    
+    private void insertCollectionFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) throws JcrMappingException
+    {
+        try
+        {
+            Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+            while (collectionDescriptorIterator.hasNext())
+            {
+                CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+                String jcrName = collectionDescriptor.getJcrName();
+                String fieldIdName = collectionDescriptor.getFieldId();
+                Node collectionNode = null;
+                
+                // If a jcrName is defined for this collection : add or get the node used for the collection                
+                if (jcrName != null)
+                {
+                    collectionNode = objectNode.addNode(jcrName);
+                }
+                else
+                {
+                    collectionNode = objectNode; 
+                }
+                
+                //TODO : manage null value for the collection
+                Collection collection = (Collection) PropertyUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
+                
+                Iterator collectionIterator = collection.iterator();
+                while(collectionIterator.hasNext())
+                {
+                    Object item = collectionIterator.next();
+                    String jcrNameCollection = (String) PropertyUtils.getNestedProperty(item, fieldIdName);
+                    this.insertNode(session, collectionNode, jcrNameCollection, item);    
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the bean fields", e);
+        }
+        
+    }    
+    
+    private void updateCollectionFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) throws JcrMappingException
+    {
+        try
+        {
+            Iterator collectionDescriptorIterator = classDescriptor.getCollectionDescriptors().iterator();
+            while (collectionDescriptorIterator.hasNext())
+            {
+                CollectionDescriptor collectionDescriptor = (CollectionDescriptor) collectionDescriptorIterator.next();
+                String jcrName = collectionDescriptor.getJcrName();
+                String fieldIdName = collectionDescriptor.getFieldId();
+                Node collectionNode = null;
+                
+                // If a jcrName is defined for this collection : add or get the node used for the collection                
+                if (jcrName != null)
+                {
+                    collectionNode = objectNode.getNode(jcrName);
+                }
+                else
+                {
+                    collectionNode = objectNode; 
+                }
+                
+                //TODO : manage null value for the collection
+                Collection collection = (Collection) PropertyUtils.getNestedProperty(object, collectionDescriptor.getFieldName());
+                
+                Iterator collectionIterator = collection.iterator();
+                while(collectionIterator.hasNext())
+                {
+                    Object item = collectionIterator.next();
+                    String jcrNameCollection = (String) PropertyUtils.getNestedProperty(item, fieldIdName);
+                    this.updateNode(session, collectionNode, jcrNameCollection, item);    
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the bean fields", e);
+        }
+        
+    }      
+
+    private void storeSimpleFields(Object object, ClassDescriptor classDescriptor, Node objectNode) throws JcrMappingException
+    {
+        try
+        {
+            Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
+            while (fieldDescriptorIterator.hasNext())
+            {
+                FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();
+                String fieldName = fieldDescriptor.getFieldName();
+                String jcrName = fieldDescriptor.getJcrName();
+                
+                Object fieldValue = PropertyUtils.getNestedProperty(object, fieldName);                
+                
+                AtomicTypeConverter converter = atomicTypeConverterFactory.getJCRTypeConverter(PropertyUtils.getPropertyType(object, fieldName));
+                Value value = converter.getJcrValueFromJavaObject(fieldValue);
+                objectNode.setProperty(jcrName, value);
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to store the bean fields", e);
+        }
+    }
+}

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/repository/RepositoryUtil.java Mon Sep  5 12:22:30 2005
@@ -198,79 +198,5 @@
         }        
         return pathElements[pathElements.length-1];
     }
-    
-    /**
-     * Method converter between object type and Jackrabbit value object
-     * @param object
-     * @return the Jcr value object 
-     * @throws JcrMappingException
-     */
-    public static Value getValue(Object object) throws JcrMappingException
-    {
-           if (object instanceof String)
-           {
-               return new StringValue((String) object);
-           }
-           
-           if (object instanceof Timestamp)
-           {
-               Calendar calendar = Calendar.getInstance();
-               calendar.setTimeInMillis( ((Timestamp) object).getTime());
-               return new DateValue(calendar);
-               
-           }
-           
-           if (object instanceof Date)
-           {
-               Calendar calendar = Calendar.getInstance();
-               calendar.setTime((Date) object);
-               return new DateValue(calendar);
-               
-           }
-           
-           throw new JcrMappingException("Unsupported object type : " + object.getClass());
-    }
-
-    /**
-     * Method converter between Jackrabbit value object and object type
-     * @param object
-     * @return the Jcr value object 
-     * @throws JcrMappingException
-     */
-    public static Object getObject(Value value) throws JcrMappingException
-    {
-        try
-        {
-           if (value.getType() == PropertyType.STRING)
-           {
-               return value.getString();
-           }
-
-           if (value.getType() == PropertyType.DATE)
-           {
-               return value.getDate().getTime();
-               
-           }
-           
-           /*  
-           * PropertyType.DATE
-           * PropertyType.BINARY
-           * PropertyType.DOUBLE
-           * PropertyType.LONG
-           * PropertyType.BOOLEAN
-           * PropertyType.NAME
-           * PropertyType.PATH
-           * PropertyType.REFERENCE
-           * PropertyType.UNDEFINED
-           */
-           
-           throw new JcrMappingException("Unsupported value type : " + value);
-        }
-        catch(Exception e)
-        {
-            throw new JcrMappingException("Unsupported value type : " + value, e);
-        }
-    }
-    
-
+      
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml Mon Sep  5 12:22:30 2005
@@ -59,12 +59,11 @@
 			<field-descriptor fieldName="b2" jcrName="b2" />
             
 		</class-descriptor>
-
-		<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.C"  jcrNodeType= "nt:unstructured" >
+		
+		<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.C"  jcrNodeType="graffito:C" >
 		    <!-- Field-descriptor is used to map simple attributes to jcr property -->
-			<field-descriptor fieldName="id" jcrName="id" />   
-			<field-descriptor fieldName="name" jcrName="name" />
-            
+			<field-descriptor fieldName="id" jcrName="graffito:id" />   
+			<field-descriptor fieldName="name" jcrName="graffito:name" />            
 		</class-descriptor>		
 		
 </graffito-jcr>

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestAll.java Mon Sep  5 12:22:30 2005
@@ -20,7 +20,6 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.portals.graffito.jcr.converter.impl.ConverterManagerTest;
 import org.apache.portals.graffito.jcr.persistence.impl.PersistencManagerSetupTest;
 import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerTest;
 import org.apache.portals.graffito.jcr.repository.RepositoryUtilTest;
@@ -40,8 +39,7 @@
     {
         TestSuite suite = new TestSuite("graffito jcr-mapping tests");
         suite.addTestSuite(PersistencManagerSetupTest.class);
-        suite.addTestSuite(PersistenceManagerTest.class);
-        suite.addTestSuite(ConverterManagerTest.class);
+        suite.addTestSuite(PersistenceManagerTest.class);        
         suite.addTestSuite(RepositoryUtilTest.class);
         return suite;
     }

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java Mon Sep  5 12:22:30 2005
@@ -21,8 +21,6 @@
 
 import junit.framework.TestCase;
 
-import org.apache.portals.graffito.jcr.converter.ConverterManager;
-import org.apache.portals.graffito.jcr.converter.impl.ConverterManagerImpl;
 import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
 import org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator;
 import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
@@ -59,17 +57,15 @@
     protected void setUp() throws Exception
     {
         DigesterMapperImpl mapper =  new DigesterMapperImpl("./src/test/jcrmapping.xml");
-        
-        /* Reads the object converters from an xml configuration file. This
-        file contains the mapping for object converter classes. */
-        ConverterManager converterManager = new ConverterManagerImpl("src/conf/convertertest/converters.xml", mapper);
-        
+               
         RepositoryUtil.registerRepository("repositoryTest", "src/conf/repository.xml", "target/repository");
         Repository repository = RepositoryUtil.getRepository("repositoryTest");
         // optaining a read/write session to the repository
         Session session = RepositoryUtil.login(repository, "superuser", "superuser");
         CustomNodeTypeCreator customNodeTypeCreator = new CustomNodeTypeCreatorImpl();
-        setPersistenceManager(new PersistenceManagerImpl(converterManager, repository, session, customNodeTypeCreator));
+        persistenceManager = new PersistenceManagerImpl(mapper, repository, session, customNodeTypeCreator);
+        persistenceManager.setupRepository();
+        
     }
 
     /**

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java?rev=278817&r1=278816&r2=278817&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java Mon Sep  5 12:22:30 2005
@@ -48,7 +48,7 @@
      */
     public void testSetupRepository() throws Exception
     {
-        getPersistenceManager().setupRepository();
+        //getPersistenceManager().setupRepository(); => Done in TestBase in order to garantee a correct initialisation
         
         assertNotNull(getPersistenceManager().getSession().getRootNode());