incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r227492 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/converter/ java/org/apache/portals/graffito/jcr/converter/impl/ java/org/apache/portals/graffito/jcr/repository/ java/org/apache/portals/graffito/j...
Date Thu, 04 Aug 2005 21:18:15 GMT
Author: clombart
Date: Thu Aug  4 14:18:03 2005
New Revision: 227492

URL: http://svn.apache.org/viewcvs?rev=227492&view=rev
Log:
* Start implementation for GenericConverter.getObject()
* Support Date type in the GenericConverter.

Modified:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/Converter.java
    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/repository/RepositoryUtil.java
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/JcrSessionImpl.java
    incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml
    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/Converter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/Converter.java?rev=227492&r1=227491&r2=227492&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/Converter.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/Converter.java
Thu Aug  4 14:18:03 2005
@@ -33,5 +33,5 @@
     
     public void update(Session session, String path, Object object) throws JcrMappingException;
     
-    public Object getObject(Session session, String path) throws JcrMappingException;
+    public Object getObject(Session session, Class clazz, String path) throws JcrMappingException;
 }

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/GenericConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/GenericConverter.java?rev=227492&r1=227491&r2=227492&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/GenericConverter.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/converter/impl/GenericConverter.java
Thu Aug  4 14:18:03 2005
@@ -15,15 +15,15 @@
  */
 package org.apache.portals.graffito.jcr.converter.impl;
 
-import java.util.Collection;
 import java.util.Iterator;
 
 import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.Session;
 import javax.jcr.Value;
 
+import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.jackrabbit.value.StringValue;
 import org.apache.portals.graffito.jcr.converter.Converter;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
@@ -46,6 +46,7 @@
         this.mapper = mapper;
     }
 
+
     /**
      * 
      * @see org.apache.portals.graffito.jcr.converter.Converter#insert(javax.jcr.Session,
java.lang.String, java.lang.Object)
@@ -76,20 +77,7 @@
                Value value = RepositoryUtil.getValue(fieldValue);               
                objectNode.setProperty(fieldDescriptor.getFieldName(), value);    
            }
-           
-           
                       
-//           folderNode.setProperty("graffito:title", new StringValue(folder.getTitle()));
-//           
-//           // TODO
-//           Calendar date = new GregorianCalendar();
-//           date.setTime(new Date());
-//           folderNode.setProperty("jcr:created", date);
-//           
-//           Calendar calendar = Calendar.getInstance();
-//           calendar.setTime(folder.getLastModified());
-//           folderNode.setProperty("graffito:lastmodified", new DateValue(calendar));
-//           
            parentNode.save();
             
         }
@@ -130,27 +118,43 @@
 
     /**
      * 
-     * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.String)
+     * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.Class, java.lang.String)
      */
-    public Object getObject(Session session, String path)  throws JcrMappingException
+    public Object getObject(Session session, Class clazz,  String path)  throws JcrMappingException
     {
-        return null;
-//        try 
-//        {
-//           Folder folder = new Folder(); 
-//               
-//           Node folderNode = (Node) session.getItem(path);
+        
+        try 
+        {
+           ClassDescriptor classDescriptor = mapper.getClassDescriptor(clazz); 
+               
+           Node node = (Node) session.getItem(path);
+           Object object = clazz.newInstance();
+           
+           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);
+           }           
+           
+           return object;
+           
 //           folder.setName(folderNode.getName());
 //           folder.setDescription(folderNode.getProperty("graffito:description").getString());
  
 //           folder.setTitle(folderNode.getProperty("graffito:title").getString());
 //           folder.setCreationDate(folderNode.getProperty("jcr:created").getDate().getTime());
 //           folder.setLastModified(folderNode.getProperty("graffito:lastmodified").getDate().getTime());
 //           return folder;  
-//        }
-//        catch(Exception e)
-//        {
-//            throw new JcrMappingException("Impossible to store the object at " + path,
e);
-//        }
+        }
+        catch(Exception e)
+        {
+            throw new JcrMappingException("Impossible to get the object at " + path, 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=227492&r1=227491&r2=227492&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
Thu Aug  4 14:18:03 2005
@@ -20,6 +20,7 @@
 import java.util.Date;
 import java.util.Hashtable;
 
+import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
@@ -229,4 +230,47 @@
            
            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/java/org/apache/portals/graffito/jcr/session/impl/JcrSessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/JcrSessionImpl.java?rev=227492&r1=227491&r2=227492&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/JcrSessionImpl.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/session/impl/JcrSessionImpl.java
Thu Aug  4 14:18:03 2005
@@ -174,7 +174,7 @@
         }
         
         Converter converter = converterManager.getConverter(pojoClass);
-        return converter.getObject(session, path);
+        return converter.getObject(session, pojoClass, path);
     }
     
     /**

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=227492&r1=227491&r2=227492&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml Thu Aug  4 14:18:03 2005
@@ -5,7 +5,7 @@
 		    <!-- Field-descriptor is used to map simple attributes to jcr property -->
 			<field-descriptor fieldName="name" jcrName="name" />   
 			<field-descriptor fieldName="description" jcrName="description" />
-			<field-descriptor fieldName="title" jcrName="tile" />
+			<field-descriptor fieldName="title" jcrName="title" />
 			<field-descriptor fieldName="creationDate" jcrName="creationDate" />
 			<field-descriptor fieldName="lastModified" jcrName="lastModified" />
 			

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java?rev=227492&r1=227491&r2=227492&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/session/impl/JcrSessionTest.java
Thu Aug  4 14:18:03 2005
@@ -106,9 +106,9 @@
             // --------------------------------------------------------------------------------
             // Get the object
             // --------------------------------------------------------------------------------
          
-//            folder = (Folder) getJcrSession().getObject(Folder.class, "/test");
-//            assertNotNull("Folder object is null", folder);
-//            assertTrue("Incorrect description for folder object", folder.getDescription().equals("Folder
description"));
+            folder = (Folder) getJcrSession().getObject(Folder.class, "/test");
+            assertNotNull("Folder object is null", folder);
+            assertTrue("Incorrect description for folder object", folder.getDescription().equals("Folder
description"));
 
             // --------------------------------------------------------------------------------
             // Update the object



Mime
View raw message