Package org.apache.juneau
Class BeanMeta<T>
java.lang.Object
org.apache.juneau.BeanMeta<T>
- Type Parameters:
T
- The class type that this metadata applies to.
- Direct Known Subclasses:
BeanMetaFiltered
Encapsulates all access to the properties of a bean class (like a souped-up
BeanInfo
).
Description
Uses introspection to find all the properties associated with this class. If the@Bean
annotation
is present on the class, then that information is used to determine the properties on the class.
Otherwise, the BeanInfo
functionality in Java is used to determine the properties on the class.
Bean property ordering
The order of the properties are as follows:-
If
@Bean
annotation is specified on class, then the order is the same as the list of properties in the annotation. -
If
@Bean
annotation is not specified on the class, then the order is based on the following.- Public fields (same order as
Class.getFields()
). - Properties returned by
BeanInfo.getPropertyDescriptors()
. - Non-standard getters/setters with
@Beanp
annotation defined on them.
- Public fields (same order as
See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final BeanFilter
Optional bean filter associated with the target class.The target class that this meta object describes.The target class type that this meta object describes.protected final ConstructorInfo
The constructor for this bean.protected final String[]
For beans with constructors with Beanc annotation, this is the list of constructor arg properties.protected final BeanContext
The bean context that created this metadata object.The getter properties on the target class.protected final Map<String,
BeanPropertyMeta> The hidden properties on the target class.protected final Map<String,
BeanPropertyMeta> The properties on the target class.protected final BeanPropertyMeta[]
The properties on the target class.The setter properties on the target class.Type variables implemented by this bean. -
Constructor Summary
ModifierConstructorDescriptionprotected
BeanMeta
(ClassMeta<T> classMeta, BeanContext ctx, BeanFilter beanFilter, String[] pNames, ConstructorInfo implClassConstructor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
<T2> Optional<T2>
firstProperty
(Predicate<BeanPropertyMeta> filter, Function<BeanPropertyMeta, T2> function) Performs a function on the first property that matches the specified filter.void
forEachProperty
(Predicate<BeanPropertyMeta> filter, Consumer<BeanPropertyMeta> action) Performs an action on all matching properties.Returns theClassMeta
of this bean.final String
Returns the dictionary name for this bean as defined through the@Bean(typeName)
annotation.getPropertyMeta
(String name) Returns metadata about the specified property.Returns the metadata on all properties associated with this bean.final BeanPropertyMeta
Returns a mock bean property that resolves to the name"_type" and whose value always resolves to the dictionary name of the bean.int
hashCode()
protected T
Creates a new instance of this bean.onReadProperty
(Object bean, String name, Object value) Property read interceptor.onWriteProperty
(Object bean, String name, Object value) Property write interceptor.toString()
-
Field Details
-
classMeta
The target class type that this meta object describes. -
c
The target class that this meta object describes. -
properties
The properties on the target class. -
propertyArray
The properties on the target class. -
getterProps
The getter properties on the target class. -
setterProps
The setter properties on the target class. -
ctx
The bean context that created this metadata object. -
beanFilter
Optional bean filter associated with the target class. -
typeVarImpls
Type variables implemented by this bean. -
constructor
The constructor for this bean. -
constructorArgs
For beans with constructors with Beanc annotation, this is the list of constructor arg properties.
-
-
Constructor Details
-
BeanMeta
protected BeanMeta(ClassMeta<T> classMeta, BeanContext ctx, BeanFilter beanFilter, String[] pNames, ConstructorInfo implClassConstructor) Constructor.- Parameters:
classMeta
- The target class.ctx
- The bean context that created this object.beanFilter
- Optional bean filter associated with the target class. Can benull .pNames
- Explicit list of property names and order of properties. Ifnull , determine automatically.implClassConstructor
- The constructor to use if one cannot be found. Can benull .
-
-
Method Details
-
getClassMeta
Returns theClassMeta
of this bean.- Returns:
- The
ClassMeta
of this bean.
-
getDictionaryName
Returns the dictionary name for this bean as defined through the@Bean(typeName)
annotation.- Returns:
- The dictionary name for this bean, or
null if it has no dictionary name defined.
-
getTypeProperty
Returns a mock bean property that resolves to the name"_type" and whose value always resolves to the dictionary name of the bean.- Returns:
- The type name property.
-
getPropertyMetas
Returns the metadata on all properties associated with this bean.- Returns:
- Metadata on all properties associated with this bean.
-
forEachProperty
Performs an action on all matching properties.- Parameters:
filter
- The filter to apply.action
- The action to apply.
-
firstProperty
public <T2> Optional<T2> firstProperty(Predicate<BeanPropertyMeta> filter, Function<BeanPropertyMeta, T2> function) Performs a function on the first property that matches the specified filter.- Type Parameters:
T2
- The type to convert the property to.- Parameters:
filter
- The filter to apply.function
- The function to apply to the matching property.- Returns:
- The result of the function. Never
null .
-
getPropertyMeta
Returns metadata about the specified property.- Parameters:
name
- The name of the property on this bean.- Returns:
- The metadata about the property, or
null if no such property exists on this bean.
-
newBean
Creates a new instance of this bean.- Parameters:
outer
- The outer object if bean class is a non-static inner member class.- Returns:
- A new instance of this bean if possible, or
null if not. - Throws:
ExecutableException
- Exception occurred on invoked constructor/method/field.
-
onReadProperty
Property read interceptor.Called immediately after calling the getter to allow the value to be overridden.
- Parameters:
bean
- The bean from which the property was read.name
- The property name.value
- The value just extracted from calling the bean getter.- Returns:
- The value to serialize. Default is just to return the existing value.
-
onWriteProperty
Property write interceptor.Called immediately before calling theh setter to allow value to be overwridden.
- Parameters:
bean
- The bean from which the property was read.name
- The property name.value
- The value just parsed.- Returns:
- The value to serialize. Default is just to return the existing value.
-
toString
-
hashCode
-
equals
-