T
- Specifies the type of object that this map encapsulates.public class BeanMap<T> extends AbstractMap<String,Object> implements Delegate<T>
Map
interface that allows properties on the wrapped
object can be accessed using the get()
and put()
methods.
Use the BeanContext
class to create instances of this class.
keySet()
and entrySet()
methods are as follows:
@Bean
annotation is specified on class, then the order is the same as the list of properties
in the annotation.
@Bean
annotation is not specified on the class, then the order is the same as that returned
by the BeanInfo
class (i.e. ordered by definition in the class).
The order can also be overridden through the use of a BeanFilter
.
PojoSwaps
are defined on the class types of the properties of this bean or the bean properties
themselves, the get(Object)
and put(String, Object)
methods will automatically transform the
property value to and from the serialized form.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Map<String,List<?>> |
arrayPropertyCache
Temporary holding cache for bean properties of array types when the add() method is being used.
|
protected T |
bean
The wrapped object.
|
protected BeanMeta<T> |
meta
The BeanMeta associated with the class of the object.
|
protected Map<String,Object> |
propertyCache
Temporary holding cache for beans with read-only properties.
|
Modifier | Constructor and Description |
---|---|
protected |
BeanMap(BeanSession session,
T bean,
BeanMeta<T> meta)
Instance of this class are instantiated through the BeanContext class.
|
Modifier and Type | Method and Description |
---|---|
void |
add(String property,
Object value)
Add a value to a collection or array property.
|
Set<Map.Entry<String,Object>> |
entrySet()
Returns all the properties associated with the bean.
|
Object |
get(Object property)
Gets a property on the bean.
|
T |
getBean()
Returns the wrapped bean object.
|
T |
getBean(boolean create)
Returns the wrapped bean object.
|
BeanSession |
getBeanSession()
Returns the bean session that created this bean map.
|
ClassMeta<T> |
getClassMeta()
Returns the
ClassMeta of the wrapped bean. |
BeanMeta<T> |
getMeta()
Returns the metadata associated with this bean map.
|
protected Collection<BeanPropertyMeta> |
getProperties()
Returns a simple collection of properties for this bean map.
|
BeanMapEntry |
getProperty(String propertyName)
Returns the specified property on this bean map.
|
BeanPropertyMeta |
getPropertyMeta(String propertyName)
Returns the metadata on the specified property.
|
Object |
getRaw(Object property)
Same as
get(Object) except bypasses the POJO filter associated with the bean property or bean filter
associated with the bean class. |
List<BeanPropertyValue> |
getValues(boolean ignoreNulls,
BeanPropertyValue... prependVals)
Invokes all the getters on this bean and return the values as a list of
BeanPropertyValue objects. |
Set<String> |
keySet()
Returns the names of all properties associated with the bean.
|
BeanMap<T> |
load(Map entries)
Convenience method for loading this map with the contents of the specified map.
|
BeanMap<T> |
load(Reader r,
ReaderParser p)
Convenience method for setting multiple property values by passing in a reader.
|
BeanMap<T> |
load(String input)
Convenience method for setting multiple property values by passing in JSON text.
|
Object |
put(String property,
Object value)
Sets a property on the bean.
|
String |
resolveVars(String s)
Given a string containing variables of the form
"{property}" , replaces those variables with property
values in this bean. |
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, putAll, remove, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
protected Map<String,Object> propertyCache
protected Map<String,List<?>> arrayPropertyCache
protected BeanMap(BeanSession session, T bean, BeanMeta<T> meta)
session
- The bean session object that created this bean map.bean
- The bean to wrap inside this map.meta
- The metadata associated with the bean class.public BeanMeta<T> getMeta()
public final BeanSession getBeanSession()
public T getBean()
Triggers bean creation if bean has read-only properties set through a constructor defined by the
@BeanConstructor
annotation.
public T getBean(boolean create)
If create
is @BeanConstructor
annotation.
This method does NOT always return the bean in it's final state.
Array properties temporary stored as ArrayLists are not finalized until the getBean()
method is called.
create
- If bean hasn't been instantiated yet, then instantiate it.public Object put(String property, Object value)
If there is a PojoSwap
associated with this bean property or bean property type class, then you must pass
in a transformed value.
For example, if the bean property type class is a Date
and the bean property has the
DateSwap.ISO8601DT
swap associated with it through the
@Swap.value()
annotation, the value being passed in must be
a String containing an ISO8601 date-time string value.
put
in interface Map<String,Object>
put
in class AbstractMap<String,Object>
property
- The name of the property to set.value
- The value to set the property to.beanMapPutReturnsOldValue
is RuntimeException
- if any of the following occur.
public void add(String property, Object value)
As a general rule, adding to arrays is not recommended since the array must be recreate each time this method is called.
property
- Property name or child-element name (if @Xml.childName()
is specified).value
- The value to add to the collection or array.public Object get(Object property)
If there is a PojoSwap
associated with this bean property or bean property type class, then this method
will return the transformed value.
For example, if the bean property type class is a Date
and the bean property has the
DateSwap.ISO8601DT
swap associated with it through the
@Swap.value()
annotation, this method will return a String containing an
ISO8601 date-time string value.
get
in interface Map<String,Object>
get
in class AbstractMap<String,Object>
property
- The name of the property to get.RuntimeException
- if any of the following occur.
public Object getRaw(Object property)
get(Object)
except bypasses the POJO filter associated with the bean property or bean filter
associated with the bean class.property
- The name of the property to get.public BeanMap<T> load(String input) throws ParseException
aPersonBean.load(
input
- The text that will get parsed into a map and then added to this map.ParseException
- If the input contains a syntax error or is malformed.public BeanMap<T> load(Reader r, ReaderParser p) throws ParseException, IOException
r
- The text that will get parsed into a map and then added to this map.p
- The parser to use to parse the text.ParseException
- If the input contains a syntax error or is malformed.IOException
- Thrown by Reader
.public BeanMap<T> load(Map entries)
Identical to AbstractMap.putAll(Map)
except as a fluent-style method.
entries
- The map containing the entries to add to this map.public Set<String> keySet()
The returned set is unmodifiable.
public BeanMapEntry getProperty(String propertyName)
Allows you to get and set an individual property on a bean without having a handle to the bean itself by using
the BeanMapEntry.getValue()
and BeanMapEntry.setValue(Object)
methods.
This method can also be used to get metadata on a property by calling the BeanMapEntry.getMeta()
method.
propertyName
- The name of the property to look up.public BeanPropertyMeta getPropertyMeta(String propertyName)
propertyName
- The name of the bean property.public ClassMeta<T> getClassMeta()
ClassMeta
of the wrapped bean.getClassMeta
in interface Delegate<T>
public List<BeanPropertyValue> getValues(boolean ignoreNulls, BeanPropertyValue... prependVals)
BeanPropertyValue
objects.
This allows a snapshot of all values to be grabbed from a bean in one call.
ignoreNulls
- Don't return properties whose values are null.prependVals
- Additional bean property values to prepended to this list.
Any public String resolveVars(String s)
"{property}"
, replaces those variables with property
values in this bean.s
- The string containing variables.protected Collection<BeanPropertyMeta> getProperties()
Copyright © 2018 Apache. All rights reserved.