Property changes on: . ___________________________________________________________________ Modified: svn:ignore - derby.log target *.iws *.ipr *.iml .* jcoverage* junit*.properties + derby.log target *.iws *.ipr *.iml .* jcoverage* junit*.properties target-eclipse Index: src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/MultiValueCollectionConverterImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/MultiValueCollectionConverterImpl.java (revision 699762) +++ src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/MultiValueCollectionConverterImpl.java (working copy) @@ -32,6 +32,7 @@ import org.apache.jackrabbit.ocm.exception.JcrMappingException; import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; import org.apache.jackrabbit.ocm.manager.atomictypeconverter.AtomicTypeConverter; +import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.UndefinedTypeConverterImpl; import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableCollection; import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableObjectsUtil; import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableObjects; @@ -47,6 +48,7 @@ * * @author Christophe Lombart * @author Alexandru Popescu + * @author Boni Gopalan */ public class MultiValueCollectionConverterImpl extends AbstractCollectionConverterImpl { @@ -84,6 +86,12 @@ Object fieldValue = collectionIterator.next(); AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters .get(fieldValue.getClass()); + //If there is no proper conversion strategy defined for a specific bean type + //then system will make a best effort conversion strategy using UndefinedTypeConverter. + //@author:Boni Gopalan + if (atomicTypeConverter == null){ + atomicTypeConverter = new UndefinedTypeConverterImpl(); + } values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue); } @@ -125,6 +133,13 @@ Object fieldValue = collectionIterator.next(); AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters .get(fieldValue.getClass()); + //If there is no proper conversion strategy defined for a specific bean type + //then system will make a best effort conversion strategy using UndefinedTypeConverter. + //@author:Boni Gopalan + if (atomicTypeConverter == null){ + atomicTypeConverter = new UndefinedTypeConverterImpl(); + } + values[i] = atomicTypeConverter.getValue(valueFactory, fieldValue); } @@ -162,7 +177,12 @@ for (int i = 0; i < values.length; i++) { AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters .get(elementClass); - + //If there is no proper conversion strategy defined for a specific bean type + //then system will make a best effort conversion strategy using UndefinedTypeConverter. + //@author:Boni Gopalan + if (atomicTypeConverter == null){ + atomicTypeConverter = new UndefinedTypeConverterImpl(); + } ((ManageableCollection) objects).addObject(atomicTypeConverter.getObject(values[i])); } Index: src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java (revision 699762) +++ src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectContentManagerImpl.java (working copy) @@ -515,6 +515,8 @@ try { ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(clazz); + if (classDescriptor == null) + return false; return true; } catch (IncorrectPersistentClassException e) { return false; Index: src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java (revision 699762) +++ src/main/java/org/apache/jackrabbit/ocm/mapper/impl/AbstractMapperImpl.java (working copy) @@ -31,6 +31,7 @@ import org.apache.jackrabbit.ocm.exception.IncorrectPersistentClassException; import org.apache.jackrabbit.ocm.exception.InitMapperException; import org.apache.jackrabbit.ocm.exception.JcrMappingException; +import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.AtomicTypeConverterProviderImpl; import org.apache.jackrabbit.ocm.mapper.DescriptorReader; import org.apache.jackrabbit.ocm.mapper.Mapper; import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor; @@ -42,6 +43,7 @@ * Abstract class for {@link org.apache.jackrabbit.ocm.mapper.Mapper} * * @author Lombart Christophe + * @author : Boni Gopalan * * TODO : Add more reference tests. For exemple, the mapper has to check if the class used for the elements * of a collectiondescriptor exists. For performance reasone, we can defined some optional validations. @@ -198,7 +200,7 @@ public ClassDescriptor getClassDescriptorByClass(Class clazz) { ClassDescriptor descriptor = mappingDescriptor.getClassDescriptorByName(clazz.getName()); if (descriptor==null) { - throw new IncorrectPersistentClassException("Class of type: " + clazz.getName() + " has no descriptor."); + //throw new IncorrectPersistentClassException("Class of type: " + clazz.getName() + " has no descriptor."); } return descriptor ; } Index: src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java (revision 699762) +++ src/main/java/org/apache/jackrabbit/ocm/mapper/impl/annotation/AnnotationDescriptorReader.java (working copy) @@ -41,6 +41,7 @@ * Helper class that reads the xml mapping file and load all class descriptors into memory (object graph) * * @author Lombart Christophe + * @author : Boni Gopalan * */ public class AnnotationDescriptorReader implements DescriptorReader @@ -307,6 +308,9 @@ { setElementClassName(collectionDescriptor,ancestorType); } + else{ + collectionDescriptor.setElementClassName(Object.class.getName()); + } } } Index: src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java (revision 699762) +++ src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java (working copy) @@ -39,6 +39,7 @@ import org.apache.jackrabbit.ocm.testmodel.HierarchyNode; import org.apache.jackrabbit.ocm.testmodel.Lockable; import org.apache.jackrabbit.ocm.testmodel.MultiValue; +import org.apache.jackrabbit.ocm.testmodel.MultiValueWithObjectCollection; import org.apache.jackrabbit.ocm.testmodel.Page; import org.apache.jackrabbit.ocm.testmodel.Paragraph; import org.apache.jackrabbit.ocm.testmodel.PropertyTest; @@ -75,8 +76,8 @@ * repository. * * @author Christophe Lombart + * @author : Boni Gopalan * - * */ public abstract class AnnotationTestBase extends AbstractTestBase { @@ -116,6 +117,7 @@ classes.add(Main.class); classes.add(Element.class); classes.add(MultiValue.class); + classes.add(MultiValueWithObjectCollection.class); classes.add(Discriminator.class); classes.add(Residual.class); Index: src/test/java/org/apache/jackrabbit/ocm/manager/basic/AnnotationSimpleTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/basic/AnnotationSimpleTest.java (revision 699762) +++ src/test/java/org/apache/jackrabbit/ocm/manager/basic/AnnotationSimpleTest.java (working copy) @@ -202,8 +202,12 @@ { ObjectContentManager ocm = getObjectContentManager(); assertTrue("Class A is not persistent ", ocm.isPersistent(A.class)); - assertFalse("Class String is persistent - hum ? ", ocm.isPersistent(String.class)); + assertFalse("Class SomeRandomUnMappedType is persistent - hum ? ", ocm.isPersistent(SomeRandomUnMappedType.class)); + } +} +class SomeRandomUnMappedType{ + } \ No newline at end of file Index: src/test/java/org/apache/jackrabbit/ocm/manager/basic/DigesterSimpleTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/basic/DigesterSimpleTest.java (revision 699762) +++ src/test/java/org/apache/jackrabbit/ocm/manager/basic/DigesterSimpleTest.java (working copy) @@ -201,8 +201,9 @@ { ObjectContentManager ocm = getObjectContentManager(); assertTrue("Class A is not persistent ", ocm.isPersistent(A.class)); - assertFalse("Class String is persistent - hum ? ", ocm.isPersistent(String.class)); + assertFalse("Class SomeRandomUnMappedDigesterType is persistent - hum ? ", ocm.isPersistent(SomeRandomUnMappedDigesterType.class)); } - - +} +class SomeRandomUnMappedDigesterType{ + } \ No newline at end of file Index: src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationMultiValueWithObjectCollectionConverterImplTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationMultiValueWithObjectCollectionConverterImplTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/AnnotationMultiValueWithObjectCollectionConverterImplTest.java (revision 0) @@ -0,0 +1,130 @@ +/* + * 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.collectionconverter; + +import java.util.ArrayList; +import java.util.Iterator; + +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.testmodel.MultiValueWithObjectCollection; + +/** + * Test NTCollectionConverterImpl + * + * @author : Boni Gopalan + */ +public class AnnotationMultiValueWithObjectCollectionConverterImplTest extends + AnnotationTestBase { + private final static Log log = LogFactory + .getLog(AnnotationMultiValueWithObjectCollectionConverterImplTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public AnnotationMultiValueWithObjectCollectionConverterImplTest( + 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( + AnnotationMultiValueWithObjectCollectionConverterImplTest.class)); + } + + public void testMultiValue() { + checkMultiValue(new String[] { "Value1", "Value2", "Value3", "Value4", + "Value5" }, "/test-string", String.class); + checkMultiValue(new Long[] { 1L, 2L, 3L, 4L, 5L }, "/test-long", + Long.class); + } + + public void checkMultiValue(Object[] testData, String nodeName, Class klazz) { + try { + ObjectContentManager ocm = getObjectContentManager(); + + // -------------------------------------------------------------------------------- + // Create and store an object graph in the repository + // -------------------------------------------------------------------------------- + + MultiValueWithObjectCollection multiValue = new MultiValueWithObjectCollection(); + multiValue.setPath(nodeName); + + ArrayList values = new ArrayList(); + values.add(testData[0]); + values.add(testData[1]); + multiValue.setMultiValues(values); + + ocm.insert(multiValue); + ocm.save(); + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + multiValue = (MultiValueWithObjectCollection) ocm + .getObject(nodeName); + assertNotNull("Object is null", multiValue); + assertNull("nullMultiValues field is not null", multiValue + .getNullMultiValues()); + assertTrue("Incorrect number of values", multiValue + .getMultiValues().size() == 2); + Iterator anIterator = multiValue.getMultiValues().iterator(); + assertEquals(testData[0], klazz.cast(anIterator.next())); + assertEquals(testData[1], klazz.cast(anIterator.next())); + + // -------------------------------------------------------------------------------- + // Update the object + // -------------------------------------------------------------------------------- + ArrayList values1 = new ArrayList(); + values1.add(testData[2]); + values1.add(testData[3]); + values1.add(testData[4]); + multiValue.setMultiValues(values1); + + ocm.update(multiValue); + ocm.save(); + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + + multiValue = (MultiValueWithObjectCollection) ocm + .getObject(nodeName); + assertNotNull("Object is null", multiValue); + assertNull("nullMultiValues field is not null", multiValue + .getNullMultiValues()); + assertTrue("Incorrect number of values", multiValue + .getMultiValues().size() == 3); + assertEquals(testData[2], klazz.cast(multiValue.getMultiValues() + .iterator().next())); + + } catch (Exception e) { + e.printStackTrace(); + fail("Exception occurs during the unit test : " + e); + } + } + +} \ No newline at end of file Index: src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterMultiValueWithObjectCollectionConverterImplTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterMultiValueWithObjectCollectionConverterImplTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/manager/collectionconverter/DigesterMultiValueWithObjectCollectionConverterImplTest.java (revision 0) @@ -0,0 +1,127 @@ +/* + * 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.collectionconverter; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Iterator; + +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.DigesterTestBase; +import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup; +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.apache.jackrabbit.ocm.testmodel.MultiValueWithObjectCollection; + +/** + * Test NTCollectionConverterImpl + * + * @author : Boni Gopalan + */ +public class DigesterMultiValueWithObjectCollectionConverterImplTest extends DigesterTestBase +{ + private final static Log log = LogFactory.getLog(DigesterMultiValueWithObjectCollectionConverterImplTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public DigesterMultiValueWithObjectCollectionConverterImplTest(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(DigesterMultiValueWithObjectCollectionConverterImplTest.class)); + } + + public void testMultiValue(){ + checkMultiValue(new String [] {"Value1", "Value2", "Value3", "Value4", "Value5"}, "/test-string", String.class); + checkMultiValue(new Long [] {1L, 2L, 3L, 4L, 5L}, "/test-long", Long.class); + } + + public void checkMultiValue(Object [] testData, String nodeName, Class klazz ) + { + try + { + ObjectContentManager ocm = getObjectContentManager(); + + // -------------------------------------------------------------------------------- + // Create and store an object graph in the repository + // -------------------------------------------------------------------------------- + + MultiValueWithObjectCollection multiValue = new MultiValueWithObjectCollection(); + multiValue.setPath(nodeName); + + ArrayList values = new ArrayList(); + values.add(testData[0]); + values.add(testData[1]); + multiValue.setMultiValues(values); + + ocm.insert(multiValue); + ocm.save(); + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + multiValue = (MultiValueWithObjectCollection) ocm.getObject( nodeName); + assertNotNull("Object is null", multiValue); + assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues()); + assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 2); + Iterator anIterator = multiValue.getMultiValues().iterator(); + assertEquals(testData[0], klazz.cast(anIterator.next())); + assertEquals(testData[1], klazz.cast(anIterator.next())); + + // -------------------------------------------------------------------------------- + // Update the object + // -------------------------------------------------------------------------------- + ArrayList values1 = new ArrayList(); + values1.add(testData[2]); + values1.add(testData[3]); + values1.add(testData[4]); + multiValue.setMultiValues(values1); + + ocm.update(multiValue); + ocm.save(); + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + + multiValue = (MultiValueWithObjectCollection) ocm.getObject(nodeName); + assertNotNull("Object is null", multiValue); + assertNull("nullMultiValues field is not null", multiValue.getNullMultiValues()); + assertTrue("Incorrect number of values", multiValue.getMultiValues().size() == 3); + assertEquals(testData[2], klazz.cast(multiValue.getMultiValues().iterator().next())); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("Exception occurs during the unit test : " + e); + } + + } + + +} \ No newline at end of file Index: src/test/java/org/apache/jackrabbit/ocm/manager/uuid/DigesterUuidTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/uuid/DigesterUuidTest.java (revision 699762) +++ src/test/java/org/apache/jackrabbit/ocm/manager/uuid/DigesterUuidTest.java (working copy) @@ -512,5 +512,6 @@ } } + } \ No newline at end of file Index: src/test/java/org/apache/jackrabbit/ocm/testmodel/MultiValueWithObjectCollection.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/testmodel/MultiValueWithObjectCollection.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/testmodel/MultiValueWithObjectCollection.java (revision 0) @@ -0,0 +1,86 @@ +package org.apache.jackrabbit.ocm.testmodel; + +import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.MultiValueCollectionConverterImpl; +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; +@Node +public class MultiValueWithObjectCollection { + /** + * + * Simple object used to test multivalue properties + * + * @author Boni Gopalan + * @version $Id: Exp $ + */ + @Field(path=true) private String path; + + @Field private String name; + + @Collection(elementClassName=Object.class, collectionConverter=MultiValueCollectionConverterImpl.class) + private java.util.Collection multiValues; + + @Collection(elementClassName=Object.class, collectionConverter=MultiValueCollectionConverterImpl.class) + private java.util.Collection nullMultiValues; + + + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + /** + * @return Returns the name. + */ + public String getName() + { + return name; + } + + /** + * @param name The name to set. + */ + public void setName(String name) + { + this.name = name; + } + + /** + * @return Returns the multiValues. + */ + public java.util.Collection getMultiValues() + { + return multiValues; + } + + /** + * @param multiValues + * The multiValues to set. + */ + public void setMultiValues(java.util.Collection multiValues) + { + this.multiValues = multiValues; + } + + /** + * @return Returns the nullMultiValues. + */ + public java.util.Collection getNullMultiValues() + { + return nullMultiValues; + } + + /** + * @param nullMultiValues + * The nullMultiValues to set. + */ + public void setNullMultiValues(java.util.Collection nullMultiValues) + { + this.nullMultiValues = nullMultiValues; + } + +} Index: src/test/test-config/jcrmapping-atomic.xml =================================================================== --- src/test/test-config/jcrmapping-atomic.xml (revision 699762) +++ src/test/test-config/jcrmapping-atomic.xml (working copy) @@ -53,6 +53,22 @@ + + + + + + + + + + +