Revision: 739 http://openutils.svn.sourceforge.net/openutils/?rev=739&view=rev Author: fcarone Date: 2008-03-14 02:15:06 -0700 (Fri, 14 Mar 2008) Log Message: ----------- fields callback from anon to inner Modified Paths: -------------- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java Modified: trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java =================================================================== --- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2008-03-14 09:13:18 UTC (rev 738) +++ trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2008-03-14 09:15:06 UTC (rev 739) @@ -46,6 +46,7 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.SetUtils; import org.apache.commons.collections.Transformer; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.HashCodeBuilder; import org.hibernate.EntityMode; import org.hibernate.SessionFactory; @@ -61,9 +62,61 @@ * @author mmolaschi * @version $Id$ */ -public class SerializationInterceptor implements MethodInterceptor +public final class SerializationInterceptor implements MethodInterceptor { + private final class FieldEnhancementCallback implements ReflectionUtils.FieldCallback + { + + /** + * {@inheritDoc} + */ + public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException + { + if (StringUtils.indexOf(field.getName(), "CGLIB$") == 0) + { + return; + } + + // set field accessible + field.setAccessible(true); + + // get original value + Object oldValue = field.get(original); + + // get new value + Object newValue = null; + + if (oldValue instanceof PersistentCollection || oldValue instanceof HibernateProxy) + { + // if this field is a hibernate proxy or a persistent collection store reference + + LazyReference lazyRef = new LazyReference(); + lazyRef.setFieldClassName(field.getType().getName()); + lazyRef.setClassName(original.getClass().getName()); + lazyRef.setFieldName(field.getName()); + // load id + lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( + original, + EntityMode.POJO)); + + // get proxy for lazy + newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); + } + else + { + // get default proxy + newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); + } + + // if there is a variation store it + if (newValue != oldValue) + { + field.set(original, newValue); + } + } + } + private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>(); private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>(); @@ -332,52 +385,7 @@ else { // cycle on bean fields - ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback() - { - - /** - * {@inheritDoc} - */ - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException - { - // set field accessible - field.setAccessible(true); - - // get original value - Object oldValue = field.get(original); - - // get new value - Object newValue = null; - - if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection) - { - // if this field is a hibernate proxy or a persistent collection store reference - LazyReference lazyRef = new LazyReference(); - lazyRef.setFieldClassName(field.getType().getName()); - lazyRef.setClassName(original.getClass().getName()); - lazyRef.setFieldName(field.getName()); - // load id - lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier( - original, - EntityMode.POJO)); - - // get proxy for lazy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef); - } - else - { - // get default proxy - newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory); - } - - // if there is a variation store it - if (newValue != oldValue) - { - field.set(original, newValue); - } - } - - }); + ReflectionUtils.doWithFields(original.getClass(), new FieldEnhancementCallback()); } return original; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |