public class ProxyActionFactory extends java.lang.Object implements ActionFactory<Action>, java.lang.reflect.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 <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.
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 proxy.
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 boolean |
disabled |
private boolean |
initialised |
private java.util.Map<java.lang.String,java.lang.String> |
parameters |
private Action |
proxy |
private java.util.Map<java.lang.String,java.lang.Object> |
valueCache |
Constructor and Description |
---|
ProxyActionFactory()
Creates a new proxy factory.
|
Modifier and Type | Method and Description |
---|---|
Action[] |
getActions(InvokationContext<? super Action> context)
This method may be called one or several times for each request.
|
private java.lang.String |
getParameterName(java.lang.String methodName)
Convert a method name to a parameter name.
|
private java.lang.Object |
getParameterValue(java.lang.String parameterName,
java.lang.Class<?> returnType)
Get the value of a parameter.
|
private void |
initProxy(java.lang.Class<? extends Action> actionClass)
Initialise the proxy class.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.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(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 boolean disabled
private Action proxy
private Action[] actions
private java.util.Map<java.lang.String,java.lang.String> parameters
private java.util.Map<java.lang.String,java.lang.Object> valueCache
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 contextpublic java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
@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 setDisabled(java.lang.String disabled)
disabled
- A string that is parsed to a boolean
by Values.getBoolean(String)
private void initProxy(java.lang.Class<? extends Action> actionClass)
actionClass
- The interface that the proxy must implementprivate java.lang.String getParameterName(java.lang.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 methodprivate java.lang.Object getParameterValue(java.lang.String parameterName, java.lang.Class<?> returnType)
parameterName
- The name of the parameter