incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r263842 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/converter/generic/ java/org/apache/portals/graffito/jcr/converter/generic/collection/ java/org/apache/portals/graffito/jcr/converter/generic/impl/ ...
Date Sun, 28 Aug 2005 08:15:25 GMT
Author: clombart
Date: Sun Aug 28 01:15:06 2005
New Revision: 263842

URL: http://svn.apache.org/viewcvs?rev=263842&view=rev
Log:
Refactoring : 
* Rename JcrSession into PersistenceManager (in order to be compliant with Sandro proposal)
* Create interfaces for the Mapper & PersistenceManager with Default implementation.
* Review unit tests

Added:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/
    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/converter/generic/impl/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/impl/GenericConverter.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/CustomNodeTypeCreator.java
      - copied, changed from r239451, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/CustomNodeTypeCreator.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java
      - copied, changed from r239451, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/CustomNodeTypeCreatorImpl.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
Removed:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/GenericConverter.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/DescriptorReader.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/Mapper.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/MapperTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionSetupTest.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerImpl.java
    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/converter/impl/ConverterManagerTest.java

Added: 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/converter/generic/collection/CollectionFieldStrategy.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/collection/CollectionFieldStrategy.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,40 @@
+/*
+ * 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.converter.generic.collection;
+
+
+import java.util.Collection;
+
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+
+/**
+ * Strategy used to map a collection. The desired implementation can be specify in the
+ * mapping file.
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public interface CollectionFieldStrategy
+{
+    
+    public void insertCollection(Session session, String path, Object object) throws JcrMappingException;
+    
+    public void updateCollection(Session session, String path, Object object) throws JcrMappingException;
+    
+    public Collection getCollection(Session session, Class clazz, String path) throws JcrMappingException;
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/impl/GenericConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/impl/GenericConverter.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/impl/GenericConverter.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/generic/impl/GenericConverter.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,408 @@
+/*
+ * 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.converter.generic.impl;
+
+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.Property;
+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.converter.Converter;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
+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.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 GenericConverter implements Converter
+{
+    private DigesterMapperImpl mapper;
+
+    public GenericConverter(DigesterMapperImpl mapper)
+    {
+        this.mapper = mapper;
+    }
+
+    /**
+     * 
+     * @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 propertyName = fieldDescriptor.getJcrName();
+            Property property = node.getProperty(propertyName);
+            Value value = property.getValue();
+            Object fieldValue = RepositoryUtil.getObject(value);
+            String fieldName = fieldDescriptor.getFieldName();
+            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();
+                Object fieldValue = PropertyUtils.getNestedProperty(object, fieldDescriptor.getFieldName());
+                Value value = RepositoryUtil.getValue(fieldValue);
+                objectNode.setProperty(fieldDescriptor.getJcrName(), 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/converter/impl/ConverterManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerImpl.java?rev=263842&r1=263841&r2=263842&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerImpl.java Sun Aug 28 01:15:06 2005
@@ -24,8 +24,9 @@
 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.converter.generic.impl.GenericConverter;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -41,7 +42,7 @@
 {
     private HashMap converters = new HashMap();
     private Log log = LogFactory.getLog(ConverterManagerImpl.class); 
-    private Mapper mapper;
+    private DigesterMapperImpl mapper;
     
     /**
      * Constructor
@@ -49,7 +50,7 @@
      * @param xmlConverterFile
      * @throws JcrMappingException
      */
