org.chwf.filter
Class BeanFilter

java.lang.Object
  |
  +--org.chwf.filter.BeanFilter
Direct Known Subclasses:
GenericBeanFilter

public abstract class BeanFilter
extends java.lang.Object

The BeanFilter class is the abstract superclass of all bean filters. Bean filters serve as an abstraction layer facilitating string-to-data value conversions for Java Bean business objects. Unlike the classes in the java.beans packages, the bean filter classes are designed for thread-safety, so that they may be used in multi-thread application servers.

Author:
Paul Strack

Field Summary
static java.lang.String ATTRIBUTE_DATATYPE
          Standard name for the property's "datatype" attribute.
static java.lang.String ATTRIBUTE_LABEL
          Standard name for the property's "label" attribute.
static java.lang.String ATTRIBUTE_MAX
          Standard name for the property's "max" attribute.
static java.lang.String ATTRIBUTE_MAXLENGTH
          Standard name for the property's "maxlength" attribute.
static java.lang.String ATTRIBUTE_MIN
          Standard name for the property's "min" attribute.
static java.lang.String ATTRIBUTE_MINLENGTH
          Standard name for the property's "minlength" attribute.
static java.lang.String ATTRIBUTE_OPTIONS
          Standard name for the property's "options" attribute.
static java.lang.String ATTRIBUTE_READONLY
          Standard name for the property's "readonly" attribute.
static java.lang.String ATTRIBUTE_REQUIRED
          Standard name for the property's "required" attribute.
static java.lang.String ATTRIBUTE_SCALE
          Standard name for the property's "scale" attribute.
static java.util.List KNOWN_ATTRIBUTES
          List of known attribute names.
 
Constructor Summary
protected BeanFilter(java.lang.Class beanClass)
          Constructor to specify the class of filtered bean.
 
Method Summary
 java.lang.Object create()
          Create a new object of the bean class.
static BeanFilter findFilter(java.lang.Class beanClass)
          Find the filter for a given class.
static BeanFilter findFilter(java.lang.Object object)
          Find the filter for a given object.
static BeanFilter findFilter(java.lang.String className)
          Find the filter for the specified class name.
 java.lang.String get(java.lang.Object object, java.lang.String property)
          Get the specified property value of the target object, as a string.
 java.lang.Class getBeanClass()
          Get the bean class.
static java.lang.Object getProperty(java.lang.Object owner, java.lang.String property)
          Returns property value as an object using its getter method.
 java.lang.Object getPropertyAsObject(java.lang.Object object, java.lang.String property)
          Get the specified property value of the target object, as an object.
 PropertyFilter getPropertyFilter(java.lang.String property)
          Get a property filter for the specified property.
 PropertyFilter[] getPropertyFilters()
          Get all property filters.
protected  void putPropertyAttribute(java.lang.String property, java.lang.String attribute, java.lang.Object value)
          Put a property attribute value into a property filter.
protected  void putPropertyFilter(java.lang.String name, PropertyFilter filter)
          Put a property filter into this bean filter.
 void set(java.lang.Object object, java.lang.String property, java.lang.String value)
          Set the specified property of the target object, using a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_LABEL

public static final java.lang.String ATTRIBUTE_LABEL
Standard name for the property's "label" attribute.

ATTRIBUTE_REQUIRED

public static final java.lang.String ATTRIBUTE_REQUIRED
Standard name for the property's "required" attribute.

ATTRIBUTE_DATATYPE

public static final java.lang.String ATTRIBUTE_DATATYPE
Standard name for the property's "datatype" attribute.

ATTRIBUTE_READONLY

public static final java.lang.String ATTRIBUTE_READONLY
Standard name for the property's "readonly" attribute.

ATTRIBUTE_MIN

public static final java.lang.String ATTRIBUTE_MIN
Standard name for the property's "min" attribute.

ATTRIBUTE_MAX

public static final java.lang.String ATTRIBUTE_MAX
Standard name for the property's "max" attribute.

ATTRIBUTE_MINLENGTH

public static final java.lang.String ATTRIBUTE_MINLENGTH
Standard name for the property's "minlength" attribute.

ATTRIBUTE_MAXLENGTH

public static final java.lang.String ATTRIBUTE_MAXLENGTH
Standard name for the property's "maxlength" attribute.

ATTRIBUTE_SCALE

