jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r699627 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/mapper/impl/ main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/ main/java/org/apache/jackrabbit/ocm/mapper/model/ main/java/org/apache/jackrabbi...
Date Sat, 27 Sep 2008 12:35:13 GMT
Author: clombart
Date: Sat Sep 27 05:35:12 2008
New Revision: 699627

URL: http://svn.apache.org/viewvc?rev=699627&view=rev
Log:
Patch for JCR-1759 (Simplify the usage of OCM annotations)

Added:
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AllTests.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AnnotationSimpleTest.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedAbstractClass.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedClass.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleInterface.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/UnmappedInterface.java
Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/model/ClassDescriptor.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java?rev=699627&r1=699626&r2=699627&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java
Sat Sep 27 05:35:12 2008
@@ -20,9 +20,11 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -32,6 +34,7 @@
 import org.apache.jackrabbit.ocm.mapper.DescriptorReader;
 import org.apache.jackrabbit.ocm.mapper.Mapper;
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
+import org.apache.jackrabbit.ocm.mapper.model.ImplementDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.MappingDescriptor;
 
 /**
@@ -74,26 +77,40 @@
 
     }
 
-
+    
+    /**
+     * This method check class descriptor references (ancestor & implemented interfaces)
: 
+     * For each classdescriptor found, this method will check if the ancestor class and the
implemented 
+     * interfaces are also persistent or not. 
+     * 
+     * @param errors
+     * @return
+     */
     protected List solveReferences(List errors) {
         for(Iterator it = this.mappingDescriptor.getClassDescriptorsByClassName().entrySet().iterator();
it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             ClassDescriptor cd = (ClassDescriptor) entry.getValue();
-
+            
+            // Check if the ancestor is a persistent class
             if (null != cd.getExtend() && !"".equals(cd.getExtend()))
             {
                 ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(cd.getExtend());
 
                 if (null == superClassDescriptor)
                 {
-                    errors.add("Cannot find mapping for class "
+                	// Just a debug info because we can have a non persisted ancestor class
+                	log.debug("Cannot find mapping for class "
                             + cd.getExtend()
                             + " referenced as extends from "
                             + cd.getClassName());
+                	
+                	// This is not necessary to keep a non persisted ancestor class
+                	cd.setExtend(null);
+
                 }
                 else
                 {
-            	       log.debug("Class " +cd.getClassName() +  " extends " + cd.getExtend());
+            	    log.debug("Class " +cd.getClassName() +  " extends " + cd.getExtend());
                     cd.setSuperClassDescriptor(superClassDescriptor);
                 }
             }
@@ -102,29 +119,36 @@
                    rootClassDescriptors.add(cd);
             }
 
-            Collection interfaces = cd.getImplements();
+            // Check if the implemented interfaces are persistent classes
+            Set interfaces = cd.getImplements();
+            Set mappedInterfaces  = new HashSet();
+            
             if (interfaces.size() > 0)
             {	
             	      for (Iterator iterator = interfaces.iterator(); iterator.hasNext();)
             	      {
-            	    	          String interfaceName= (String) iterator.next();
+            	    	  String interfaceName= (String) iterator.next();
                           ClassDescriptor interfaceClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(interfaceName);
 
                           if (null == interfaceClassDescriptor)
                           {
-                              errors.add("Cannot find mapping for interface "
+                        	  // Just a debug info because we can have a non persisted interface
reference 
+                        	  log.debug("Cannot find mapping for interface "
                                       + interfaceName
                                       + " referenced as implements from "
                                       + cd.getClassName());
+                        	  
                           }
                           else
                           {
-                      	       log.debug("Class " +cd.getClassName() +  " implements " + interfaceName);
-                              //cd.setSuperClassDescriptor(interfaceClassDescriptor);
+                      	      log.debug("Class " +cd.getClassName() +  " implements " + interfaceName);
                       	      interfaceClassDescriptor.addDescendantClassDescriptor(cd);
+                      	      mappedInterfaces.add(interfaceName);
                           }
             	    	
             	      }
+            	      
+            	      cd.setImplements(mappedInterfaces); 
             }
 
         }

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=699627&r1=699626&r2=699627&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
Sat Sep 27 05:35:12 2008
@@ -104,18 +104,36 @@
 		     classDescriptor.setJcrMixinTypes(nodeAnnotation.jcrMixinTypes());
 		}
 
+		Class ancestorClass = ReflectionUtils.getAncestorClass(clazz);
+		if (ancestorClass != null)
+		{
+			classDescriptor.setExtend(ancestorClass.getName());
+		}
+			
+		// TODO : Can we still support the extend param in the annotation @Node if we are using

+		//	      the reflection to get the ancestor class ? (see the previous if)
 		if (nodeAnnotation.extend() != null && ! nodeAnnotation.extend().equals(Object.class))
 		{
 		     classDescriptor.setExtend(nodeAnnotation.extend().getName());
 		}
 
-		classDescriptor.setAbstract(nodeAnnotation.isAbstract());
+		
+		classDescriptor.setAbstract(nodeAnnotation.isAbstract()||ReflectionUtils.isAbstractClass(clazz)
);
 		classDescriptor.setInterface(clazz.isInterface());
 		return classDescriptor;
 	}
 
 	private void addImplementDescriptor(ClassDescriptor classDescriptor, Class clazz)
 	{
+		Class[] interfaces = ReflectionUtils.getInterfaces(clazz);
+		for (int i = 0; i < interfaces.length; i++) {
+			ImplementDescriptor implementDescriptor =  new ImplementDescriptor();
+            implementDescriptor.setInterfaceName(interfaces[i].getName());
+            classDescriptor.addImplementDescriptor(implementDescriptor);
+		}
+		
+		// TODO : Can we still support the annotation @Implement if we are using 
+		//	      the reflection to get the list of the interfaces ?		
 		Implement implementAnnotation = (Implement) clazz.getAnnotation(Implement.class);
 		if (implementAnnotation != null)
 		{

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/model/ClassDescriptor.java?rev=699627&r1=699626&r2=699627&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/model/ClassDescriptor.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/mapper/model/ClassDescriptor.java
Sat Sep 27 05:35:12 2008
@@ -20,9 +20,11 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -45,7 +47,7 @@
 
     private MappingDescriptor mappingDescriptor;
     private ClassDescriptor superClassDescriptor;
-    private Collection descendantClassDescriptors = new ArrayList();
+    private HashSet descendantClassDescriptors = new HashSet();
 
     private String className;
     private String jcrType;
@@ -69,7 +71,8 @@
 
 
     private boolean isInterface=false;
-    private List interfaces = new ArrayList();
+    private Set interfaces = new HashSet();
+    
 
     public void setAbstract(boolean flag) {
         this.isAbstract = flag;
@@ -410,7 +413,14 @@
 
 	private void lookupSuperDescriptor() {
         if (null != superClassDescriptor) {
-            this.hasDiscriminator = superClassDescriptor.hasDiscriminator();
+            
+        	//Check some attributes defined on the ancestor class descriptor
+        	this.hasDiscriminator = superClassDescriptor.hasDiscriminator();
+        	
+        	// If there is no mixin type on the current classdescriptor, check if there is one
on the ancestor class. 
+        	if(jcrMixinTypes == null || jcrMixinTypes.length == 0)
+        		jcrMixinTypes = superClassDescriptor.jcrMixinTypes;
+        	
             if (! this.isInterface)
             {
                 this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
@@ -509,10 +519,15 @@
     }
 
 
-    public Collection getImplements()
+    public Set getImplements()
     {
     	    return interfaces;
     }
+    
+    public void setImplements(Set interfaces)
+    {
+    	this.interfaces = interfaces;
+    }
 
     private Map mergeFields(Map existing, Collection superSource) {
         if (null == superSource) {

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java?rev=699627&r1=699626&r2=699627&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/reflection/ReflectionUtils.java
Sat Sep 27 05:35:12 2008
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.ocm.reflection;
 
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -135,7 +136,7 @@
      * @param objects
      * @return
      */
-    public static Object  invokeConstructor(String className,  Object[] params) {
+    public static Object invokeConstructor(String className,  Object[] params) {
         try {
             Class converterClass= forName(className);
 
@@ -195,7 +196,7 @@
 
     public static Class getBeanClass(Object bean)
     {
-    	     Class beanClass = bean.getClass();
+    	 Class beanClass = bean.getClass();
          if (isProxy(beanClass))
          {
         	     //CGLIB specific
@@ -245,6 +246,25 @@
 
 		return defaultImplementation.get(clazz);
 	}
-
+	
+	public static boolean isAbstractClass(Class clazz)
+	{
+			return Modifier.isAbstract(clazz.getModifiers());
+	}
+	
+	public static Class getAncestorClass(Class clazz)
+	{
+        Class ancestorClass =  clazz.getSuperclass();
+        if (ancestorClass == Object.class)
+        	return null; 
+        else
+        	return ancestorClass;
+	}
+	
+	
+	public static Class[] getInterfaces(Class clazz)
+	{
+		return clazz.getInterfaces();
+	}
 
 }

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java?rev=699627&r1=699626&r2=699627&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
Sat Sep 27 05:35:12 2008
@@ -33,6 +33,7 @@
 import org.apache.jackrabbit.ocm.testmodel.D;
 import org.apache.jackrabbit.ocm.testmodel.DFull;
 import org.apache.jackrabbit.ocm.testmodel.Default;
+import org.apache.jackrabbit.ocm.testmodel.Discriminator;
 import org.apache.jackrabbit.ocm.testmodel.E;
 import org.apache.jackrabbit.ocm.testmodel.File;
 import org.apache.jackrabbit.ocm.testmodel.HierarchyNode;
@@ -43,6 +44,9 @@
 import org.apache.jackrabbit.ocm.testmodel.PropertyTest;
 import org.apache.jackrabbit.ocm.testmodel.Residual;
 import org.apache.jackrabbit.ocm.testmodel.Resource;
+import org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedAbstractClass;
+import org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedClass;
+import org.apache.jackrabbit.ocm.testmodel.SimpleInterface;
 import org.apache.jackrabbit.ocm.testmodel.Residual.ResidualNodes;
 import org.apache.jackrabbit.ocm.testmodel.Residual.ResidualProperties;
 import org.apache.jackrabbit.ocm.testmodel.collection.Element;
@@ -112,7 +116,7 @@
 		classes.add(Main.class);
 		classes.add(Element.class);
 		classes.add(MultiValue.class);
-
+		classes.add(Discriminator.class);
 
 		classes.add(Residual.class);
 		classes.add(ResidualProperties.class);
@@ -160,6 +164,11 @@
 
 		classes.add(PressRelease.class);
 		classes.add(Author.class);
+		
+		classes.add(SimpleAnnotedAbstractClass.class);
+		classes.add(SimpleAnnotedClass.class);
+		classes.add(SimpleInterface.class);
+		
 		Mapper mapper = new AnnotationMapperImpl(classes);
 		ocm = new ObjectContentManagerImpl(session, mapper);
 

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AllTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AllTests.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AllTests.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AllTests.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.simplemapping;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+
+
+/**
+ * Package level tests.
+ *
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class AllTests {
+
+    public static Test suite() {
+        return new RepositoryLifecycleTestSetup(buildSuite());
+    }
+
+    public static Test buildSuite() {
+        TestSuite suite= new TestSuite("Test for org.apache.jackrabbit.ocm.manager.simplemapping");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(AnnotationSimpleTest.class);
+        
+
+        //$JUnit-END$
+
+        return suite;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AnnotationSimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AnnotationSimpleTest.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AnnotationSimpleTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/simplemapping/AnnotationSimpleTest.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jackrabbit.ocm.manager.simplemapping;
+
+
+import java.util.Collection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.AnnotationTestBase;
+import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedClass;
+import org.apache.jackrabbit.ocm.testmodel.SimpleInterface;
+
+/**
+ * Test atomic persistence fields
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class AnnotationSimpleTest extends AnnotationTestBase
+{
+    private final static Log log = LogFactory.getLog(AnnotationSimpleTest.class);
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public AnnotationSimpleTest(String testName) throws Exception
+    {
+        super(testName);
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new RepositoryLifecycleTestSetup(new TestSuite(AnnotationSimpleTest.class));
+    }
+
+
+    public void testSimpleAnnotedClasses()
+    {
+        try
+        {
+        	ObjectContentManager ocm = getObjectContentManager();
+        	SimpleAnnotedClass a = new SimpleAnnotedClass(); 
+        	a.setPath("/test");
+        	a.setTest("test");
+        	
+            ocm.insert(a);
+            ocm.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
+            a = null;
+            a = (SimpleAnnotedClass) ocm.getObject( "/test");
+            assertNotNull("A is null", a);
+            assertEquals("Invalid value for test", "test", a.getTest());
+            
+            // --------------------------------------------------------------------------------
+            // Update
+            // --------------------------------------------------------------------------------
+            a.setTest("another test");
+            ocm.update(a);
+            ocm.save();
+
+            // --------------------------------------------------------------------------------
+            // Get the object
+            // --------------------------------------------------------------------------------
+            a = null;
+            a = (SimpleAnnotedClass) ocm.getObject( "/test");
+            assertNotNull("A is null", a);
+            assertEquals("Invalid value for test", "another test", a.getTest());
+            
+            // --------------------------------------------------------------------------------
+            // Search on the interface
+            // --------------------------------------------------------------------------------
+            QueryManager queryManager = ocm.getQueryManager();
+            Filter filter = queryManager.createFilter(SimpleInterface.class); 
+            filter.addEqualTo("test", "another test");
+            Query q = queryManager.createQuery(filter);
+            
+            Collection result = ocm.getObjects(q);
+            assertNotNull(result);
+            assertEquals("Invalid number of SimpleInterface found", 1, result.size());
+            
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            fail("Exception occurs during the unit test : " + e);
+        }
+
+    }
+
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java?rev=699627&r1=699626&r2=699627&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/mapper/AnnotationMapperImplTest.java
Sat Sep 27 05:35:12 2008
@@ -34,6 +34,9 @@
 import org.apache.jackrabbit.ocm.testmodel.B;
 import org.apache.jackrabbit.ocm.testmodel.C;
 import org.apache.jackrabbit.ocm.testmodel.PropertyTest;
+import org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedAbstractClass;
+import org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedClass;
+import org.apache.jackrabbit.ocm.testmodel.SimpleInterface;
 import org.apache.jackrabbit.ocm.testmodel.inheritance.Ancestor;
 import org.apache.jackrabbit.ocm.testmodel.inheritance.AnotherDescendant;
 import org.apache.jackrabbit.ocm.testmodel.inheritance.Descendant;
@@ -61,7 +64,7 @@
 
 	public static Test suite() {
 		// All methods starting with "test" will be executed in the test suite.
-		return new TestSuite(DigesterMapperImplTest.class);
+		return new TestSuite(AnnotationMapperImplTest.class);
 	}
 
 	/**
@@ -393,8 +396,8 @@
 			assertNull("The interface has an ancestor", classDescriptor.getSuperClassDescriptor());
 			assertTrue("The interface has not implementation/descendant", classDescriptor.hasDescendants());
 			Collection descendants = classDescriptor.getDescendantClassDescriptors();
-			assertEquals("Invalid number of implementation/descendants", descendants.size(), 1);
-			assertEquals("Invalid interface implementation",( (ClassDescriptor) descendants.iterator().next()).getClassName(),
"org.apache.jackrabbit.ocm.testmodel.inheritance.AnotherDescendant");
+			assertEquals("Invalid number of implementation/descendants",2, descendants.size());
+			//assertEquals("Invalid interface implementation",( (ClassDescriptor) descendants.iterator().next()).getClassName(),
"org.apache.jackrabbit.ocm.testmodel.inheritance.AnotherDescendant");
 			assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
 			assertFalse("Incalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
 			
@@ -440,7 +443,7 @@
 			assertNotNull("Classdescriptor is null", classDescriptor);
 			assertTrue("Document is not  an interface", classDescriptor.isInterface());
 			assertFalse("Document  has a discriminator", classDescriptor.hasDiscriminator());
-			assertEquals("Invalid number of implemented interface", classDescriptor.getImplements().size(),
0);			
+			assertEquals("Invalid number of implemented interface", classDescriptor.getImplements().size(),
1);			
 			assertFalse("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
 			assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
 			descendants = classDescriptor.getDescendantClassDescriptors();			
@@ -512,6 +515,35 @@
 		}
 	}
 	
+	public void testSimpleAnnotations()
+	{
+		try {
+			Mapper mapper = getMapper();
+			assertNotNull("Mapper is null", mapper);
+
+			ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(SimpleAnnotedAbstractClass.class);
+			assertNotNull("ClassDescriptor for SimpleAnnotedAbstractClass is null", classDescriptor);
+			assertTrue("SimpleAnnotedAbstractClass is not Abstract ", classDescriptor.isAbstract());
+			
+			classDescriptor = mapper.getClassDescriptorByClass(SimpleAnnotedClass.class);
+			assertNotNull("ClassDescriptor for SimpleAnnotedClass is null", classDescriptor);
+			assertFalse("SimpleAnnotedClass is Abstract ", classDescriptor.isAbstract());
+			assertEquals("Invalid ancestor class for SimpleAnnotedClass ",
+						 "org.apache.jackrabbit.ocm.testmodel.SimpleAnnotedAbstractClass",
+						  classDescriptor.getSuperClassDescriptor().getClassName());
+			assertEquals("Invalid number of implemented interface", 1, classDescriptor.getImplements().size());
+			
+			String  interfaceName = (String) classDescriptor.getImplements().iterator().next();
+			assertEquals("Invalid interface for SimpleAnnotationClass", 
+					    "org.apache.jackrabbit.ocm.testmodel.SimpleInterface",
+					    interfaceName);
+			
+		} catch (JcrMappingException e) {
+			e.printStackTrace();
+			fail("Impossible to test simple annotation " + e);
+		}
+	}
+	
 	private Mapper getMapper()
 	{
 		List<Class> classes = new ArrayList<Class>();
@@ -528,11 +560,20 @@
 		classes.add( org.apache.jackrabbit.ocm.testmodel.inheritance.withmixin.Descendant.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.inheritance.withmixin.SubDescendant.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.inheritance.impl.CmsObjectImpl.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.inheritance.impl.FolderImpl.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.inheritance.impl.ContentImpl.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.inheritance.impl.DocumentImpl.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.CmsObject.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.Folder.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.Content.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.Document.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.Interface.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.interfaces.AnotherInterface.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.Main.class);
+		classes.add(SimpleAnnotedAbstractClass.class);
+		classes.add(SimpleAnnotedClass.class);
+		classes.add(SimpleInterface.class);
+		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.A.class);
 		
 		Mapper mapper = new AnnotationMapperImpl(classes);
 		return mapper;

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedAbstractClass.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedAbstractClass.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedAbstractClass.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedAbstractClass.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,30 @@
+package org.apache.jackrabbit.ocm.testmodel;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+
+@Node
+public abstract class SimpleAnnotedAbstractClass {
+
+	@Field(path=true) String path; 
+	@Field String test;
+
+	public String getTest() {
+		return test;
+	}
+
+	public void setTest(String test) {
+		this.test = test;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	} 
+		
+		
+}

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedClass.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedClass.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedClass.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleAnnotedClass.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,27 @@
+package org.apache.jackrabbit.ocm.testmodel;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+
+
+@Node
+public class SimpleAnnotedClass 
+       extends SimpleAnnotedAbstractClass // The ancestor is also a mapped class
+       implements 
+       			  // The following interface is also mapped
+       			  SimpleInterface, 
+       			  // The following interface is not mapped.So, the ObjectContentManager will not
manage it 
+                  UnmappedInterface { 
+
+	private int testInt;
+
+	public int getTestInt() {
+		return testInt;
+	}
+
+	public void setTestInt(int testInt) {
+		this.testInt = testInt;
+	} 
+	
+	
+}

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleInterface.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleInterface.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleInterface.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/SimpleInterface.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,9 @@
+package org.apache.jackrabbit.ocm.testmodel;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+@Node
+public interface SimpleInterface {
+
+
+}

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/UnmappedInterface.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/UnmappedInterface.java?rev=699627&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/UnmappedInterface.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/UnmappedInterface.java
Sat Sep 27 05:35:12 2008
@@ -0,0 +1,9 @@
+package org.apache.jackrabbit.ocm.testmodel;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+
+public interface UnmappedInterface {
+
+
+}



Mime
View raw message