net.sf.morph.reflect
Interface BeanReflector

All Superinterfaces:
net.sf.composite.Component, Reflector, SizableReflector
All Known Implementing Classes:
ArrayReflector, BaseBeanReflector, BaseServletReflector, ContextReflector, DynaBeanReflector, HttpSessionAttributeReflector, ListReflector, MapReflector, ObjectReflector, PageContextAttributeReflector, ResultSetReflector, ServletContextAttributeReflector, ServletContextInitParameterReflector, ServletRequestAttributeReflector, ServletRequestParameterReflector, ServletRequestReflector, SimpleDelegatingReflector, SortedSetReflector, StubbornDelegatingReflector, VelocityContextReflector, VelocityContextReflector

public interface BeanReflector
extends Reflector, SizableReflector

Exposes information available in 'bean-like' structures. Examples of 'bean-like' structures include a java.lang.Object, a java.util.Map, or any other class that logically has a set of properties that can be manipulated by name.

Since:
Nov 6, 2004
Author:
Matt Sgarlata

Field Summary
static java.lang.String IMPLICIT_PROPERTY_CLASS
          implicit "class" property
static java.lang.String IMPLICIT_PROPERTY_PROPERTY_NAMES
          implicit "propertyNames" property
static java.lang.String IMPLICIT_PROPERTY_THIS
          implicit "this" property
 
Fields inherited from interface net.sf.morph.reflect.SizableReflector
IMPLICIT_PROPERTY_SIZE
 
Method Summary
 java.lang.Object get(java.lang.Object bean, java.lang.String propertyName)
          Retrieves the value of the given property.
 java.lang.String[] getPropertyNames(java.lang.Object bean)
          Gets the names of the properties which are currently defined for the given bean.
 java.lang.Class getType(java.lang.Object bean, java.lang.String propertyName)
          Specifies the least restrictive type that may be assigned to the given property.
 boolean isReadable(java.lang.Object bean, java.lang.String propertyName)
          Specifies whether the given property is readable.
 boolean isWriteable(java.lang.Object bean, java.lang.String propertyName)
          Specifies whether the given property is writeable.
 void set(java.lang.Object bean, java.lang.String propertyName, java.lang.Object propertyValue)
          Sets the value of the given property.
 
Methods inherited from interface net.sf.morph.reflect.SizableReflector
getSize
 

Field Detail

IMPLICIT_PROPERTY_CLASS

static final java.lang.String IMPLICIT_PROPERTY_CLASS
implicit "class" property

See Also:
Constant Field Values

IMPLICIT_PROPERTY_PROPERTY_NAMES

static final java.lang.String IMPLICIT_PROPERTY_PROPERTY_NAMES
implicit "propertyNames" property

See Also:
Constant Field Values

IMPLICIT_PROPERTY_THIS

static final java.lang.String IMPLICIT_PROPERTY_THIS
implicit "this" property

See Also:
Constant Field Values
Method Detail

getPropertyNames

java.lang.String[] getPropertyNames(java.lang.Object bean)
                                    throws ReflectionException
Gets the names of the properties which are currently defined for the given bean. Note that some beans (e.g. - Maps) allow the creation of new properties, which means isWriteable may return true for property names that are not included in the return value of this method.

Parameters:
bean - the bean for which we would like a list of properties
Returns:
the names of the properties which are currently defined for the given bean. Note that some beans (e.g. - Maps) allow the creation of new properties, which means isWriteable may return true for property names that are not included in the return value of this method.
Throws:
ReflectionException - if bean is null

getType

java.lang.Class getType(java.lang.Object bean,
                        java.lang.String propertyName)
                        throws ReflectionException
Specifies the least restrictive type that may be assigned to the given property. In the case of a weakly typed bean, the correct value to return is simply Object.class, which indicates that any type can be assigned to the given property.

Parameters:
bean - the bean
propertyName - the name of the property
Returns:
the least restrictive type that may be assigned to the given property. In the case of a weakly typed bean, the correct value to return is simply Object.class, which indicates that any type can be assigned to the given property
Throws:
ReflectionException - if bean or propertyName are null or
this is a strongly typed bean reflector and the given property does not exist or
if the type could not be retrieved for some reason

isReadable

boolean isReadable(java.lang.Object bean,
                   java.lang.String propertyName)
                   throws ReflectionException
Specifies whether the given property is readable. A reflector can always determine if a property is readable by attempting to read the property value, so this method can be counted on to truly indicate whether or not the given property is readable.

Parameters:
bean - the bean
propertyName - the name of the property
Returns:
true if the property is readable, or
false, otherwise
Throws:
ReflectionException - if bean or propertyName are null or
if the readability of the property cannot be determined

isWriteable

boolean isWriteable(java.lang.Object bean,
                    java.lang.String propertyName)
                    throws ReflectionException
Specifies whether the given property is writeable. If the reflector cannot determine whether the given property is writeable, it may simply return true. This method only guarantees that if isWriteable returns false, the method is not writeable. The method may or may not be writeable if this method returns true.

Parameters:
bean - the bean
propertyName - the name of the property
Returns:
false if the property is not writeable or
true if the property is writeable or if this reflector cannot determine for sure whether or not the property is writeable
Throws:
ReflectionException - if bean or propertyName are null or
if the writeability of the property cannot be determined

get

java.lang.Object get(java.lang.Object bean,
                     java.lang.String propertyName)
                     throws ReflectionException
Retrieves the value of the given property.

Parameters:
bean - the bean
propertyName - the name of the property
Returns:
the property's value
Throws:
ReflectionException - if bean or propertyName is null or
if the value of the property cannot be determined or

set

void set(java.lang.Object bean,
         java.lang.String propertyName,
         java.lang.Object propertyValue)
         throws ReflectionException
Sets the value of the given property.

Parameters:
bean - the bean
propertyName - the name of the property
propertyValue - the value to assign to the given property
Throws:
ReflectionException - if bean or propertyName are null or
if the property cannot be set for some other reason (e.g. because propertyValue is of the wrong type)


Copyright © 2004-2008.