Class MethodProperty

Proxy class for creating Properties from pairs of getter and setter methods of a Bean property. An instance of this class can be thought as having been attached to a field of an object. Accessing the object through the Property interface directly manipulates the underlying field.

It's assumed that the return value returned by the getter method is assignable to the type of the property, and the setter method parameter is assignable to that value.

A valid getter method must always be available, but instance of this class can be constructed with a null setter method in which case the resulting MethodProperty is read-only.

Synopsis

Since

3.0

Inheritance Path.  java.lang.Object-> com.itmill.toolkit.data.util.MethodProperty

MethodProperty(Class, Object, Method, Method)

Parameters

type

type of the property

instance

object that includes the property

getMethod

the getter method

setMethod

the setter method

Creates a new instance of MethodProperty with the getter and setter methods. The getter method of a MethodProperty instantiated with this constructor will be called with no arguments, and the setter method with only the new value as the sole argument.

If the setter method is null , the resulting MethodProperty will be read-only, otherwise it will be read-write.

MethodProperty(Class, Object, Method, Method, Object[], Object[], int)

Parameters

type

type of the property

instance

object that includes the property

getMethod

the getter method

setMethod

the setter method

getArgs

fixed argument list to be passed to the getter method

setArgs

fixed argument list to be passed to the setter method

setArgumentIndex

the index of the argument in setArgs to be replaced with newValue when setValue(java.lang.Object) is called

Creates a new instance of MethodProperty from the getter and setter methods, and argument lists. This constructor behaves exctly like MethodProperty(java.lang.Class, java.lang.Object, java.lang.String, java.lang.String, java.lang.Object[], java.lang.Object[], int) except that instead of names of the getter and setter methods this constructor is given the actual methods themselves.

MethodProperty(Class, Object, String, String)

Parameters

type

type of the property

instance

object that includes the property

getMethodName

name of the getter method

setMethodName

name of the setter method

Creates a new instance of MethodProperty from named getter and setter methods. The getter method of a MethodProperty instantiated with this constructor will be called with no arguments, and the setter method with only the new value as the sole argument.

If the setter method is null , the resulting MethodProperty will be read-only, otherwise it will be read-write.

MethodProperty(Class, Object, String, String, Object[], Object[], int)

Parameters

type

type of the property

instance

object that includes the property

getMethodName

the name of the getter method

setMethodName

the name of the setter method

getArgs

fixed argument list to be passed to the getter method

setArgs

fixed argument list to be passed to the setter method

setArgumentIndex

the index of the argument in setArgs to be replaced with newValue when setValue(java.lang.Object) is called

Creates a new instance of MethodProperty from named getter and setter methods and argument lists. The getter method of a MethodProperty instantiated with this constructor will be called with getArgs as arguments. setArgs will be used as the arguments for the setter method, though the argument indexed by setArgumentIndex will be replaced with the argument passed to the setValue(java.lang.Object) method.

For example, if the setArgs contains A , B and C , and setArgumentIndex = 1 , the call methodProperty.setValue(X) would result in the setter method to be called with the parameter set of {A, X, C}

MethodProperty(Object, String)

Parameters

instance

object that includes the property

beanPropertyName

name of the property to bind to

Creates a new instance of MethodProperty from a named bean property. This constructor takes an object and the name of a bean property and initializes itself with the accessor methods for the property. The getter method of a MethodProperty instantiated with this constructor will be called with no arguments, and the setter method with only the new value as the sole argument.

If the setter method is unavailable, the resulting MethodProperty will be read-only, otherwise it will be read-write.

Method names are constucted from the bean property by adding get/is/are/set prefix and capitalising the first character in the name of the given bean property

addListener(Property.ReadOnlyStatusChangeListener)

Parameters

listener

the new Listener to be registered

Registers a new read-only status change listener for this Property.

getType()

Parameters

return

type of the Property

Returns the type of the Property. The methods getValue and setValue must be compatible with this type: one must be able to safely cast the value returned from getValue to the given type and pass any variable assignable to this type as an argument to setValue .

getValue()

Parameters

return

the value of the Property

Gets the value stored in the Property. The value is resolved by calling the specified getter method with the argument specified at instantiation.

isReadOnly()

Parameters

return

true if the object is in read-only mode, false if it's not

Tests if the object is in read-only mode. In read-only mode calls to setValue will throw ReadOnlyException s and will not modify the value of the Property.

removeListener(Property.ReadOnlyStatusChangeListener)

Parameters

listener

listener to be removed

Remove a previously registered read-only status change listener.

setArguments(Object[], Object[], int)

Parameters

getArgs

fixed argument list to be passed to the getter method

setArgs

fixed argument list to be passed to the setter method

setArgumentIndex

the index of the argument in setArgs to be replaced with newValue when setValue(java.lang.Object) is called

Sets the setter method and getter method argument lists.

setReadOnly(boolean)

Parameters

newStatus

new read-only status of the Property

Sets the Property's read-only mode to the specified status.

setValue(Object)

Parameters

newValue

New value of the property.

Exceptions

if the object is in read-only mode

if newValue can't be converted into the Property's native type directly or through String

Set the value of the property. This method supports setting from String s if either String is directly assignable to property type, or the type class contains a string constructor.

toString()

Parameters

return

String representation of the value stored in the Property

Returns the value of the MethodProperty in human readable textual format. The return value should be assignable to the setValue method if the Property is not in read-only mode.