Package jodd.bean
Class BeanUtilBean
- java.lang.Object
-
- jodd.bean.BeanUtilBean
-
-
Field Summary
Fields Modifier and Type Field Description protected ClassIntrospectorintrospectorprotected booleanisDeclaredprotected booleanisForcedprotected booleanisSilentprotected TypeConverterManagertypeConverterManager-
Fields inherited from interface jodd.bean.BeanUtil
declared, declaredForced, declaredForcedSilent, declaredSilent, forced, forcedSilent, pojo, silent
-
-
Constructor Summary
Constructors Constructor Description BeanUtilBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ObjectarrayForcedGet(jodd.bean.BeanProperty bp, java.lang.Object array, int index)Returns the element of an array forced.protected voidarrayForcedSet(jodd.bean.BeanProperty bp, java.lang.Object array, int index, java.lang.Object value)Sets the array element forced.protected java.lang.ObjectconvertIndexToMapKey(Getter getter, java.lang.Object index)Converts Map index to key type.protected java.lang.ObjectconvertToCollection(java.lang.Object value, java.lang.Class destinationType, java.lang.Class componentType)Converter to collection.protected java.lang.ObjectconvertType(java.lang.Object value, java.lang.Class type)Converts object to destination type.protected java.lang.ObjectcreateBeanProperty(jodd.bean.BeanProperty bp)Creates new instance for current property name through its setter.BeanUtilBeandeclared(boolean declared)Sets the declared flag.protected java.lang.ObjectensureArraySize(jodd.bean.BeanProperty bp, java.lang.Object array, java.lang.Class componentType, int index)protected voidensureListSize(java.util.List list, int size)protected java.lang.ClassextractGenericComponentType(Getter getter)Extracts generic component type of a property.protected java.lang.StringextractIndex(jodd.bean.BeanProperty bp)Extract index string from non-nested property name.java.lang.StringextractThisReference(java.lang.String propertyName)Extract the first name of this reference.protected java.lang.ClassextractType(jodd.bean.BeanProperty bp)Extracts type of current property.BeanUtilBeanforced(boolean forced)Sets the forced flag.<T> TgetIndexProperty(java.lang.Object bean, java.lang.String property, int index)Returns value of indexed property.protected java.lang.ObjectgetIndexProperty(jodd.bean.BeanProperty bp)Get non-nested property value: either simple or indexed property.<T> TgetProperty(java.lang.Object bean, java.lang.String name)Returns value of bean's property.java.lang.Class<?>getPropertyType(java.lang.Object bean, java.lang.String name)Returns property type.<T> TgetSimpleProperty(java.lang.Object bean, java.lang.String property)Reads simple property.protected java.lang.ObjectgetSimpleProperty(jodd.bean.BeanProperty bp)protected booleanhasIndexProperty(jodd.bean.BeanProperty bp)booleanhasProperty(java.lang.Object bean, java.lang.String name)Returnstrueif bean has a property.booleanhasRootProperty(java.lang.Object bean, java.lang.String name)Returnstrueif bean has only a root property.booleanhasSimpleProperty(java.lang.Object bean, java.lang.String property)Returnstrueif simple property exist.protected booleanhasSimpleProperty(jodd.bean.BeanProperty bp)protected intindexOfDot(java.lang.String name)Finds the very first next dot.protected java.lang.ObjectinvokeSetter(Setter setter, jodd.bean.BeanProperty bp, java.lang.Object value)Invokes setter, but first converts type to match the setter type.protected intparseInt(java.lang.String indexString, jodd.bean.BeanProperty bp)protected booleanresolveExistingNestedProperties(jodd.bean.BeanProperty bp)protected voidresolveNestedProperties(jodd.bean.BeanProperty bp)Resolves nested property name to the very last indexed property.voidsetIndexProperty(java.lang.Object bean, java.lang.String property, int index, java.lang.Object value)Sets indexed property.protected voidsetIndexProperty(jodd.bean.BeanProperty bp, java.lang.Object value)Sets indexed or regular properties (no nested!).voidsetIntrospector(ClassIntrospector introspector)Setsintrospectorimplementation.voidsetProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)Sets Java Bean property.voidsetSimpleProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)Sets simple property.protected voidsetSimpleProperty(jodd.bean.BeanProperty bp, java.lang.Object value)Sets a value of simple property.voidsetTypeConverterManager(TypeConverterManager typeConverterManager)Setstype converter managerimplementation.BeanUtilBeansilent(boolean silent)Sets the silent flag.
-
-
-
Field Detail
-
isDeclared
protected boolean isDeclared
-
isForced
protected boolean isForced
-
isSilent
protected boolean isSilent
-
introspector
protected ClassIntrospector introspector
-
typeConverterManager
protected TypeConverterManager typeConverterManager
-
-
Method Detail
-
declared
public BeanUtilBean declared(boolean declared)
Sets the declared flag.
-
forced
public BeanUtilBean forced(boolean forced)
Sets the forced flag.
-
silent
public BeanUtilBean silent(boolean silent)
Sets the silent flag.
-
resolveNestedProperties
protected void resolveNestedProperties(jodd.bean.BeanProperty bp)
Resolves nested property name to the very last indexed property. If forced,nullor non-existing properties will be created.
-
resolveExistingNestedProperties
protected boolean resolveExistingNestedProperties(jodd.bean.BeanProperty bp)
-
hasSimpleProperty
public boolean hasSimpleProperty(java.lang.Object bean, java.lang.String property)Description copied from interface:BeanUtilReturnstrueif simple property exist.- Specified by:
hasSimplePropertyin interfaceBeanUtil
-
hasSimpleProperty
protected boolean hasSimpleProperty(jodd.bean.BeanProperty bp)
-
getSimpleProperty
public <T> T getSimpleProperty(java.lang.Object bean, java.lang.String property)Description copied from interface:BeanUtilReads simple property.- Specified by:
getSimplePropertyin interfaceBeanUtil
-
getSimpleProperty
protected java.lang.Object getSimpleProperty(jodd.bean.BeanProperty bp)
-
setSimpleProperty
public void setSimpleProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)Description copied from interface:BeanUtilSets simple property.- Specified by:
setSimplePropertyin interfaceBeanUtil
-
setSimpleProperty
protected void setSimpleProperty(jodd.bean.BeanProperty bp, java.lang.Object value)Sets a value of simple property.
-
hasIndexProperty
protected boolean hasIndexProperty(jodd.bean.BeanProperty bp)
-
getIndexProperty
public <T> T getIndexProperty(java.lang.Object bean, java.lang.String property, int index)Description copied from interface:BeanUtilReturns value of indexed property.- Specified by:
getIndexPropertyin interfaceBeanUtil
-
getIndexProperty
protected java.lang.Object getIndexProperty(jodd.bean.BeanProperty bp)
Get non-nested property value: either simple or indexed property. If forced, missing bean will be created if possible.
-
setIndexProperty
public void setIndexProperty(java.lang.Object bean, java.lang.String property, int index, java.lang.Object value)Description copied from interface:BeanUtilSets indexed property.- Specified by:
setIndexPropertyin interfaceBeanUtil
-
setIndexProperty
protected void setIndexProperty(jodd.bean.BeanProperty bp, java.lang.Object value)Sets indexed or regular properties (no nested!).
-
setProperty
public void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object value)Description copied from interface:BeanUtilSets Java Bean property.- Specified by:
setPropertyin interfaceBeanUtil- Parameters:
bean- Java POJO bean or a Mapname- property namevalue- property value
-
getProperty
public <T> T getProperty(java.lang.Object bean, java.lang.String name)Returns value of bean's property.- Specified by:
getPropertyin interfaceBeanUtil
-
hasProperty
public boolean hasProperty(java.lang.Object bean, java.lang.String name)Description copied from interface:BeanUtilReturnstrueif bean has a property.- Specified by:
hasPropertyin interfaceBeanUtil
-
hasRootProperty
public boolean hasRootProperty(java.lang.Object bean, java.lang.String name)Description copied from interface:BeanUtilReturnstrueif bean has only a root property. If yes, this means that property may be injected into the bean. If not, bean does not contain the property.- Specified by:
hasRootPropertyin interfaceBeanUtil
-
getPropertyType
public java.lang.Class<?> getPropertyType(java.lang.Object bean, java.lang.String name)Description copied from interface:BeanUtilReturns property type.- Specified by:
getPropertyTypein interfaceBeanUtil
-
extractThisReference
public java.lang.String extractThisReference(java.lang.String propertyName)
Extract the first name of this reference.- Specified by:
extractThisReferencein interfaceBeanUtil
-
setIntrospector
public void setIntrospector(ClassIntrospector introspector)
Setsintrospectorimplementation.
-
setTypeConverterManager
public void setTypeConverterManager(TypeConverterManager typeConverterManager)
Setstype converter managerimplementation.
-
convertType
protected java.lang.Object convertType(java.lang.Object value, java.lang.Class type)Converts object to destination type. Invoked before the value is set into destination. ThrowsTypeConversionExceptionif conversion fails.
-
convertToCollection
protected java.lang.Object convertToCollection(java.lang.Object value, java.lang.Class destinationType, java.lang.Class componentType)Converter to collection.
-
invokeSetter
protected java.lang.Object invokeSetter(Setter setter, jodd.bean.BeanProperty bp, java.lang.Object value)
Invokes setter, but first converts type to match the setter type.
-
arrayForcedGet
protected java.lang.Object arrayForcedGet(jodd.bean.BeanProperty bp, java.lang.Object array, int index)Returns the element of an array forced. If value isnull, it will be instantiated. If not the last part of indexed bean property, array will be expanded to the index if necessary.
-
arrayForcedSet
protected void arrayForcedSet(jodd.bean.BeanProperty bp, java.lang.Object array, int index, java.lang.Object value)Sets the array element forced. If index is greater then arrays length, array will be expanded to the index. If speed is critical, it is better to allocate an array with proper size before using this method.
-
ensureArraySize
protected java.lang.Object ensureArraySize(jodd.bean.BeanProperty bp, java.lang.Object array, java.lang.Class componentType, int index)
-
ensureListSize
protected void ensureListSize(java.util.List list, int size)
-
indexOfDot
protected int indexOfDot(java.lang.String name)
Finds the very first next dot. Ignores dots between index brackets. Returns-1when dot is not found.
-
extractIndex
protected java.lang.String extractIndex(jodd.bean.BeanProperty bp)
Extract index string from non-nested property name. If index is found, it is stripped from bean property name. If no index is found, it returnsnull.
-
parseInt
protected int parseInt(java.lang.String indexString, jodd.bean.BeanProperty bp)
-
createBeanProperty
protected java.lang.Object createBeanProperty(jodd.bean.BeanProperty bp)
Creates new instance for current property name through its setter. It uses default constructor!
-
extractGenericComponentType
protected java.lang.Class extractGenericComponentType(Getter getter)
Extracts generic component type of a property. ReturnsObject.classwhen property does not have component.
-
convertIndexToMapKey
protected java.lang.Object convertIndexToMapKey(Getter getter, java.lang.Object index)
Converts Map index to key type. If conversion fails, original value will be returned.
-
extractType
protected java.lang.Class extractType(jodd.bean.BeanProperty bp)
Extracts type of current property.
-
-