org.chwf.filter
Class GenericBeanFilter

java.lang.Object
  |
  +--org.chwf.filter.BeanFilter
        |
        +--org.chwf.filter.GenericBeanFilter

public class GenericBeanFilter
extends BeanFilter

Generic default filter created through introspection. Custom bean filters can subclass this class, instead of BeanFilter, to set most of the filter's functionality through reflection. The custom filter can then customize the filters for individual properties and methods by calling the appropriate putFilter method:

    package example;
    import java.text.*;
    import org.chwf.filter.*;
    
    public class AccountFilter extends GenericBeanFilter {
      public AccountFilter() {
        super(Account.class);
    
        // startDate property filter as an anonymous inner class:
        PropertyFilter sdFilter = 
            new PropertyFilter("startDate", java.util.Date.class) {
    
          public String get(Object object) {
            DateFormat df = SimpleDateFormat("mm/dd/yyyy");
            java.util.Date date = ((Account) object).getStartDate();
            if (date == null) {
              return null;
            } else {
              return df.format(date);
            }
          }
    
          public void set(Object object, String value) {
            DateFormat df = SimpleDateFormat("mm/dd/yyyy");
            try {
              ((Account) object).setStartDate(df.parse(value));
            } catch (java.text.ParseException ex) {
              throw new IllegalArgumentException(ex.getMessage());
            }
          }
        };
 
        putPropertyFilter("startDate", sdFilter);
    
        initializePropertyAttributes(); // Using configuration
      }
    }

Author:
Paul Strack

Fields inherited from class org.chwf.filter.BeanFilter
ATTRIBUTE_DATATYPE, ATTRIBUTE_LABEL, ATTRIBUTE_MAX, ATTRIBUTE_MAXLENGTH, ATTRIBUTE_MIN, ATTRIBUTE_MINLENGTH, ATTRIBUTE_OPTIONS, ATTRIBUTE_READONLY, ATTRIBUTE_REQUIRED, ATTRIBUTE_SCALE, KNOWN_ATTRIBUTES
 
Constructor Summary
GenericBeanFilter(java.lang.Class beanClass)
          This constructor initializes the property and method filters for the bean.
 
Method Summary
protected  void initializePropertyAttributes()
          This method initializes property attributes, using the JavaBean config file described in the package documentation.
 
Methods inherited from class org.chwf.filter.BeanFilter
create, findFilter, findFilter, findFilter, get, getBeanClass, getProperty, getPropertyAsObject, getPropertyFilter, getPropertyFilters, putPropertyAttribute, putPropertyFilter, set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericBeanFilter

public GenericBeanFilter(java.lang.Class beanClass)
                  throws InitializationException
This constructor initializes the property and method filters for the bean. It does not initialize property attributes.

Parameters:
beanClass - The class being filtered.
Throws:
InitializationException - If initialization fails for any reason.
Method Detail

initializePropertyAttributes

protected void initializePropertyAttributes()
                                     throws InitializationException
This method initializes property attributes, using the JavaBean config file described in the package documentation.

Throws:
InitializationException - If introspection fails.


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