2.17.2: 2011-06-17

net.sf.basedb.util.extensions.debug
Class ProxyActionFactory

java.lang.Object
  extended by net.sf.basedb.util.extensions.debug.ProxyActionFactory
All Implemented Interfaces:
InvocationHandler, ActionFactory<Action>

public class ProxyActionFactory
extends Object
implements ActionFactory<Action>, InvocationHandler

Generic action factory class that can generate instances of actions if the action class is an interface. Use this factory for development and debugging only. The performance and memory requirements of this implementation is unsure for a production environment.

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.gif</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:

Version:
2.7
Author:
nicklas
Last modified
$Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Field Summary
private  Action[] actions
           
private  boolean disabled
           
private  boolean initialised
           
private  Map<String,String> parameters
           
private  Action proxy
           
private  Map<String,Object> valueCache
           
 
Constructor Summary
ProxyActionFactory()
          Creates a new proxy factory.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

disabled

private boolean disabled

proxy

private Action proxy

actions

private Action[] actions

parameters

private Map<String,String> parameters

valueCache

private Map<String,Object> valueCache

initialised

private volatile boolean initialised
Constructor Detail

ProxyActionFactory

public ProxyActionFactory()
Creates a new proxy factory.

Method Detail

prepareContext

public boolean prepareContext(InvokationContext<? super Action> context)
Description copied from interface: ActionFactory
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. For example, the factory may check the permissions of the logged in user and determine that they are inadequate. The boolean return value determines if the extension is enabled or disabled.
  • Initialise the context with resources that the actions may need. With the BASE web-client this means that it is possible to add scripts or stylesheets that is needed by the extension. See JspContext.

Specified by:
prepareContext in interface ActionFactory<Action>
Parameters:
context - The current invokation context
Returns:
TRUE if the extension should be enabled, FALSE if the extension should be disabled

getActions

public Action[] getActions(InvokationContext context)
Description copied from interface: ActionFactory
This method may be called one or several times for each request. This is decided by the extension point. If, for example, the extension point is a pure single-item extension point then this method is probably only called once. If the extension point is a per-item extension point in a list context, then this method may be called once for every item in the list. The context parameter contains all information about the context of the extension point, including the current item, if any.

Specified by:
getActions in interface ActionFactory<Action>
Parameters:
context - The current invokation context
Returns:
An array of actions that should be added to the extension point. Returns null or an empty array if there are no actions in the current context.

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

setParameter

@PathSetter
@VariableSetter
public void setParameter(String name,
                                                   String value)
Set generic parameters.

Parameters:
name - The name of the parameter
value - The value of the parameter

setDisabled

public void setDisabled(String disabled)
Sets the disabled/enabled status of this factory.

Parameters:
disabled - A string that is parsed to a boolean by Values.getBoolean(String)

initProxy

private void initProxy(Class<? extends Action> actionClass)
Initialise the proxy class.

Parameters:
actionClass - The interface that the proxy must implement

getParameterName

private String getParameterName(String methodName)
Convert a method name to a parameter name. Methods that start with 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.

Parameters:
methodName - The name of the method
Returns:
The name of the parameter

getParameterValue

private Object getParameterValue(String parameterName,
                                 Class<?> returnType)
Get the value of a parameter.

Parameters:
parameterName - The name of the parameter
Returns:
The value of the parameter

2.17.2: 2011-06-17