org.mentawai.filter
Class PushVOFilter

java.lang.Object
  extended by org.mentawai.filter.PushVOFilter
All Implemented Interfaces:
Filter

public class PushVOFilter
extends Object
implements Filter

A filter that tries to populate a bean with the action input values.
Use this filter if you want to provide your action with a ready-to-use bean instead of a bunch of action input values.
This filter tries to inject all the action input values in a Java object through setters.
It can also inject directly in the bean's attributes, even if the field is private.
And it can also use prefix to separate attributes from multiple objects.
If enabled, it will try to automatically convert the fields beforing injecting based on the field type, if it can find one. Right now it only tries to convert booleans, ints, doubles and short dates, but you can extend this if you need to.

Author:
Sergio Oliveira

Constructor Summary
PushVOFilter(Class<? extends Object> klass)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
PushVOFilter(Class klass, boolean tryField)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
PushVOFilter(Class klass, String key)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
PushVOFilter(Class klass, String key, boolean tryField)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
PushVOFilter(Class klass, String key, boolean tryField, boolean convert, String prefix)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
PushVOFilter(Class klass, String key, boolean tryField, String prefix)
          Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.
 
Method Summary
 void destroy()
          Gives a chance to the filter to deallocalte any resources before it is destroyed.
 String filter(InvocationChain chain)
          Executes the filter.
protected  Object getConvertedValue(String className, String value, Locale loc)
          You can override this method to code more automatic conversions.
protected  boolean setValue(Object bean, String name, Object value, Locale loc)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PushVOFilter

public PushVOFilter(Class<? extends Object> klass)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values.

Parameters:
klass - The class to use to create the object.

PushVOFilter

public PushVOFilter(Class klass,
                    boolean tryField)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values. If tryField is true and it cannot find a setter for the input value, it will try to directly access the attribute, even if it is a private field.

Parameters:
klass - The class to use to create the object.
tryField - A flag indicating whether this filter should try to access private attributes.

PushVOFilter

public PushVOFilter(Class klass,
                    String key)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values. The object will be placed in the action input with the given key.

Parameters:
klass - The class to use to create the object.
key - The key name used to place the object in the action input.

PushVOFilter

public PushVOFilter(Class klass,
                    String key,
                    boolean tryField)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values. The object will be placed in the action input with the given key. If tryField is true and it cannot find a setter for the input value, it will try to directly access the attribute, even if it is a private field.

Parameters:
klass - The class to use to create the object.
key - The key name used to place the object in the action input.
tryField - A flag indicating whether this filter should try to access private attributes.

PushVOFilter

public PushVOFilter(Class klass,
                    String key,
                    boolean tryField,
                    String prefix)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values. The object will be placed in the action input with the given key. If tryField is true and it cannot find a setter for the input value, it will try to directly access the attribute, even if it is a private field. If prefix is not null, it will look for prefix.attribute and remove the prefix before injecting.

Parameters:
klass - The class to use to create the object.
key - The key name used to place the object in the action input.
tryField - A flag indicating whether this filter should try to access private attributes.
prefix - The prefix that will come on every attribute. (Ex. user.name)

PushVOFilter

public PushVOFilter(Class klass,
                    String key,
                    boolean tryField,
                    boolean convert,
                    String prefix)
Creates a PushVOFilter that will try to create an object with the given class and populate this object with the action input values. The object will be placed in the action input with the given key. If tryField is true and it cannot find a setter for the input value, it will try to directly access the attribute, even if it is a private field. If prefix is not null, it will look for prefix.attribute and remove the prefix before injecting. If convert is true, it will try to automatically convert to the object field class.

Parameters:
klass - The class to use to create the object.
key - The key name used to place the object in the action input.
tryField - A flag indicating whether this filter should try to access private attributes.
convert - A flag to indicate whether we should try to convert or not.
prefix - The prefix that will come on every attribute. (Ex. user.name)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

filter

public String filter(InvocationChain chain)
              throws Exception
Description copied from interface: Filter
Executes the filter.

Specified by:
filter in interface Filter
Parameters:
chain - The InvocationChain for the action this filter is being applied to.
Returns:
The result of the filter or the action the filter is being applied to.
Throws:
Exception

getConvertedValue

protected Object getConvertedValue(String className,
                                   String value,
                                   Locale loc)
You can override this method to code more automatic conversions. Right now it only converts int, double, booleans and short dates.

Parameters:
className - The type to convert to
value - The value to convert
loc - The locale to use for conversion (useful for date)
Returns:
The converted value

setValue

protected boolean setValue(Object bean,
                           String name,
                           Object value,
                           Locale loc)

destroy

public void destroy()
Description copied from interface: Filter
Gives a chance to the filter to deallocalte any resources before it is destroyed. This is called when the web application is stopped, in other words, this has nothing to do with garbage collection.

Specified by:
destroy in interface Filter


Copyright © 2013. All Rights Reserved.