org.joda.beans
Interface MetaProperty<P>

Type Parameters:
P - the type of the property content
All Superinterfaces:
BeanQuery<P>
All Known Implementing Classes:
BasicMetaProperty, DirectMetaProperty, ReflectiveMetaProperty, StandaloneMetaProperty

public interface MetaProperty<P>
extends BeanQuery<P>

A meta-property, defining those aspects of a property which are not specific to a particular bean, such as the property type and name.


Method Summary
<A extends Annotation>
A
annotation(Class<A> annotation)
          Gets an annotation from the property.
 List<Annotation> annotations()
          Gets the annotations of the property.
 Property<P> createProperty(Bean bean)
          Creates a property that binds this meta-property to a specific bean.
 Class<?> declaringType()
          Get the type that declares the property, represented as a Class.
 boolean equals(Object obj)
          Checks if this meta-property equals another.
 P get(Bean bean)
          Gets the value of the property for the specified bean.
 String getString(Bean bean)
          Gets the value of the property for the specified bean converted to a string.
 String getString(Bean bean, org.joda.convert.StringConvert stringConvert)
          Gets the value of the property for the specified bean converted to a string.
 int hashCode()
          Returns a suitable hash code.
 MetaBean metaBean()
          Gets the meta-bean which owns this meta-property.
 String name()
          Gets the property name.
 Type propertyGenericType()
          Gets the generic types of the property.
 Class<P> propertyType()
          Get the type of the property represented as a Class.
 P put(Bean bean, Object value)
          Sets the value of the property on the associated bean and returns the previous value.
 void set(Bean bean, Object value)
          Sets the value of the property on the specified bean.
 void setString(Bean bean, String value)
          Sets the value of the property on the specified bean from a string by conversion.
 void setString(Bean bean, String value, org.joda.convert.StringConvert stringConvert)
          Sets the value of the property on the specified bean from a string by conversion.
 PropertyStyle style()
          Gets the style of the property, such as read-only, read-write or write-only.
 

Method Detail

createProperty

Property<P> createProperty(Bean bean)
Creates a property that binds this meta-property to a specific bean.

This method returns a Property instance that connects this meta-property to the specified bean. The result can be queried and passed around without further reference to the bean.

Parameters:
bean - the bean to create the property for, not null
Returns:
the property, not null

metaBean

MetaBean metaBean()
Gets the meta-bean which owns this meta-property.

Each meta-property is fully owned by a single bean.

Returns:
the meta-bean, not null

name

String name()
Gets the property name.

The JavaBean style methods getFoo() and setFoo() will lead to a property name of 'foo' and so on.

Returns:
the name of the property, not empty

declaringType

Class<?> declaringType()
Get the type that declares the property, represented as a Class.

This is the type of the bean where the property is declared.

Returns:
the type declaring the property, not null

propertyType

Class<P> propertyType()
Get the type of the property represented as a Class.

This is the type of the property. For example, the surname of a person would typically be a String.

Returns:
the type of the property, not null

propertyGenericType

Type propertyGenericType()
Gets the generic types of the property.

This provides access to the generic type declared in the source code.

Returns:
the full generic type of the property, unmodifiable, not null

style

PropertyStyle style()
Gets the style of the property, such as read-only, read-write or write-only.

Rather than testing against specific values, it is strongly recommended to call the helper methods on the returned style.

Returns:
the property style, not null

annotations

List<Annotation> annotations()
Gets the annotations of the property.

The annotations are queried from the property. This is typically accomplished by querying the annotations of the underlying instance variable.

Returns:
the annotations, unmodifiable, not null

annotation

<A extends Annotation> A annotation(Class<A> annotation)
Gets an annotation from the property.

The annotations are queried from the property. This is typically accomplished by querying the annotations of the underlying instance variable.

Type Parameters:
A - the annotation type
Parameters:
annotation - the annotation class to find, not null
Returns:
the annotation, not null
Throws:
NoSuchElementException - if the annotation is not specified

get

