You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-commits@incubator.apache.org by cl...@apache.org on 2006/04/04 22:27:39 UTC
svn commit: r391430 - in /incubator/graffito/trunk/jcr/jcr-mapping: ./
src/java/org/apache/portals/graffito/jcr/persistence/impl/
src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/
src/java/org/apache/portals/graffito/jcr/reflec...
Author: clombart
Date: Tue Apr 4 15:27:36 2006
New Revision: 391430
URL: http://svn.apache.org/viewcvs?rev=391430&view=rev
Log:
Starting proxy support for the bean fields, The support for collection field will follow in a couple of days.
Added:
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AllTests.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Detail.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java
Modified:
incubator/graffito/trunk/jcr/jcr-mapping/.classpath
incubator/graffito/trunk/jcr/jcr-mapping/project.xml
incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.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/reflection/ReflectionUtils.java
incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
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
Modified: incubator/graffito/trunk/jcr/jcr-mapping/.classpath
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/.classpath?rev=391430&r1=391429&r2=391430&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/.classpath (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/.classpath Tue Apr 4 15:27:36 2006
@@ -1,22 +1,44 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/java"/>
- <classpathentry output="target/test-classes" kind="src" path="src/test"/>
- <classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="MAVEN_REPO/org.apache.jackrabbit/jars/jackrabbit-1.0-SNAPSHOT.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/concurrent/jars/concurrent-1.3.4.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/geronimo-spec/jars/geronimo-spec-jta-1.0-M1.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/jsr170/jars/jcr-1.0.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.8.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/lucene/jars/lucene-1.4.3.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xercesImpl-2.6.2.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xmlParserAPIs-2.0.2.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/org.apache.derby/jars/derby-10.1.1.0.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-beanutils/jars/commons-beanutils-1.7.0.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-digester/jars/commons-digester-1.7.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-logging/jars/commons-logging-1.0.2.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.1.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classpath>
+ <classpathentry excluding="" kind="src" path="src/java">
+ </classpathentry>
+ <classpathentry output="target/test-classes" kind="src" path="src/test">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar">
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/org.apache.jackrabbit/jars/jackrabbit-1.0-20060108-SNAPSHOT.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/concurrent/jars/concurrent-1.3.4.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/geronimo-spec/jars/geronimo-spec-jta-1.0-M1.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/jsr170/jars/jcr-1.0.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.8.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/lucene/jars/lucene-1.4.3.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xercesImpl-2.6.2.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xmlParserAPIs-2.0.2.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/org.apache.derby/jars/derby-10.1.1.0.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-beanutils/jars/commons-beanutils-1.7.0.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-digester/jars/commons-digester-1.7.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-logging/jars/commons-logging-1.0.2.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.1.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/cglib/jars/cglib-full-2.0.2.jar">
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes">
+ </classpathentry>
+</classpath>
\ No newline at end of file
Modified: incubator/graffito/trunk/jcr/jcr-mapping/project.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/project.xml?rev=391430&r1=391429&r2=391430&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/project.xml (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/project.xml Tue Apr 4 15:27:36 2006
@@ -130,7 +130,11 @@
</properties>
</dependency>
-
+ <dependency>
+ <id>cglib</id>
+ <version>${cglib.version}</version>
+ </dependency>
+
</dependencies>
<build>
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java?rev=391430&r1=391429&r2=391430&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/impl/PersistenceManagerImpl.java Tue Apr 4 15:27:36 2006
@@ -48,7 +48,6 @@
import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
import org.apache.portals.graffito.jcr.persistence.PersistenceManager;
-import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.DefaultAtomicTypeConverterProvider;
import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ObjectConverterImpl;
@@ -90,12 +89,6 @@
*/
protected ObjectConverter objectConverter;
- /**
- * No-arg constructor.
- * Permits post initialization.
- */
- public PersistenceManagerImpl() {
- }
/**
* Creates a new <code>PersistenceManager</code> that uses the passed in
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/BeanLazyLoader.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,50 @@
+/*
+ * 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.objectconverter.impl;
+
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+
+import net.sf.cglib.proxy.LazyLoader;
+
+public class BeanLazyLoader implements LazyLoader
+{
+
+ private final static Log log = LogFactory.getLog(BeanLazyLoader.class);
+
+ private ObjectConverter objectConverter;
+ private Session session;
+ private Class beanClass;
+ private String path;
+
+
+ public BeanLazyLoader(ObjectConverter objectConverter, Session session, Class beanClass, String path)
+ {
+ this.objectConverter = objectConverter;
+ this.session = session;
+ this.beanClass = beanClass;
+ this.path = path;
+ }
+
+ public Object loadObject()
+ {
+ return objectConverter.getObject(session, beanClass, path);
+ }
+}
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=391430&r1=391429&r2=391430&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 Tue Apr 4 15:27:36 2006
@@ -55,6 +55,8 @@
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}
*
@@ -70,6 +72,8 @@
private Mapper mapper;
private AtomicTypeConverterProvider atomicTypeConverterProvider;
+
+ private ProxyManager proxyManager;
/**
* No-arg constructor.
@@ -87,6 +91,7 @@
public ObjectConverterImpl(Mapper mapper, AtomicTypeConverterProvider converterProvider) {
this.mapper = mapper;
this.atomicTypeConverterProvider = converterProvider;
+ this.proxyManager = new ProxyManager(this);
}
/**
@@ -203,7 +208,7 @@
*/
public void update(Session session, Node parentNode, String nodeName, Object object) {
try {
- ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
+ ClassDescriptor classDescriptor = getClassDescriptor(ReflectionUtils.getBeanClass(object));
Node objectNode = parentNode.getNode(nodeName);
checkNodeType(session, classDescriptor);
@@ -419,7 +424,8 @@
String propertyName = fieldDescriptor.getJcrName();
if (fieldDescriptor.isPath()) {
- if (null == initializedBean) { // HINT: lazy initialize target bean
+ // HINT: lazy initialize target bean - The bean can be null when it is inline
+ if (null == initializedBean) {
initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
}
@@ -442,7 +448,8 @@
else {
if (node.hasProperty(propertyName)) {
Value propValue = node.getProperty(propertyName).getValue();
- if (null != propValue && null == initializedBean) { // HINT: lazy initialize target bean
+ // HINT: lazy initialize target bean - The bean can be null when it is inline
+ if (null != propValue && null == initializedBean) {
initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
}
@@ -482,38 +489,37 @@
/**
* Retrieve bean fields
*/
- private void retrieveBeanFields(Session session,
- ClassDescriptor classDescriptor,
- Node node,
- String path,
- Object object) {
- Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
- while (beanDescriptorIterator.hasNext()) {
- BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
- String beanName = beanDescriptor.getFieldName();
- Class beanClass = ReflectionUtils.getPropertyType(object, beanName);
- Object bean = null;
- if (beanDescriptor.isInline()) {
- bean = this.retrieveSimpleFields(session, getClassDescriptor(beanClass), node, bean);
- }
- else if (null != beanDescriptor.getBeanConverter()) {
- bean = beanDescriptor.getBeanConverter().getObject(session,
- node,
- beanDescriptor,
- beanClass);
- }
- else {
- bean = this.getObject(session,
- beanClass,
- path + "/" + beanDescriptor.getJcrName());
- }
- ReflectionUtils.setNestedProperty(object, beanName, bean);
- }
+ private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor, Node node, String path, Object object) {
+ Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors()
+ .iterator();
+ while (beanDescriptorIterator.hasNext()) {
+ BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator
+ .next();
+ String beanName = beanDescriptor.getFieldName();
+ Class beanClass = ReflectionUtils.getPropertyType(object, beanName);
+ Object bean = null;
+ if (beanDescriptor.isProxy()) {
+ bean = proxyManager.createBeanProxy(session, beanClass, path + "/" + beanDescriptor.getJcrName());
+
+ } else {
+ if (beanDescriptor.isInline()) {
+ bean = this.retrieveSimpleFields(session,
+ getClassDescriptor(beanClass), node, bean);
+ } else if (null != beanDescriptor.getBeanConverter()) {
+ bean = beanDescriptor.getBeanConverter().getObject(session,
+ node, beanDescriptor, beanClass);
+ } else {
+ bean = this.getObject(session, beanClass, path + "/"
+ + beanDescriptor.getJcrName());
+ }
+ }
+ ReflectionUtils.setNestedProperty(object, beanName, bean);
+ }
}
/**
- * Retrieve Collection fields
- */
+ * Retrieve Collection fields
+ */
private void retrieveCollectionFields(Session session,
ClassDescriptor classDescriptor,
Node node,
@@ -579,8 +585,7 @@
while (beanDescriptorIterator.hasNext()) {
BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
jcrName = beanDescriptor.getJcrName();
- Object bean = ReflectionUtils.getNestedProperty(object,
- beanDescriptor.getFieldName());
+ Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());
// if the bean is null, remove existing node
if ((bean == null)) {
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyManager.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.objectconverter.impl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.LazyLoader;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter;
+
+public class ProxyManager {
+
+ private final static Log log = LogFactory.getLog(ProxyManager.class);
+
+ private ObjectConverter objectConverter;
+
+ public ProxyManager(ObjectConverter objectConverter)
+ {
+ this.objectConverter = objectConverter;
+ }
+
+ public Object createBeanProxy(Session session, Class beanClass, String path)
+ {
+
+ try {
+ if (!session.itemExists(path)) {
+ return null;
+ }
+ } catch (RepositoryException e) {
+ throw new org.apache.portals.graffito.jcr.exception.RepositoryException(
+ "Impossible to check,if the object exits on " + path, e);
+ }
+
+ log.debug("Create proxy for " + path);
+ LazyLoader loader = new BeanLazyLoader(this.objectConverter, session, beanClass, path) ;
+ return Enhancer.create(beanClass, loader);
+ }
+
+}
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java?rev=391430&r1=391429&r2=391430&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/reflection/ReflectionUtils.java Tue Apr 4 15:27:36 2006
@@ -17,6 +17,8 @@
import java.lang.reflect.InvocationTargetException;
+import net.sf.cglib.proxy.Enhancer;
+
import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.portals.graffito.jcr.exception.JcrMappingException;
@@ -136,5 +138,21 @@
catch(Exception ex) {
throw new JcrMappingException("Cannot load class " + clazz, ex);
}
+ }
+
+ public static boolean isProxy(Class beanClass)
+ {
+ return Enhancer.isEnhanced(beanClass);
+ }
+
+ public static Class getBeanClass(Object bean)
+ {
+ Class beanClass = bean.getClass();
+ if (isProxy(beanClass))
+ {
+ //CGLIB specific
+ return beanClass.getSuperclass();
+ }
+ return beanClass;
}
}
Added: 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=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test-config/jcrmapping-proxy.xml Tue Apr 4 15:27:36 2006
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!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">
+ <!-- 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" />
+ <bean-descriptor fieldName="nullDetail" jcrName="nulldetail" proxy="true" jcrNodeType="nt:unstructured" />
+ <bean-descriptor fieldName="detail" jcrName="detail" proxy="false" jcrNodeType="nt:unstructured" />
+ </class-descriptor>
+
+ <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>
+
+</graffito-jcr>
+
\ No newline at end of file
Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java?rev=391430&r1=391429&r2=391430&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/AllTests.java Tue Apr 4 15:27:36 2006
@@ -20,7 +20,6 @@
import junit.framework.TestSuite;
import org.apache.portals.graffito.jcr.mapper.DigesterMapperImplTest;
-import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.BeanDescriptorTest;
import org.apache.portals.graffito.jcr.query.impl.QueryManagerTest;
import org.apache.portals.graffito.jcr.repository.RepositoryUtilTest;
@@ -42,9 +41,10 @@
suite.addTestSuite(DigesterMapperImplTest.class);
suite.addTestSuite(RepositoryUtilTest.class);
suite.addTestSuite(QueryManagerTest.class);
- suite.addTestSuite(BeanDescriptorTest.class);
+
// package level tests
+ suite.addTest(org.apache.portals.graffito.jcr.persistence.objectconverter.impl.AllTests.buildSuite());
suite.addTest(org.apache.portals.graffito.jcr.persistence.atomicconverter.AllTests.buildSuite());
suite.addTest(org.apache.portals.graffito.jcr.persistence.collectionconverter.impl.AllTests.buildSuite());
suite.addTest(org.apache.portals.graffito.jcr.persistence.impl.AllTests.buildSuite());
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=391430&r1=391429&r2=391430&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 Tue Apr 4 15:27:36 2006
@@ -191,6 +191,7 @@
{
Repository repository = RepositoryUtil.getRepository("repositoryTest");
String[] files = { "./src/test-config/jcrmapping.xml",
+ "./src/test-config/jcrmapping-proxy.xml",
"./src/test-config/jcrmapping-atomic.xml",
"./src/test-config/jcrmapping-beandescriptor.xml",
"./src/test-config/jcrmapping-inheritance.xml"};
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=391430&r1=391429&r2=391430&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 Tue Apr 4 15:27:36 2006
@@ -35,294 +35,337 @@
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.proxy.Main;
/**
* Test Mapper
*
* @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
*/
-public class DigesterMapperImplTest extends TestCase
-{
- /**
- * <p>Defines the test case name for junit.</p>
- * @param testName The test case name.
- */
- public DigesterMapperImplTest(String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- // All methods starting with "test" will be executed in the test suite.
- return new TestSuite(DigesterMapperImplTest.class);
- }
-
- /**
- * Simple test mapper
- *
- */
- public void testMapper()
- {
- try
- {
-
-
- Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping-testmappings.xml")
- .buildMapper();
- assertNotNull("Mapper is null", mapper);
-
- ClassDescriptor classDescriptor = mapper.getClassDescriptor(A.class);
- assertNotNull("ClassDescriptor is null", classDescriptor);
- assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
- assertTrue("Invalid path field", classDescriptor.getPathFieldDescriptor().getFieldName().equals("path"));
- assertEquals("Invalid mixins", "mixin:a", classDescriptor.getJcrMixinTypes()[0] );
-
- FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor("a1");
- assertNotNull("FieldDescriptor is null", fieldDescriptor);
- assertTrue("Invalid jcrName for field a1", fieldDescriptor.getJcrName().equals("a1"));
-
- BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
- assertNotNull("BeanDescriptor is null", beanDescriptor);
- assertTrue("Invalid jcrName for field b", beanDescriptor.getJcrName().equals("b"));
- assertEquals("Invalid bean-descriptor inline", true, beanDescriptor.isInline());
- assertNull("Invalid bean default converter", beanDescriptor.getConverter());
- assertNull("Invalid bean converter", beanDescriptor.getBeanConverter());
-
-
- CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor("collection");
- assertNotNull("CollectionDescriptor is null", collectionDescriptor);
- assertTrue("Invalid jcrName for field collection", collectionDescriptor.getJcrName().equals("collection"));
- }
- catch (JcrMappingException e)
- {
- e.printStackTrace();
- fail("Impossible to retrieve the converter " + e);
- }
- }
-
- /**
- * Test optional mapping properties
- *
- */
- public void testMapperOptionalProperties()
- {
- try
- {
- Mapper mapper = new DigesterMapperImpl("./src/test-config/jcrmapping.xml")
- .buildMapper();
- assertNotNull("Mapper is null", mapper);
-
- ClassDescriptor classDescriptor = mapper.getClassDescriptor(B.class);
- assertNotNull("ClassDescriptor is null", classDescriptor);
- assertTrue("Invalid classname", classDescriptor.getClassName().equals(B.class.getName()));
- assertEquals(classDescriptor.getJcrSuperTypes(), "nt:base");
-
- FieldDescriptor b1Field = classDescriptor.getFieldDescriptor("b1");
- assertNotNull("FieldDescriptor is null", b1Field);
- assertEquals(b1Field.getFieldName(), "b1");
- assertEquals(b1Field.getJcrType(), "String");
- assertFalse(b1Field.isJcrAutoCreated());
- assertFalse(b1Field.isJcrMandatory());
- assertFalse(b1Field.isJcrProtected());
- assertFalse(b1Field.isJcrMultiple());
- assertEquals(b1Field.getJcrOnParentVersion(), "IGNORE");
-
- FieldDescriptor b2Field = classDescriptor.getFieldDescriptor("b2");
- assertNotNull("FieldDescriptor is null", b2Field);
- assertEquals(b2Field.getFieldName(), "b2");
- assertEquals(b2Field.getJcrType(), "String");
- assertFalse(b2Field.isJcrAutoCreated());
- assertFalse(b2Field.isJcrMandatory());
- assertFalse(b2Field.isJcrProtected());
- assertFalse(b2Field.isJcrMultiple());
- assertEquals(b2Field.getJcrOnParentVersion(), "IGNORE");
-
- ClassDescriptor classDescriptor2 = mapper.getClassDescriptor(A.class);
- assertNotNull("ClassDescriptor is null", classDescriptor2);
- assertTrue("Invalid classname", classDescriptor2.getClassName().equals(A.class.getName()));
-
- BeanDescriptor beanDescriptor = classDescriptor2.getBeanDescriptor("b");
- assertNotNull(beanDescriptor);
- assertEquals(beanDescriptor.getFieldName(), "b");
- assertEquals(beanDescriptor.getJcrNodeType(), "nt:unstructured");
- assertFalse(beanDescriptor.isJcrAutoCreated());
- assertFalse(beanDescriptor.isJcrMandatory());
- assertFalse(beanDescriptor.isJcrProtected());
- assertFalse(beanDescriptor.isJcrSameNameSiblings());
- assertEquals(beanDescriptor.getJcrOnParentVersion(), "IGNORE");
-
- CollectionDescriptor collectionDescriptor = classDescriptor2.getCollectionDescriptor("collection");
- assertNotNull(collectionDescriptor);
- assertEquals(collectionDescriptor.getJcrNodeType(), "graffito:C");
- assertFalse(collectionDescriptor.isJcrAutoCreated());
- assertFalse(collectionDescriptor.isJcrMandatory());
- assertFalse(collectionDescriptor.isJcrProtected());
- assertFalse(collectionDescriptor.isJcrSameNameSiblings());
- assertEquals(collectionDescriptor.getJcrOnParentVersion(), "IGNORE");
- }
- catch (JcrMappingException e)
- {
- e.printStackTrace();
- fail("Impossible to retrieve the converter " + e);
- }
- }
-
- /**
- *
- * Test Node Type per hierarchy setting
- */
- public void testMapperNtHierarchy()
- {
- try
- {
- 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"};
- Mapper mapper = new DigesterMapperImpl(files) .buildMapper();
-
- assertNotNull("Mapper is null", mapper);
-
- ClassDescriptor classDescriptor = mapper.getClassDescriptor(Ancestor.class);
- 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());
- 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());
- assertFalse("Ancestor class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
-
- Collection descendandDescriptors = classDescriptor.getDescendantClassDescriptors();
- assertEquals("Invalid number of descendants", descendandDescriptors.size(), 2);
-
- classDescriptor = mapper.getClassDescriptor(Descendant.class);
- 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());
- assertNotNull("ancerstorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
- assertFalse("The descendant class is abstract", classDescriptor.isAbstract());
- assertNotNull("The descendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
- 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.size(), 1);
- assertTrue("Descendant class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
- assertFalse("Descendant class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
-
-
- classDescriptor = mapper.getClassDescriptor(SubDescendant.class);
- 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());
- assertNotNull("ancestorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
- assertFalse("The subdescendant class is abstract", classDescriptor.isAbstract());
- assertNotNull("The subdescendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
- 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.size(), 0);
- assertTrue("SubDescendant class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
- assertFalse("SubDescendant class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
-
- }
- catch (JcrMappingException e)
- {
- e.printStackTrace();
- fail("Impossible to retrieve the converter " + e);
- }
- }
-
-
- /**
- *
- * Test Node Type per concrete class setting
- */
- public void testMapperNtConcreteClass()
- {
- try
- {
- 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"};
-// 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);
- 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());
- assertTrue("The cmsobject class is not abstract", classDescriptor.isAbstract());
- assertNull("The cmsobject class has an ancestor", classDescriptor.getSuperClassDescriptor());
- assertFalse("The cmsobject class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
- assertTrue("The cmsobject class have not a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
- assertTrue ("The cmsobject class has no descendant ", classDescriptor.hasDescendants());
- assertEquals("Invalid number of descendants", classDescriptor.getDescendantClassDescriptors().size(), 2);
-
- classDescriptor = mapper.getClassDescriptor(Document.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());
- 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");
- assertFalse("The document class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
- assertTrue("The document class have not a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
- assertFalse ("The document class has no descendant ", classDescriptor.hasDescendants());
- assertEquals("Invalid number of descendants", classDescriptor.getDescendantClassDescriptors().size(), 0);
-
-
-
-
-// Collection descendandDescriptors = classDescriptor.getDescendantClassDescriptors();
-// assertEquals("Invalid number of descendants", descendandDescriptors.size(), 2);
-//
-// classDescriptor = mapper.getClassDescriptor(Descendant.class);
-// 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());
-// assertNotNull("ancerstorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
-// assertFalse("The descendant class is abstract", classDescriptor.isAbstract());
-// assertNotNull("The descendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
-// 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.size(), 1);
-// assertTrue("Descendant class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
-// assertFalse("Descendant class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
-//
-//
-// classDescriptor = mapper.getClassDescriptor(SubDescendant.class);
-// 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());
-// assertNotNull("ancestorField is null in the descendant class", classDescriptor.getFieldDescriptor("ancestorField"));
-// assertFalse("The subdescendant class is abstract", classDescriptor.isAbstract());
-// assertNotNull("The subdescendant class has not an ancestor", classDescriptor.getSuperClassDescriptor());
-// 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.size(), 0);
-// assertTrue("SubDescendant class doesn't have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerHierarchyStrategy());
-// assertFalse("SubDescendant class have a node type per hierarchy strategy", classDescriptor.usesNodeTypePerConcreteClassStrategy());
-//
- }
- catch (JcrMappingException e)
- {
- e.printStackTrace();
- fail("Impossible to retrieve the converter " + e);
- }
- }
+public class DigesterMapperImplTest extends TestCase {
+ /**
+ * <p>Defines the test case name for junit.</p>
+ * @param testName The test case name.
+ */
+ public DigesterMapperImplTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ // All methods starting with "test" will be executed in the test suite.
+ return new TestSuite(DigesterMapperImplTest.class);
+ }
+
+ /**
+ * Simple test mapper
+ *
+ */
+ public void testMapper() {
+ try {
+
+ Mapper mapper = new DigesterMapperImpl(
+ "./src/test-config/jcrmapping-testmappings.xml")
+ .buildMapper();
+ assertNotNull("Mapper is null", mapper);
+
+ ClassDescriptor classDescriptor = mapper.getClassDescriptor(A.class);
+ assertNotNull("ClassDescriptor is null", classDescriptor);
+ assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
+ assertTrue("Invalid path field", classDescriptor.getPathFieldDescriptor().getFieldName().equals("path"));
+ assertEquals("Invalid mixins", "mixin:a", classDescriptor.getJcrMixinTypes()[0]);
+
+ FieldDescriptor fieldDescriptor = classDescriptor .getFieldDescriptor("a1");
+ assertNotNull("FieldDescriptor is null", fieldDescriptor);
+ assertTrue("Invalid jcrName for field a1", fieldDescriptor.getJcrName().equals("a1"));
+
+ BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
+ assertNotNull("BeanDescriptor is null", beanDescriptor);
+ assertTrue("Invalid jcrName for field b", beanDescriptor .getJcrName().equals("b"));
+ assertEquals("Invalid bean-descriptor inline", true, beanDescriptor.isInline());
+ assertNull("Invalid bean default converter", beanDescriptor.getConverter());
+ assertNull("Invalid bean converter", beanDescriptor .getBeanConverter());
+
+ CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor("collection");
+ assertNotNull("CollectionDescriptor is null", collectionDescriptor);
+ assertTrue("Invalid jcrName for field collection",collectionDescriptor.getJcrName().equals("collection"));
+ } catch (JcrMappingException e) {
+ e.printStackTrace();
+ fail("Impossible to retrieve the converter " + e);
+ }
+ }
+
+ /**
+ * Test optional mapping properties
+ *
+ */
+ public void testMapperOptionalProperties() {
+ try {
+ Mapper mapper = new DigesterMapperImpl(
+ "./src/test-config/jcrmapping.xml").buildMapper();
+ assertNotNull("Mapper is null", mapper);
+
+ ClassDescriptor classDescriptor = mapper
+ .getClassDescriptor(B.class);
+ assertNotNull("ClassDescriptor is null", classDescriptor);
+ assertTrue("Invalid classname", classDescriptor.getClassName()
+ .equals(B.class.getName()));
+ assertEquals(classDescriptor.getJcrSuperTypes(), "nt:base");
+
+ FieldDescriptor b1Field = classDescriptor.getFieldDescriptor("b1");
+ assertNotNull("FieldDescriptor is null", b1Field);
+ assertEquals(b1Field.getFieldName(), "b1");
+ assertEquals(b1Field.getJcrType(), "String");
+ assertFalse(b1Field.isJcrAutoCreated());
+ assertFalse(b1Field.isJcrMandatory());
+ assertFalse(b1Field.isJcrProtected());
+ assertFalse(b1Field.isJcrMultiple());
+ assertEquals(b1Field.getJcrOnParentVersion(), "IGNORE");
+
+ FieldDescriptor b2Field = classDescriptor.getFieldDescriptor("b2");
+ assertNotNull("FieldDescriptor is null", b2Field);
+ assertEquals(b2Field.getFieldName(), "b2");
+ assertEquals(b2Field.getJcrType(), "String");
+ assertFalse(b2Field.isJcrAutoCreated());
+ assertFalse(b2Field.isJcrMandatory());
+ assertFalse(b2Field.isJcrProtected());
+ assertFalse(b2Field.isJcrMultiple());
+ assertEquals(b2Field.getJcrOnParentVersion(), "IGNORE");
+
+ ClassDescriptor classDescriptor2 = mapper
+ .getClassDescriptor(A.class);
+ assertNotNull("ClassDescriptor is null", classDescriptor2);
+ assertTrue("Invalid classname", classDescriptor2.getClassName()
+ .equals(A.class.getName()));
+
+ BeanDescriptor beanDescriptor = classDescriptor2
+ .getBeanDescriptor("b");
+ assertNotNull(beanDescriptor);
+ assertEquals(beanDescriptor.getFieldName(), "b");
+ assertEquals(beanDescriptor.getJcrNodeType(), "nt:unstructured");
+ assertFalse(beanDescriptor.isJcrAutoCreated());
+ assertFalse(beanDescriptor.isJcrMandatory());
+ assertFalse(beanDescriptor.isJcrProtected());
+ assertFalse(beanDescriptor.isJcrSameNameSiblings());
+ assertEquals(beanDescriptor.getJcrOnParentVersion(), "IGNORE");
+
+ CollectionDescriptor collectionDescriptor = classDescriptor2
+ .getCollectionDescriptor("collection");
+ assertNotNull(collectionDescriptor);
+ assertEquals(collectionDescriptor.getJcrNodeType(), "graffito:C");
+ assertFalse(collectionDescriptor.isJcrAutoCreated());
+ assertFalse(collectionDescriptor.isJcrMandatory());
+ assertFalse(collectionDescriptor.isJcrProtected());
+ assertFalse(collectionDescriptor.isJcrSameNameSiblings());
+ assertEquals(collectionDescriptor.getJcrOnParentVersion(), "IGNORE");
+ } catch (JcrMappingException e) {
+ e.printStackTrace();
+ fail("Impossible to retrieve the converter " + e);
+ }
+ }
+
+ /**
+ *
+ * Test Node Type per hierarchy setting
+ */
+ public void testMapperNtHierarchy() {
+ try {
+ 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" };
+ Mapper mapper = new DigesterMapperImpl(files).buildMapper();
+
+ assertNotNull("Mapper is null", mapper);
+
+ ClassDescriptor classDescriptor = mapper
+ .getClassDescriptor(Ancestor.class);
+ 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());
+ 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());
+ assertFalse(
+ "Ancestor class have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerConcreteClassStrategy());
+
+ Collection descendandDescriptors = classDescriptor
+ .getDescendantClassDescriptors();
+ assertEquals("Invalid number of descendants", descendandDescriptors
+ .size(), 2);
+
+ classDescriptor = mapper.getClassDescriptor(Descendant.class);
+ 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());
+ assertNotNull("ancerstorField is null in the descendant class",
+ classDescriptor.getFieldDescriptor("ancestorField"));
+ assertFalse("The descendant class is abstract", classDescriptor
+ .isAbstract());
+ assertNotNull("The descendant class has not an ancestor",
+ classDescriptor.getSuperClassDescriptor());
+ 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
+ .size(), 1);
+ assertTrue(
+ "Descendant class doesn't have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerHierarchyStrategy());
+ assertFalse(
+ "Descendant class have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerConcreteClassStrategy());
+
+ classDescriptor = mapper.getClassDescriptor(SubDescendant.class);
+ 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());
+ assertNotNull("ancestorField is null in the descendant class",
+ classDescriptor.getFieldDescriptor("ancestorField"));
+ assertFalse("The subdescendant class is abstract", classDescriptor
+ .isAbstract());
+ assertNotNull("The subdescendant class has not an ancestor",
+ classDescriptor.getSuperClassDescriptor());
+ 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
+ .size(), 0);
+ assertTrue(
+ "SubDescendant class doesn't have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerHierarchyStrategy());
+ assertFalse(
+ "SubDescendant class have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerConcreteClassStrategy());
+
+ } catch (JcrMappingException e) {
+ e.printStackTrace();
+ fail("Impossible to retrieve the converter " + e);
+ }
+ }
+
+ /**
+ *
+ * Test Node Type per concrete class setting
+ */
+ public void testMapperNtConcreteClass() {
+ try {
+ 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" };
+ // 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);
+ 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());
+ assertTrue("The cmsobject class is not abstract", classDescriptor
+ .isAbstract());
+ assertNull("The cmsobject class has an ancestor", classDescriptor
+ .getSuperClassDescriptor());
+ assertFalse(
+ "The cmsobject class have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerHierarchyStrategy());
+ assertTrue(
+ "The cmsobject class have not a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerConcreteClassStrategy());
+ assertTrue("The cmsobject class has no descendant ",
+ classDescriptor.hasDescendants());
+ assertEquals("Invalid number of descendants", classDescriptor
+ .getDescendantClassDescriptors().size(), 2);
+
+ classDescriptor = mapper.getClassDescriptor(Document.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());
+ 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");
+ assertFalse(
+ "The document class have a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerHierarchyStrategy());
+ assertTrue(
+ "The document class have not a node type per hierarchy strategy",
+ classDescriptor.usesNodeTypePerConcreteClassStrategy());
+ assertFalse("The document class has no descendant ",
+ classDescriptor.hasDescendants());
+ assertEquals("Invalid number of descendants", classDescriptor
+ .getDescendantClassDescriptors().size(), 0);
+
+ } catch (JcrMappingException e) {
+ e.printStackTrace();
+ fail("Impossible to retrieve the converter " + e);
+ }
+ }
+
+ /**
+ *
+ * Test Node Type per concrete class setting
+ */
+ public void testProxy() {
+ try {
+ String[] files = { "./src/test-config/jcrmapping-proxy.xml" };
+
+ Mapper mapper = new DigesterMapperImpl(files).buildMapper();
+
+ assertNotNull("Mapper is null", mapper);
+
+ ClassDescriptor classDescriptor = mapper.getClassDescriptor(Main.class);
+ assertNotNull("ClassDescriptor is null", classDescriptor);
+ assertTrue("Invalid proxy setting", classDescriptor.getBeanDescriptor("proxyDetail").isProxy());
+ assertFalse("Invalid proxy setting", classDescriptor.getBeanDescriptor("detail").isProxy());
+
+
+ } catch (JcrMappingException e) {
+ e.printStackTrace();
+ fail("Impossible to retrieve the converter " + e);
+ }
+ }
}
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AllTests.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AllTests.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/AllTests.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,47 @@
+/* ========================================================================
+ * 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.objectconverter.impl;
+
+import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Package level tests.
+ *
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ */
+public class AllTests {
+
+ public static Test suite() {
+ return new RepositoryLifecycleTestSetup(buildSuite());
+ }
+
+ public static Test buildSuite() {
+ TestSuite suite= new TestSuite("Test for org.apache.portals.graffito.jcr.persistence.objectconverter.impl");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(BeanDescriptorTest.class);
+ suite.addTestSuite(ProxyTest.class);
+
+
+ //$JUnit-END$
+
+ return suite;
+ }
+}
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/objectconverter/impl/ProxyTest.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,139 @@
+/* ========================================================================
+ * 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.objectconverter.impl;
+
+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.testmodel.proxy.Detail;
+import org.apache.portals.graffito.jcr.testmodel.proxy.Main;
+
+/**
+ * Test inheritance with node type per concrete class (without discreminator field)
+ *
+ * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
+ */
+public class ProxyTest extends TestBase {
+ private final static Log log = LogFactory.getLog(ProxyTest.class);
+
+ /**
+ * <p>Defines the test case name for junit.</p>
+ * @param testName The test case name.
+ */
+ public ProxyTest(String testName) throws Exception {
+ super(testName);
+
+ }
+
+ public static Test suite() {
+ // All methods starting with "test" will be executed in the test suite.
+ return new RepositoryLifecycleTestSetup(new TestSuite(
+ ProxyTest.class));
+ }
+
+ public void tearDown() throws Exception {
+
+ cleanUpRepisotory();
+ super.tearDown();
+
+ }
+
+ public void testBeanProxy() {
+
+ try {
+ PersistenceManager persistenceManager = this.getPersistenceManager();
+
+ Detail detail = new Detail();
+ detail.setField("FieldValue");
+
+ Detail proxyDetail = new Detail();
+ proxyDetail.setField("ProxyFieldValue");
+
+ Main main = new Main();
+ main.setPath("/test");
+ main.setDetail(detail);
+ main.setProxyDetail(proxyDetail);
+
+ persistenceManager.insert(main);
+ persistenceManager.save();
+
+
+ //---------------------------------------------------------------------------------------------------------
+ // Retrieve the main object
+ //---------------------------------------------------------------------------------------------------------
+
+ main = (Main) persistenceManager.getObject(Main.class, "/test");
+ assertNotNull("detail is null", main.getDetail());
+ assertTrue("Invalid detail bean", main.getDetail().getField().equals("FieldValue"));
+
+ assertNotNull("proxydetail is null", main.getProxyDetail());
+ Object proxyObject = main.getProxyDetail();
+ assertTrue("Invalid class specify for the proxy bean", proxyObject instanceof Detail);
+ assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("ProxyFieldValue"));
+
+ Detail nullDetail = main.getNullDetail();
+ assertNull("nulldetail is not null",nullDetail );
+
+
+ //---------------------------------------------------------------------------------------------------------
+ // Update
+ //---------------------------------------------------------------------------------------------------------
+ detail = new Detail();
+ detail.setField("AnotherFieldValue");
+
+ proxyDetail = new Detail();
+ proxyDetail.setField("AnotherProxyFieldValue");
+
+ main.setDetail(detail);
+ main.setProxyDetail(proxyDetail);
+
+ persistenceManager.update(main);
+ persistenceManager.save();
+
+ //---------------------------------------------------------------------------------------------------------
+ // Retrieve the main object
+ //---------------------------------------------------------------------------------------------------------
+
+ main = (Main) persistenceManager.getObject(Main.class, "/test");
+ assertNotNull("detail is null", main.getDetail());
+ assertTrue("Invalid detail bean", main.getDetail().getField().equals("AnotherFieldValue"));
+
+ assertNotNull("proxydetail is null", main.getProxyDetail());
+ proxyObject = main.getProxyDetail();
+ assertTrue("Invalid class specify for the proxy bean", proxyObject instanceof Detail);
+ assertTrue("Invalid proxy detail bean",proxyDetail .getField().equals("AnotherProxyFieldValue"));
+
+ assertNull("nulldetail is not null",main.getNullDetail());
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ }
+
+
+
+
+
+}
\ No newline at end of file
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Detail.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Detail.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Detail.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Detail.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,42 @@
+/* ========================================================================
+ * 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.testmodel.proxy;
+
+public class Detail
+{
+ private String path;
+ private String field;
+
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public void setField(String field) {
+ this.field = field;
+ }
+
+
+}
Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java?rev=391430&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java (added)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/testmodel/proxy/Main.java Tue Apr 4 15:27:36 2006
@@ -0,0 +1,62 @@
+/* ========================================================================
+ * 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.testmodel.proxy;
+
+public class Main
+{
+
+ private String path;
+ private Detail proxyDetail;
+ private Detail nullDetail;
+ private Detail detail;
+
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public Detail getDetail() {
+ return detail;
+ }
+
+ public void setDetail(Detail detail) {
+ this.detail = detail;
+ }
+
+ public Detail getProxyDetail() {
+ return proxyDetail;
+ }
+
+ public void setProxyDetail(Detail proxyDetail) {
+ this.proxyDetail = proxyDetail;
+ }
+
+ public Detail getNullDetail() {
+ return nullDetail;
+ }
+
+ public void setNullDetail(Detail nullDetail) {
+ this.nullDetail = nullDetail;
+ }
+
+
+
+}