POJO - is the templated type of the pojo.public interface PojoDescriptor<POJO> extends PojoAttributeType<POJO>
properties of a
Pojo. A Pojo in this manner is more or
less any java object. BeanInfo.
public interface Pojo {
Integer getFooBar();
void setFooBar(int s);
boolean hasSomeFlag();
void setSomeFlag(Boolean flag);
boolean isCool();
void setCool();
List<String> getColors();
void addColor(String color);
void removeColor(String color);
}
This interface does NOT completely follow the JAVA-Beans specification. The properties "fooBar" and
"someFlag" do NOT have the same type for reading and writing. Therefore the Introspector
for java-beans or commons-beanutils can NOT be used to
read and write these properties. Using this utility the properties can be accessed as described in the
following table:
Name |
Mode |
Property-Type |
Method |
Note |
|---|---|---|---|---|
| fooBar | get | Integer | getFooBar() | - |
| fooBar | set | int | setFooBar(int) | - |
| someFlag | get | boolean | hasSomeFlag() | - |
| someFlag | set | Boolean | setSomeFlag(Boolean) | - |
| cool | get | boolean | isCool() | - |
| colors | get | List<String> | getColors() | - |
| color | add | String | addColor(String) | - |
| color | remove | String | removeColor(String) | - |
| colors | add | String | addColor(String) | enhanced copy |
| colors | remove | String | removeColor(String) | enhanced copy |
| colors | indexed-set | String | getColors().set(int, String) | enhanced virtual accessor |
getAccessor methods. If the type of your
POJO is unknown at compile-time, you need to parameterize with the
unbound wildcard as PojoDescriptor<?>. In that case you can not call the
get or set methods.PojoPropertyDescriptor| Modifier and Type | Method and Description |
|---|---|
Object |
addPropertyItem(POJO pojo,
String propertyName,
Object item)
|
<ACCESSOR extends PojoPropertyAccessor> |
getAccessor(String property,
PojoPropertyAccessorMode<ACCESSOR> mode)
This method gets the
accessor for the property with the given
propertyName and for the given access mode. |
<ACCESSOR extends PojoPropertyAccessor> |
getAccessor(String property,
PojoPropertyAccessorMode<ACCESSOR> mode,
boolean required)
|
Object |
getProperty(POJO pojo,
String property)
|
<V> V |
getProperty(POJO pojo,
TypedProperty<V> property)
This method gets the value of the specified property in a type-safe way.
|
PojoPropertyDescriptor |
getPropertyDescriptor(String propertyName)
This method gets the
descriptor for the property identified by the given
propertyName. |
PojoPropertyDescriptor |
getPropertyDescriptor(TypedProperty<?> property)
This method gets the
descriptor for the given property. |
Collection<? extends PojoPropertyDescriptor> |
getPropertyDescriptors()
This method gets the
descriptors of all properties of the according
pojo. |
Object |
getPropertyItem(POJO pojo,
String propertyName,
int index)
This method gets the item with the given
index from the list-like
property with the given propertyName of the given
pojo using the
indexed getter accessor. |
int |
getPropertySize(POJO pojo,
String propertyName)
|
POJO |
newInstance()
Creates a new instance.
|
Boolean |
removePropertyItem(POJO pojo,
String propertyName,
Object item)
This method removes the given
item from an array or Collection using the
remove
property with the given propertyName from the given
pojo accessor. |
Object |
setProperty(POJO pojo,
String property,
Object value)
|
<V> void |
setProperty(POJO pojo,
TypedProperty<V> property,
V value)
This method sets the value of the specified property in a type-safe way.
|
Object |
setPropertyItem(POJO pojo,
String propertyName,
int index,
Object item)
This method sets the given
item at the given index in the list-like
property with the given propertyName of the given
pojo using the
indexed setter accessor. |
getPojoClass, getPojoTypePOJO newInstance()
new instance of the POJO.PojoPropertyDescriptor getPropertyDescriptor(String propertyName)
descriptor for the property identified by the given
propertyName.propertyName - is the name of the requested property.propertyName or
null if no such property exists for the according pojo.PojoPropertyDescriptor getPropertyDescriptor(TypedProperty<?> property) throws PojoPropertyNotFoundException
descriptor for the given property.property - is the TypedProperty.property.PojoPropertyNotFoundException - if the specified property was NOT found.Collection<? extends PojoPropertyDescriptor> getPropertyDescriptors()
descriptors of all properties of the according
pojo.property descriptors<ACCESSOR extends PojoPropertyAccessor> ACCESSOR getAccessor(String property, PojoPropertyAccessorMode<ACCESSOR> mode)
accessor for the property with the given
propertyName and for the given access mode.ACCESSOR - is the type of the requested accessor.property - is the name of the property. If the given
mode is
GET it is
treated as for getProperty(Object, String). If the given mode is
SET it is
treated as for setProperty(Object, String, Object).mode - is the mode of the requested accessor. Use
PojoPropertyAccessorModes for available
modes.null if NOT found (there is no property named
propertyName, the property has no accessor for the given mode, etc.).<ACCESSOR extends PojoPropertyAccessor> ACCESSOR getAccessor(String property, PojoPropertyAccessorMode<ACCESSOR> mode, boolean required) throws PojoPropertyNotFoundException
ACCESSOR - is the type of the requested accessor.property - is the name of the property. If the given
mode is
GET it is
treated as for getProperty(Object, String). If the given mode is
SET it is
treated as for setProperty(Object, String, Object).mode - is the mode of the requested accessor. Use
PojoPropertyAccessorModes for available
modes.required - - if true the accessor is required and an exception is thrown if NOT found.null if NOT found and required is
false.PojoPropertyNotFoundException - if required is true and no property named
propertyName was found or no accessor exists for that property with the given
mode.getPropertyDescriptor(String),
PojoPropertyDescriptor.getAccessor(PojoPropertyAccessorMode)Object getProperty(POJO pojo, String property) throws PojoPropertyNotFoundException, ReflectionException
property identified by the given
property from the given pojo. The result depends on the form of the given
property as shown by the following table:property |
accessor | example | equivalent |
|---|---|---|---|
[a-zA-Z][a-zA-Z0-9]* |
PojoPropertyAccessorNonArgMode.GET
|
fooBar |
|
[a-zA-Z][a-zA-Z0-9]* "[" [0-9]+ "]" |
PojoPropertyAccessorIndexedNonArgMode.GET_INDEXED
|
fooBar[42] |
|
[a-zA-Z][a-zA-Z0-9]* "['" [a-zA-Z0-9]+ "']" |
PojoPropertyAccessorOneArgMode.GET_MAPPED |
fooBar['key'] |
|
pojo - is the POJO instance where to access the property.property - identifies the property to get as described above.type of the according
getter.
Depending on the POJO, the value may be null.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
(getter).ReflectionException - if the underlying accessor
caused an error during reflection.<V> V getProperty(POJO pojo, TypedProperty<V> property) throws PojoPropertyNotFoundException, ReflectionException
V - is the generic type of the requested property value.pojo - is the POJO instance where to access the property.property - is the TypedProperty identifying the property to get.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
(getter).ReflectionException - if the underlying accessor
caused an error during reflection.getProperty(Object, String)Object setProperty(POJO pojo, String property, Object value) throws PojoPropertyNotFoundException, ReflectionException
value for the property
with the given property of the given pojo. The effect depends on the form of
the given property as shown by the following table:property |
accessor | example | equivalent |
|---|---|---|---|
[a-zA-Z][a-zA-Z0-9]* |
PojoPropertyAccessorOneArgMode.SET
|
fooBar |
|
[a-zA-Z][a-zA-Z0-9]* "[" [0-9]+ "]" |
PojoPropertyAccessorIndexedOneArgMode.SET_INDEXED
|
fooBar[42] |
|
[a-zA-Z][a-zA-Z0-9]* "['" [a-zA-Z0-9]+ "']" |
PojoPropertyAccessorTwoArgMode.SET_MAPPED |
fooBar['key'] |
|
pojo - is the POJO instance where to access the property.property - identifies the property to set as explained above.value - is the property value to set. Depending on the POJO the value may be null.null if the return type is
void what should be the regular case.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
(setter).ReflectionException - if the underlying accessor
caused an error during reflection.<V> void setProperty(POJO pojo, TypedProperty<V> property, V value) throws PojoPropertyNotFoundException, ReflectionException
V - is the generic type of the property value to set.pojo - is the Pojo owning the property.property - is the TypedProperty identifying the property to set.value - is the new property value to set.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
(setter).ReflectionException - if the underlying accessor
caused an error during reflection.setProperty(Object, String, Object)int getPropertySize(POJO pojo, String propertyName) throws PojoPropertyNotFoundException, ReflectionException
pojo - is the POJO instance where to access the property.propertyName - is the name of the property.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
.ReflectionException - if the underlying accessor
caused an error during reflection.Object addPropertyItem(POJO pojo, String propertyName, Object item) throws PojoPropertyNotFoundException, ReflectionException
item to the list-like property with the given propertyName from the given pojo using the
add
accessor.pojo - is the POJO instance where to access the property.propertyName - is the name of the property.item - is the item to add to the property.null if the return type is void
what should be the regular case.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
.ReflectionException - if the underlying accessor
caused an error during reflection.Boolean removePropertyItem(POJO pojo, String propertyName, Object item) throws PojoPropertyNotFoundException, ReflectionException
item from an array or Collection using the
remove
property with the given propertyName from the given
pojo accessor.pojo - is the POJO instance where to access the property.propertyName - is the name of the property.item - is the item to remove from the property.Boolean.TRUE if the item has been removed successfully and Boolean.FALSE if the
item was NOT present in the array or Collection, or null if the accessor is
pointing to a remove method that returns no boolean.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
.ReflectionException - if the underlying accessor
caused an error during reflection.Object getPropertyItem(POJO pojo, String propertyName, int index) throws PojoPropertyNotFoundException, ReflectionException
index from the list-like
property with the given propertyName of the given
pojo using the
indexed getter accessor.pojo - is the POJO instance where to add the given property
item.propertyName - is the name of the property.index - is the position of the requested item (see List.get(int)).null if the return type is void
what should be the regular case.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
.ReflectionException - if the underlying accessor
caused an error during reflection.Object setPropertyItem(POJO pojo, String propertyName, int index, Object item) throws PojoPropertyNotFoundException, ReflectionException
item at the given index in the list-like
property with the given propertyName of the given
pojo using the
indexed setter accessor.pojo - is the POJO instance where to access the property.propertyName - is the name of the property.index - is the position of the item to set (see List.set(int, Object)).item - is the item to set at the given index.null if the return type is void
what should be the regular case.PojoPropertyNotFoundException - if the property with the given propertyName was NOT
found or has no such accessor
.ReflectionException - if the underlying accessor
caused an error during reflection.Copyright © 2001–2015 mmm-Team. All rights reserved.