P get(Bean bean)
Gets the value of the property for the specified bean.

For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

Specified by:
get in interface BeanQuery<P>
Parameters:
bean - the bean to query, not null
Returns:
the value of the property on the specified bean, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
UnsupportedOperationException - if the property is write-only

set

void set(Bean bean,
         Object value)
Sets the value of the property on the specified bean.

The value must be of the correct type for the property. For a standard JavaBean, this is equivalent to calling setFoo() on the bean. Alternate implementations may perform any logic to change the value.

Parameters:
bean - the bean to update, not null
value - the value to set into the property on the specified bean, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
ClassCastException - if the value is of an invalid type for the property
UnsupportedOperationException - if the property is read-only
RuntimeException - if the value is rejected by the property (use appropriate subclasses)

put

P put(Bean bean,
      Object value)
Sets the value of the property on the associated bean and returns the previous value.

The value must be of the correct type for the property. This is a combination of the get and set methods that matches the definition of put in a Map.

Parameters:
bean - the bean to update, not null
value - the value to set into the property on the specified bean, may be null
Returns:
the old value of the property, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
ClassCastException - if the value is of an invalid type for the property
UnsupportedOperationException - if the property is read-only
RuntimeException - if the value is rejected by the property (use appropriate subclasses)

getString

String getString(Bean bean)
Gets the value of the property for the specified bean converted to a string.

This converts the result of get(Bean) to a standard format string. Conversion uses Joda-Convert. Not all object types can be converted to a string, see Joda-Convert.

For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

Parameters:
bean - the bean to query, not null
Returns:
the value of the property on the specified bean, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
UnsupportedOperationException - if the property is write-only
RuntimeException - if the value cannot be converted to a string (use appropriate subclasses)

getString

String getString(Bean bean,
                 org.joda.convert.StringConvert stringConvert)
Gets the value of the property for the specified bean converted to a string.

This converts the result of get(Bean) to a standard format string using the supplied converter. Not all object types can be converted to a string, see Joda-Convert.

For a standard JavaBean, this is equivalent to calling getFoo() on the bean. Alternate implementations may perform any logic to obtain the value.

Parameters:
bean - the bean to query, not null
stringConvert - the converter to use, not null
Returns:
the value of the property on the specified bean, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
UnsupportedOperationException - if the property is write-only
RuntimeException - if the value cannot be converted to a string (use appropriate subclasses)

setString

void setString(Bean bean,
               String value)
Sets the value of the property on the specified bean from a string by conversion.

This converts the string to the correct type for the property and then sets it using set(Bean, Object). Conversion uses Joda-Convert.

Parameters:
bean - the bean to update, not null
value - the value to set into the property on the specified bean, may be null
Throws:
ClassCastException - if the bean is of an incorrect type
ClassCastException - if the value is of an invalid type for the property
UnsupportedOperationException - if the property is read-only
RuntimeException - if the value is rejected by the property (use appropriate subclasses)

setString

void setString(Bean bean,
               String value,
               org.joda.convert.StringConvert stringConvert)
Sets the value of the property on the specified bean from a string by conversion.

This converts the string to the correct type for the property using the supplied converter and then sets it using set(Bean, Object).

Parameters:
bean - the bean to update, not null
value - the value to set into the property on the specified bean, may be null
stringConvert - the converter, not null
Throws:
ClassCastException - if the bean is of an incorrect type
ClassCastException - if the value is of an invalid type for the property
UnsupportedOperationException - if the property is read-only
RuntimeException - if the value is rejected by the property (use appropriate subclasses)

equals

boolean equals(Object obj)
Checks if this meta-property equals another.

This compares the property name and declaring type. It does not compare the property or bean types.

Overrides:
equals in class Object
Parameters:
obj - the other meta-property, null returns false
Returns:
true if equal

hashCode

int hashCode()
Returns a suitable hash code.

Overrides:
hashCode in class Object
Returns:
the hash code


Copyright © 2007–2015 Joda.org. All rights reserved.