T - the type of the beanMetaBean, TypedMetaBean<T>public final class LightMetaBean<T extends Bean> extends java.lang.Object implements TypedMetaBean<T>
The properties are found using the PropertyDefinition annotation.
There must be a constructor matching the property definitions (arguments of same order and types).
This uses method handles to avoid problems with reflection setAccessible() in Java SE 9.
The old reflection approach is still present, but deprecated.
| Modifier and Type | Method | Description |
|---|---|---|
java.lang.Class<T> |
beanType() |
Get the type of the bean, represented as a
Class. |
BeanBuilder<T> |
builder() |
Creates a bean builder that can be used to create an instance of this bean.
|
boolean |
equals(java.lang.Object obj) |
|
int |
hashCode() |
|
boolean |
isBuildable() |
Checks whether this bean is buildable or not.
|
<R> MetaProperty<R> |
metaProperty(java.lang.String propertyName) |
Gets a meta-property by name.
|
java.util.Map<java.lang.String,MetaProperty<?>> |
metaPropertyMap() |
Gets the map of meta-properties, keyed by property name.
|
static <B extends Bean> |
of(java.lang.Class<B> beanClass) |
Deprecated.
Use method handles version of this method
|
static <B extends Bean> |
of(java.lang.Class<B> beanType,
java.lang.invoke.MethodHandles.Lookup lookup) |
Obtains an instance of the meta-bean using standard default values.
|
static <B extends Bean> |
of(java.lang.Class<B> beanType,
java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Object... defaultValues) |
Deprecated.
Use version with field names, because no way to determine order of fields by reflection
|
static <B extends Bean> |
of(java.lang.Class<B> beanType,
java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.String[] fieldNames,
java.lang.Object... defaultValues) |
Obtains an instance of the meta-bean specifying default values.
|
java.lang.String |
toString() |
Returns a string that summarises the meta-bean.
|
LightMetaBean<T> |
withAlias(java.lang.String alias,
java.lang.String realName) |
Adds an alias to the meta-bean.
|
annotation, annotations, beanName, metaPropertyCount, metaPropertyExists, metaPropertyIterable@Deprecated public static <B extends Bean> LightMetaBean<B> of(java.lang.Class<B> beanClass)
The properties will be determined using reflection to find the
PropertyDefinition annotation.
B - the type of the beanbeanClass - the bean class, not nullpublic static <B extends Bean> LightMetaBean<B> of(java.lang.Class<B> beanType, java.lang.invoke.MethodHandles.Lookup lookup)
The properties will be determined using reflection to find the fields.
Each field must have a PropertyDefinition annotation.
The order of the properties is undefined as Java fields are not necessarily
returned in source code order.
The default values for primitives are determined automatically.
If the bean has non-primitive values like lists and maps that need defaulting
then of(Class, java.lang.invoke.MethodHandles.Lookup, String[], Object...)
must be used.
B - the type of the beanbeanType - the bean type, not nulllookup - the method handle lookup, not null@Deprecated public static <B extends Bean> LightMetaBean<B> of(java.lang.Class<B> beanType, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Object... defaultValues)
The properties will be determined using reflection to find the
PropertyDefinition annotation.
The default values must be provided if they cannot be determined automatically. Default values for primitives are determined automatically, but empty lists and maps are not.
B - the type of the beanbeanType - the bean type, not nulllookup - the method handle lookup, not nulldefaultValues - the default values, one for each property, not nullpublic static <B extends Bean> LightMetaBean<B> of(java.lang.Class<B> beanType, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.String[] fieldNames, java.lang.Object... defaultValues)
The properties will be determined using reflection to find the
PropertyDefinition annotation.
The field names must be specified as reflection does not return fields in source code order. The default values must be provided if they cannot be determined automatically. Default values for primitives are determined automatically, but empty lists and maps are not.
B - the type of the beanbeanType - the bean type, not nulllookup - the method handle lookup, not nullfieldNames - the field names, one for each property, not nulldefaultValues - the default values, one for each property, not nullpublic LightMetaBean<T> withAlias(java.lang.String alias, java.lang.String realName)
When using metaProperty(String), the alias will return the
meta-property of the real name.
alias - the aliasrealName - the real namejava.lang.IllegalArgumentException - if the realName is invalidpublic boolean isBuildable()
MetaBean
A buildable bean can be constructed using MetaBean.builder().
If this method returns true then builder() must return a valid builder.
If this method returns false then builder() must throw UnsupportedOperationException.
isBuildable in interface MetaBeanpublic BeanBuilder<T> builder()
MetaBeanThe 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.
public java.lang.Class<T> beanType()
MetaBeanClass.
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.
public <R> MetaProperty<R> metaProperty(java.lang.String propertyName)
MetaBeanEach 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.
metaProperty in interface MetaBeanR - the property type, optional, enabling auto-castingpropertyName - the property name to retrieve, not nullpublic java.util.Map<java.lang.String,MetaProperty<?>> metaPropertyMap()
MetaBean
Where possible, use MetaBean.metaPropertyIterable() instead as it typically has better performance.
metaPropertyMap in interface MetaBeanpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2007–2018 Joda.org. All rights reserved.