-    public ConverterManagerImpl(String xmlConverterFile, Mapper mapper) throws JcrMappingException    
+    public ConverterManagerImpl(String xmlConverterFile, DigesterMapperImpl mapper) throws JcrMappingException    
     {
         try
         {

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,67 @@
+/*
+ * 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.mapper.impl;
+
+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.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
+
+/**
+ *
+ * Digester implementation for {@link org.apache.portals.graffito.jcr.mapper.Mapper}
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class DigesterMapperImpl implements Mapper
+{    
+    private MappingDescriptor mappingDescriptor;
+    private Log log = LogFactory.getLog(DigesterMapperImpl.class); 
+    
+    /**
+     * Constructor
+     *  
+     * @param xmlFile
+     * @throws JcrMappingException
+     */
+    public DigesterMapperImpl(String xmlFile) throws JcrMappingException
+    {
+        log.info("Read the xml mapping file : " +  xmlFile);
+        mappingDescriptor = DisgesterDescriptorReader.loadClassDescriptors(xmlFile);
+    }
+
+    /**
+     * Get the mapping defition to be used for a specific java bean
+     * @param clazz The java bean class
+     * @return The mapping class found for the desired java bean class 
+     * @throws JcrMappingException
+     */
+    public ClassDescriptor getClassDescriptor(Class clazz) throws JcrMappingException
+    {        
+        try
+        {
+            return mappingDescriptor.getClassDescriptor(clazz.getName());
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to retrieve the Mapping class for " + clazz, e);
+        }
+    }
+
+}

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DisgesterDescriptorReader.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,105 @@
+/*
+ * 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.mapper.impl;
+
+import java.io.File;
+
+import org.apache.commons.digester.Digester;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+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.mapper.model.MappingDescriptor;
+
+/**
+ * This class read the xml mapping file and load all class descriptors into memory (object graph)
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public class DisgesterDescriptorReader
+{
+    /**
+     * Load all class descriptors found in the xml mapping file.
+     * 
+     * @param xmlFile the xml mapping file reference
+     * @return a {@link MappingDescriptor}
+     * 
+     * @throws JcrMappingException when it is not possible to read the xml mapping file
+     * 
+     */
+    public static MappingDescriptor loadClassDescriptors(String xmlFile) throws JcrMappingException
+    {
+        try
+        {
+            Digester digester = new Digester();
+            digester.setValidating(false); // TODO : validate - add DTD
+
+            digester.addObjectCreate("graffito-jcr", MappingDescriptor.class);
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the class-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor", ClassDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor", "className", "className");
+            digester.addSetProperties("graffito-jcr/class-descriptor", "jcrNodeType", "jcrNodeType");
+            digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor");
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the field-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/field-descriptor", FieldDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "fieldName", "fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrName", "jcrName");
+            digester.addSetNext("graffito-jcr/class-descriptor/field-descriptor", "addFieldDescriptor");
+            
+            // --------------------------------------------------------------------------------
+            // Rules used for the bean-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/bean-descriptor", BeanDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "fieldName", "fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrName", "jcrName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "proxy", "proxy");
+            digester.addSetNext("graffito-jcr/class-descriptor/bean-descriptor", "addBeanDescriptor");
+
+            // --------------------------------------------------------------------------------
+            // Rules used for the collection-descriptor element
+            // --------------------------------------------------------------------------------
+
+            digester.addObjectCreate("graffito-jcr/class-descriptor/collection-descriptor", CollectionDescriptor.class);
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "fieldName", "fieldName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrName", "jcrName");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "proxy", "proxy");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "fieldId", "fieldId");
+            digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "className", "className");
+            digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor");
+            
+            
+            File input = new File(xmlFile);
+            MappingDescriptor mappingDescriptor= (MappingDescriptor)digester.parse( input );
+            return mappingDescriptor;
+        }
+        catch (Exception e)
+        {
+            throw new JcrMappingException("Impossible to read the xml mapping file", e);
+        }
+    }
+}
+

