net.sf.basedb.util.extensions.debug
Class BeanActionFactory
java.lang.Object
net.sf.basedb.util.extensions.debug.BeanActionFactory
- All Implemented Interfaces:
- ActionFactory<Action>
public class BeanActionFactory
- extends Object
- implements ActionFactory<Action>
Generic action factory class that can generate instances of
actions if there exists a bean-like implementation of the
action class.
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.gif</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:
- Version:
- 2.7
- Author:
- nicklas
- Last modified
- $Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
beanClassName
private String beanClassName
disabled
private boolean disabled
bean
private Action bean
actions
private Action[] actions
parameters
private Map<String,String> parameters
initialised
private volatile boolean initialised
BeanActionFactory
public BeanActionFactory()
- Creates a new proxy factory.
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.
setParameter
@PathSetter
@VariableSetter
public void setParameter(String name,
String value)
- Set generic parameters.
- Parameters:
name
- The name of the parametervalue
- The value of the parameter
setBeanClass
public void setBeanClass(String beanClass)
- Set the name of the class to use as a bean. The bean
must implement the action class of the extension point.
- Parameters:
beanClass
-
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)
initBean
private void initBean(Class<? extends Action> actionClass)
- Create the bean object. Call all setter methods that
corresponds to parameters found in the XML file.
- Parameters:
actionClass
- The interface that the proxy must implement
createBean
private Action createBean(Class<? extends Action> actionClass)
- Create the bean instance.
- Returns:
- A bean instance
findSetterMethod
private Method findSetterMethod(String parameterName,
Class<?> beanClass)
- Find a setter method for the specified parameter.
Try: setParam(String), T getParam() or T isParam() --> setParam(T)
getMethodName
private String getMethodName(String prefix,
String parameterName)
- Convert the parameter name to a method name.
First character of parameter name is upper-cased. The prefix
is then prepended. Ex, 'icon' --> 'setIcon'
- Parameters:
parameterName
- The parameter name
- Returns:
- The tag name prefixed with 'set' and the first letter captialized
getMethod
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.
- Parameters:
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
- Returns:
- The Method or null if no such method can be found
convertValue
private Object convertValue(String sValue,
Class<?> type)
- Convert a string value to another type.
- Parameters:
sValue
- The value to converttype
- The class to convert the string value to
- Returns:
- The converted value, or null if it couldn't be converted