From graffito-commits-returnugarcia@example.com Sat May 13 15:07:46 2006 Return-Path: <graffito-commits-returnugarcia@example.com> Delivered-To: ugarcia@example.com Received: (qmail 66792 invoked from network); 13 May 2006 15:07:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 13 May 2006 15:07:46 -0000 Received: (qmail 19039 invoked by uid 500); 13 May 2006 15:07:45 -0000 Mailing-List: contact ugarcia@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:ugarcia@example.com> List-Unsubscribe: <mailto:ugarcia@example.com> List-Post: <mailto:ugarcia@example.com> List-Id: <graffito-commits.incubator.apache.org> Reply-To: ugarcia@example.com Delivered-To: mailing list ugarcia@example.com Received: (qmail 19027 invoked by uid 99); 13 May 2006 15:07:45 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 May 2006 08:07:45 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO minotaur.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 13 May 2006 08:07:44 -0700 Received: (qmail 66761 invoked by uid 65534); 13 May 2006 15:07:24 -0000 Message-ID: <ugarcia@example.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r406117 - /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/ Date: Sat, 13 May 2006 15:07:24 -0000 To: ugarcia@example.com From: ugarcia@example.com X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: clombart Date: Sat May 13 08:07:23 2006 New Revision: 406117 URL: http://svn.apache.org/viewcvs?rev=406117&view=rev Log: Add several modifications : * jcrNodeType is not mandatory.If not present the default value is "nt:unstructured". * discriminator field descriptor was removed. Only the flag discriminator is defined on the class descriptor. If this flag is true, a mixin node type "graffito:discriminator" is added to the node. This type contains one property to store the java classname (graffito:classname). With this implementation, the discriminator field is not necessary. So, the persistence mechanism is still transparent for the jaba beans. * Interface support : like the inheritance support, there are 2 differents strategies : node type per concrete class or per complete hierarchy. The hierarchy strategy requires a discriminator node type. Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/ From graffito-commits-returnugarcia@example.com Sat May 13 15:08:39 2006 Return-Path: <graffito-commits-returnugarcia@example.com> Delivered-To: ugarcia@example.com Received: (qmail 66965 invoked from network); 13 May 2006 15:08:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 13 May 2006 15:08:39 -0000 Received: (qmail 19285 invoked by uid 500); 13 May 2006 15:08:38 -0000 Mailing-List: contact ugarcia@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:ugarcia@example.com> List-Unsubscribe: <mailto:ugarcia@example.com> List-Post: <mailto:ugarcia@example.com> List-Id: <graffito-commits.incubator.apache.org> Reply-To: ugarcia@example.com Delivered-To: mailing list ugarcia@example.com Received: (qmail 19273 invoked by uid 99); 13 May 2006 15:08:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 May 2006 08:08:37 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO minotaur.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 13 May 2006 08:08:34 -0700 Received: (qmail 66908 invoked by uid 65534); 13 May 2006 15:08:13 -0000 Message-ID: <ugarcia@example.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r406118 [1/2] - in /incubator/graffito/trunk/jcr/jcr-mapping/src: dtd/ java/org/apache/portals/graffito/jcr/mapper/impl/ java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/ java/org/apache/po... Date: Sat, 13 May 2006 15:08:06 -0000 To: ugarcia@example.com From: ugarcia@example.com X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: clombart Date: Sat May 13 08:08:04 2006 New Revision: 406118 URL: http://svn.apache.org/viewcvs?rev=406118&view=rev Log: Add several modifications : * jcrNodeType is not mandatory.If not present the default value is "nt:unstructured". * discriminator field descriptor was removed. Only the flag discriminator is defined on the class descriptor. If this flag is true, a mixin node type "graffito:discriminator" is added to the node. This type contains one property to store the java classname (graffito:classname). With this implementation, the discriminator field is not necessary. So, the persistence mechanism is still transparent for the jaba beans. * Interface support : like the inheritance support, there are 2 differents strategies : node type per concrete class or per complete hierarchy. The hierarchy strategy requires a discriminator node type. Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ImplementDescriptor.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceConstant.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceConcreteClassTest.java - copied, changed from r393615, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceHierarchyTest.java - copied, changed from r388968, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtHierarchyTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceConcreteClassTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceHierarchyTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/CmsObjectImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/ContentImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/DocumentImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/DocumentStream.java - copied, changed from r390238, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/DocumentStream.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/impl/FolderImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/AnotherInterface.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/CmsObject.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/Content.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/Document.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/Folder.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/interfaces/Interface.java Removed: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtHierarchyTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/CmsObject.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Content.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Document.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/DocumentStream.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Folder.java Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/AnotherDescendant.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/inheritance/Descendant.java Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd Sat May 13 08:08:04 2006 @@ -28,21 +28,26 @@ * jcrSuperTypes : the jcr super types, optional * jcrMixinTypes: the jcr mixin types (comma separated list) (optional) * extends: name of super class (optional) - * extends-strategy: - * polymorphism: specify the behavior of this class in queries; default implicit * abstract: true if this class is abstract and it is used in hierarchy mappings - * discriminator-value: use only when extends-strategy="concreteclass" and abstract="false" + * discriminator true if the mapped node requires an graffito:discriminator node type. This type contains a classname property. --> -<!ELEMENT class-descriptor (field-descriptor*, bean-descriptor*, collection-descriptor*)> +<!ELEMENT class-descriptor (implement-descriptor*, field-descriptor*, bean-descriptor*, collection-descriptor*)> <!ATTLIST class-descriptor className CDATA #REQUIRED jcrNodeType CDATA #IMPLIED jcrSuperTypes CDATA #IMPLIED jcrMixinTypes CDATA #IMPLIED - extends CDATA #IMPLIED + extend CDATA #IMPLIED abstract (true|false) "false" - discriminatorValue CDATA #IMPLIED + interface (true|false) "false" + discriminator (true|false) "true" +> + +<!ELEMENT implement-descriptor EMPTY> + +<!ATTLIST implement-descriptor + interfaceName CDATA #REQUIRED > <!-- @@ -67,7 +72,6 @@ jcrName CDATA #IMPLIED id (true | false) "false" path (true | false) "false" - discriminator (true | false) "false" jcrType (String | Date | Long | Double | Boolean | Binary) #IMPLIED jcrAutoCreated (true | false) "false" jcrMandatory (true | false) "false" Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java Sat May 13 08:08:04 2006 @@ -26,7 +26,9 @@ import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor; import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor; import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor; +import org.apache.portals.graffito.jcr.mapper.model.ImplementDescriptor; import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor; +import org.xml.sax.SAXParseException; /** * Helper class that reads the xml mapping file and load all class descriptors into memory (object graph) @@ -68,80 +70,47 @@ digester.register("-//The Apache Software Foundation//DTD Repository//EN", this.dtdResolver.toString()); } - - digester.addObjectCreate("graffito-jcr", MappingDescriptor.class); - digester.addSetProperties("graffito-jcr", "package", "package"); + + MappingDescriptor mappingDescriptor = new MappingDescriptor(); + digester.push(mappingDescriptor); + + // TODO : activater the following line wich cause some bugs when loading the xml stream + //digester.addSetProperties("graffito-jcr", package, pa); // -------------------------------------------------------------------------------- // Rules used for the class-descriptor element - // -------------------------------------------------------------------------------- - + // -------------------------------------------------------------------------------- digester.addObjectCreate("graffito-jcr/class-descriptor", ClassDescriptor.class); - digester.addSetProperties("graffito-jcr/class-descriptor", "className", "className"); - digester.addSetProperties("graffito-jcr/class-descriptor", "jcrNodeType", "jcrNodeType"); - digester.addSetProperties("graffito-jcr/class-descriptor", "jcrSuperTypes", "jcrSuperTypes"); - digester.addSetProperties("graffito-jcr/class-descriptor", "jcrMixinTypes", "jcrMixinTypes"); - digester.addSetProperties("graffito-jcr/class-descriptor", "extends", "superClass"); - digester.addSetProperties("graffito-jcr/class-descriptor", "abstract", "abstract"); - digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor"); + digester.addSetProperties("graffito-jcr/class-descriptor"); + digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor"); // -------------------------------------------------------------------------------- // Rules used for the field-descriptor element // -------------------------------------------------------------------------------- - + digester.addObjectCreate("graffito-jcr/class-descriptor/implement-descriptor", ImplementDescriptor.class); + digester.addSetProperties("graffito-jcr/class-descriptor/implement-descriptor"); + digester.addSetNext("graffito-jcr/class-descriptor/implement-descriptor", "addImplementDescriptor"); + + // -------------------------------------------------------------------------------- + // Rules used for the field-descriptor element + // -------------------------------------------------------------------------------- digester.addObjectCreate("graffito-jcr/class-descriptor/field-descriptor", FieldDescriptor.class); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "fieldName", "fieldName"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "fieldType", "fieldType"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrName", "jcrName"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "id", "id"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "path", "path"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "discriminator", "discriminator"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrType", "jcrType"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrAutoCreated", "jcrAutoCreated"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrMandatory", "jcrMandatory"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrOnParentVersion", "jcrOnParentVersion"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrProtected", "jcrProtected"); - digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrMultiple", "jcrMultiple"); - + digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor"); 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.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "inline", "inline"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "converter", "converter"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrNodeType", "jcrNodeType"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrAutoCreated", "jcrAutoCreated"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrMandatory", "jcrMandatory"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrOnParentVersion", "jcrOnParentVersion"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrProtected", "jcrProtected"); - digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor", "jcrSameNameSiblings", "jcrSameNameSiblings"); - + digester.addSetProperties("graffito-jcr/class-descriptor/bean-descriptor"); digester.addSetNext("graffito-jcr/class-descriptor/bean-descriptor", "addBeanDescriptor"); // -------------------------------------------------------------------------------- // Rules used for the collection-descriptor element // -------------------------------------------------------------------------------- - digester.addObjectCreate("graffito-jcr/class-descriptor/collection-descriptor", CollectionDescriptor.class); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "fieldName", "fieldName"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrName", "jcrName"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "proxy", "proxy"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "elementClassName", "elementClassName"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "collectionConverter", "collectionConverterClassName"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "collectionClassName", "collectionClassName"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrNodeType", "jcrNodeType"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrAutoCreated", "jcrAutoCreated"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrMandatory", "jcrMandatory"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrOnParentVersion", "jcrOnParentVersion"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrProtected", "jcrProtected"); - digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor", "jcrSameNameSiblings", "jcrSameNameSiblings"); - digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor"); + digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor"); + digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor"); return (MappingDescriptor) digester.parse(stream); } @@ -164,9 +133,10 @@ { return loadClassDescriptors(new FileInputStream(xmlFile)); } + catch (FileNotFoundException e) { - throw new InitMapperException(e); + throw new InitMapperException("Mapping file not found : " + xmlFile,e); } } } Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java Sat May 13 08:08:04 2006 @@ -170,23 +170,53 @@ Map.Entry entry = (Map.Entry) it.next(); ClassDescriptor cd = (ClassDescriptor) entry.getValue(); - if (null != cd.getSuperClass() && !"".equals(cd.getSuperClass())) { - ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptor(cd.getSuperClass()); + if (null != cd.getExtend() && !"".equals(cd.getExtend())) + { + ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptor(cd.getExtend()); - if (null == superClassDescriptor) { + if (null == superClassDescriptor) + { errors.add("Cannot find mapping for class " - + cd.getSuperClass() + + cd.getExtend() + " referenced as extends from " + cd.getClassName()); } - else { - log.debug("Class " +cd.getClassName() + " extends " + cd.getSuperClass()); + else + { + log.debug("Class " +cd.getClassName() + " extends " + cd.getExtend()); cd.setSuperClassDescriptor(superClassDescriptor); } } - else { - rootClassDescriptors.add(cd); + else + { + rootClassDescriptors.add(cd); } + + Collection interfaces = cd.getImplements(); + if (interfaces.size() > 0) + { + for (Iterator iterator = interfaces.iterator(); iterator.hasNext();) + { + String interfaceName= (String) iterator.next(); + ClassDescriptor interfaceClassDescriptor = this.mappingDescriptor.getClassDescriptor(interfaceName); + + if (null == interfaceClassDescriptor) + { + errors.add("Cannot find mapping for interface " + + interfaceName + + " referenced as implements from " + + cd.getClassName()); + } + else + { + log.debug("Class " +cd.getClassName() + " implements " + interfaceName); + //cd.setSuperClassDescriptor(interfaceClassDescriptor); + interfaceClassDescriptor.addDescendantClassDescriptor(cd); + } + + } + } + } return errors; Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java Sat May 13 08:08:04 2006 @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; @@ -51,7 +52,6 @@ private String[] jcrMixinTypes = new String[0]; private FieldDescriptor idFieldDescriptor; private FieldDescriptor pathFieldDescriptor; - private FieldDescriptor discriminatorFieldDescriptor; private Map fieldDescriptors = new HashMap(); private Map beanDescriptors = new HashMap(); @@ -60,19 +60,45 @@ private Map fieldNames = new HashMap(); private String superClassName; - private String extendsStrategy; - private boolean abstractClass = false; + private String extendsStrategy; + private boolean isAbstract = false; private boolean hasDescendant = false; + private boolean hasDiscriminator = true; + + private boolean isInterface=false; + private List interfaces = new ArrayList(); public void setAbstract(boolean flag) { - this.abstractClass = flag; + this.isAbstract = flag; } public boolean isAbstract() { - return this.abstractClass; + return this.isAbstract; } + public void setInterface(boolean flag) { + this.isInterface = flag; + } + + public boolean isInterface() { + return isInterface; + } + + public boolean hasInterfaces() + { + return this.interfaces.size() > 0; + } + + public void setDiscriminator(boolean flag) + { + this.hasDiscriminator = flag; + } + + public boolean hasDiscriminator() { + return this.hasDiscriminator; + } + public boolean usesNodeTypePerHierarchyStrategy() { return NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy); } @@ -120,14 +146,16 @@ if (fieldDescriptor.isPath()) { this.pathFieldDescriptor = fieldDescriptor; } - if (fieldDescriptor.isDiscriminator()) { - this.discriminatorFieldDescriptor = fieldDescriptor; - } fieldDescriptors.put(fieldDescriptor.getFieldName(), fieldDescriptor); fieldNames.put(fieldDescriptor.getFieldName(), fieldDescriptor.getJcrName()); } + public void addImplementDescriptor(ImplementDescriptor implementDescriptor) + { + interfaces.add(implementDescriptor.getInterfaceName()); + } + /** * Get the FieldDescriptor to used for a specific java bean attribute * @param fieldName The java bean attribute name @@ -224,28 +252,13 @@ return null; } - public FieldDescriptor getDiscriminatorFieldDescriptor() { - if (null != this.discriminatorFieldDescriptor) { - return this.discriminatorFieldDescriptor; - } - - if (null != this.superClassDescriptor) { - return this.superClassDescriptor.getDiscriminatorFieldDescriptor(); - } - - return null; - } - - public boolean hasDiscriminatorField() { - return this.getDiscriminatorFieldDescriptor() != null; - } /** * Check if this class has an ID * @return true if the class has an ID */ - public boolean hasIdField() { - return this.idFieldDescriptor != null; + public boolean hasIdField() { + return (this.idFieldDescriptor != null && ! this.idFieldDescriptor.equals("")); } /** @@ -254,7 +267,31 @@ * @return the JCR name found */ public String getJcrName(String fieldName) { - return (String) this.fieldNames.get(fieldName); + String jcrName = (String) this.fieldNames.get(fieldName); + if (this.isInterface && jcrName == null) + { + return this.getJcrNameFromDescendants(this, fieldName); + } + + return jcrName; + } + + private String getJcrNameFromDescendants(ClassDescriptor classDescriptor, String fieldName ) + { + Iterator descendants = classDescriptor.getDescendantClassDescriptors().iterator(); + while (descendants.hasNext()) + { + ClassDescriptor descendant = (ClassDescriptor) descendants.next(); + String jcrName = (String) descendant.fieldNames.get(fieldName); + if(jcrName != null) + { + return jcrName; + } + return this.getJcrNameFromDescendants(descendant, fieldName); + } + return null; + + } public Map getFieldNames() { @@ -319,7 +356,7 @@ validateBeanFields(); lookupSuperDescriptor(); lookupInheritanceSettings(); - validateInheritanceSettings(); +// validateInheritanceSettings(); } private void validateClassName() { @@ -346,16 +383,21 @@ private void lookupSuperDescriptor() { if (null != superClassDescriptor) { - this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors()); - this.beanDescriptors = mergeBeans(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors()); - this.collectionDescriptors = mergeCollections(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors()); - this.fieldNames.putAll(this.superClassDescriptor.getFieldNames()); + this.hasDiscriminator = superClassDescriptor.hasDiscriminator(); + if (! this.isInterface) + { + this.fieldDescriptors = mergeFields(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors()); + this.beanDescriptors = mergeBeans(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors()); + this.collectionDescriptors = mergeCollections(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors()); + this.fieldNames.putAll(this.superClassDescriptor.getFieldNames()); + } + } } private void lookupInheritanceSettings() { - if ((null != this.superClassDescriptor) || (this.hasDescendants() )) { - if (this.hasDiscriminatorField()) { + if ((null != this.superClassDescriptor) || (this.hasDescendants()) || this.hasInterfaces()) { + if (this.hasDiscriminator()) { this.extendsStrategy = NODETYPE_PER_HIERARCHY; } else { @@ -364,36 +406,19 @@ } } - private void validateInheritanceSettings() { - if (NODETYPE_PER_CONCRETECLASS.equals(this.extendsStrategy)) { - this.discriminatorFieldDescriptor = getDiscriminatorFieldDescriptor(); - - if (null != this.discriminatorFieldDescriptor) { - throw new JcrMappingException("Discriminator specify for the class : " + className + " but it is a node type per concrete class hierarchy"); - } - } - else if (NODETYPE_PER_HIERARCHY.equals(this.extendsStrategy)) { - this.discriminatorFieldDescriptor = getDiscriminatorFieldDescriptor(); - - if (null == this.discriminatorFieldDescriptor) { - throw new JcrMappingException("No discriminator specify for the class : " + className); - } - } - } - /** * @return return the super class name if defined in mapping, or * <tt>null</tt> if not set */ - public String getSuperClass() { + public String getExtend() { return this.superClassName; } /** * @param className */ - public void setSuperClass(String className) { + public void setExtend(String className) { this.superClassName = className; } @@ -452,7 +477,13 @@ this.superClassDescriptor= superClassDescriptor; superClassDescriptor.addDescendantClassDescriptor(this); } + + public Collection getImplements() + { + return interfaces; + } + private Map mergeFields(Map existing, Collection superSource) { if (null == superSource) { return existing; @@ -464,9 +495,9 @@ if (!merged.containsKey(fieldDescriptor.getFieldName())) { merged.put(fieldDescriptor.getFieldName(), fieldDescriptor); } - else { - log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getSuperClass()); - } +// else { +// log.warn("Field name conflict in " + this.className + " - field : " +fieldDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend()); +// } } return merged; @@ -484,9 +515,9 @@ if (!merged.containsKey(beanDescriptor.getFieldName())) { merged.put(beanDescriptor.getFieldName(), beanDescriptor); } - else { - log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getSuperClass()); - } +// else { +// log.warn("Bean name conflict in " + this.className + " - field : " +beanDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend()); +// } } return merged; @@ -503,13 +534,33 @@ if (!merged.containsKey(collectionDescriptor.getFieldName())) { merged.put(collectionDescriptor.getFieldName(), collectionDescriptor); } - else { - log.warn("Collection name conflict in " + this.className + " - field : " +collectionDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getSuperClass()); - } +// else { +// log.warn("Collection name conflict in " + this.className + " - field : " +collectionDescriptor.getFieldName() + " - this field name is also defined in the ancestor class : " + this.getExtend()); +// } } return merged; } + + +// private List mergeInterfaces(List existing, Collection superSource) { +// if (null == superSource) { +// return existing; +// } +// +// ArrayList merged = new ArrayList(existing); +// for (Iterator it = superSource.iterator(); it.hasNext();) +// { +// String interfaceName = (String) it.next(); +// if (! merged.contains(interfaceName)) +// { +// merged.add(interfaceName); +// } +// } +// +// return merged; +// } + public String toString() { return "Class Descriptor : " + this.getClassName(); Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/CollectionDescriptor.java Sat May 13 08:08:04 2006 @@ -105,7 +105,7 @@ * * @return The collection converter class name */ - public String getCollectionConverterClassName() + public String getCollectionConverter() { return collectionConverterClassName; } @@ -114,7 +114,7 @@ * Set the collection converter class name * @param collectionConverterClassName The converter to set */ - public void setCollectionConverterClassName(String collectionConverterClassName) + public void setCollectionConverter(String collectionConverterClassName) { this.collectionConverterClassName = collectionConverterClassName; } Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java Sat May 13 08:08:04 2006 @@ -38,7 +38,7 @@ private ClassDescriptor classDescriptor; private boolean id; private boolean path; - private boolean discriminator; + /** * @return Returns the fieldName. @@ -241,14 +241,6 @@ */ public void setJcrMultiple(boolean value) { this.jcrMultiple = value; - } - - public void setDiscriminator(boolean value) { - this.discriminator = value; - } - - public boolean isDiscriminator() { - return this.discriminator; } /** Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ImplementDescriptor.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ImplementDescriptor.java?rev=406118&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ImplementDescriptor.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ImplementDescriptor.java Sat May 13 08:08:04 2006 @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2005 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; + + +/** + * + * + * ImplementDescriptor is used by the mapper to read general information on a implemented interface + * + * @author <a href="mailto:ugarcia@example.com">Lombart Christophe </a> + * + */ +public class ImplementDescriptor { + private String interfaceName; + + public String getInterfaceName() { + return interfaceName; + } + + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + public String toString() { + + return "Field Descriptor : " + this.interfaceName; + } +} Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java Sat May 13 08:08:04 2006 @@ -55,8 +55,8 @@ if (null != this.packageName && !"".equals(this.packageName)) { classDescriptor.setClassName(this.packageName + "." + classDescriptor.getClassName()); - if (null != classDescriptor.getSuperClass() && !"".equals(classDescriptor.getSuperClass())) { - classDescriptor.setSuperClass(this.packageName + "." + classDescriptor.getSuperClass()); + if (null != classDescriptor.getExtend() && !"".equals(classDescriptor.getExtend())) { + classDescriptor.setExtend(this.packageName + "." + classDescriptor.getExtend()); } } Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceConstant.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceConstant.java?rev=406118&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceConstant.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/PersistenceConstant.java Sat May 13 08:08:04 2006 @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2005 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.persistence; + + + +/** + * + * General Persistence Constants use in several classes + * + * @author <a href="mailto:ugarcia@example.com">Lombart Christophe </a> + * + */ +public interface PersistenceConstant +{ + public static final String NT_UNSTRUCTURED = "nt:unstructured"; + public static final String DISCRIMINATOR_NODE_TYPE = "graffito:discriminator"; + public static final String DISCRIMINATOR_PROPERTY_NAME = "graffito:classname"; + + +} \ No newline at end of file Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/collectionconverter/impl/DefaultCollectionConverterImpl.java Sat May 13 08:08:04 2006 @@ -100,7 +100,7 @@ if (jcrName == null) { throw new JcrMappingException( "The JcrName attribute is not defined for the CollectionDescriptor : " - + collectionDescriptor.getFieldName()); + + collectionDescriptor.getFieldName() + " for the classdescriptor : " + collectionDescriptor.getClassDescriptor().getClassName()); } Node collectionNode = parentNode.addNode(jcrName); Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ObjectConverterImpl.java Sat May 13 08:08:04 2006 @@ -42,6 +42,7 @@ import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor; import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor; import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor; +import org.apache.portals.graffito.jcr.persistence.PersistenceConstant; import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter; import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider; import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.NullTypeConverterImpl; @@ -53,11 +54,12 @@ import org.apache.portals.graffito.jcr.reflection.ReflectionUtils; import org.apache.portals.graffito.jcr.repository.RepositoryUtil; +import sun.reflect.misc.ReflectUtil; + /** * Default implementation for {@link ObjectConverterImpl} * - * @author <a href="mailto:ugarcia@example.com">Lombart - * Christophe </a> + * @author <a href="mailto:ugarcia@example.com">Lombart Christophe </a> * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a> */ public class ObjectConverterImpl implements ObjectConverter { @@ -143,7 +145,7 @@ String jcrNodeType = classDescriptor.getJcrNodeType(); if ((jcrNodeType == null) || jcrNodeType.equals("")) { - throw new JcrMappingException("Undefined node type for " + parentNode); + jcrNodeType= PersistenceConstant.NT_UNSTRUCTURED; } Node objectNode = null; @@ -157,20 +159,45 @@ + object.getClass(), re); } - if (null != classDescriptor.getJcrMixinTypes()) { - String[] mixinTypes = classDescriptor.getJcrMixinTypes(); - for (int i = 0; i < mixinTypes.length; i++) { - try { - objectNode.addMixin(mixinTypes[i].trim()); - } catch (NoSuchNodeTypeException nsnte) { - throw new JcrMappingException("Unknown mixin type " + mixinTypes[i].trim() + " for mapped class " - + object.getClass(), nsnte); - } catch (RepositoryException re) { - throw new PersistenceException("Cannot create new node of type " + jcrNodeType + " from mapped class " - + object.getClass(), re); + String[] mixinTypes = classDescriptor.getJcrMixinTypes(); + String mixinTypeName = null; + try { + + // Add mixin types + if (null != classDescriptor.getJcrMixinTypes()) { + for (int i = 0; i < mixinTypes.length; i++) { + mixinTypeName = mixinTypes[i].trim(); + objectNode.addMixin(mixinTypeName); } } + + // Add mixin types defined in the associated interfaces + if (! classDescriptor.hasDiscriminator() && classDescriptor.hasInterfaces()) + { + Iterator interfacesIterator = classDescriptor.getImplements().iterator(); + while (interfacesIterator.hasNext()) + { + String interfaceName = (String) interfacesIterator.next(); + ClassDescriptor interfaceDescriptor = mapper.getClassDescriptor(ReflectionUtils.forName(interfaceName)); + objectNode.addMixin(interfaceDescriptor.getJcrNodeType().trim()); + } + } + + // If required, add the discriminator node type + if (classDescriptor.hasDiscriminator()) + { + mixinTypeName = PersistenceConstant.DISCRIMINATOR_NODE_TYPE; + objectNode.addMixin(mixinTypeName); + objectNode.setProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME, ReflectionUtils.getBeanClass(object).getName()); + } + } catch (NoSuchNodeTypeException nsnte) { + throw new JcrMappingException( + "Unknown mixin type " + mixinTypeName + " for mapped class " + object.getClass(), nsnte); + } catch (RepositoryException re) { + throw new PersistenceException("Cannot create new node of type " + jcrNodeType + " from mapped class " + + object.getClass(), re); } + storeSimpleFields(session, object, classDescriptor, objectNode); insertBeanFields(session, object, classDescriptor, objectNode); @@ -207,7 +234,8 @@ Node objectNode = parentNode.getNode(nodeName); checkNodeType(session, classDescriptor); - checkCompatibleNodeTypes(session, objectNode, classDescriptor, false); + + checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false); storeSimpleFields(session, object, classDescriptor, objectNode); updateBeanFields(session, object, classDescriptor, objectNode); @@ -235,18 +263,19 @@ checkNodeType(session, classDescriptor); Node node = (Node) session.getItem(path); - - checkCompatibleNodeTypes(session, node, classDescriptor, true); + if (! classDescriptor.isInterface()) + { + checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true); + } + Object object = null; - if (classDescriptor.usesNodeTypePerHierarchyStrategy()) { - String discriminatorProperty = classDescriptor.getDiscriminatorFieldDescriptor().getJcrName(); - - if (!node.hasProperty(discriminatorProperty)) { + if (classDescriptor.usesNodeTypePerHierarchyStrategy()) { + if (!node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) { throw new PersistenceException("Cannot fetch object of type '" + clazz.getName() + "' using NODETYPE_PER_HIERARCHY. Discriminator property is not present."); } - String className = node.getProperty(discriminatorProperty).getValue().getString(); + String className = node.getProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString(); classDescriptor = getClassDescriptor(Class.forName(className)); object = ReflectionUtils.newInstance(className); } else { @@ -288,11 +317,31 @@ * thrown if an error occured in the underlying repository */ private void checkNodeType(Session session, ClassDescriptor classDescriptor) { + String jcrTypeName = null; try { - session.getWorkspace().getNodeTypeManager().getNodeType(classDescriptor.getJcrNodeType()); + + + //Don't check the primary node type for interfaces. They are only associated to mixin node type + if ( classDescriptor.isInterface()) + { + String[] mixinTypes = classDescriptor.getJcrMixinTypes(); + for (int i=0; i<mixinTypes.length; i++) + { + jcrTypeName = mixinTypes[i]; + session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName); + } + } + else + { + jcrTypeName = classDescriptor.getJcrNodeType(); + if(jcrTypeName != null && ! jcrTypeName.equals("")) + { + session.getWorkspace().getNodeTypeManager().getNodeType(jcrTypeName); + } + } } catch (NoSuchNodeTypeException nsnte) { - throw new JcrMappingException("Mapping for class '" + classDescriptor.getClassName() + "' use unknown node type '" - + classDescriptor.getJcrNodeType() + "'"); + throw new JcrMappingException("Mapping for class '" + classDescriptor.getClassName() + "' use unknown primary or mixin node type '" + + jcrTypeName + "'"); } catch (RepositoryException re) { throw new org.apache.portals.graffito.jcr.exception.RepositoryException(re); } @@ -318,7 +367,7 @@ * @throws org.apache.portals.graffito.jcr.exception.RepositoryException * thrown if an error occured in the underlying repository */ - private void checkCompatibleNodeTypes(Session session, Node node, ClassDescriptor classDescriptor, boolean checkVersionNode) { + private void checkCompatiblePrimaryNodeTypes(Session session, Node node, ClassDescriptor classDescriptor, boolean checkVersionNode) { try { NodeType nodeType = node.getPrimaryNodeType(); @@ -352,6 +401,13 @@ * <tt>false</tt> otherwise */ private boolean checkCompatibleNodeTypes(NodeType nodeType, ClassDescriptor descriptor) { + + //return true if node type is not used + if (descriptor.getJcrNodeType() == null ||descriptor.getJcrNodeType().equals("") ) + { + return true; + } + if (nodeType.getName().equals(descriptor.getJcrNodeType())) { return true; } @@ -412,14 +468,13 @@ ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath()); - } else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) { + } else if (classDescriptor.usesNodeTypePerHierarchyStrategy() && classDescriptor.hasDiscriminator()) { - if (node.hasProperty(classDescriptor.getDiscriminatorFieldDescriptor().getJcrName())) { + if (node.hasProperty(PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME)) { if (null == initializedBean) { initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName()); } - String value = node.getProperty(classDescriptor.getDiscriminatorFieldDescriptor().getJcrName()) - .getValue().getString(); + String value = node.getProperty(propertyName).getValue().getString(); ReflectionUtils.setNestedProperty(initializedBean, fieldName, value); } else { throw new PersistenceException("Class '" + classDescriptor.getClassName() @@ -610,19 +665,13 @@ continue; } - if (classDescriptor.usesNodeTypePerHierarchyStrategy() && fieldDescriptor.isDiscriminator()) { - objectNode.setProperty(fieldDescriptor.getJcrName(), classDescriptor.getClassName()); - continue; - } - boolean protectedProperty = fieldDescriptor.isJcrProtected(); if (objectNode.hasProperty(jcrName)) { protectedProperty = objectNode.getProperty(jcrName).getDefinition().isProtected(); } - if (!protectedProperty) { // DO NOT TRY TO WRITE PROTECTED - // PROPERTIES + if (!protectedProperty) { // DO NOT TRY TO WRITE PROTECTED PROPERTIES Object fieldValue = ReflectionUtils.getNestedProperty(object, fieldName); AtomicTypeConverter converter = getAtomicTypeConverter(fieldDescriptor, object, fieldName); Value value = converter.getValue(valueFactory, fieldValue); @@ -657,7 +706,7 @@ } private CollectionConverter getCollectionConverter(Session session, CollectionDescriptor collectionDescriptor) { - String className = collectionDescriptor.getCollectionConverterClassName(); + String className = collectionDescriptor.getCollectionConverter(); Map atomicTypeConverters = this.atomicTypeConverterProvider.getAtomicTypeConverters(); if (className == null) { return new DefaultCollectionConverterImpl(atomicTypeConverters, this, this.mapper); Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/query/impl/QueryManagerImpl.java Sat May 13 08:08:04 2006 @@ -23,13 +23,14 @@ import org.apache.portals.graffito.jcr.mapper.Mapper; import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor; import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor; +import org.apache.portals.graffito.jcr.persistence.PersistenceConstant; import org.apache.portals.graffito.jcr.query.Filter; import org.apache.portals.graffito.jcr.query.Query; import org.apache.portals.graffito.jcr.query.QueryManager; public class QueryManagerImpl implements QueryManager { - - private Mapper mapper; + + private Mapper mapper; private Map atomicTypeConverters; public QueryManagerImpl(Mapper mapper, Map atomicTypeConverters) { @@ -53,7 +54,7 @@ // Check if the class has an inheritance discriminator field ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass()); - if (classDescriptor.hasDiscriminatorField()) { + if (classDescriptor.hasDiscriminator()) { Filter discrininatorFilter = buildDiscriminatorFilter(query, classDescriptor); filter = filter.addAndFilter(discrininatorFilter); } @@ -88,10 +89,8 @@ private Filter buildDiscriminatorFilter(Query query, ClassDescriptor classDescriptor) { Filter discriminatorFilter = this.createFilter(query.getFilter().getFilterClass()); - if (!classDescriptor.isAbstract()) { - FieldDescriptor fieldDescriptor = classDescriptor.getDiscriminatorFieldDescriptor(); - discriminatorFilter.addEqualTo(fieldDescriptor.getFieldName(), - classDescriptor.getClassName()); + if (!classDescriptor.isAbstract() && (! classDescriptor.isInterface()) ) { + discriminatorFilter.addJCRExpression("@" + PersistenceConstant.DISCRIMINATOR_PROPERTY_NAME + "='" + classDescriptor.getClassName() + "'"); } if (classDescriptor.hasDescendants()) { @@ -113,7 +112,15 @@ private String getNodeType(Filter filter) { ClassDescriptor classDescriptor = mapper.getClassDescriptor(filter.getFilterClass()); - return classDescriptor.getJcrNodeType(); + String jcrNodeType = classDescriptor.getJcrNodeType(); + if (jcrNodeType == null || jcrNodeType.equals("")) + { + return PersistenceConstant.NT_UNSTRUCTURED; + } + else + { + return jcrNodeType; + } } } Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-atomic.xml Sat May 13 08:08:04 2006 @@ -3,7 +3,7 @@ <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "./src/dtd/graffito-jcr-mapping.dtd"> <graffito-jcr> <class-descriptor - className="org.apache.portals.graffito.jcr.testmodel.Atomic" jcrNodeType="nt:unstructured"> + className="org.apache.portals.graffito.jcr.testmodel.Atomic" jcrNodeType="nt:unstructured" discriminator="false" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="string" jcrName="string" /> <field-descriptor fieldName="booleanObject" jcrName="booleanObject" /> @@ -20,7 +20,7 @@ </class-descriptor> <class-descriptor - className="org.apache.portals.graffito.jcr.testmodel.MultiValue" jcrNodeType="nt:unstructured"> + className="org.apache.portals.graffito.jcr.testmodel.MultiValue" jcrNodeType="nt:unstructured" discriminator="false" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="name" jcrName="name" /> <collection-descriptor fieldName="multiValues" jcrName="multiValue" proxy="false" Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-inheritance.xml Sat May 13 08:08:04 2006 @@ -3,34 +3,58 @@ <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "./src/dtd/graffito-jcr-mapping.dtd"> <graffito-jcr> - <!-- MAPPING USED TO TEST NODE TYPE PER HIERARCHY --> - - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" jcrNodeType="nt:unstructured" abstract="true" > + <!--MAPPING USED TO TEST INTERFACES WITHOUT NODE TYPE --> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.Interface" interface="true" /> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.AnotherInterface" interface="true" /> + + <!--MAPPING USED TO TEST INTERFACES WITH NODE TYPE --> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject" interface="true" discriminator="false" + jcrNodeType="graffito:cmsobject" /> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.Folder" interface="true" discriminator="false" + extend="org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject" jcrNodeType="graffito:folder" /> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.Content" interface="true" discriminator="false" + extend="org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject" jcrNodeType="graffito:content" /> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.interfaces.Document" interface="true" discriminator="false" + extend="org.apache.portals.graffito.jcr.testmodel.interfaces.Content" jcrNodeType="graffito:document" /> + + + <!-- MAPPING USED TO TEST NODE TYPE PER HIERARCHY --> + + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" abstract="true" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="ancestorField" jcrName="ancestorField" /> - <field-descriptor fieldName="discriminator" jcrName="discriminator" discriminator="true" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant" jcrNodeType="nt:unstructured" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor"> + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.AnotherInterface" /> <field-descriptor fieldName="descendantField" jcrName="descendantField" /> </class-descriptor > - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant" jcrNodeType="nt:unstructured" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor" > + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.Interface" /> <field-descriptor fieldName="anotherDescendantField" jcrName="anotherDescendantField" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant" jcrNodeType="nt:unstructured" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant" > <field-descriptor fieldName="subDescendantField" jcrName="subDescendantField" /> </class-descriptor> <!-- MAPPING USED TO TEST NODE TYPE PER CONCRETE CLASS --> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" jcrNodeType="graffito:cmsobject" abstract="true" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl" jcrNodeType="graffito:cmsobjectimpl" + discriminator="false" abstract="true" > + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject" /> + <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="name" jcrName="graffito:name" id="true" /> <!-- bean-descriptor fieldName="parentFolder" @@ -38,25 +62,28 @@ </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Folder" jcrNodeType="graffito:folder" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.FolderImpl" jcrNodeType="graffito:folderimpl" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl" > + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.Folder" /> <collection-descriptor fieldName="children" proxy="true" - elementClassName="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" + elementClassName="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl" collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" /> </class-descriptor > - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Content" jcrNodeType="graffito:content" abstract="true" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.ContentImpl" jcrNodeType="graffito:contentimpl" abstract="true" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl" > + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.Content" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.Document" jcrNodeType="graffito:document" - extends="org.apache.portals.graffito.jcr.testmodel.inheritance.Content" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl" jcrNodeType="graffito:documentimpl" + extend="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.ContentImpl" > + <implement-descriptor interfaceName="org.apache.portals.graffito.jcr.testmodel.interfaces.Document" /> <field-descriptor fieldName="contentType" jcrName="graffito:contenttype" /> <field-descriptor fieldName="size" jcrName="graffito:size" /> <bean-descriptor fieldName="documentStream" jcrName="graffito:documentstream" proxy="true" /> </class-descriptor > - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.DocumentStream" jcrNodeType="graffito:documentstream" > + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentStream" jcrNodeType="graffito:documentstream" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="encoding" jcrName="graffito:encoding" /> <field-descriptor fieldName="content" jcrName="graffito:binarycontent" /> Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml Sat May 13 08:08:04 2006 @@ -3,7 +3,7 @@ <!DOCTYPE graffito-jcr PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "./src/dtd/graffito-jcr-mapping.dtd"> <graffito-jcr> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.proxy.Main" jcrNodeType="nt:unstructured"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.proxy.Main" jcrNodeType="nt:unstructured" > <!-- Field-descriptor is used to map simple attributes to jcr property --> <field-descriptor fieldName="path" path="true" /> <bean-descriptor fieldName="proxyDetail" jcrName="proxydetail" proxy="true" jcrNodeType="nt:unstructured" /> @@ -16,7 +16,7 @@ elementClassName="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured"/> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.proxy.Detail" jcrNodeType="nt:unstructured" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="field" jcrName="field" /> </class-descriptor> Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping.xml Sat May 13 08:08:04 2006 @@ -53,14 +53,14 @@ </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.C" jcrNodeType="graffito:C"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.C" jcrNodeType="graffito:C" discriminator="false" > <!-- Field-descriptor is used to map simple attributes to jcr property --> <field-descriptor fieldName="id" jcrName="graffito:id" id="true" /> <field-descriptor fieldName="name" jcrName="graffito:name" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="graffito:page"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="graffito:page" discriminator="false" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="title" jcrName="graffito:title" /> <collection-descriptor fieldName="paragraphs" proxy="false" @@ -68,23 +68,23 @@ collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Paragraph" jcrNodeType="graffito:paragraph" discriminator="false" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="text" jcrName="graffito:text"/> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Main" jcrNodeType="nt:unstructured"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Main" jcrNodeType="nt:unstructured" discriminator="false" > <field-descriptor fieldName="path" path="true" /> <field-descriptor fieldName="text" jcrName="text" /> - <collection-descriptor fieldName="elements" proxy="false" + <collection-descriptor fieldName="elements" proxy="false" elementClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.Element" collectionConverter="org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.NTCollectionConverterImpl" collectionClassName="org.apache.portals.graffito.jcr.testmodel.hashmap.HashMapElement" /> </class-descriptor> - <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element" jcrNodeType="graffito:element"> + <class-descriptor className="org.apache.portals.graffito.jcr.testmodel.hashmap.Element" jcrNodeType="graffito:element" discriminator="false" > <field-descriptor fieldName="id" jcrName="graffito:id" /> <field-descriptor fieldName="text" jcrName="graffito:text" /> </class-descriptor> Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/repository/repository/nodetypes/custom_nodetypes.xml Sat May 13 08:08:04 2006 @@ -66,7 +66,7 @@ <propertyDefinition name="graffito:text" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" /> </nodeType> - <nodeType name="graffito:cmsobject" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> + <nodeType name="graffito:cmsobjectimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> <supertypes> <supertype>nt:base</supertype> </supertypes> @@ -75,16 +75,16 @@ </nodeType> - <nodeType name="graffito:content" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> + <nodeType name="graffito:contentimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> <supertypes> - <supertype>graffito:cmsobject</supertype> + <supertype>graffito:cmsobjectimpl</supertype> </supertypes> </nodeType> - <nodeType name="graffito:document" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> + <nodeType name="graffito:documentimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> <supertypes> - <supertype>graffito:content</supertype> + <supertype>graffito:contentimpl</supertype> </supertypes> <propertyDefinition name="graffito:contenttype" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" /> <propertyDefinition name="graffito:size" requiredType="Long" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" /> @@ -95,13 +95,13 @@ </childNodeDefinition> </nodeType> - <nodeType name="graffito:folder" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> + <nodeType name="graffito:folderimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName=""> <supertypes> - <supertype>graffito:cmsobject</supertype> + <supertype>graffito:cmsobjectimpl</supertype> </supertypes> - <childNodeDefinition name="*" defaultPrimaryType="graffito:cmsobject" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="true"> + <childNodeDefinition name="*" defaultPrimaryType="graffito:cmsobjectimpl" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="true"> <requiredPrimaryTypes> - <requiredPrimaryType>graffito:cmsobject</requiredPrimaryType> + <requiredPrimaryType>graffito:cmsobjectimpl</requiredPrimaryType> </requiredPrimaryTypes> </childNodeDefinition> </nodeType> @@ -116,6 +116,37 @@ <propertyDefinition name="graffito:binarycontent" requiredType="Binary" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" /> </nodeType> - + <nodeType name="graffito:discriminator" isMixin="true"> + <supertypes> + <supertype>nt:base</supertype> + </supertypes> + <propertyDefinition name="graffito:classname" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" /> + </nodeType> + + + <nodeType name="graffito:cmsobject" isMixin="true"> + <supertypes> + <supertype>nt:base</supertype> + </supertypes> + </nodeType> + + <nodeType name="graffito:folder" isMixin="true"> + <supertypes> + <supertype>graffito:cmsobject</supertype> + </supertypes> + </nodeType> + + <nodeType name="graffito:content" isMixin="true"> + <supertypes> + <supertype>graffito:cmsobject</supertype> + </supertypes> + </nodeType> + + <nodeType name="graffito:document" isMixin="true"> + <supertypes> + <supertype>graffito:content</supertype> + </supertypes> + </nodeType> + </nodeTypes> Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/TestBase.java Sat May 13 08:08:04 2006 @@ -66,7 +66,7 @@ import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.TimestampTypeConverterImpl; import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.UtilDateTypeConverterImpl; import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerImpl; -import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerNtHierarchyTest; +import org.apache.portals.graffito.jcr.persistence.impl.PersistenceManagerInheritanceHierarchyTest; import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter; import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl; import org.apache.portals.graffito.jcr.query.QueryManager; @@ -268,7 +268,8 @@ while (iterator.hasNext()) { Object object = iterator.next(); - if (ReflectionUtils.getNestedProperty(object, "path").equals(path)) + String itemPath = (String) ReflectionUtils.getNestedProperty(object, "path"); + if (itemPath.equals(path)) { if (object.getClass() == objectClass) { From graffito-commits-returnugarcia@example.com Sat May 13 15:08:39 2006 Return-Path: <graffito-commits-returnugarcia@example.com> Delivered-To: ugarcia@example.com Received: (qmail 66973 invoked from network); 13 May 2006 15:08:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 13 May 2006 15:08:39 -0000 Received: (qmail 19304 invoked by uid 500); 13 May 2006 15:08:38 -0000 Mailing-List: contact ugarcia@example.com; run by ezmlm Precedence: bulk List-Help: <mailto:ugarcia@example.com> List-Unsubscribe: <mailto:ugarcia@example.com> List-Post: <mailto:ugarcia@example.com> List-Id: <graffito-commits.incubator.apache.org> Reply-To: ugarcia@example.com Delivered-To: mailing list ugarcia@example.com Received: (qmail 19274 invoked by uid 99); 13 May 2006 15:08:38 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 May 2006 08:08:38 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO minotaur.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 13 May 2006 08:08:34 -0700 Received: (qmail 66911 invoked by uid 65534); 13 May 2006 15:08:13 -0000 Message-ID: <ugarcia@example.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r406118 [2/2] - in /incubator/graffito/trunk/jcr/jcr-mapping/src: dtd/ java/org/apache/portals/graffito/jcr/mapper/impl/ java/org/apache/portals/graffito/jcr/mapper/model/ java/org/apache/portals/graffito/jcr/persistence/ java/org/apache/po... Date: Sat, 13 May 2006 15:08:06 -0000 To: ugarcia@example.com From: ugarcia@example.com X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/mapper/DigesterMapperImplTest.java Sat May 13 08:08:04 2006 @@ -31,10 +31,14 @@ import org.apache.portals.graffito.jcr.testmodel.A; import org.apache.portals.graffito.jcr.testmodel.B; import org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor; -import org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject; +import org.apache.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant; import org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant; -import org.apache.portals.graffito.jcr.testmodel.inheritance.Document; import org.apache.portals.graffito.jcr.testmodel.inheritance.SubDescendant; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl; +import org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject; +import org.apache.portals.graffito.jcr.testmodel.interfaces.Document; +import org.apache.portals.graffito.jcr.testmodel.interfaces.Interface; import org.apache.portals.graffito.jcr.testmodel.proxy.Main; /** @@ -172,7 +176,8 @@ String[] files = { "./src/test-config/jcrmapping.xml", "./src/test-config/jcrmapping-atomic.xml", "./src/test-config/jcrmapping-beandescriptor.xml", - "./src/test-config/jcrmapping-inheritance.xml" }; + "./src/test-config/jcrmapping-inheritance.xml" }; + Mapper mapper = new DigesterMapperImpl(files).buildMapper(); assertNotNull("Mapper is null", mapper); @@ -182,17 +187,12 @@ assertNotNull("Classdescriptor is null", classDescriptor); assertEquals("Incorrect path field", classDescriptor .getPathFieldDescriptor().getFieldName(), "path"); - assertEquals("Incorrect discriminator field", classDescriptor - .getDiscriminatorFieldDescriptor().getFieldName(), - "discriminator"); assertTrue("The ancestor class has no discriminator", - classDescriptor.hasDiscriminatorField()); + classDescriptor.hasDiscriminator()); assertTrue("The ancestor class is not abstract", classDescriptor .isAbstract()); assertNull("The ancestor class has an ancestor", classDescriptor .getSuperClassDescriptor()); - assertEquals("Incorrect JcrName", classDescriptor - .getJcrName("discriminator"), "discriminator"); assertTrue( "Ancestor class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); @@ -209,11 +209,8 @@ assertNotNull("Classdescriptor is null", classDescriptor); assertEquals("Incorrect path field", classDescriptor .getPathFieldDescriptor().getFieldName(), "path"); - assertEquals("Incorrect discriminator field", classDescriptor - .getDiscriminatorFieldDescriptor().getFieldName(), - "discriminator"); assertTrue("The descendant class has no discriminator", - classDescriptor.hasDiscriminatorField()); + classDescriptor.hasDiscriminator()); assertNotNull("ancerstorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField")); assertFalse("The descendant class is abstract", classDescriptor @@ -223,8 +220,6 @@ assertEquals("Invalid ancestor class for the descendant class", classDescriptor.getSuperClassDescriptor().getClassName(), "org.apache.portals.graffito.jcr.testmodel.inheritance.Ancestor"); - assertEquals("Incorrect JcrName", classDescriptor - .getJcrName("discriminator"), "discriminator"); descendandDescriptors = classDescriptor .getDescendantClassDescriptors(); assertEquals("Invalid number of descendants", descendandDescriptors @@ -240,11 +235,8 @@ assertNotNull("Classdescriptor is null", classDescriptor); assertEquals("Incorrect path field", classDescriptor .getPathFieldDescriptor().getFieldName(), "path"); - assertEquals("Incorrect discriminator field", classDescriptor - .getDiscriminatorFieldDescriptor().getFieldName(), - "discriminator"); assertTrue("The subdescendant class has no discriminator", - classDescriptor.hasDiscriminatorField()); + classDescriptor.hasDiscriminator()); assertNotNull("ancestorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField")); assertFalse("The subdescendant class is abstract", classDescriptor @@ -254,8 +246,6 @@ assertEquals("Invalid ancestor class for the descendant class", classDescriptor.getSuperClassDescriptor().getClassName(), "org.apache.portals.graffito.jcr.testmodel.inheritance.Descendant"); - assertEquals("Incorrect JcrName", classDescriptor - .getJcrName("discriminator"), "discriminator"); descendandDescriptors = classDescriptor .getDescendantClassDescriptors(); assertEquals("Invalid number of descendants", descendandDescriptors @@ -276,7 +266,7 @@ /** * * Test Node Type per concrete class setting - */ + */ public void testMapperNtConcreteClass() { try { String[] files = { "./src/test-config/jcrmapping.xml", @@ -289,15 +279,12 @@ assertNotNull("Mapper is null", mapper); - ClassDescriptor classDescriptor = mapper - .getClassDescriptor(CmsObject.class); + ClassDescriptor classDescriptor = mapper.getClassDescriptor(CmsObjectImpl.class); assertNotNull("Classdescriptor is null", classDescriptor); assertEquals("Incorrect path field", classDescriptor .getPathFieldDescriptor().getFieldName(), "path"); assertFalse("The cms object class has discriminator", - classDescriptor.hasDiscriminatorField()); - assertNull("The cms object class has an discriminator field", - classDescriptor.getDiscriminatorFieldDescriptor()); + classDescriptor.hasDiscriminator()); assertTrue("The cmsobject class is not abstract", classDescriptor .isAbstract()); assertNull("The cmsobject class has an ancestor", classDescriptor @@ -313,21 +300,19 @@ assertEquals("Invalid number of descendants", classDescriptor .getDescendantClassDescriptors().size(), 2); - classDescriptor = mapper.getClassDescriptor(Document.class); + classDescriptor = mapper.getClassDescriptor(DocumentImpl.class); assertNotNull("Classdescriptor is null", classDescriptor); assertEquals("Incorrect path field", classDescriptor .getPathFieldDescriptor().getFieldName(), "path"); assertFalse("The document class has discriminator", - classDescriptor.hasDiscriminatorField()); - assertNull("The document has an discriminator field", - classDescriptor.getDiscriminatorFieldDescriptor()); + classDescriptor.hasDiscriminator()); assertFalse("The document class is abstract", classDescriptor .isAbstract()); assertNotNull("The document class has not an ancestor", classDescriptor.getSuperClassDescriptor()); assertEquals("The document class has an invalid ancestor ancestor", classDescriptor.getSuperClassDescriptor().getClassName(), - "org.apache.portals.graffito.jcr.testmodel.inheritance.Content"); + "org.apache.portals.graffito.jcr.testmodel.inheritance.impl.ContentImpl"); assertFalse( "The document class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); @@ -346,8 +331,98 @@ } /** - * - * Test Node Type per concrete class setting + * Test interface setting + */ + public void testInterfaceWithDiscriminator() { + try { + String[] files = {"./src/test-config/jcrmapping-inheritance.xml"}; + Mapper mapper = new DigesterMapperImpl(files).buildMapper(); + + assertNotNull("Mapper is null", mapper); + ClassDescriptor classDescriptor = mapper.getClassDescriptor(Interface.class); + assertNotNull("Classdescriptor is null", classDescriptor); + assertTrue("Interface is not an interface", classDescriptor.isInterface()); + assertTrue("Interface has not a discriminator", classDescriptor.hasDiscriminator()); + String[] mixinTypes = classDescriptor.getJcrMixinTypes(); + assertEquals("Invalid mixin type for the interface",mixinTypes.length , 0); + 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.portals.graffito.jcr.testmodel.inheritance.AnotherDescendant"); + assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); + assertFalse("Incalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy()); + + classDescriptor = mapper.getClassDescriptor(AnotherDescendant.class); + assertNotNull("Classdescriptor is null", classDescriptor); + assertFalse("Interface is an interface", classDescriptor.isInterface()); + assertTrue("AnotherDescendant has not a discriminator", classDescriptor.hasDiscriminator()); + assertEquals("Invalid number of implemented interface", classDescriptor.getImplements().size(), 1); + assertEquals("Invalid interface name", classDescriptor.getImplements().iterator().next(), "org.apache.portals.graffito.jcr.testmodel.interfaces.Interface"); + assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); + assertFalse("Invalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy()); + + + } catch (JcrMappingException e) { + e.printStackTrace(); + fail("Impossible to retrieve the converter " + e); + } + } + + /** + * Test interface setting + */ + public void testInterfaceWithoutDiscriminator() + { + try { + String[] files = {"./src/test-config/jcrmapping-inheritance.xml"}; + Mapper mapper = new DigesterMapperImpl(files).buildMapper(); + + assertNotNull("Mapper is null", mapper); + ClassDescriptor classDescriptor = mapper.getClassDescriptor(CmsObject.class); + assertNotNull("Classdescriptor is null", classDescriptor); + assertTrue("CmsObject is not an interface", classDescriptor.isInterface()); + assertFalse("Interface has a discriminator", classDescriptor.hasDiscriminator()); + String[] mixinTypes = classDescriptor.getJcrMixinTypes(); + assertEquals("Invalid mixin type for the interface",mixinTypes.length , 0); + 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(),3); + assertFalse("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); + assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy()); + + + classDescriptor = mapper.getClassDescriptor(Document.class); + 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); + assertFalse("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); + assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy()); + descendants = classDescriptor.getDescendantClassDescriptors(); + assertEquals("Invalid number of implementation/descendants", descendants.size(),1); + + + classDescriptor = mapper.getClassDescriptor(DocumentImpl.class); + assertNotNull("Classdescriptor is null", classDescriptor); + assertFalse("DocumentImpl is an interface", classDescriptor.isInterface()); + assertFalse("DocumentImpl has a discriminator", classDescriptor.hasDiscriminator()); + assertTrue("DocumentImpl has not interface", classDescriptor.hasInterfaces()); + assertEquals("Invalid number of implemented interface", classDescriptor.getImplements().size(), 1); + assertFalse("Invalid extend strategy", classDescriptor.usesNodeTypePerHierarchyStrategy()); + assertTrue("Invalid extend strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy()); + + + } catch (JcrMappingException e) { + e.printStackTrace(); + fail("Impossible to retrieve the converter " + e); + } + } + + /** + * + * Test Node Type per concrete class setting */ public void testProxy() { try { @@ -368,4 +443,5 @@ fail("Impossible to retrieve the converter " + e); } } + } Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java?rev=406118&r1=406117&r2=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/AllTests.java Sat May 13 08:08:04 2006 @@ -38,10 +38,12 @@ //$JUnit-BEGIN$ suite.addTestSuite(PersistenceManagerAtomicQueryTest.class); suite.addTestSuite(PersistenceManagerBasicVersionningTest.class); + suite.addTestSuite(PersistenceManagerInheritanceConcreteClassTest.class); + suite.addTestSuite(PersistenceManagerInheritanceHierarchyTest.class); + suite.addTestSuite(PersistenceManagerInterfaceConcreteClassTest.class); + suite.addTestSuite(PersistenceManagerInterfaceHierarchyTest.class); suite.addTestSuite(PersistenceManagerIteratorQueryTest.class); - suite.addTestSuite(PersistenceManagerMultiValueQueryTest.class); - suite.addTestSuite(PersistenceManagerNtConcreteClassTest.class); - suite.addTestSuite(PersistenceManagerNtHierarchyTest.class); + suite.addTestSuite(PersistenceManagerMultiValueQueryTest.class); suite.addTestSuite(PersistenceManagerRemoveTest.class); suite.addTestSuite(PersistenceManagerSameNameSiblingTest.class); suite.addTestSuite(PersistenceManagerScopeQueryTest.class); Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceConcreteClassTest.java (from r393615, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java) URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceConcreteClassTest.java?p2=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceConcreteClassTest.java&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java&r1=393615&r2=406118&rev=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtConcreteClassTest.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceConcreteClassTest.java Sat May 13 08:08:04 2006 @@ -30,25 +30,25 @@ import org.apache.portals.graffito.jcr.query.Query; import org.apache.portals.graffito.jcr.query.QueryManager; import org.apache.portals.graffito.jcr.testmodel.Atomic; -import org.apache.portals.graffito.jcr.testmodel.inheritance.CmsObject; -import org.apache.portals.graffito.jcr.testmodel.inheritance.Content; -import org.apache.portals.graffito.jcr.testmodel.inheritance.DocumentStream; -import org.apache.portals.graffito.jcr.testmodel.inheritance.Document; -import org.apache.portals.graffito.jcr.testmodel.inheritance.Folder; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.ContentImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentStream; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.FolderImpl; /** * Test inheritance with node type per concrete class (without discreminator field) * * @author <a href="mailto:ugarcia@example.com">Christophe Lombart</a> */ -public class PersistenceManagerNtConcreteClassTest extends TestBase { - private final static Log log = LogFactory.getLog(PersistenceManagerNtConcreteClassTest.class); +public class PersistenceManagerInheritanceConcreteClassTest extends TestBase { + private final static Log log = LogFactory.getLog(PersistenceManagerInheritanceConcreteClassTest.class); /** * <p>Defines the test case name for junit.</p> * @param testName The test case name. */ - public PersistenceManagerNtConcreteClassTest(String testName) throws Exception { + public PersistenceManagerInheritanceConcreteClassTest(String testName) throws Exception { super(testName); } @@ -56,7 +56,7 @@ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new RepositoryLifecycleTestSetup(new TestSuite( - PersistenceManagerNtConcreteClassTest.class)); + PersistenceManagerInheritanceConcreteClassTest.class)); } public void tearDown() throws Exception { @@ -75,7 +75,7 @@ //--------------------------------------------------------------------------------------------------------- // Insert a Document //--------------------------------------------------------------------------------------------------------- - Document document = new Document(); + DocumentImpl document = new DocumentImpl(); document.setPath("/document1"); document.setName("document name"); document.setContentType("plain/text"); @@ -92,7 +92,7 @@ // Retrieve a document object //--------------------------------------------------------------------------------------------------------- - document = (Document) persistenceManager.getObject(Document.class, "/document1"); + document = (DocumentImpl) persistenceManager.getObject(DocumentImpl.class, "/document1"); assertEquals("Document path is invalid", document.getPath(), "/document1"); assertEquals("Content type is invalid", document.getContentType(), "plain/text"); assertNotNull("document stream is null", document.getDocumentStream()); @@ -109,14 +109,14 @@ //--------------------------------------------------------------------------------------------------------- // Retrieve the updated descendant object //--------------------------------------------------------------------------------------------------------- - document = (Document) persistenceManager.getObject(Document.class, "/document1"); + document = (DocumentImpl) persistenceManager.getObject(DocumentImpl.class, "/document1"); assertEquals("document name is incorrect", document.getName(), "anotherName"); assertEquals("Document path is invalid", document.getPath(), "/document1"); assertEquals("Content type is invalid", document.getContentType(), "plain/text"); assertNotNull("document stream is null", document.getDocumentStream()); assertTrue("Invalid document stream", document.getDocumentStream().getEncoding().equals("utf-8")); - CmsObject cmsObject = (CmsObject) persistenceManager.getObject(CmsObject.class, "/document1"); + CmsObjectImpl cmsObject = (CmsObjectImpl) persistenceManager.getObject(CmsObjectImpl.class, "/document1"); assertEquals("cmsObject name is incorrect", cmsObject.getName(), "anotherName"); assertEquals("cmsObject path is invalid", cmsObject.getPath(), "/document1"); @@ -135,7 +135,7 @@ //--------------------------------------------------------------------------------------------------------- // Insert cmsobjects //--------------------------------------------------------------------------------------------------------- - Document document = new Document(); + DocumentImpl document = new DocumentImpl(); document.setPath("/document1"); document.setName("document name 1"); document.setContentType("plain/text"); @@ -145,7 +145,7 @@ document.setDocumentStream(documentStream); persistenceManager.insert(document); - document = new Document(); + document = new DocumentImpl(); document.setPath("/document2"); document.setName("document name 2"); document.setContentType("plain/text"); @@ -155,7 +155,7 @@ document.setDocumentStream(documentStream); persistenceManager.insert(document); - document = new Document(); + document = new DocumentImpl(); document.setPath("/document3"); document.setName("document 3"); document.setContentType("plain/text"); @@ -165,13 +165,13 @@ document.setDocumentStream(documentStream); persistenceManager.insert(document); - Folder folder = new Folder(); + FolderImpl folder = new FolderImpl(); folder.setPath("/folder1"); folder.setName("folder1"); persistenceManager.insert(folder); - document = new Document(); + document = new DocumentImpl(); document.setName("document4"); document.setContentType("plain/text"); documentStream = new DocumentStream(); @@ -179,10 +179,10 @@ documentStream.setContent("Test Content 4".getBytes()); document.setDocumentStream(documentStream); - Folder subFolder = new Folder(); + FolderImpl subFolder = new FolderImpl(); subFolder.setName("subfolder"); - folder = new Folder(); + folder = new FolderImpl(); folder.setPath("/folder2"); folder.setName("folder2"); folder.addChild(document); @@ -201,94 +201,94 @@ // Retrieve Folders found on the root level //--------------------------------------------------------------------------------------------------------- QueryManager queryManager = persistenceManager.getQueryManager(); - Filter filter = queryManager.createFilter(Folder.class); + Filter filter = queryManager.createFilter(FolderImpl.class); Query query = queryManager.createQuery(filter); filter.setScope("/"); Collection result = persistenceManager.getObjects(query); assertEquals("Invalid number of folders found", result.size(), 2); - assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder2", Folder.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder2", FolderImpl.class)); //--------------------------------------------------------------------------------------------------------- // Retrieve Documents //--------------------------------------------------------------------------------------------------------- queryManager = persistenceManager.getQueryManager(); - filter = queryManager.createFilter(Document.class); + filter = queryManager.createFilter(DocumentImpl.class); filter.addLike("name", "document name%"); query = queryManager.createQuery(filter); result = persistenceManager.getObjects(query); assertEquals("Invalid number of documents found", result.size(),2); - assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class)); //--------------------------------------------------------------------------------------------------------- // Retrieve folder2 //--------------------------------------------------------------------------------------------------------- - Folder folder2 = (Folder) persistenceManager.getObject(Folder.class, "/folder2"); + FolderImpl folder2 = (FolderImpl) persistenceManager.getObject(FolderImpl.class, "/folder2"); assertNotNull("folder 2 is null", folder2); assertEquals("Invalid number of cms object found in folder2 children", folder2.getChildren().size() ,2); - assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", Document.class)); - assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", Folder.class)); + assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class)); - CmsObject cmsObject = (CmsObject) persistenceManager.getObject(CmsObject.class, "/folder2"); + CmsObjectImpl cmsObject = (CmsObjectImpl) persistenceManager.getObject(CmsObjectImpl.class, "/folder2"); assertNotNull("folder 2 is null", cmsObject); - assertTrue("Invalid instance for folder 2", cmsObject instanceof Folder); + assertTrue("Invalid instance for folder 2", cmsObject instanceof FolderImpl); assertEquals("Invalid number of documents found in folder2 children", folder2.getChildren().size(),2); - assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", Document.class)); - assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", Folder.class)); + assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class)); //--------------------------------------------------------------------------------------------------------- // Retrieve Contents (ancestor of Documents) //--------------------------------------------------------------------------------------------------------- queryManager = persistenceManager.getQueryManager(); - filter = queryManager.createFilter(Content.class); + filter = queryManager.createFilter(ContentImpl.class); filter.addLike("name", "document name%"); query = queryManager.createQuery(filter); result = persistenceManager.getObjects(query); assertEquals("Invalid number of documents found", result.size(),2); - assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class)); //--------------------------------------------------------------------------------------------------------- // Retrieve all cmsobjects found on the root level //--------------------------------------------------------------------------------------------------------- queryManager = persistenceManager.getQueryManager(); - filter = queryManager.createFilter(CmsObject.class); + filter = queryManager.createFilter(CmsObjectImpl.class); filter.setScope("/"); query = queryManager.createQuery(filter); result = persistenceManager.getObjects(query); assertEquals("Invalid ancestor object found", result.size(),5); - assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document3", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder2",Folder.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class)); //--------------------------------------------------------------------------------------------------------- // Retrieve all cmsobjects found anywhere //--------------------------------------------------------------------------------------------------------- queryManager = persistenceManager.getQueryManager(); - filter = queryManager.createFilter(CmsObject.class); + filter = queryManager.createFilter(CmsObjectImpl.class); query = queryManager.createQuery(filter); result = persistenceManager.getObjects(query); assertEquals("Invalid ancestor object found", result.size(),7); - assertTrue("Invalid item in the collection", this.contains(result, "/document1", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document2", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/document3", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder2/document4", Document.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder1",Folder.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder2",Folder.class)); - assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",Folder.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder2/document4", DocumentImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class)); + assertTrue("Invalid item in the collection", this.contains(result, "/folder2/subfolder",FolderImpl.class)); } @@ -298,13 +298,13 @@ //--------------------------------------------------------------------------------------------------------- // Insert cmsobjects //--------------------------------------------------------------------------------------------------------- - Folder folder = new Folder(); + FolderImpl folder = new FolderImpl(); folder.setPath("/mainfolder"); folder.setName("Main folder"); for (int i=1; i<=100;i++) { - Document document = new Document(); + DocumentImpl document = new DocumentImpl(); document.setName("document" + i); document.setContentType("plain/text"); DocumentStream documentStream = new DocumentStream(); @@ -313,7 +313,7 @@ document.setDocumentStream(documentStream); folder.addChild(document); - Folder subFolder = new Folder(); + FolderImpl subFolder = new FolderImpl(); subFolder.setName("folder" + i); subFolder.addChild(document); folder.addChild(subFolder); @@ -327,14 +327,14 @@ //--------------------------------------------------------------------------------------------------------- // Retrieve Folder //--------------------------------------------------------------------------------------------------------- - folder = (Folder) persistenceManager.getObject(Folder.class,"/mainfolder"); + folder = (FolderImpl) persistenceManager.getObject(FolderImpl.class,"/mainfolder"); assertNotNull("Folder is null",folder); Collection children = folder.getChildren(); assertEquals("Invalid number of children", children.size(), 200); for (int i=1; i<=100;i++) { - assertTrue("Invalid item in the collection : " +"/mainfolder/document" + i , this.contains(children, "/mainfolder/document" + i,Document.class)); - assertTrue("Invalid item in the collection : " + "/mainfolder/folder" + i, this.contains(children, "/mainfolder/folder" + i, Folder.class)); + assertTrue("Invalid item in the collection : " +"/mainfolder/document" + i , this.contains(children, "/mainfolder/document" + i,DocumentImpl.class)); + assertTrue("Invalid item in the collection : " + "/mainfolder/folder" + i, this.contains(children, "/mainfolder/folder" + i, FolderImpl.class)); } Copied: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceHierarchyTest.java (from r388968, incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtHierarchyTest.java) URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceHierarchyTest.java?p2=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceHierarchyTest.java&p1=incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtHierarchyTest.java&r1=388968&r2=406118&rev=406118&view=diff ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerNtHierarchyTest.java (original) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInheritanceHierarchyTest.java Sat May 13 08:08:04 2006 @@ -40,14 +40,14 @@ * * @author <a href="mailto:ugarcia@example.com">Christophe Lombart</a> */ -public class PersistenceManagerNtHierarchyTest extends TestBase { - private final static Log log = LogFactory.getLog(PersistenceManagerNtHierarchyTest.class); +public class PersistenceManagerInheritanceHierarchyTest extends TestBase { + private final static Log log = LogFactory.getLog(PersistenceManagerInheritanceHierarchyTest.class); /** * <p>Defines the test case name for junit.</p> * @param testName The test case name. */ - public PersistenceManagerNtHierarchyTest(String testName) throws Exception { + public PersistenceManagerInheritanceHierarchyTest(String testName) throws Exception { super(testName); } @@ -55,7 +55,7 @@ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new RepositoryLifecycleTestSetup(new TestSuite( - PersistenceManagerNtHierarchyTest.class)); + PersistenceManagerInheritanceHierarchyTest.class)); } public void tearDown() throws Exception { Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceConcreteClassTest.java URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceConcreteClassTest.java?rev=406118&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceConcreteClassTest.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerInterfaceConcreteClassTest.java Sat May 13 08:08:04 2006 @@ -0,0 +1,346 @@ +/* ======================================================================== + * Copyright 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.persistence.impl; + +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.portals.graffito.jcr.RepositoryLifecycleTestSetup; +import org.apache.portals.graffito.jcr.TestBase; +import org.apache.portals.graffito.jcr.persistence.PersistenceManager; +import org.apache.portals.graffito.jcr.query.Filter; +import org.apache.portals.graffito.jcr.query.Query; +import org.apache.portals.graffito.jcr.query.QueryManager; +import org.apache.portals.graffito.jcr.testmodel.Atomic; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.CmsObjectImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentImpl; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.DocumentStream; +import org.apache.portals.graffito.jcr.testmodel.inheritance.impl.FolderImpl; +import org.apache.portals.graffito.jcr.testmodel.interfaces.CmsObject; +import org.apache.portals.graffito.jcr.testmodel.interfaces.Content; +import org.apache.portals.graffito.jcr.testmodel.interfaces.Document; +import org.apache.portals.graffito.jcr.testmodel.interfaces.Folder; + +/** + * Test interface (with discreminator field) + * + * @author <a href="mailto:ugarcia@example.com">Christophe Lombart</a> + */ +public class PersistenceManagerInterfaceConcreteClassTest extends TestBase { + private final static Log log = LogFactory.getLog(PersistenceManagerInterfaceConcreteClassTest.class); +
{'source': 'Apache Software Foundation Public Mail Archives'}