From c51d5b544121a42f3b18a28ecf4f129df665f91d Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Fri, 18 Mar 2011 09:36:26 -0500 Subject: [PATCH] Added TypeInformation to the MappingContextEvent --- .../data/mapping/BasicMappingContext.java | 24 ++++++++++--------- .../mapping/event/MappingContextEvent.java | 15 ++++++++---- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingContext.java index 95f6d5ac8..f2186327e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingContext.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicMappingContext.java @@ -81,7 +81,7 @@ public class BasicMappingContext implements MappingContext, InitializingBean, Ap this.builder = builder; this.conversionService = conversionService; } - + /** * @param customSimpleTypes the customSimpleTypes to set */ @@ -147,7 +147,7 @@ public class BasicMappingContext implements MappingContext, InitializingBean, Ap if (property.isIdProperty()) { entity.setIdProperty(property); } - + TypeInformation nestedType = getNestedTypeToAdd(property); if (nestedType != null) { addPersistentEntity(nestedType); @@ -166,7 +166,9 @@ public class BasicMappingContext implements MappingContext, InitializingBean, Ap entity.setPreferredConstructor(builder.getPreferredConstructor(type)); // Inform listeners - applicationContext.publishEvent(new MappingContextEvent(entity)); + if (null != applicationContext) { + applicationContext.publishEvent(new MappingContextEvent(entity, typeInformation)); + } // Cache persistentEntities.put(entity.getPropertyInformation(), entity); @@ -186,33 +188,33 @@ public class BasicMappingContext implements MappingContext, InitializingBean, Ap * {@link PersistentEntity}. Will return the property's {@link TypeInformation} directly if it is a potential entity, * a collections component type if it's a collection as well as the value type of a {@link Map} if it's a map * property. - * + * * @param property * @return the TypeInformation to be added as {@link PersistentEntity} or {@literal */ private TypeInformation getNestedTypeToAdd(PersistentProperty property) { - + TypeInformation typeInformation = property.getTypeInformation(); - + if (customSimpleTypes.contains(typeInformation.getType())) { return null; } - + if (property.isEntity()) { return typeInformation; } - + if (property.isCollection()) { return getTypeInformationIfNotSimpleType(typeInformation.getComponentType()); } - + if (property.isMap()) { return getTypeInformationIfNotSimpleType(typeInformation.getMapValueType()); } - + return null; } - + private TypeInformation getTypeInformationIfNotSimpleType(TypeInformation information) { return information == null || MappingBeanHelper.isSimpleType(information.getType()) ? null : information; } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java index eca62fba7..df2b5542e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java @@ -18,19 +18,26 @@ package org.springframework.data.mapping.event; import org.springframework.context.ApplicationEvent; import org.springframework.data.mapping.model.PersistentEntity; +import org.springframework.data.util.TypeInformation; /** * @author Jon Brisbin */ public class MappingContextEvent extends ApplicationEvent { - public MappingContextEvent(PersistentEntity source) { + private TypeInformation typeInformation; + + public MappingContextEvent(PersistentEntity source, TypeInformation typeInformation) { super(source); + this.typeInformation = typeInformation; } - @Override - public PersistentEntity getSource() { - return (PersistentEntity) super.getSource(); + public TypeInformation getTypeInformation() { + return typeInformation; + } + + public PersistentEntity getPersistentEntity() { + return (PersistentEntity) source; } }