jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r646938 [2/2] - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/ main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/ main/java/org/apache/jackrabbit/ocm/manager/obje...
Date Thu, 10 Apr 2008 19:47:30 GMT
Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java
Thu Apr 10 12:47:23 2008
@@ -20,6 +20,9 @@
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
@@ -32,6 +35,7 @@
 import org.apache.jackrabbit.ocm.mapper.model.FieldDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.ImplementDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.MappingDescriptor;
+import org.apache.jackrabbit.ocm.reflection.ReflectionUtils;
 
 /**
  * Helper class that reads the xml mapping file and load all class descriptors into memory
(object graph)
@@ -42,7 +46,7 @@
 public class AnnotationDescriptorReader implements DescriptorReader
 {
 	private static final Log log = LogFactory.getLog(AnnotationDescriptorReader.class);
-	
+
 	List<Class> annotatedClassNames;
     public AnnotationDescriptorReader(List<Class> annotatedClassNames)
     {
@@ -53,24 +57,24 @@
 
     public MappingDescriptor loadClassDescriptors()
 	{
-		MappingDescriptor mappingDescriptor = new MappingDescriptor();	
+		MappingDescriptor mappingDescriptor = new MappingDescriptor();
 		for (Class clazz : annotatedClassNames) {
-			
+
 			ClassDescriptor classDescriptor = buildClassDescriptor(mappingDescriptor, clazz);
 			mappingDescriptor.addClassDescriptor(classDescriptor);
 		}
 		return mappingDescriptor;
-		
+
 	}
-	
+
 	private ClassDescriptor buildClassDescriptor(MappingDescriptor mappingDescriptor, Class
clazz)
 	{
 		ClassDescriptor classDescriptor = null;
-		
+
 		Node nodeAnnotation =  (Node) clazz.getAnnotation(Node.class);
 		if (nodeAnnotation != null)
 		{
-			classDescriptor = createClassDescriptor(clazz, nodeAnnotation);	
+			classDescriptor = createClassDescriptor(clazz, nodeAnnotation);
 			addImplementDescriptor(classDescriptor, clazz);
 			addAttributeDescriptors(mappingDescriptor, classDescriptor, clazz);
 			return classDescriptor;
@@ -79,9 +83,9 @@
 		{
 			throw  new InitMapperException("The annotation @Node is not defined for the persistent
class " + clazz.getName());
 		}
-	
-		
-		
+
+
+
 	}
 
 	private ClassDescriptor createClassDescriptor(Class clazz, Node nodeAnnotation)
@@ -94,22 +98,22 @@
 		{
 		     classDescriptor.setJcrSuperTypes(nodeAnnotation.jcrSuperTypes());
 		}
-		
+
 		if (nodeAnnotation.jcrMixinTypes() != null && ! nodeAnnotation.jcrMixinTypes().equals(""))
-		{		
+		{
 		     classDescriptor.setJcrMixinTypes(nodeAnnotation.jcrMixinTypes());
 		}
-		
+
 		if (nodeAnnotation.extend() != null && ! nodeAnnotation.extend().equals(Object.class))
 		{
 		     classDescriptor.setExtend(nodeAnnotation.extend().getName());
 		}
-		
+
 		classDescriptor.setAbstract(nodeAnnotation.isAbstract());
 		classDescriptor.setInterface(clazz.isInterface());
 		return classDescriptor;
 	}
-	
+
 	private void addImplementDescriptor(ClassDescriptor classDescriptor, Class clazz)
 	{
 		Implement implementAnnotation = (Implement) clazz.getAnnotation(Implement.class);
@@ -119,9 +123,9 @@
             implementDescriptor.setInterfaceName(implementAnnotation.interfaceName().getName());
             classDescriptor.addImplementDescriptor(implementDescriptor);
 		}
-		
+
 	}
-	
+
 	/**
 	 * Add FieldDescriptors, BeanDescriptors and CollectionDescriptors.
 	 * The descriptots can be defined on the getter methods or on the field declation.
@@ -137,103 +141,126 @@
 	}
 
 	private void addDescriptorsFromFields(MappingDescriptor mappingDescriptor, ClassDescriptor
classDescriptor, Class clazz) {
-	
+
 		java.lang.reflect.Field[] fields = clazz.getDeclaredFields();
+
 	    for (int index = 0; index < fields.length; index++)
 	    {
+
 			Field fieldAnnotation = fields[index].getAnnotation(Field.class);
 			if (fieldAnnotation != null) {
 				addFieldDescriptor(classDescriptor, fields[index].getName(), fieldAnnotation);
 			}
-			
+
 			// Check if there is an Bean annotation
 			Bean beanAnnotation = fields[index].getAnnotation(Bean.class);
 			if (beanAnnotation != null) {
 				addBeanDescriptor(classDescriptor, fields[index].getName(), beanAnnotation);
 			}
-			
+
 			// Check if there is an Collection annotation
 			Collection collectionAnnotation = fields[index].getAnnotation(Collection.class);
 			if (collectionAnnotation != null) {
-				addCollectionDescriptor(mappingDescriptor, classDescriptor, fields[index].getName(),
-						                fields[index].getName(), collectionAnnotation);
+				addCollectionDescriptor(mappingDescriptor, classDescriptor, fields[index], collectionAnnotation);
 			}
-					
-		   	
+
+
 		}
-		
+
 	}
 
 	private void addDescriptorsFromGetters(MappingDescriptor mappingDescriptor, ClassDescriptor
classDescriptor, Class clazz) {
 		BeanInfo beanInfo;
 		try {
 			beanInfo = Introspector.getBeanInfo(clazz);
-		} catch (IntrospectionException e) {
-			throw new RuntimeException(e);
-		}
-		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
-		for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+			PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+			for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
 
-			// Check if there is an Field annotation
-			Field fieldAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Field.class);
-			if (fieldAnnotation != null) {
-				addFieldDescriptor(classDescriptor, propertyDescriptor.getName(), fieldAnnotation);
-			}
-			
-			// Check if there is an Bean annotation
-			Bean beanAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Bean.class);
-			if (beanAnnotation != null) {
-				addBeanDescriptor(classDescriptor, propertyDescriptor.getName(), beanAnnotation);
-			}
-			
-			// Check if there is an Collection annotation
-			Collection collectionAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Collection.class);
-			if (collectionAnnotation != null) {
-				addCollectionDescriptor(mappingDescriptor, classDescriptor, propertyDescriptor.getName(),
-						                propertyDescriptor.getReadMethod().getReturnType().getName(), collectionAnnotation);
+				// Check if there is an Field annotation
+				Field fieldAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Field.class);
+				if (fieldAnnotation != null) {
+					addFieldDescriptor(classDescriptor, propertyDescriptor.getName(), fieldAnnotation);
+				}
+
+				// Check if there is an Bean annotation
+				Bean beanAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Bean.class);
+				if (beanAnnotation != null) {
+					addBeanDescriptor(classDescriptor, propertyDescriptor.getName(), beanAnnotation);
+				}
+
+				// Check if there is an Collection annotation
+				Collection collectionAnnotation = propertyDescriptor.getReadMethod().getAnnotation(Collection.class);
+				if (collectionAnnotation != null) {
+
+					addCollectionDescriptor(mappingDescriptor, classDescriptor,
+							                propertyDescriptor.getPropertyType().getDeclaredField(propertyDescriptor.getName()),
+							                collectionAnnotation);
+				}
 			}
+		} catch (Exception e) {
+			throw new InitMapperException("Impossible to read the mapping descriptor from the getter",
e);
 		}
+
 	}
 
 
 	private void addCollectionDescriptor(MappingDescriptor mappingDescriptor, ClassDescriptor
descriptor,
-			                             String fieldName, String collectionClassName, Collection
collectionAnnotation) {
-		
+			                             java.lang.reflect.Field field, Collection collectionAnnotation)
{
+
 		Class targetClass = collectionAnnotation.elementClassName();
-		CollectionDescriptor collectionDescriptor = new CollectionDescriptor();	
-		
-		collectionDescriptor.setFieldName(fieldName);
-		
+		CollectionDescriptor collectionDescriptor = new CollectionDescriptor();
+
+		collectionDescriptor.setFieldName(field.getName());
+
 		if (collectionAnnotation.jcrName() != null && ! collectionAnnotation.jcrName().equals(""))
 		{
 		   collectionDescriptor.setJcrName(collectionAnnotation.jcrName());
 		}
 		else
 		{
-		   collectionDescriptor.setJcrName(fieldName);
+		   collectionDescriptor.setJcrName(field.getName());
 		}
-		
+
 		Node annotationNode = (Node) targetClass.getAnnotation(Node.class);
 		collectionDescriptor.setProxy(collectionAnnotation.proxy());
-		
+
 		collectionDescriptor.setAutoInsert(collectionAnnotation.autoInsert());
 		collectionDescriptor.setAutoRetrieve(collectionAnnotation.autoRetrieve());
 		collectionDescriptor.setAutoUpdate(collectionAnnotation.autoUpdate());
-		collectionDescriptor.setCollectionClassName(collectionClassName);
+		collectionDescriptor.setCollectionClassName(field.getName());
 		if (! collectionAnnotation.elementClassName().equals(Object.class))
 		{
 			collectionDescriptor.setElementClassName(collectionAnnotation.elementClassName().getName());
 		}
 		else
 		{
-		    collectionDescriptor.setElementClassName(targetClass.getName());
+
+//		    collectionDescriptor.setElementClassName(targetClass.getName());
+			Type type = field.getGenericType();
+			if (type instanceof ParameterizedType)
+			{
+				Type[] paramType = ((ParameterizedType) type).getActualTypeArguments();
+				//TODO : change this condition. No sure if it will be all the time true.
+				// If only one type argument, the attribute is certainly a collection
+				if (paramType.length == 1)
+				{
+					collectionDescriptor.setElementClassName(paramType[0].toString().replace("class ", ""));
+				}
+				// either, it is certainly a map
+				else
+				{
+					collectionDescriptor.setElementClassName(paramType[1].toString().replace("class ", ""));
+				}
+
+			}
+
 		}
 
 		if (! collectionAnnotation.collectionClassName().equals(Object.class))
 		{
 			collectionDescriptor.setCollectionClassName(collectionAnnotation.collectionClassName().getName());
 		}
-		
+
 		collectionDescriptor.setCollectionConverter(collectionAnnotation.collectionConverter().getName());
 		if (annotationNode != null)
 		{
@@ -244,11 +271,11 @@
 		collectionDescriptor.setJcrProtected(collectionAnnotation.jcrProtected());
 		collectionDescriptor.setJcrOnParentVersion(collectionAnnotation.jcrOnParentVersion());
 		collectionDescriptor.setJcrMandatory(collectionAnnotation.jcrMandatory());
-		
+
 
 		descriptor.addCollectionDescriptor(collectionDescriptor);
 	}
-	
+
 	private void addBeanDescriptor(ClassDescriptor classDescriptor, String fieldName, Bean beanAnnotation)
{
 		BeanDescriptor beanDescriptor = new BeanDescriptor();
 		beanDescriptor.setFieldName(fieldName);
@@ -260,8 +287,8 @@
 		{
 			beanDescriptor.setJcrName(fieldName);
 		}
-		
-		beanDescriptor.setProxy(beanAnnotation.proxy());				
+
+		beanDescriptor.setProxy(beanAnnotation.proxy());
 		beanDescriptor.setConverter(beanAnnotation.converter().getName());
 		beanDescriptor.setAutoInsert(beanAnnotation.autoInsert());
 		beanDescriptor.setAutoRetrieve(beanAnnotation.autoRetrieve());
@@ -270,8 +297,8 @@
 		beanDescriptor.setJcrAutoCreated(beanAnnotation.jcrAutoCreated());
 		beanDescriptor.setJcrMandatory(beanAnnotation.jcrMandatory());
 		beanDescriptor.setJcrOnParentVersion(beanAnnotation.jcrOnParentVersion());
-		beanDescriptor.setJcrProtected(beanAnnotation.jcrProtected());			
-		beanDescriptor.setJcrSameNameSiblings(beanAnnotation.jcrSameNameSiblings());				
+		beanDescriptor.setJcrProtected(beanAnnotation.jcrProtected());
+		beanDescriptor.setJcrSameNameSiblings(beanAnnotation.jcrSameNameSiblings());
 
 		classDescriptor.addBeanDescriptor(beanDescriptor);
 	}
@@ -279,55 +306,55 @@
 
 	private void addFieldDescriptor(ClassDescriptor classDescriptor, String fieldName, Field
fieldAnnotation)
 	{
-				
-		FieldDescriptor fieldDescriptor = new FieldDescriptor();				
+
+		FieldDescriptor fieldDescriptor = new FieldDescriptor();
 		fieldDescriptor.setFieldName(fieldName);
 		if ((fieldAnnotation.jcrName() != null) && (!fieldAnnotation.jcrName().equals("")))
 		{
-			fieldDescriptor.setJcrName(fieldAnnotation.jcrName());	
+			fieldDescriptor.setJcrName(fieldAnnotation.jcrName());
 		}
 		else
 		{
-			fieldDescriptor.setJcrName(fieldName);	
+			fieldDescriptor.setJcrName(fieldName);
 		}
-		fieldDescriptor.setId(fieldAnnotation.id());				
+		fieldDescriptor.setId(fieldAnnotation.id());
 		fieldDescriptor.setPath(fieldAnnotation.path());
 		fieldDescriptor.setUuid(fieldAnnotation.uuid());
-		
+
 		// It is not possible to set a null value into an annotation attribute.
 		// If the converter == Object.class, it should be considered as null
 		if (! fieldAnnotation.converter().equals(Object.class))
 		{
 		    fieldDescriptor.setConverter(fieldAnnotation.converter().getName());
 		}
-		
+
 		// It is not possible to set a null value into an annotation attribute.
 		// If the jcrDefaultValue value is an empty string => it should be considered as null
 		if ((fieldAnnotation.jcrDefaultValue() != null) && (!fieldAnnotation.jcrDefaultValue().equals("")))
 		{
 		     fieldDescriptor.setJcrDefaultValue(fieldAnnotation.jcrDefaultValue());
 		}
-		
+
 		// It is not possible to set a null value into an annotation attribute.
 		// If the jcrValueConstraints value is an empty string => it should be considered as
null
 		if ((fieldAnnotation.jcrValueConstraints() != null) && (!fieldAnnotation.jcrValueConstraints().equals("")))
-		{	
+		{
 		     fieldDescriptor.setJcrValueConstraints(fieldAnnotation.jcrValueConstraints());
 		}
-		
+
 		// It is not possible to set a null value into an annotation attribute.
 		// If the jcrProperty value is an empty string => it should be considered as null
 		if ((fieldAnnotation.jcrType() != null) && (!fieldAnnotation.jcrType().equals("")))
 		{
 		    fieldDescriptor.setJcrType(fieldAnnotation.jcrType());
 		}
-		
+
 		fieldDescriptor.setJcrAutoCreated(fieldAnnotation.jcrAutoCreated());
 		fieldDescriptor.setJcrMandatory(fieldAnnotation.jcrMandatory());
 		fieldDescriptor.setJcrOnParentVersion(fieldAnnotation.jcrOnParentVersion());
 		fieldDescriptor.setJcrProtected(fieldAnnotation.jcrProtected());
 		fieldDescriptor.setJcrMultiple(fieldAnnotation.jcrMultiple());
-		
+
 		//fieldDescriptor.setJcrType(value)
 		classDescriptor.addFieldDescriptor(fieldDescriptor);
 	}

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationHashMapTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationHashMapTest.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationHashMapTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationHashMapTest.java
Thu Apr 10 12:47:23 2008
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.ocm.manager.collectionconverter;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -58,7 +61,7 @@
         try
         {
         	ObjectContentManager ocm = getObjectContentManager();
-        	
+
             // --------------------------------------------------------------------------------
             // Create and store an object graph in the repository with null hashmap
             // --------------------------------------------------------------------------------
@@ -76,6 +79,7 @@
             main = (Main) ocm.getObject( "/test");
             assertTrue("Incorrect text", main.getText().equals("Main text"));
             assertNull("HashMap is not null", main.getHashMap());
+            assertNull("Map is not null", main.getMap());
 
             // --------------------------------------------------------------------------------
             // Update an object graph in the repository
@@ -86,17 +90,22 @@
             main.setText("Main text");
 
             HashMapElement hashMapElement = new HashMapElement();
+            Map<String, Element> map = new HashMap<String, Element>();
+
             Element e1 = new Element();
             e1.setId("e1");
             e1.setText("Element 1");
             hashMapElement.addObject(e1);
+            map.put("e1", e1);
 
             Element e2 = new Element();
             e2.setId("e2");
             e2.setText("Element 2");
             hashMapElement.addObject(e2);
+            map.put("e2", e2);
 
             main.setHashMap(hashMapElement);
+            main.setMap(map);
 
             ocm.update(main);
             ocm.save();
@@ -106,28 +115,37 @@
             // --------------------------------------------------------------------------------
             main = (Main) ocm.getObject( "/test");
             assertNotNull("main.getHashMap() is null", main.getHashMap());
+            assertNotNull("main.getHashMap() is null", main.getMap());
             assertTrue("Incorrect text", main.getText().equals("Main text"));
             assertTrue("Incorrect para element", ((Element) main.getHashMap().get("e1")).getText().equals("Element
1"));
+            assertTrue("Incorrect para element", ((Element) main.getMap().get("e1")).getText().equals("Element
1"));
 
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
             hashMapElement = new HashMapElement();
+            map = new HashMap<String, Element>();
+
             e1 = new Element();
             e1.setId("e1");
             e1.setText("Element 1");
             hashMapElement.addObject(e1);
+            map.put("e1", e1);
 
             e2 = new Element();
             e2.setId("e3");
             e2.setText("Element 3");
             hashMapElement.addObject(e2);
+            map.put("e3", e2);
 
             Element e3 = new Element();
             e3.setId("e4");
             e3.setText("Element 4");
             hashMapElement.addObject(e3);
+            map.put("e4", e3);
+
             main.setHashMap(hashMapElement);
+            main.setMap(map);
 
             ocm.update(main);
             ocm.save();
@@ -138,7 +156,7 @@
             assertNotNull("main.getElements() is null", main.getHashMap());
             assertTrue("Incorrect text", main.getText().equals("Main text"));
             assertTrue("Incorrect para element", ((Element) main.getHashMap().get("e4")).getText().equals("Element
4"));
-
+            assertTrue("Incorrect para element", main.getMap().get("e4").getText().equals("Element
4"));
         }
         catch (Exception e)
         {

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualNodesCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualNodesCollectionConverterImplTest.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualNodesCollectionConverterImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualNodesCollectionConverterImplTest.java
Thu Apr 10 12:47:23 2008
@@ -24,7 +24,7 @@
 import org.apache.jackrabbit.ocm.AnnotationTestBase;
 import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
 import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManagedHashMap;
+import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManageableHashMap;
 import org.apache.jackrabbit.ocm.testmodel.Paragraph;
 import org.apache.jackrabbit.ocm.testmodel.Residual;
 
@@ -82,7 +82,7 @@
             residual = new Residual.ResidualNodes();
             residual.setPath("/test");
 
-            ManagedHashMap map = new ManagedHashMap();
+            ManageableHashMap map = new ManageableHashMap();
             map.put("value1", new Paragraph("Value1"));
             map.put("value2", new Paragraph("Value2"));
             map.put("value3", new Paragraph("Value3"));
@@ -104,7 +104,7 @@
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
-            map = new ManagedHashMap();
+            map = new ManageableHashMap();
             map.put("value11", new Paragraph("Value11"));
             map.put("value12", new Paragraph("Value12"));
             map.put("value13", new Paragraph("Value13"));

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualPropertiesCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualPropertiesCollectionConverterImplTest.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualPropertiesCollectionConverterImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationResidualPropertiesCollectionConverterImplTest.java
Thu Apr 10 12:47:23 2008
@@ -28,7 +28,7 @@
 import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
 import org.apache.jackrabbit.ocm.DigesterTestBase;
 import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManagedHashMap;
+import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManageableHashMap;
 import org.apache.jackrabbit.ocm.testmodel.Residual;
 
 /**
@@ -86,7 +86,7 @@
             residual = new Residual.ResidualProperties();
             residual.setPath("/test");
 
-            ManagedHashMap map = new ManagedHashMap();
+            ManageableHashMap map = new ManageableHashMap();
             map.put("value1", "Value1");
             map.put("value2", "Value2");
             map.put("value3", "Value3");
@@ -112,7 +112,7 @@
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
-            map = new ManagedHashMap();
+            map = new ManageableHashMap();
             map.put("value11", "Value11");
             map.put("value12", "Value12");
             map.put("value13", "Value13");

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualNodesCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualNodesCollectionConverterImplTest.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualNodesCollectionConverterImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualNodesCollectionConverterImplTest.java
Thu Apr 10 12:47:23 2008
@@ -24,7 +24,7 @@
 import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
 import org.apache.jackrabbit.ocm.DigesterTestBase;
 import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManagedHashMap;
+import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManageableHashMap;
 import org.apache.jackrabbit.ocm.testmodel.Paragraph;
 import org.apache.jackrabbit.ocm.testmodel.Residual;
 
@@ -81,7 +81,7 @@
             residual = new Residual.ResidualNodes();
             residual.setPath("/test");
 
-            ManagedHashMap map = new ManagedHashMap();
+            ManageableHashMap map = new ManageableHashMap();
             map.put("value1", new Paragraph("Value1"));
             map.put("value2", new Paragraph("Value2"));
             map.put("value3", new Paragraph("Value3"));
@@ -103,7 +103,7 @@
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
-            map = new ManagedHashMap();
+            map = new ManageableHashMap();
             map.put("value11", new Paragraph("Value11"));
             map.put("value12", new Paragraph("Value12"));
             map.put("value13", new Paragraph("Value13"));

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualPropertiesCollectionConverterImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualPropertiesCollectionConverterImplTest.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualPropertiesCollectionConverterImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterResidualPropertiesCollectionConverterImplTest.java
Thu Apr 10 12:47:23 2008
@@ -27,7 +27,7 @@
 import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
 import org.apache.jackrabbit.ocm.DigesterTestBase;
 import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
-import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManagedHashMap;
+import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManageableHashMap;
 import org.apache.jackrabbit.ocm.testmodel.Residual;
 
 /**
@@ -86,7 +86,7 @@
             residual = new Residual.ResidualProperties();
             residual.setPath("/test");
 
-            ManagedHashMap map = new ManagedHashMap();
+            ManageableHashMap map = new ManageableHashMap();
             map.put("value1", "Value1");
             map.put("value2", "Value2");
             map.put("value3", "Value3");
@@ -112,7 +112,7 @@
             // --------------------------------------------------------------------------------
             // Update the object
             // --------------------------------------------------------------------------------
-            map = new ManagedHashMap();
+            map = new ManageableHashMap();
             map.put("value11", "Value11");
             map.put("value12", "Value12");
             map.put("value13", "Value13");

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/Residual.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/Residual.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/Residual.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/Residual.java
Thu Apr 10 12:47:23 2008
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.ocm.testmodel;
 
-import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManagedHashMap;
+import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ManageableHashMap;
 import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ResidualNodesCollectionConverterImpl;
 import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.ResidualPropertiesCollectionConverterImpl;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection;
@@ -37,19 +37,19 @@
 {
 	@Field(path=true) private String path;
 
-    private ManagedHashMap elements;
+    private ManageableHashMap elements;
 
 	/**
      * @return Returns the elements.
      */
-    public ManagedHashMap getElements()
+    public ManageableHashMap getElements()
     {
         return elements;
     }
     /**
      * @param elements The elements to set.
      */
-    public void setElements(ManagedHashMap elements)
+    public void setElements(ManageableHashMap elements)
     {
         this.elements = elements;
     }
@@ -58,8 +58,8 @@
     @Node(extend=Residual.class) public static class ResidualProperties extends Residual
     {
         @Collection( jcrName="value*",elementClassName=String.class,collectionConverter=ResidualPropertiesCollectionConverterImpl.class,
-                collectionClassName=ManagedHashMap.class)
-        private ManagedHashMap elements;
+                collectionClassName=ManageableHashMap.class)
+        private ManageableHashMap elements;
 
 
     }
@@ -68,8 +68,8 @@
     {
     	
         @Collection( jcrName="value*",elementClassName=Object.class,collectionConverter=ResidualNodesCollectionConverterImpl.class,
-                collectionClassName=ManagedHashMap.class)
-        private ManagedHashMap elements;
+                collectionClassName=ManageableHashMap.class)
+        private ManageableHashMap elements;
 
     	
     }

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Element.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Element.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Element.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Element.java
Thu Apr 10 12:47:23 2008
@@ -28,7 +28,8 @@
 @Node(jcrType="ocm:element", discriminator=false)
 public class Element
 {
-    @Field(jcrName="ocm:id") private String id;
+	// an ID field can be used as a unique identifier (for exemple, it can be used as key in
a Map)
+    @Field(jcrName="ocm:id", id=true) private String id;
     @Field(jcrName="ocm:text") private String text;
 
 

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/HashMapElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/HashMapElement.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/HashMapElement.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/HashMapElement.java
Thu Apr 10 12:47:23 2008
@@ -50,7 +50,7 @@
 
 	public int getSize()
 	{
-		
+
 		return this.size();
 	}
 

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Main.java?rev=646938&r1=646937&r2=646938&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Main.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/collection/Main.java
Thu Apr 10 12:47:23 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.ocm.testmodel.collection;
 
+import java.util.Map;
+
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
 import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
@@ -34,9 +36,12 @@
     @Collection (elementClassName=Element.class, collectionClassName=HashMapElement.class)
     private HashMapElement hashMap;
 
+    @Collection private Map<String, Element> map;
+
     @Collection (elementClassName=Element.class, collectionClassName=ArrayListElement.class)
     private ArrayListElement list;
 
+
     public String getPath() {
 		return path;
 	}
@@ -62,7 +67,7 @@
     {
 		return list;
 	}
-	
+
     public void setList(ArrayListElement list)
     {
 		this.list = list;
@@ -81,6 +86,16 @@
     {
         this.text = text;
     }
+
+	public Map<String, Element> getMap()
+	{
+		return map;
+	}
+
+	public void setMap(Map<String, Element> map)
+	{
+		this.map = map;
+	}
 
 
 }



Mime
View raw message