public class ProxyActionFactory extends Object implements ActionFactory<Action>, InvocationHandler
This class works ONLY if the ExtensionPoint.getActionClass()
is an interface, eg. Class.isInterface()
return true. If so,
we use Java reflection to generate a Proxy
that implements
the desired action class interface.
Parameters in the XML file will be passed on as return values for
method calls on the proxy, 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 returned as a result of calling
getIcon()
on the
proxy. Null is returned for parameters that have not been specified
in the XML file.
<enabled>1</enabled> will return
true
if
isEnabled()
is called on the proxy.
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 boolean |
disabled |
private boolean |
initialised |
private Map<String,String> |
parameters |
private Action |
proxy |
private Map<String,Object> |
valueCache |
Constructor and Description |
---|
ProxyActionFactory()
Creates a new proxy factory.
|
Modifier and Type | Method and Description |
---|---|
Action[] |
getActions(InvokationContext context)
This method may be called one or several times for each request.
|
private String |
getParameterName(String methodName)
Convert a method name to a parameter name.
|
private Object |
getParameterValue(String parameterName,
Class<?> returnType)
Get the value of a parameter.
|
private void |
initProxy(Class<? extends Action> actionClass)
Initialise the proxy class.
|
Object |
invoke(Object proxy,
Method method,
Object[] args) |
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 |
setDisabled(String disabled)
Sets the disabled/enabled status of this factory.
|
void |
setParameter(String name,
String value)
Set generic parameters.
|
private boolean disabled
private Action proxy
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 context)
ActionFactory
getActions
in interface ActionFactory<Action>
context
- The current invokation contextpublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
@PathSetter @VariableSetter public void setParameter(String name, String value)
name
- The name of the parametervalue
- The value of the parameterpublic void setDisabled(String disabled)
disabled
- A string that is parsed to a boolean
by Values.getBoolean(String)
private void initProxy(Class<? extends Action> actionClass)
actionClass
- The interface that the proxy must implementprivate String getParameterName(String methodName)
get
or is
will have that part
removed. The first character of the remaining name is converted to
lower case. All other method names are left as they are.methodName
- The name of the method