public class BeanActionFactory extends java.lang.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
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:
Parameters supported by this factory<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.
<enabled>1</enabled> will return
true
if
isEnabled()
is called on the bean.
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 java.lang.String |
beanClassName |
private boolean |
disabled |
private boolean |
initialised |
private java.util.Map<java.lang.String,java.lang.String> |
parameters |
Constructor and Description |
---|
BeanActionFactory()
Creates a new proxy factory.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.Object |
convertValue(java.lang.String sValue,
java.lang.Class<?> type)
Convert a string value to another type.
|
private Action |
createBean(java.lang.Class<? extends Action> actionClass)
Create the bean instance.
|
private java.lang.reflect.Method |
findSetterMethod(java.lang.String parameterName,
java.lang.Class<?> beanClass)
Find a setter method for the specified parameter.
|
Action[] |
getActions(InvokationContext context)
This method may be called one or several times for each request.
|
private java.lang.reflect.Method |
getMethod(java.lang.Class<?> beanClass,
java.lang.String name,
java.lang.Class<?> param)
Get a method with a specific name with optionally, takes
a single parameter of given type.
|
private java.lang.String |
getMethodName(java.lang.String prefix,
java.lang.String parameterName)
Convert the parameter name to a method name.
|
private void |
initBean(java.lang.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(java.lang.String beanClass)
Set the name of the class to use as a bean.
|
void |
setDisabled(java.lang.String disabled)
Sets the disabled/enabled status of this factory.
|
void |
setParameter(java.lang.String name,
java.lang.String value)
Set generic parameters.
|
private java.lang.String beanClassName
private boolean disabled
private Action bean
private Action[] actions
private java.util.Map<java.lang.String,java.lang.String> parameters
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 context)
ActionFactory
getActions
in interface ActionFactory<Action>
context
- The current invokation context@PathSetter @VariableSetter public void setParameter(java.lang.String name, java.lang.String value)
name
- The name of the parametervalue
- The value of the parameterpublic void setBeanClass(java.lang.String beanClass)
beanClass
- public void setDisabled(java.lang.String disabled)
disabled
- A string that is parsed to a boolean
by Values.getBoolean(String)
private void initBean(java.lang.Class<? extends Action> actionClass)
actionClass
- The interface that the proxy must implementprivate Action createBean(java.lang.Class<? extends Action> actionClass)
private java.lang.reflect.Method findSetterMethod(java.lang.String parameterName, java.lang.Class<?> beanClass)
private java.lang.String getMethodName(java.lang.String prefix, java.lang.String parameterName)
parameterName
- The parameter nameprivate java.lang.reflect.Method getMethod(java.lang.Class<?> beanClass, java.lang.String name, java.lang.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 parametersprivate java.lang.Object convertValue(java.lang.String sValue, java.lang.Class<?> type)
sValue
- The value to converttype
- The class to convert the string value to