eu.beesoft.gaia.util
Class Miner

java.lang.Object
  extended by eu.beesoft.gaia.util.Miner

public class Miner
extends java.lang.Object

Miner is a class dedicated to support the data binding. From external perspective it has two simple methods:

Property name can be a simple property name, or you can use the dot-convention to chain objects referenced from properties. For example, if object A has property a that references object B, and object B has property b that references object C, and object C has property c you want to get, you can use as property name text a.b.c to get / set this property.

Miner prioritizes a method access (via getters / setters), but if the method for the property cannot be found, it uses the field access.

You can use this class "as is". But you have to subclass it if


Constructor Summary
Miner()
          Creates a new instance of the Miner.
 
Method Summary
protected  java.lang.Object createObject(java.lang.String simplePropertyName, java.lang.Object owner)
          Creates object for given property and object owner.
 java.lang.Object getValue(java.lang.String dottedPropertyName, java.lang.Object object)
          Returns value from the property with the given dottedPropertyName of the object object.
protected  java.lang.Object getValueFromProperty(java.lang.String simplePropertyName, java.lang.Object object)
          Returns value from the property with the given simplePropertyName of the object object.
 void setValue(java.lang.Object value, java.lang.String dottedPropertyName, java.lang.Object object)
          Sets value to the object's property.
protected  void setValueToProperty(java.lang.Object value, java.lang.String simplePropertyName, java.lang.Object object)
          Sets value to the object's property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Miner

public Miner()
Creates a new instance of the Miner.

Method Detail

getValue

public java.lang.Object getValue(java.lang.String dottedPropertyName,
                                 java.lang.Object object)
Returns value from the property with the given dottedPropertyName of the object object. If dottedPropertyName contains '.' character, the method parses it to simple property names and obtains last value from this chain. If given object is null, returns null.

Parameters:
dottedPropertyName - - name of requested property, or dot-separated names of chained properties
object - - object (container of properties)
Returns:
value from the required property of the object
Throws:
java.lang.RuntimeException - if dottedPropertyName is null, or if cannot find getter(s) for given property(ies) or field(s) with that name(s)

getValueFromProperty

protected java.lang.Object getValueFromProperty(java.lang.String simplePropertyName,
                                                java.lang.Object object)
Returns value from the property with the given simplePropertyName of the object object. First it tries to get the value via getter. If not found, field access is used. Method is invoked from getValue(String, Object) method.

Parameters:
simplePropertyName - - name of the object property
object - - object (owner of the property)
Returns:
value of the object's property
Throws:
java.lang.RuntimeException - if cannot find getter for given property or field with that name

setValue

public void setValue(java.lang.Object value,
                     java.lang.String dottedPropertyName,
                     java.lang.Object object)
Sets value to the object's property. If dottedPropertyName contains '.' character the method parses it to simple property names and sets value to the last member of this chain. If given object or any object in the chain is null, method createObject(String, Object) is invoked to complete chain.

Parameters:
value - - value to set
dottedPropertyName - - name of the requested property, or dot-separated names of chained properties
object - - object (container of properties)
Throws:
java.lang.RuntimeException - if dottedPropertyName is null, or if cannot find setter(s) for given property(ies) or field(s) with that name(s)

setValueToProperty

protected void setValueToProperty(java.lang.Object value,
                                  java.lang.String simplePropertyName,
                                  java.lang.Object object)
Sets value to the object's property. First it tries to set the value via setter. If not found, field access is used. Method is invoked from setValue(Object, String, Object) method.

Parameters:
value - - value to set
simplePropertyName - - name of the requested property
object - - object (container of properties)
Throws:
java.lang.RuntimeException - if cannot find setter for given property or field with that name

createObject

protected java.lang.Object createObject(java.lang.String simplePropertyName,
                                        java.lang.Object owner)
Creates object for given property and object owner. This method is invoked from setValue(Object, String, Object) to refill chain of objects.

In this implementation method throws RuntimeException, so if you have null objects in the middle of the chain of your objects, you have to override it. Don't set / add created object to the owner, just create it and return.

Parameters:
simplePropertyName - - name of the property where created object belongs
owner -
Returns:
newly created object