public static final java.lang.String ATTRIBUTE_SCALE
Standard name for the property's "scale" attribute.

ATTRIBUTE_OPTIONS

public static final java.lang.String ATTRIBUTE_OPTIONS
Standard name for the property's "options" attribute.

KNOWN_ATTRIBUTES

public static final java.util.List KNOWN_ATTRIBUTES
List of known attribute names. This list is useful for filtering out unknown attributes, so that they can be (a) ignored or (b) passed onto another layer without any processing.
Constructor Detail

BeanFilter

protected BeanFilter(java.lang.Class beanClass)
Constructor to specify the class of filtered bean. This constructor is called by subclasses: super(beanClass);

Parameters:
beanClass - The class of the filtered bean.
Method Detail

findFilter

public static BeanFilter findFilter(java.lang.Object object)
                             throws InitializationException
Find the filter for a given object.

Parameters:
object - The object being filtered.
Returns:
The filter.
Throws:
InitializationException - If the filter cannot be initialized.

findFilter

public static BeanFilter findFilter(java.lang.Class beanClass)
                             throws InitializationException
Find the filter for a given class.

Parameters:
beanClass - The class of the filtered bean.
Returns:
The filter.
Throws:
InitializationException - If the filter cannot be initialized.

findFilter

public static BeanFilter findFilter(java.lang.String className)
                             throws InitializationException
Find the filter for the specified class name. This method first searches for the filter class beanClass + "Filter". If it cannot create this object, it creates a GenericBeanFilter for the bean class using reflection.

Parameters:
className - This must be the fully qualified name of the class.
Returns:
The filter.
Throws:
InitializationException - If the filter cannot be initialized.

get

public java.lang.String get(java.lang.Object object,
                            java.lang.String property)
                     throws FilterException
Get the specified property value of the target object, as a string.

Parameters:
object - The target object.
property - The property being retrieved.
Returns:
The property value.
Throws:
FilterException - For read failure.

getPropertyAsObject

public java.lang.Object getPropertyAsObject(java.lang.Object object,
                                            java.lang.String property)
                                     throws FilterException
Get the specified property value of the target object, as an object.

Parameters:
object - The target object.
property - The property being retrieved.
Returns:
The property value.
Throws:
FilterException - For read failure.

set

public void set(java.lang.Object object,
                java.lang.String property,
                java.lang.String value)
         throws FilterException,
                ConversionException
Set the specified property of the target object, using a string.

Parameters:
object - The target object.
property - The property being updated.
value - The new property value.
Throws:
FilterException - For write failure.
ConversionException - If the value cannot be converted to the correct type.

create

public java.lang.Object create()
                        throws java.lang.UnsupportedOperationException,
                               OperationException
Create a new object of the bean class.

Returns:
A new object.
Throws:
java.lang.UnsupportedOperationException - If create is not supported for this bean.
OperationException - If the create operation itself throws an exception. The underlying exception is wrapped in this one.

getPropertyFilter

public PropertyFilter getPropertyFilter(java.lang.String property)
                                 throws PropertyNotFoundException
Get a property filter for the specified property.

Parameters:
property - The property.
Returns:
The property filter.
Throws:
PropertyNotFoundException - If the bean does not have the property.

getPropertyFilters

public PropertyFilter[] getPropertyFilters()
Get all property filters.

Returns:
An array of property filters.

getBeanClass

public java.lang.Class getBeanClass()
Get the bean class.

Returns:
The bean class.

putPropertyFilter

protected void putPropertyFilter(java.lang.String name,
                                 PropertyFilter filter)
Put a property filter into this bean filter. This overwrites any existing filter.

Parameters:
name - The property name.
filter - The property filter.

putPropertyAttribute

protected void putPropertyAttribute(java.lang.String property,
                                    java.lang.String attribute,
                                    java.lang.Object value)
                             throws PropertyNotFoundException
Put a property attribute value into a property filter.

Parameters:
property - The property name.
attribute - The attribute name.
value - The attribute value.
Throws:
PropertyNotFoundException - If the object does not have the property.

getProperty

public static java.lang.Object getProperty(java.lang.Object owner,
                                           java.lang.String property)
Returns property value as an object using its getter method.

Parameters:
owner - The owning object.
property - The bean property or null if it cannot be found.
Returns:
The property value.


Copyright © 2002-2004, Paul Strack. All Rights Reserved.