net.sf.mmm.util.pojo.descriptor.base
Class AbstractPojoDescriptor<POJO>

java.lang.Object
  extended by net.sf.mmm.util.pojo.descriptor.base.AbstractPojoDescriptor<POJO>
Type Parameters:
POJO - is the templated type of the POJO.
All Implemented Interfaces:
PojoAttributeType<POJO>, PojoDescriptor<POJO>
Direct Known Subclasses:
PojoDescriptorImpl

public abstract class AbstractPojoDescriptor<POJO>
extends Object
implements PojoDescriptor<POJO>

This is the abstract base implementation of the PojoDescriptor interface.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  GenericType<POJO> pojoType
           
 
Constructor Summary
AbstractPojoDescriptor(GenericType<POJO> pojoType)
          The constructor.
 
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.
<ACCESSOR extends PojoPropertyAccessor>
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.
abstract  PojoPropertyDescriptorImpl getOrCreatePropertyDescriptor(String propertyName)
          This method gets the property-descriptor for the given propertyName.
 Class<POJO> getPojoClass()
          This method gets the type reflecting the Pojo this object is related to.
 GenericType<POJO> getPojoType()
          This method gets the GenericType reflecting the Pojo this object is related to.
 Object getProperty(POJO pojoInstance, String property)
          This method gets the property identified by the given property from the given pojoInstance.
abstract  Collection<? extends AbstractPojoPropertyDescriptor> 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 propertyName, 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.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.pojo.descriptor.api.PojoDescriptor
getAccessor, getPropertyDescriptor
 

Field Detail

pojoType

private final GenericType<POJO> pojoType
See Also:
getPojoType()
Constructor Detail

AbstractPojoDescriptor

public AbstractPojoDescriptor(GenericType<POJO> pojoType)
The constructor.

Parameters:
pojoType - is the pojo-type.
Method Detail

getPojoClass

public Class<POJO> getPojoClass()
This method gets the type reflecting the Pojo this object is related to.

Specified by:
getPojoClass in interface PojoAttributeType<POJO>
Returns:
the type of the according Pojo.

getPojoType

public GenericType<POJO> getPojoType()
This method gets the GenericType reflecting the Pojo this object is related to.

Specified by:
getPojoType in interface PojoAttributeType<POJO>
Returns:
the type of the according Pojo.

getPropertyDescriptors

public abstract Collection<? extends AbstractPojoPropertyDescriptor> getPropertyDescriptors()
This method gets the descriptors of all properties of the according pojo.

Specified by:
getPropertyDescriptors in interface PojoDescriptor<POJO>
Returns:
a collection with all property descriptors

getOrCreatePropertyDescriptor

public abstract PojoPropertyDescriptorImpl getOrCreatePropertyDescriptor(String propertyName)
This method gets the property-descriptor for the given propertyName.

Parameters:
propertyName - is the name of the requested property-descriptor.
Returns:
the requested property-descriptor or null if NO property exists with the given propertyName.

getAccessor

public <ACCESSOR extends PojoPropertyAccessor> 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.

Specified by:
getAccessor in interface PojoDescriptor<POJO>
Type Parameters:
ACCESSOR - is the type of the requested accessor.
Parameters:
property - is the name of the property. If the given mode is GET it is treated as for PojoDescriptor.getProperty(Object, String). If the given mode is SET it is treated as for PojoDescriptor.setProperty(Object, String, Object).
mode - is the mode of the requested accessor.
Returns:
the requested accessor or null if NOT found (there is no property named propertyName, the property has no accessor for the given mode, etc.).

getProperty

public Object getProperty(POJO pojoInstance,
                          String property)
This method gets the 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
  • getFooBar()
[a-zA-Z][a-zA-Z0-9]* "[" [0-9]+ "]" PojoPropertyAccessorIndexedNonArgMode.GET_INDEXED fooBar[42]
  • getFooBar(42)
  • getFooBar()[42]
  • getFooBar().get(42)
[a-zA-Z][a-zA-Z0-9]* "['" [a-zA-Z0-9]+ "']" PojoPropertyAccessorOneArgMode.GET_MAPPED fooBar['key']
  • getFooBar("key")
  • getFooBar().get("key")

Specified by:
getProperty in interface PojoDescriptor<POJO>
Parameters:
pojoInstance - is the POJO instance where to access the property.
property - identifies the property to get as described above.
Returns:
the value of the requested property. It will be an instance of the type of the according getter. Depending on the POJO, the value may be null.

setProperty

public Object setProperty(POJO pojoInstance,
                          String propertyName,
                          Object value)
This method sets the given 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
  • setFooBar(value)
[a-zA-Z][a-zA-Z0-9]* "[" [0-9]+ "]" PojoPropertyAccessorIndexedOneArgMode.SET_INDEXED fooBar[42]
  • setFooBar(42, value)
  • getFooBar()[42]=value
  • getFooBar().set(42, value)
[a-zA-Z][a-zA-Z0-9]* "['" [a-zA-Z0-9]+ "']" PojoPropertyAccessorTwoArgMode.SET_MAPPED fooBar['key']
  • setFooBar("key", value)
  • getFooBar().put("key", value)

Specified by:
setProperty in interface PojoDescriptor<POJO>
Parameters:
pojoInstance - is the POJO instance where to access the property.
propertyName - identifies the property to set as explained above.
value - is the property value to set. Depending on the POJO the value may be null.
Returns:
the result of the setter method. Will be null if the return type is void what should be the regular case.

getPropertySize

public int getPropertySize(POJO pojoInstance,
                           String propertyName)
This method gets the size of the property with the given propertyName from the given pojoInstance.

Specified by:
getPropertySize in interface PojoDescriptor<POJO>
Parameters:
pojoInstance - is the POJO instance where to access the property.
propertyName - is the name of the property.
Returns:
the size of the requested property.

addPropertyItem

public 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.

Specified by:
addPropertyItem in interface PojoDescriptor<POJO>
Parameters:
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.
Returns:
the result of the add-method. Will be null if the return type is void what should be the regular case.

removePropertyItem

public 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.

Specified by:
removePropertyItem in interface PojoDescriptor<POJO>
Parameters:
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.
Returns:
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.

getPropertyItem

public 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.

Specified by:
getPropertyItem in interface PojoDescriptor<POJO>
Parameters:
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)).
Returns:
the result of the add-method. Will be null if the return type is void what should be the regular case.

setPropertyItem

public 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.

Specified by:
setPropertyItem in interface PojoDescriptor<POJO>
Parameters:
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.
Returns:
the result of the add-method. Will be null if the return type is void what should be the regular case.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2001-2010 mmm-Team. All Rights Reserved.