|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
POJO - is the templated type of the pojo.public interface PojoDescriptor<POJO>
This interface describes the properties of a
Pojo. A
Pojo in this manner is more or less any java
object.
This interface is an alternative to BeanInfo.
Look at the following example:
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| Method Summary | ||
|---|---|---|
Object |
addPropertyItem(POJO pojoInstance,
String propertyName,
Object item)
This method adds the given item to the list-like
property with the given
propertyName from the given pojoInstance using
the
add accessor. |
|
|
getAccessor(String property,
PojoPropertyAccessorMode<ACCESSOR> mode)
This method gets the accessor for the property
with the given propertyName and for the given access
mode. |
|
|
getAccessor(String property,
PojoPropertyAccessorMode<ACCESSOR> mode,
boolean required)
This method gets the accessor for the given from the
descriptor with the given
. |
|
Object |
getProperty(POJO pojoInstance,
String property)
This method gets the property
identified by the given property from the given
pojoInstance. |
|
PojoPropertyDescriptor |
getPropertyDescriptor(String propertyName)
This method gets the descriptor for the
property identified by the given propertyName. |
|
Collection<? extends PojoPropertyDescriptor> |
getPropertyDescriptors()
This method gets the descriptors of all
properties of the according pojo. |
|
Object |
getPropertyItem(POJO pojoInstance,
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 pojoInstance using the
indexed getter
accessor. |
|
int |
getPropertySize(POJO pojoInstance,
String propertyName)
This method gets the size of the property with the given
propertyName from the given pojoInstance. |
|
Boolean |
removePropertyItem(POJO pojoInstance,
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 pojoInstance
accessor. |
|
Object |
setProperty(POJO pojoInstance,
String property,
Object value)
This method sets the given value for the
property with the given
property of the given pojoInstance. |
|
Object |
setPropertyItem(POJO pojoInstance,
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
pojoInstance using the
indexed setter
accessor. |
|
| Methods inherited from interface net.sf.mmm.util.pojo.descriptor.api.attribute.PojoAttributeType |
|---|
getPojoClass, getPojoType |
| Method Detail |
|---|
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.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.
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
mode from the
descriptor with the given
propertyName
.
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.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 pojoInstance,
String property)
throws PojoPropertyNotFoundException,
ReflectionException
property
identified by the given property from the given
pojoInstance. 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'] |
|
pojoInstance - 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.
ReflectionException - if the underlying
accessor caused
an error during reflection.
Object setProperty(POJO pojoInstance,
String property,
Object value)
throws PojoPropertyNotFoundException,
ReflectionException
value for the
property with the given
property of the given pojoInstance. 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'] |
|
pojoInstance - 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.
ReflectionException - if the underlying
accessor caused
an error during reflection.
int getPropertySize(POJO pojoInstance,
String propertyName)
throws PojoPropertyNotFoundException,
ReflectionException
size of the property with the given
propertyName from the given pojoInstance.
pojoInstance - 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 pojoInstance,
String propertyName,
Object item)
throws PojoPropertyNotFoundException,
ReflectionException
item to the list-like
property with the given
propertyName from the given pojoInstance using
the
add accessor.
pojoInstance - 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 pojoInstance,
String propertyName,
Object item)
throws PojoPropertyNotFoundException,
ReflectionException
item from an array or
Collection using the
remove
property with the given
propertyName from the given pojoInstance
accessor.
pojoInstance - 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 pojoInstance,
String propertyName,
int index)
throws PojoPropertyNotFoundException,
ReflectionException
index from the
list-like property with the given
propertyName of the given pojoInstance using the
indexed getter
accessor.
pojoInstance - 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 pojoInstance,
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
pojoInstance using the
indexed setter
accessor.
pojoInstance - 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||