public class BeanActionFactory extends Object implements ActionFactory<Action>
Parameters in the XML file will be set on the bean if there is
a setter method with the same name as the parameter tag,
following the usual syntax rules. Eg. the parameter value
<icon>/images/icon.png</icon>
will
be passed to the setIcon(String)
method on the
bean. If there is no such method the factory will check if
there is a getIcon()
or isIcon()
method with a return type other than String
. If so,
the factory will try a second time to find a setIcon()
method with the same parameter type. Methods corresponding to
parameters that have not been set in the XML file are never
called.
The factory can convert the string values to other data types for the
following classes: int, long, float, double and boolean. It can handle
both primitive and wrapper classes. Example:
<enabled>1</enabled>
will return true
if
isEnabled()
is called on the bean.
Parameters supported by this factory
This factory supports all parameters. Some parameters may trigger special
actions:
true
the prepareContext(InvokationContext)
method returns false
Modifier and Type | Field and Description |
---|---|
private Action[] |
actions |
private Action |
bean |
private String |
beanClassName |
private boolean |
disabled |
private boolean |
initialised |
private Map<String,String> |
parameters |
Constructor and Description |
---|
BeanActionFactory()
Creates a new proxy factory.
|
Modifier and Type | Method and Description |
---|---|
private Object |
convertValue(String sValue,
Class<?> type)
Convert a string value to another type.
|
private Action |
createBean(Class<? extends Action> actionClass)
Create the bean instance.
|
private Method |
findSetterMethod(String parameterName,
Class<?> beanClass)
Find a setter method for the specified parameter.
|
Action[] |
getActions(InvokationContext<? super Action> context)
This method may be called one or several times for each request.
|
private Method |
getMethod(Class<?> beanClass,
String name,
Class<?> param)
Get a method with a specific name with optionally, takes
a single parameter of given type.
|
private String |
getMethodName(String prefix,
String parameterName)
Convert the parameter name to a method name.
|
private void |
initBean(Class<? extends Action> actionClass)
Create the bean object.
|
boolean |
prepareContext(InvokationContext<? super Action> context)
This method is called once for each request/use of an
extension and have two purposes:
The factory should decide if the extension should be enabled or
not.
|
void |
setBeanClass(String beanClass)
Set the name of the class to use as a bean.
|
void |
setDisabled(String disabled)
Sets the disabled/enabled status of this factory.
|
void |
setParameter(String name,
String value)
Set generic parameters.
|
private String beanClassName
private boolean disabled
private Action bean
private Action[] actions
private volatile boolean initialised
public boolean prepareContext(InvokationContext<? super Action> context)
ActionFactory
JspContext
.
prepareContext
in interface ActionFactory<Action>
context
- The current invokation contextpublic Action[] getActions(InvokationContext<? super Action> context)
ActionFactory
getActions
in interface ActionFactory<Action>
context
- The current invokation context@PathSetter @VariableSetter public void setParameter(String name, String value)
name
- The name of the parametervalue
- The value of the parameterpublic void setBeanClass(String beanClass)
public void setDisabled(String disabled)
disabled
- A string that is parsed to a boolean
by Values.getBoolean(String)
private void initBean(Class<? extends Action> actionClass)
actionClass
- The interface that the proxy must implementprivate Action createBean(Class<? extends Action> actionClass)
private Method findSetterMethod(String parameterName, Class<?> beanClass)
private String getMethodName(String prefix, String parameterName)
parameterName
- The parameter nameprivate Method getMethod(Class<?> beanClass, String name, Class<?> param)
beanClass
- The class to look for the method inname
- The name of the methodparam
- The type of the parameter, or null to look for
a method with not parameters