org.mentawai.filter
Class PushInjectionFilter

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

public class PushInjectionFilter
extends Object
implements Filter

A filter that tries to inject the input values in the action through setters. (Ex. setUsername(), setPassword(), etc.) It can also inject the input value directly in the attribute, even if it is a private field. Use this filter if you don't want to deal with the action input object and instaed you want to inject its values in the action. This filter tries to inject all the input values in the action. If enabled (default), it will also try to convert the values automatically by looking into the action field by reflection.

Author:
Sergio Oliveira

Constructor Summary
PushInjectionFilter()
          Creates an PushInjectionFilter that can be used by any action class.
PushInjectionFilter(boolean tryField)
          Creates an PushInjectionFilter that can be used by any action class.
PushInjectionFilter(boolean tryField, boolean convert)
          Creates an PushInjectionFilter that can be used by any action class.
 
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 target, String name, Object value, Locale loc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushInjectionFilter

public PushInjectionFilter()
Creates an PushInjectionFilter that can be used by any action class. You may use this filter per action or as a global filter.


PushInjectionFilter

public PushInjectionFilter(boolean tryField)
Creates an PushInjectionFilter that can be used by any action class. You may use this filter per action or as a global filter. 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:
tryField - A flag indicating whether this filter should try to access private attributes.

PushInjectionFilter

public PushInjectionFilter(boolean tryField,
                           boolean convert)
Creates an PushInjectionFilter that can be used by any action class. You may use this filter per action or as a global filter. 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 convert flag is true (default), it will try to automatically convert.

Parameters:
tryField - A flag indicating whether this filter should try to access private attributes.
Method Detail

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 target,
                           String name,
                           Object value,
                           Locale loc)

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

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.