DynamicMetaBean, TypedMetaBean<T>BasicMetaBean, DirectMetaBean, LightMetaBean, MinimalMetaBean, ReflectiveMetaBeanpublic interface MetaBean
This interface can be thought of as the equivalent of Class but for beans.
In most cases the meta-bean will be code generated and the concrete class will have additional methods.
| Modifier and Type | Method | Description |
|---|---|---|
default <A extends java.lang.annotation.Annotation> |
annotation(java.lang.Class<A> annotationClass) |
Gets an annotation from the bean.
|
default java.util.List<java.lang.annotation.Annotation> |
annotations() |
Gets the annotations associated with this bean.
|
default java.lang.String |
beanName() |
Gets the bean name, which is normally the fully qualified class name of the bean.
|
java.lang.Class<? extends Bean> |
beanType() |
Get the type of the bean, represented as a
Class. |
BeanBuilder<? extends Bean> |
builder() |
Creates a bean builder that can be used to create an instance of this bean.
|
boolean |
isBuildable() |
Checks whether this bean is buildable or not.
|
default <R> MetaProperty<R> |
metaProperty(java.lang.String propertyName) |
Gets a meta-property by name.
|
default int |
metaPropertyCount() |
Counts the number of properties.
|
default boolean |
metaPropertyExists(java.lang.String propertyName) |
Checks if a property exists.
|
default java.lang.Iterable<MetaProperty<?>> |
metaPropertyIterable() |
Gets an iterator of meta-properties.
|
java.util.Map<java.lang.String,MetaProperty<?>> |
metaPropertyMap() |
Gets the map of meta-properties, keyed by property name.
|
static MetaBean |
of(java.lang.Class<?> cls) |
Obtains a meta-bean from a
Class. |
static void |
register(MetaBean metaBean) |
Registers a meta-bean.
|
static MetaBean of(java.lang.Class<?> cls)
Class.
This will return a meta-bean if it has been registered, or if the class
implements DynamicBean and has a no-args constructor.
Note that the common case where the meta-bean is registered by a static initializer is handled.
cls - the class to get the meta-bean for, not nulljava.lang.IllegalArgumentException - if unable to obtain the meta-beanstatic void register(MetaBean metaBean)
This should be done for all beans in a static factory where possible. If the meta-bean is dynamic, this method should not be called.
metaBean - the meta-bean, not nulljava.lang.IllegalArgumentException - if unable to registerboolean isBuildable()
A buildable bean can be constructed using builder().
If this method returns true then builder() must return a valid builder.
If this method returns false then builder() must throw UnsupportedOperationException.
BeanBuilder<? extends Bean> builder()
The builder is used in two main ways. The first is to allow immutable beans to be constructed. The second is to enable automated tools like serialization/deserialization.
The builder can be thought of as a Map of MetaProperty to value.
Note that the implementation is not necessarily an actual map.
java.lang.UnsupportedOperationException - if the bean cannot be createddefault java.lang.String beanName()
This is primarily used for human-readable output.
java.lang.Class<? extends Bean> beanType()
Class.
A MetaBean can be thought of as the equivalent of Class but for beans.
This method allows the actual Class instance of the bean to be obtained.
default int metaPropertyCount()
Each meta-bean manages a single bean with a known set of properties. This method returns the count of properties.
default boolean metaPropertyExists(java.lang.String propertyName)
Each meta-bean manages a single bean with a known set of properties. This method checks whether there is a property with the specified name.
propertyName - the property name to check, null returns falsedefault <R> MetaProperty<R> metaProperty(java.lang.String propertyName)
Each meta-bean manages a single bean with a known set of properties. This method returns the property with the specified name.
The base interface throws an exception if the name is not recognised.
By contrast, the DynamicMetaBean subinterface creates the property on demand.
R - the property type, optional, enabling auto-castingpropertyName - the property name to retrieve, not nulljava.util.NoSuchElementException - if the property name is invaliddefault java.lang.Iterable<MetaProperty<?>> metaPropertyIterable()
This method returns an Iterable, which is simpler than a Map.
As a result, implementations may be able to optimise, and so this method should be
preferred to metaPropertyMap() where a choice is possible.
java.util.Map<java.lang.String,MetaProperty<?>> metaPropertyMap()
Where possible, use metaPropertyIterable() instead as it typically has better performance.
default java.util.List<java.lang.annotation.Annotation> annotations()
The annotations are queried from the bean.
This is typically accomplished by querying the annotations of an underlying
Class however any strategy is permitted.
If the implementation has a mutable set of annotations, then the result of this method must stream over those annotations in existence when this method is called to avoid concurrency issues.
The default implementation uses the annotations from beanType().
default <A extends java.lang.annotation.Annotation> A annotation(java.lang.Class<A> annotationClass)
The annotations are queried from the bean.
This is typically accomplished by querying the annotations of an underlying
Class however any strategy is permitted.
A - the annotation typeannotationClass - the annotation class to find, not nulljava.util.NoSuchElementException - if the annotation is not specifiedCopyright © 2007–2018 Joda.org. All rights reserved.