Copied: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/CustomNodeTypeCreator.java (from r239451, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/CustomNodeTypeCreator.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/CustomNodeTypeCreator.java?p2=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/CustomNodeTypeCreator.java&p1=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/CustomNodeTypeCreator.java&r1=239451&r2=263842&rev=263842&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/CustomNodeTypeCreator.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/CustomNodeTypeCreator.java Sun Aug 28 01:15:06 2005
@@ -13,9 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.session;
+package org.apache.portals.graffito.jcr.persistence;
 
 import org.apache.portals.graffito.jcr.exception.CustomNodeTypeCreationException;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 
 /** Interface for custom node type creator implementations.
  *
@@ -42,5 +43,5 @@
     /** Jcr session to be injected into implementation.
      * @param jcrSession JcrSession
      */
-    void setJcrSession(JcrSession jcrSession);
+    void setJcrSession(PersistenceManagerImpl jcrSession);
 }

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceManager.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,111 @@
+/*
+ * 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;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+
+/**
+ * The persistence manager encapsulate a JCR session. 
+ * This is the main component used to manage objects into the JCR repository.
+ * 
+ * @author Sandro Boehme 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ * @version $Id: Exp $
+ */
+public interface PersistenceManager
+{
+    /** 
+     * This method creates the graffito namespaces and custom node types
+     *  required for running a graffito managed jcr repository.
+     * 
+     * @throws JcrMappingException JcrMappingException
+     */
+    public void setupRepository() throws JcrMappingException;
+    /**
+     * 
+     * @return The JCR repository object
+     */
+    public Repository getRepository();
+
+    /**
+     * 
+     * @return The associated JCR session 
+     */
+    public Session getSession();
+
+    /**
+     * 
+     * @return The user name
+     */
+    public String getUser();
+
+    /**
+     * Check if an item exists
+     * @param path the JCR item path
+     * @throws org.apache.portals.graffito.jcr.exception.JcrMappingException 
+     * @return true if the item exists
+     */
+    public boolean itemExists(String path) throws JcrMappingException;
+
+    /**
+     * Insert an object into the JCR repository
+     * @param path the target path 
+     * @param object the object to add
+     * @throws org.apache.portals.graffito.jcr.exception.JcrMappingException 
+     */
+    public void insert(String path, Object object) throws JcrMappingException;
+
+    /**
+     * Update an object 
+     * @param path the object paht
+     * @param object the object to update
+     * @throws org.apache.portals.graffito.jcr.exception.JcrMappingException 
+     */
+    public void update(String path, Object object) throws JcrMappingException;
+
+    /**
+     * Get an object from the JCR repository 
+     * @param pojoClass the object class
+     * @param path the object pagt
+     * @throws org.apache.portals.graffito.jcr.exception.JcrMappingException 
+     * @return the object found or null
+     */
+    public Object getObject(Class pojoClass, String path) throws JcrMappingException;
+
+    /**
+     * Remove an object from a JCR repository
+     * @param path the object paht
+     * @throws org.apache.portals.graffito.jcr.exception.JcrMappingException 
+     */
+    public void remove(String path) throws JcrMappingException;
+        
+    /** 
+     * Getter for property jcrCustomNodeTypeCreator.
+     * 
+     * @return jcrCustomNodeTypeCreator
+     */
+    public CustomNodeTypeCreator getJcrCustomNodeTypeCreator();
+
+    /** 
+     * Setter for property jcrCustomNodeTypeCreator.
+     * 
+     * @param object CustomNodeTypeCreator
+     */
+    public void setJcrCustomNodeTypeCreator(CustomNodeTypeCreator object);
+}
\ No newline at end of file

Copied: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java (from r239451, incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/CustomNodeTypeCreatorImpl.java)
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java?p2=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java&p1=incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/CustomNodeTypeCreatorImpl.java&r1=239451&r2=263842&rev=263842&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/CustomNodeTypeCreatorImpl.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/CustomNodeTypeCreatorImpl.java Sun Aug 28 01:15:06 2005
@@ -13,14 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.portals.graffito.jcr.session.impl;
+package org.apache.portals.graffito.jcr.persistence.impl;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.portals.graffito.jcr.exception.CustomNodeTypeCreationException;
-import org.apache.portals.graffito.jcr.session.CustomNodeTypeCreator;
-import org.apache.portals.graffito.jcr.session.JcrSession;
+import org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
 
 /** Default implementation of the jackrabbit custom node creator.
  *
@@ -35,7 +35,7 @@
     
     /** Session to the jcr repository.
      */
-    private JcrSession jcrSession;
+    private PersistenceManagerImpl jcrSession;
     
     /** Creates a new instance of CustomNodeTypeCreatorImpl. */
     public CustomNodeTypeCreatorImpl()
@@ -45,7 +45,7 @@
     /** Creates a new instance of CustomNodeTypeCreatorImpl with a jcr session. 
      * @param jcrSession JcrSession
      */
-    public CustomNodeTypeCreatorImpl(JcrSession jcrSession)
+    public CustomNodeTypeCreatorImpl(PersistenceManagerImpl jcrSession)
     {
         this.jcrSession = jcrSession;
     }
@@ -81,7 +81,7 @@
      * 
      * @param jcrSession JcrSession
      */
-    public void setJcrSession(JcrSession jcrSession)
+    public void setJcrSession(PersistenceManagerImpl jcrSession)
     {
         this.jcrSession = jcrSession;
     }
@@ -90,7 +90,7 @@
      * 
      * @return jcrSession
      */
-    public JcrSession getJcrSession()
+    public PersistenceManager getJcrSession()
     {
         return jcrSession;
     }

