Spring Data Commons

org.springframework.data.mapping.context
Class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>

java.lang.Object
  extended by org.springframework.data.mapping.context.AbstractMappingContext<E,P>
All Implemented Interfaces:
EventListener, Aware, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware, ApplicationListener<ContextRefreshedEvent>, MappingContext<E,P>

public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
extends Object
implements MappingContext<E,P>, InitializingBean, ApplicationEventPublisherAware, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>

Base class to build mapping metadata and thus create instances of PersistentEntity and PersistentProperty.

The implementation uses a ReentrantReadWriteLock to make sure PersistentEntity are completely populated before accessing them from outside.

Author:
Jon Brisbin , Oliver Gierke

Constructor Summary
AbstractMappingContext()
           
 
Method Summary
protected  E addPersistentEntity(Class<?> type)
          Adds the given type to the MappingContext.
protected  E addPersistentEntity(TypeInformation<?> typeInformation)
          Adds the given TypeInformation to the MappingContext.
 void afterPropertiesSet()
          Deprecated. 
protected abstract
<T> E
createPersistentEntity(TypeInformation<T> typeInformation)
          Creates the concrete PersistentEntity instance.
protected abstract  P createPersistentProperty(Field field, PropertyDescriptor descriptor, E owner, SimpleTypeHolder simpleTypeHolder)
          Creates the concrete instance of PersistentProperty.
 List<Validator> getEntityValidators(E entity)
          Obtains a validator for the given entity TODO: Why do we need validators at the MappingContext?
 Collection<E> getPersistentEntities()
          Returns all PersistentEntitys held in the context.
 E getPersistentEntity(Class<?> type)
          Returns a PersistentEntity for the given Class.
 E getPersistentEntity(P persistentProperty)
          Returns the PersistentEntity mapped by the given PersistentProperty.
 E getPersistentEntity(TypeInformation<?> type)
          Returns a PersistentEntity for the given TypeInformation.
 PersistentPropertyPath<P> getPersistentPropertyPath(PropertyPath propertyPath)
          Returns all PersistentPropertys for the given path expression based on the given PropertyPath.
 void initialize()
          Initializes the mapping context.
 void onApplicationEvent(ContextRefreshedEvent event)
           
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
          Deprecated. 
 void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet)
          Sets the Set of types to populate the context initially.
 void setSimpleTypeHolder(SimpleTypeHolder simpleTypes)
          Configures the SimpleTypeHolder to be used by the MappingContext.
 void setStrict(boolean strict)
          Configures whether the MappingContext is in strict mode which means, that it will throw MappingExceptions in case one tries to lookup a PersistentEntity not already in the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMappingContext

public AbstractMappingContext()
Method Detail

setApplicationEventPublisher

@Deprecated
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
Deprecated. 

Use setApplicationContext(ApplicationContext) instead.

Specified by:
setApplicationEventPublisher in interface ApplicationEventPublisherAware
See Also:
setApplicationContext(ApplicationContext), ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException

setInitialEntitySet

public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet)
Sets the Set of types to populate the context initially.

Parameters:
initialEntitySet -

setStrict

public void setStrict(boolean strict)
Configures whether the MappingContext is in strict mode which means, that it will throw MappingExceptions in case one tries to lookup a PersistentEntity not already in the context. This defaults to false so that unknown types will be transparently added to the MappingContext if not known in advance.

Parameters:
strict -

setSimpleTypeHolder

public void setSimpleTypeHolder(SimpleTypeHolder simpleTypes)
Configures the SimpleTypeHolder to be used by the MappingContext. Allows customization of what types will be regarded as simple types and thus not recursively analysed. Setting this to null will reset the context to use the default SimpleTypeHolder.

Parameters:
simpleTypes -

getPersistentEntities

public Collection<E> getPersistentEntities()
Description copied from interface: MappingContext
Returns all PersistentEntitys held in the context.

Specified by:
getPersistentEntities in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Returns:

getPersistentEntity

public E getPersistentEntity(Class<?> type)
Description copied from interface: MappingContext
Returns a PersistentEntity for the given Class.

Specified by:
getPersistentEntity in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Returns:

getPersistentEntity

public E getPersistentEntity(TypeInformation<?> type)
Description copied from interface: MappingContext
Returns a PersistentEntity for the given TypeInformation.

Specified by:
getPersistentEntity in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Returns:

getPersistentEntity

public E getPersistentEntity(P persistentProperty)
Description copied from interface: MappingContext
Returns the PersistentEntity mapped by the given PersistentProperty.

Specified by:
getPersistentEntity in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Returns:
the PersistentEntity mapped by the given PersistentProperty or null if no PersistentEntity exists for it or the PersistentProperty does not refer to an entity.

getPersistentPropertyPath

public PersistentPropertyPath<P> getPersistentPropertyPath(PropertyPath propertyPath)
Description copied from interface: MappingContext
Returns all PersistentPropertys for the given path expression based on the given PropertyPath.

Specified by:
getPersistentPropertyPath in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Returns:

getEntityValidators

public List<Validator> getEntityValidators(E entity)
Description copied from interface: MappingContext
Obtains a validator for the given entity TODO: Why do we need validators at the MappingContext?

Specified by:
getEntityValidators in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
Parameters:
entity - The entity
Returns:
A validator or null if none exists for the given entity

addPersistentEntity

protected E addPersistentEntity(Class<?> type)
Adds the given type to the MappingContext.

Parameters:
type -
Returns:

addPersistentEntity

protected E addPersistentEntity(TypeInformation<?> typeInformation)
Adds the given TypeInformation to the MappingContext.

Parameters:
typeInformation -
Returns:

createPersistentEntity

protected abstract <T> E createPersistentEntity(TypeInformation<T> typeInformation)
Creates the concrete PersistentEntity instance.

Type Parameters:
T -
Parameters:
typeInformation -
Returns:

createPersistentProperty

protected abstract P createPersistentProperty(Field field,
                                              PropertyDescriptor descriptor,
                                              E owner,
                                              SimpleTypeHolder simpleTypeHolder)
Creates the concrete instance of PersistentProperty.

Parameters:
field -
descriptor -
owner -
simpleTypeHolder -
Returns:

afterPropertiesSet

@Deprecated
public void afterPropertiesSet()
Deprecated. 

Initial entity population is now done on receiving the ContextRefreshedEvent. If implementations still need the InitializingBean hook implement the interface yourself. Assume not entities being added at invocation time yet.

Specified by:
afterPropertiesSet in interface InitializingBean
See Also:
onApplicationEvent(ContextRefreshedEvent), InitializingBean.afterPropertiesSet()

onApplicationEvent

public void onApplicationEvent(ContextRefreshedEvent event)
Specified by:
onApplicationEvent in interface ApplicationListener<ContextRefreshedEvent>

initialize

public void initialize()
Initializes the mapping context. Will add the types configured through setInitialEntitySet(Set) to the context.


Spring Data Commons

Copyright © 2012. All Rights Reserved.