incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r227519 - in /incubator/graffito/trunk/jcr-mapping/src: java/org/apache/portals/graffito/jcr/converter/impl/ java/org/apache/portals/graffito/jcr/mapper/ java/org/apache/portals/graffito/jcr/mapper/model/ test/ test/org/apache/portals/graff...
Date Thu, 04 Aug 2005 23:46:48 GMT
Author: clombart
Date: Thu Aug  4 16:46:36 2005
New Revision: 227519

URL: http://svn.apache.org/viewcvs?rev=227519&view=rev
Log:
Add BeanDescriptor - By this way, it is possible to map a complex java bean attribute to jcr
subnode - see comments in the mapping file (src/test/jcrmapping.xml)


Added:
    incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/A.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/B.java
Modified:
    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/model/ClassDescriptor.java
    incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml
    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/testconverter/DocumentConverter.java
    incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java

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=227519&r1=227518&r2=227519&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 16:46:36 2005
@@ -22,7 +22,6 @@
 import javax.jcr.Session;
 import javax.jcr.Value;
 
-import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.portals.graffito.jcr.converter.Converter;
 import org.apache.portals.graffito.jcr.exception.JcrMappingException;
@@ -144,12 +143,6 @@
            
            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)
         {

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/DescriptorReader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/DescriptorReader.java?rev=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/DescriptorReader.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/DescriptorReader.java
Thu Aug  4 16:46:36 2005
@@ -19,6 +19,7 @@
 
 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.FieldDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
@@ -67,6 +68,15 @@
             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");
 
             File input = new File(xmlFile);
             MappingDescriptor mappingDescriptor= (MappingDescriptor)digester.parse( input
);
@@ -78,3 +88,4 @@
         }
     }
 }
+

Added: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java?rev=227519&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/BeanDescriptor.java
Thu Aug  4 16:46:36 2005
@@ -0,0 +1,77 @@
+/*
+ * 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.model;
+
+/**
+ * 
+ * This class information to map one java bean field (attribute) into subnode
+ * 
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class BeanDescriptor
+{
+
+     private String fieldName;
+     private String jcrName;
+     private boolean proxy; 
+    
+    /**
+     * @return Returns the fieldName.
+     */
+    public String getFieldName()
+    {
+        return fieldName;
+    }
+    /**
+     * @param fieldName The fieldName to set.
+     */
+    public void setFieldName(String fieldName)
+    {
+        this.fieldName = fieldName;
+    }
+    /**
+     * @return Returns the jcrName.
+     */
+    public String getJcrName()
+    {
+        return jcrName;
+    }
+    /**
+     * @param jcrName The jcrName to set.
+     */
+    public void setJcrName(String jcrName)
+    {
+        this.jcrName = jcrName;
+    }
+    
+    
+    /**
+     * @return Returns the proxy.
+     */
+    public boolean isProxy()
+    {
+        return proxy;
+    }
+    /**
+     * @param proxy The proxy to set.
+     */
+    public void setProxy(boolean proxy)
+    {
+        this.proxy = proxy;
+    }
+}

Modified: incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?rev=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
Thu Aug  4 16:46:36 2005
@@ -15,7 +15,6 @@
  */
 package org.apache.portals.graffito.jcr.mapper.model;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 
@@ -33,6 +32,7 @@
      private String jcrNodeType;
      
      HashMap fieldDescriptors = new HashMap();
+     HashMap beanDescriptors = new HashMap();
     
     
     /**
@@ -94,4 +94,36 @@
     {
         return fieldDescriptors.values();   
     }
+    
+    /**
+     * Add a new BeanDescriptor
+     * @param beanDescriptor the new bean descriptor to add
+     */
+                  
+    public void addBeanDescriptor(BeanDescriptor beanDescriptor )
+    {
+        beanDescriptors.put(beanDescriptor.getFieldName(), beanDescriptor);
+    }
+
+    /**
+     * Get the BeanDescriptor to used for a specific java bean attribute
+     * @param fieldName The java bean attribute name
+     * 
+     * @return the {@link BeanDescriptor} found or null
+     */
+    public BeanDescriptor getBeanDescriptor(String fieldName)
+    {
+        return (BeanDescriptor) beanDescriptors.get(fieldName);
+    }
+    
+    
+    /**
+     * 
+     * @return all {@link BeanDescriptor} defined in this ClassDescriptor
+     */
+    public Collection getBeanDescriptors()
+    {
+        return beanDescriptors.values();   
+    }
+    
 }

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=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml (original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/jcrmapping.xml Thu Aug  4 16:46:36 2005
@@ -8,27 +8,34 @@
 			<field-descriptor fieldName="title" jcrName="title" />
 			<field-descriptor fieldName="creationDate" jcrName="creationDate" />
 			<field-descriptor fieldName="lastModified" jcrName="lastModified" />
-			
-			<!-- reference-descriptor name="" 
-				class-ref=""
-			 proxy="false" 
-			 auto-retrieve="true"
-			 auto-update="link" 
-			 auto-delete="link" >
-			 <foreignkey field-ref=""/>
-			</reference-descriptor -->				
+						
+		</class-descriptor>
 
-			
-			<!-- collection-descriptor name="folders"
-				element-class-ref=""
-				proxy="true"	     
-				auto-retrieve="true"      
-				auto-update="link"
-				auto-delete="link" > 
-					<inverse-foreignkey field-ref=""/>
-			</collection-descriptor -->  	    
-			
-			
-			
+        <!--
+		       The following classes are used to test object associations
+				A has an assocition (1..1) with B => B is mapped as subnode in A
+				A has a collection of C => there are n subnode used to map the collection of C
+		
+		-->
+		
+		<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.A"  jcrNodeType=
"nt:unstructured" >
+		    <!-- Field-descriptor is used to map simple attributes to jcr property -->
+			<field-descriptor fieldName="a1" jcrName="a1" />   
+			<field-descriptor fieldName="a2" jcrName="a2" />
+            
+            <!-- bean-descriptor is used to map bean into subnode : the definition of
the associated class has to be defined in this mapping file 
+			     proxy="true" => use lazy laoding for this attribute b when retrieving A
+			-->
+            <bean-descriptor fieldName = "b" proxy="false"  jcrName="b" />
+             			
+		</class-descriptor>
+		
+		<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.B"  jcrNodeType=
"nt:unstructured" >
+		    <!-- Field-descriptor is used to map simple attributes to jcr property -->
+			<field-descriptor fieldName="b1" jcrName="b1" />   
+			<field-descriptor fieldName="b2" jcrName="b2" />
+            
 		</class-descriptor>
+
+		
 </graffito-jcr>

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/MapperTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/MapperTest.java?rev=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/MapperTest.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/MapperTest.java
Thu Aug  4 16:46:36 2005
@@ -21,8 +21,10 @@
 import junit.framework.TestSuite;
 
 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.FieldDescriptor;
+import org.apache.portals.graffito.jcr.testmodel.A;
 import org.apache.portals.graffito.jcr.testmodel.Folder;
 
 /**
@@ -76,13 +78,18 @@
             Mapper mapper = new Mapper("./src/test/jcrmapping.xml");
             assertNotNull("Mapper is null", mapper);
             
-            ClassDescriptor classDescriptor = mapper.getClassDescriptor(Folder.class);
+            ClassDescriptor classDescriptor = mapper.getClassDescriptor(A.class);
             assertNotNull("ClassDescriptor is null", classDescriptor);
-            assertTrue("Invalid classname", classDescriptor.getClassName().equals(Folder.class.getName()));
+            assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
             
-            FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor("description");
+            FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor("a1");
             assertNotNull("FieldDescriptor is null", fieldDescriptor);
-            assertTrue("Invalid jcrName for field description", fieldDescriptor.getJcrName().equals("description"));
+            assertTrue("Invalid jcrName for field description", fieldDescriptor.getJcrName().equals("a1"));
+            
+            BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
+            assertNotNull("BeanDescriptor is null", beanDescriptor);
+            assertTrue("Invalid jcrName for field description", beanDescriptor.getJcrName().equals("b"));
+            
             
         }
         catch (JcrMappingException e)

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java?rev=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/DocumentConverter.java
Thu Aug  4 16:46:36 2005
@@ -122,7 +122,7 @@
      * 
      * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.String)
      */
-    public Object getObject(Session session, String path)  throws JcrMappingException
+    public Object getObject(Session session, Class clazz,  String path)  throws JcrMappingException
     {
         try 
         {

Modified: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java?rev=227519&r1=227518&r2=227519&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
(original)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testconverter/FolderConverter.java
Thu Aug  4 16:46:36 2005
@@ -110,7 +110,7 @@
      * 
      * @see org.apache.portals.graffito.jcr.converter.Converter#getObject(javax.jcr.Session,
java.lang.String)
      */
-    public Object getObject(Session session, String path)  throws JcrMappingException
+    public Object getObject(Session session, Class clazz,  String path)  throws JcrMappingException
     {
         try 
         {

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/A.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/A.java?rev=227519&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/A.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/A.java
Thu Aug  4 16:46:36 2005
@@ -0,0 +1,72 @@
+/*
+ * 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.testmodel;
+
+/**
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class A
+{
+    private String a1;
+    private String a2;
+    private B b;
+    
+    
+    /**
+     * @return Returns the a1.
+     */
+    public String getA1()
+    {
+        return a1;
+    }
+    /**
+     * @param a1 The a1 to set.
+     */
+    public void setA1(String a1)
+    {
+        this.a1 = a1;
+    }
+    /**
+     * @return Returns the a2.
+     */
+    public String getA2()
+    {
+        return a2;
+    }
+    /**
+     * @param a2 The a2 to set.
+     */
+    public void setA2(String a2)
+    {
+        this.a2 = a2;
+    }
+    /**
+     * @return Returns the b.
+     */
+    public B getB()
+    {
+        return b;
+    }
+    /**
+     * @param b The b to set.
+     */
+    public void setB(B b)
+    {
+        this.b = b;
+    }
+}

Added: incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/B.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/B.java?rev=227519&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/B.java
(added)
+++ incubator/graffito/trunk/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/B.java
Thu Aug  4 16:46:36 2005
@@ -0,0 +1,57 @@
+/*
+ * 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.testmodel;
+
+/**
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ * @version $Id: Exp $
+ */
+public class B
+{
+     private String b1;
+     private String b2;
+     
+     
+    /**
+     * @return Returns the b1.
+     */
+    public String getB1()
+    {
+        return b1;
+    }
+    /**
+     * @param b1 The b1 to set.
+     */
+    public void setB1(String b1)
+    {
+        this.b1 = b1;
+    }
+    /**
+     * @return Returns the b2.
+     */
+    public String getB2()
+    {
+        return b2;
+    }
+    /**
+     * @param b2 The b2 to set.
+     */
+    public void setB2(String b2)
+    {
+        this.b2 = b2;
+    }
+}



Mime
View raw message