Added: 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=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,275 @@
+/*
+ * 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.impl;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+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.persistence.CustomNodeTypeCreator;
+import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
+
+/** Interface that specifies howto interact with a jcr repository (JCR broker).
+ * 
+ * @author Sandro Boehme
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe</a>
+ * 
+ * @version $Id: Exp $
+ */
+public class PersistenceManagerImpl implements PersistenceManager
+{
+    /** Logger.
+     */
+    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;
+    
+    /** Jackrabbit jcr session.
+     */
+    private Session session;
+
+    /** Custom node type creator dependency needed during repository setup.
+     */
+    private CustomNodeTypeCreator jcrCustomNodeTypeCreator;
+
+    /** Graffito namespace prefix constant.
+     */
+    private static final String GRAFFITO_NAMESPACE_PREFIX   = "graffito";
+
+    /** Graffito namespace constant.
+     */
+    private static final String GRAFFITO_NAMESPACE          = "http://incubator.apache.org/graffito";
+
+    /**
+     * Contructor for setting up a session to interact with a jcr repository. 
+     * 
+     * @param converterManager The converter manager
+     * @param repository The Repository
+     * @param session The JCR Session
+     * @param jcrCustomNodeTypeCreator Custom node type creator
+     */
+    public PersistenceManagerImpl(ConverterManager converterManager, Repository repository,
+            Session session, CustomNodeTypeCreator jcrCustomNodeTypeCreator)
+    {
+        this.converterManager = converterManager;
+        this.repository = repository;
+        this.session = session;
+        this.jcrCustomNodeTypeCreator = jcrCustomNodeTypeCreator;
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#setupRepository()
+     */
+    public void setupRepository() throws JcrMappingException
+    {
+         try
+         {
+            String[] jcrNamespaces = getSession().getWorkspace().getNamespaceRegistry().getPrefixes();
+            boolean createGraffitoNamespace = true;
+            for (int i = 0; i < jcrNamespaces.length; i++)
+            {
+                if (jcrNamespaces[i].equals(GRAFFITO_NAMESPACE_PREFIX))
+                {
+                    createGraffitoNamespace = false;
+                    log.debug("Graffito namespace exists.");
+                }
+            }
+             
+            if (createGraffitoNamespace)
+            {
+                getSession().getWorkspace().getNamespaceRegistry().registerNamespace(GRAFFITO_NAMESPACE_PREFIX, GRAFFITO_NAMESPACE);
+                log.info("Successfully created graffito namespace.");
+            }
+            
+            if (getSession().getRootNode() != null)
+            {
+                log.info("Jcr repository setup successfull.");
+            }
+            
+            if (getJcrCustomNodeTypeCreator().createInitialJcrCustomNodeTypes())
+            {
+                log.info("Jcr custom node type creation successful.");
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("Error while setting up the jcr repository.", e);
+            throw new JcrMappingException(e.getMessage());
+        }
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getRepository()
+     */
+    public Repository getRepository()
+    {       
+        return this.repository;
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getSession()
+     */
+    public Session getSession()
+    {
+        return this.session; 
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getUser()
+     */
+    public String getUser()
+    {
+        return getSession().getUserID();
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.session.JcrSession#getObject(java.lang.Class, java.lang.String)
+     */
+    public Object getObject(Class pojoClass, String path) throws JcrMappingException
+    {   
+        try
+        {
+            if (!session.itemExists(path))
+            {
+                return null;
+            }
+        }
+        catch (RepositoryException re)
+        {
+            throw new JcrMappingException(re.getMessage());
+        }
+        
+        Converter converter = converterManager.getConverter(pojoClass);
+        return converter.getObject(session, pojoClass, path);
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#insert(java.lang.String, java.lang.Object)
+     */
+    public void insert(String path, Object object)  throws JcrMappingException
+    {
+        try
+        {
+            if (session.itemExists(path))
+            {
+                throw new JcrMappingException("Path already exists : " + path);
+            }
+        }
+        catch (RepositoryException re)
+        {
+            throw new JcrMappingException(re.getMessage());
+        }
+        
+        Converter converter = converterManager.getConverter(object.getClass());
+        converter.insert(session, path, object);
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#update(java.lang.String, java.lang.Object)
+     */
+    public void update(String path, Object object)  throws JcrMappingException
+    {
+        try
+        {
+            if (! session.itemExists(path))
+            {
+                throw new JcrMappingException("Path is not existing : " + path);
+            }
+        }
+        catch (RepositoryException re)
+        {
+            throw new JcrMappingException(re.getMessage());
+        }
+        
+        Converter converter = converterManager.getConverter(object.getClass());
+        converter.update(session, path, object);
+    }
+        
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#remove(java.lang.String)
+     */
+    public void remove(String path) throws JcrMappingException
+    {
+    
+        try
+        {
+            Item item = session.getItem(path);
+            Node parent = item.getParent();
+            item.remove();
+            parent.save();
+        }
+        catch (RepositoryException re)
+        {
+            throw new JcrMappingException(re.getMessage());
+        }
+    }
+    
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#itemExists(java.lang.String)
+     */
+    public boolean itemExists(String path) throws JcrMappingException
+    {
+        try
+        {
+            return session.itemExists(path);
+        }
+        catch (RepositoryException re)
+        {
+            throw new JcrMappingException(re.getMessage());
+        }
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#getJcrCustomNodeTypeCreator()
+     */
+    public CustomNodeTypeCreator getJcrCustomNodeTypeCreator()
+    {
+        return jcrCustomNodeTypeCreator;
+    }
+
+    /**
+     * 
+     * @see org.apache.portals.graffito.jcr.persistence.PersistenceManager#setJcrCustomNodeTypeCreator(org.apache.portals.graffito.jcr.persistence.CustomNodeTypeCreator)
+     */
+    public void setJcrCustomNodeTypeCreator(CustomNodeTypeCreator object)
+    {
+        this.jcrCustomNodeTypeCreator = object;
+    }
+  
+}

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=263842&r1=263841&r2=263842&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 Sun Aug 28 01:15:06 2005
@@ -21,9 +21,9 @@
 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;
-import org.apache.portals.graffito.jcr.session.impl.JcrSessionTest;
-import org.apache.portals.graffito.jcr.session.impl.JcrSessionSetupTest;
 
 /** Test all suite to control the order of testcases.
  *
@@ -39,8 +39,8 @@
     public static Test suite()
     {
         TestSuite suite = new TestSuite("graffito jcr-mapping tests");
-        suite.addTestSuite(JcrSessionSetupTest.class);
-        suite.addTestSuite(JcrSessionTest.class);
+        suite.addTestSuite(PersistencManagerSetupTest.class);
+        suite.addTestSuite(PersistenceManagerTest.class);
         suite.addTestSuite(ConverterManagerTest.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=263842&r1=263841&r2=263842&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 Sun Aug 28 01:15:06 2005
@@ -16,21 +16,23 @@
  */
 package org.apache.portals.graffito.jcr;
 
-import junit.framework.TestCase;
-
 import javax.jcr.Repository;
 import javax.jcr.Session;
 
+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.Mapper;
+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;
+import org.apache.portals.graffito.jcr.persistence.impl.CustomNodeTypeCreatorImpl;
+import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl;
 import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
-import org.apache.portals.graffito.jcr.session.CustomNodeTypeCreator;
-import org.apache.portals.graffito.jcr.session.JcrSession;
-import org.apache.portals.graffito.jcr.session.impl.CustomNodeTypeCreatorImpl;
-import org.apache.portals.graffito.jcr.session.impl.JcrSessionImpl;
 
-/** Base class for testcases. Provides priviledged access to the jcr test
+
+/** 
+ * Base class for testcases. Provides priviledged access to the jcr test
  * repository.
  *
  * @author <a href="mailto:okiessler@apache.org">Oliver Kiessler</a>
@@ -40,7 +42,7 @@
 {
     /** Jcr session to work with.
      */
-    private JcrSession jcrSession;
+    private PersistenceManager persistenceManager;
 
     /**
      * <p>Defines the test case name for junit.</p>
@@ -56,7 +58,7 @@
      */
     protected void setUp() throws Exception
     {
-        Mapper mapper =  new Mapper("./src/test/jcrmapping.xml");
+        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. */
@@ -67,7 +69,7 @@
         // optaining a read/write session to the repository
         Session session = RepositoryUtil.login(repository, "superuser", "superuser");
         CustomNodeTypeCreator customNodeTypeCreator = new CustomNodeTypeCreatorImpl();
-        setJcrSession(new JcrSessionImpl(converterManager, repository, session, customNodeTypeCreator));
+        setPersistenceManager(new PersistenceManagerImpl(converterManager, repository, session, customNodeTypeCreator));
     }
 
     /**
@@ -75,23 +77,23 @@
      */
     public void tearDown() throws Exception
     {
-        getJcrSession().getSession().save();
-        getJcrSession().getSession().logout();
+        getPersistenceManager().getSession().save();
+        getPersistenceManager().getSession().logout();
     }    
 
-    /** Getter for property jcrSession.
+    /** Getter for property persistenceManager.
      * @return jcrSession
      */
-    public JcrSession getJcrSession()
+    public PersistenceManager getPersistenceManager()
     {
-        return jcrSession;
+        return persistenceManager;
     }
 
     /** Setter for property jcrSession.
-     * @param jcrSession Jcr Repository session 
+     * @param persistenceManager The persistence manager 
      */
-    public void setJcrSession(JcrSession jcrSession)
+    public void setPersistenceManager(PersistenceManager persistenceManager)
     {
-        this.jcrSession = jcrSession;
+        this.persistenceManager = persistenceManager;
     }
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerTest.java?rev=263842&r1=263841&r2=263842&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerTest.java (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/converter/impl/ConverterManagerTest.java Sun Aug 28 01:15:06 2005
@@ -16,23 +16,21 @@
  */
 package org.apache.portals.graffito.jcr.converter.impl;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 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.converter.impl.ConverterManagerImpl;
+import org.apache.portals.graffito.jcr.converter.generic.impl.GenericConverter;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
-import org.apache.portals.graffito.jcr.mapper.Mapper;
+import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
 import org.apache.portals.graffito.jcr.testconverter.DocumentConverter;
-import org.apache.portals.graffito.jcr.testconverter.FolderConverter;
 import org.apache.portals.graffito.jcr.testmodel.Document;
 import org.apache.portals.graffito.jcr.testmodel.Folder;
 
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 /**
  * Test ConverterManager
  *
@@ -59,7 +57,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        Mapper mapper =  new Mapper("./src/test/jcrmapping.xml");        
+        DigesterMapperImpl mapper =  new DigesterMapperImpl("./src/test/jcrmapping.xml");        
         converterManager = new ConverterManagerImpl("src/conf/convertertest/converters.xml", mapper);
     }
 

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,105 @@
+/* ========================================================================
+ * Copyright 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.mapper;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
+import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
+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.testmodel.A;
+
+/**
+ * Test Mapper
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class DigesterMapperImplTest extends TestCase
+{
+
+    
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public DigesterMapperImplTest(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(DigesterMapperImplTest.class);
+    }
+
+    /**
+     * Test for getConverter
+     *
+     */
+    public void testMapper()    
+    {
+        try
+        {
+            DigesterMapperImpl mapper = new DigesterMapperImpl("./src/test/jcrmapping.xml");
+            assertNotNull("Mapper is null", mapper);
+            
+            ClassDescriptor classDescriptor = mapper.getClassDescriptor(A.class);
+            assertNotNull("ClassDescriptor is null", classDescriptor);
+            assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
+            
+            FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor("a1");
+            assertNotNull("FieldDescriptor is null", fieldDescriptor);
+            assertTrue("Invalid jcrName for field a1", fieldDescriptor.getJcrName().equals("a1"));
+            
+            BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
+            assertNotNull("BeanDescriptor is null", beanDescriptor);
+            assertTrue("Invalid jcrName for field b", beanDescriptor.getJcrName().equals("b"));
+            
+            CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor("collection");
+            assertNotNull("CollectionDescriptor is null", collectionDescriptor);
+            assertTrue("Invalid jcrName for field collection", collectionDescriptor.getJcrName().equals("collection"));
+            
+        }
+        catch (JcrMappingException e)
+        {
+              fail("Impossible to retrieve the converter " + e);
+        }
+    }
+
+}
\ No newline at end of file

Added: 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=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistencManagerSetupTest.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,61 @@
+/* ========================================================================
+ * Copyright 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.impl;
+
+import javax.jcr.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.portals.graffito.jcr.TestBase;
+
+/**
+ * Test JcrSession Setup Repository.
+ *
+ * @author <a href="mailto:oliver.kiessler@gmail.com">Oliver Kiessler</a>
+ */
+public class PersistencManagerSetupTest extends TestBase
+{
+    /** Logger.
+     */
+    private final static Log log = LogFactory.getLog(PersistencManagerSetupTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistencManagerSetupTest(String testName)
+    {
+        super(testName);
+    }
+
+    /** Testmethod for setupRepository of JcrSession.
+     * @throws Exception Exception
+     */
+    public void testSetupRepository() throws Exception
+    {
+        getPersistenceManager().setupRepository();
+        
+        assertNotNull(getPersistenceManager().getSession().getRootNode());
+        
+        Node testNode = getPersistenceManager().getSession().getRootNode().addNode("testnode", "nt:unstructured");
+        testNode.setProperty("testprop", "some value");
+
+        assertNotNull(getPersistenceManager().getSession().getItem("/testnode"));
+        assertNotNull(getPersistenceManager().getSession().getItem("/testnode/testprop"));
+    }
+}
\ No newline at end of file

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java?rev=263842&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java (added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerTest.java Sun Aug 28 01:15:06 2005
@@ -0,0 +1,309 @@
+/* ========================================================================
+ * Copyright 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.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.TestBase;
+import org.apache.portals.graffito.jcr.testmodel.A;
+import org.apache.portals.graffito.jcr.testmodel.B;
+import org.apache.portals.graffito.jcr.testmodel.C;
+import org.apache.portals.graffito.jcr.testmodel.Folder;
+
+/**
+ * Test JcrSession
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class PersistenceManagerTest extends TestBase
+{
+    private final static Log log = LogFactory.getLog(PersistenceManagerTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public PersistenceManagerTest(String testName)
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(PersistenceManagerTest.class);
+    }
+
+    public void testClassA()
+    {
+        try
+        {
+
+            if (getPersistenceManager().itemExists("/test"))
+            {
+                getPersistenceManager().remove("/test");
+            }
+
+            // --------------------------------------------------------------------------------
+            // Create and store an object graph in the repository
+            // --------------------------------------------------------------------------------
+            A a = new A();
+            a.setA1("a1");
+            a.setA2("a2");
+            B b = new B();
+            b.setB1("b1");
+            b.setB2("b2");
+            a.setB(b);
+            
+            C c1 = new C();
+            c1.setId("first");
+            c1.setName("First Element");
+            C c2 = new C();
+            c2.setId("second");
+            c2.setName("second Element");
+            
+            C c3 = new C();
+            c3.setId("second");
+            c3.setName("second Element");
+            
+            
+            Collection collection = new ArrayList();
+            collection.add(c1);
+            collection.add(c2);
+            collection.add(c3);
+            
+            a.setCollection(collection);
+            
+            getPersistenceManager().insert("/test", a);
+
+            // --------------------------------------------------------------------------------
+            // Check the jcr node structure
+            // --------------------------------------------------------------------------------
+            Session session = getPersistenceManager().getSession();
+            Node node = (Node) session.getItem("/test");
+            assertNotNull("A is null", node);
+            
+            assertTrue("Incorrect Name for '/test'", node.getName().equals("test"));
+
+            Property a1 = node.getProperty("a1");
+            assertNotNull("a1  is null", a1);
+            assertTrue("Incorrect a1", a1.getString().equals("a1"));
+            
+            Node nodeB = node.getNode("b");
+            assertNotNull("b is null", nodeB);
+            assertTrue("Incorrect b", nodeB.getName().equals("b"));
+            
+            Node nodeCollection = node.getNode("collection");
+            assertNotNull("collection is null", nodeCollection);
+            assertTrue("Incorrect number of items in the collection", nodeCollection.getNodes().getSize() == 3);
+            
+             
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (A) getPersistenceManager().getObject(A.class, "/test");
+            assertNotNull("a is null", a);
+            assertTrue("Incorrect a1", a.getA1().equals("a1"));
+            assertNotNull("a.b is null", a.getB());
+            assertTrue("Incorrect a.b.b1", a.getB().getB1().equals("b1"));
+            assertNotNull("a.collection is null", a.getCollection());
+            assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
+            
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------
+            a.setA1("new value");
+            B newB = new B();
+            newB.setB1("new B1");
+            newB.setB2("new B2");
+            a.setB(newB);
+            
+            
+            getPersistenceManager().update("/test", a);
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            a = (A) getPersistenceManager().getObject(A.class, "/test");
+            assertNotNull("a is null", a);
+            assertTrue("Incorrect a1", a.getA1().equals("new value"));
+            assertNotNull("a.b is null", a.getB());
+            assertTrue("Incorrect a.b.b1", a.getB().getB1().equals("new B1"));
+
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+        
+    }
+    
+    /**
+     * 
+     * Test for Folder object 
+     *
+     */
+    public void testFolder()
+    {
+        try
+        {
+
+            if (getPersistenceManager().itemExists("/test"))
+            {
+                getPersistenceManager().remove("/test");
+            }
+
+            // --------------------------------------------------------------------------------
+            // Create and store a folder in the repository
+            // --------------------------------------------------------------------------------
+            Folder folder = new Folder();
+            folder.setCreationDate(new Date());
+            folder.setDescription("Folder description");
+            folder.setTitle("Folder Title");
+            folder.setLastModified(new Date());
+            
+            folder.setName("TestFolder");
+            folder.setTitle("Folder Title");
+
+            getPersistenceManager().insert("/test", folder);
+
+            // --------------------------------------------------------------------------------
+            // Check the jcr node structure
+            // --------------------------------------------------------------------------------
+            Session session = getPersistenceManager().getSession();
+            Node folderNode = (Node) session.getItem("/test");
+            assertNotNull("Folder node is null", folderNode);
+            
+            //TODO - custom node types not working yet!
+            //assertTrue("Incorrect primary type", folderNode.getPrimaryNodeType().getName().equals("graffito:folder"));
+            
+            assertTrue("Incorrect Name for '/test'", folderNode.getName().equals("test"));
+
+            Property description = folderNode.getProperty("description");
+            assertNotNull("Folder description  is null", description);
+            assertTrue("Incorrect description for '/test'", description.getString().equals("Folder description"));
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------           
+            folder = (Folder) getPersistenceManager().getObject(Folder.class, "/test");
+            assertNotNull("Folder object is null", folder);
+            assertTrue("Incorrect description for folder object", folder.getDescription().equals("Folder description"));
+
+            // --------------------------------------------------------------------------------
+            // Update the object
+            // --------------------------------------------------------------------------------           
+//            folder.setDescription("new folder description");
+//            getPersistenceManager().update("/test", folder);
+//
+//            assertTrue("Incorrect description for folder object", ((Property) session.getItem("/test/graffito:description"))
+//                    .getString().equals("new folder description"));
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+    }
+    
+    /**
+     * 
+     * Test for document object 
+     *
+     */
+//    public void testDocument()
+//    {
+//        try
+//        {
+//
+//            if (getPersistenceManager().itemExists("/testdoc"))
+//            {
+//                getPersistenceManager().remove("/testdoc");
+//            }
+//
+//            // --------------------------------------------------------------------------------
+//            // Create and store a document in the repository
+//            // --------------------------------------------------------------------------------
+//            Document document = new Document();
+//            document.setCreationDate(new Date());
+//            document.setDescription("Document description");
+//            document.setTitle("Document Title");
+//            document.setLastModified(new Date());           
+//            document.setName("testdoc");
+//            
+//            Content content = new Content();
+//            content.setContent("test".getBytes());
+//            document.setContentType("plain/text");
+//            content.setEncoding("utf-8");
+//            document.setContent(content);            
+//            
+//            getPersistenceManager().insert("/testdoc", document);
+//
+//            // --------------------------------------------------------------------------------
+//            // Check the jcr node structure
+//            // --------------------------------------------------------------------------------
+//            Session session = getPersistenceManager().getSession();
+//            Node documentNode = (Node) session.getItem("/testdoc");
+//            assertNotNull("Document node is null", documentNode);
+//            
+//            //TODO - custom node types not working yet!
+//            //assertTrue("Incorrect primary type", documentNode.getPrimaryNodeType().getName().equals("graffito:file"));
+//            
+//            assertTrue("Incorrect Name for '/testdoc'", documentNode.getName().equals("testdoc"));
+//
+//            Property description = documentNode.getProperty("graffito:description");
+//            assertNotNull("document description  is null", description);
+//            assertTrue("Incorrect description for '/testdoc'", description.getString().equals("Document description"));
+//
+//            // --------------------------------------------------------------------------------
+//            // Get the object
+//            // --------------------------------------------------------------------------------           
+//            document = (Document) getPersistenceManager().getObject(Document.class, "/testdoc");
+//            assertNotNull("Folder object is null", document);
+//            assertTrue("Incorrect description for folder object", document.getDescription().equals("Document description"));
+//
+//            // --------------------------------------------------------------------------------
+//            // Update the object
+//            // --------------------------------------------------------------------------------           
+//            document.setDescription("new document description");
+//            getPersistenceManager().update("/testdoc", document);
+//
+//            assertTrue("Incorrect description for document object", ((Property) session.getItem("/testdoc/graffito:description"))
+//                    .getString().equals("new document description"));
+//
+//        }
+//        catch (Exception e)
+//        {
+//            e.printStackTrace();
+//            fail("Exception occurs during the unit test : " + e);
+//        }
+//    }
+}
\ No newline at end of file



Mime
View raw message