Spring Data Core

org.springframework.data.mapping.model
Class BeanWrapper<T>

java.lang.Object
  extended by org.springframework.data.mapping.model.BeanWrapper<T>

public class BeanWrapper<T>
extends Object

Value object to allow creation of objects using the metamodel, setting and getting properties.

Author:
Oliver Gierke

Method Summary
static
<T> BeanWrapper<T>
create(T bean, ConversionService conversionService)
          Creates a new BeanWrapper for the given bean instance and ConversionService.
 T getBean()
          Returns the underlying bean instance.
 Object getProperty(PersistentProperty<?> property)
          Returns the value of the given PersistentProperty of the underlying bean instance.
<S> S
getProperty(PersistentProperty<?> property, Class<? extends S> type)
          Returns the value of the given PersistentProperty potentially converted to the given type.
 void setProperty(PersistentProperty<?> property, Object value)
          Sets the given PersistentProperty to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static <T> BeanWrapper<T> create(T bean,
                                        ConversionService conversionService)
Creates a new BeanWrapper for the given bean instance and ConversionService. If ConversionService is null no property type conversion will take place.

Type Parameters:
T -
Parameters:
bean - must not be null.
conversionService - can be null.
Returns:

setProperty

public void setProperty(PersistentProperty<?> property,
                        Object value)
Sets the given PersistentProperty to the given value. Will do type conversion if a ConversionService is configured.

Parameters:
property - must not be null.
value - can be null.
Throws:
MappingException - in case an exception occurred when setting the property value.

getProperty

public Object getProperty(PersistentProperty<?> property)
Returns the value of the given PersistentProperty of the underlying bean instance.

Type Parameters:
S -
Parameters:
property - must not be null.
Returns:

getProperty

public <S> S getProperty(PersistentProperty<?> property,
                         Class<? extends S> type)
Returns the value of the given PersistentProperty potentially converted to the given type.

Type Parameters:
S -
Parameters:
property - must not be null.
type - can be null.
Returns:
Throws:
MappingException - in case an exception occured when accessing the property.

getBean

public T getBean()
Returns the underlying bean instance.

Returns:
will never be null.

Spring Data Core

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.