Package org.apache.velocity.tools
Class ToolInfo
- java.lang.Object
-
- org.apache.velocity.tools.ToolInfo
-
- All Implemented Interfaces:
java.io.Serializable
public class ToolInfo extends java.lang.Object implements java.io.SerializableManages data needed to create instances of a tool. New instances are returned for every call to create(obj).- Version:
- $Id: ToolInfo.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna, Henning P. Schmiedehausen
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONFIGURE_METHOD_NAME
-
Constructor Summary
Constructors Constructor Description ToolInfo(java.lang.String key, java.lang.Class clazz)Creates a new instance using the minimum required info necessary for a tool.ToolInfo(java.lang.String key, java.lang.Class clazz, java.lang.Class factory)Creates a new instance using the minimum required info necessary for a tool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProperties(java.util.Map<java.lang.String,java.lang.Object> parentProps)Adds a map of properties from a parent scope to the properties for this tool.protected java.util.Map<java.lang.String,java.lang.Object>combine(java.util.Map<java.lang.String,java.lang.Object>... maps)Combine several property mapsprotected voidconfigure(java.lang.Object tool, java.util.Map<java.lang.String,java.lang.Object> configuration)Actually performs configuration of the newly instantiated tool using the combined final set of configuration properties.java.lang.Objectcreate(java.util.Map<java.lang.String,java.lang.Object> dynamicProperties)Returns a new instance of the tool.java.lang.StringgetClassname()Get tool class nameprotected java.lang.reflect.MethodgetConfigure()Try to find aconfigure()method.java.lang.ClassgetFactory()Get factory classjava.lang.StringgetKey()Get tool keyjava.util.Map<java.lang.String,java.lang.Object>getProperties()Get tool propertiesprotected java.util.Map<java.lang.String,java.lang.Object>getProps()Get tools property (synchronized version)java.lang.ClassgetToolClass()Get tool classbooleanhasConfigure()Get whether this tool has aconfigure()methodbooleanhasPermission(java.lang.String path)protected voidinvoke(java.lang.reflect.Method method, java.lang.Object tool, java.lang.Object param)Invoke a single argument method on a toolbooleanisSkipSetters()Get whether setters are to be skippedprotected java.lang.ObjectnewInstance()Creates a new instance for this tool.java.lang.ObjectputProperty(java.lang.String name, java.lang.Object value)Puts a new property for this tool.voidrestrictTo(java.lang.String path)voidsetClass(java.lang.Class clazz)Set the tool classvoidsetFactory(java.lang.Class factory)Set the factory class used to create tool instances.voidsetKey(java.lang.String key)Set the tool keyprotected voidsetProperty(java.lang.Object tool, java.lang.String name, java.lang.Object value)Set a property on a tool instancevoidsetSkipSetters(boolean cfgOnly)Set whether or not to skip setters.
-
-
-
Field Detail
-
CONFIGURE_METHOD_NAME
public static final java.lang.String CONFIGURE_METHOD_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ToolInfo
public ToolInfo(java.lang.String key, java.lang.Class clazz)Creates a new instance using the minimum required info necessary for a tool.- Parameters:
key- tool keyclazz- tool class
-
ToolInfo
public ToolInfo(java.lang.String key, java.lang.Class clazz, java.lang.Class factory)Creates a new instance using the minimum required info necessary for a tool.- Parameters:
key- tool keyclazz- tool class
-
-
Method Detail
-
setKey
public void setKey(java.lang.String key)
Set the tool key- Parameters:
key- tool key
-
setClass
public void setClass(java.lang.Class clazz)
Set the tool class- Parameters:
clazz- the java.lang.Class of the tool
-
setFactory
public void setFactory(java.lang.Class factory)
Set the factory class used to create tool instances.
The factory is supposed to have one of those three methods:
- createToolClassName()
- newToolClassName()
- getToolClassName()
where ToolClassName is the tool's class name.
If this method takes one
java.util.Mapargument, it will be given the tool's configuration map.- Parameters:
factory- factory class
-
restrictTo
public void restrictTo(java.lang.String path)
- Parameters:
path- the full or partial request path restriction of the tool
-
setSkipSetters
public void setSkipSetters(boolean cfgOnly)
Set whether or not to skip setters.- Parameters:
cfgOnly- flag value
-
addProperties
public void addProperties(java.util.Map<java.lang.String,java.lang.Object> parentProps)
Adds a map of properties from a parent scope to the properties for this tool. Only new properties will be added; any that are already set for this tool will be ignored.- Parameters:
parentProps- parent properties map
-
putProperty
public java.lang.Object putProperty(java.lang.String name, java.lang.Object value)Puts a new property for this tool.- Parameters:
name- property namevalue- property value- Returns:
- previous property value
-
getProps
protected java.util.Map<java.lang.String,java.lang.Object> getProps()
Get tools property (synchronized version)- Returns:
- tools property
-
getKey
public java.lang.String getKey()
Get tool key- Returns:
- tool key
-
getClassname
public java.lang.String getClassname()
Get tool class name- Returns:
- tool class name
-
getToolClass
public java.lang.Class getToolClass()
Get tool class- Returns:
- tool class
-
getFactory
public java.lang.Class getFactory()
Get factory class- Returns:
- factory class or null if not provided
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Get tool properties- Returns:
- tools properties
-
hasConfigure
public boolean hasConfigure()
Get whether this tool has aconfigure()method- Returns:
trueif the tool has aconfigure()method,falseotherwise
-
isSkipSetters
public boolean isSkipSetters()
Get whether setters are to be skipped- Returns:
- whether to skip setters
-
hasPermission
public boolean hasPermission(java.lang.String path)
- Parameters:
path- the path of a template requesting this tool- Returns:
trueif the specified request path matches the restrictions of this tool. If there is no request path restriction for this tool, it will always returntrue.
-
create
public java.lang.Object create(java.util.Map<java.lang.String,java.lang.Object> dynamicProperties)
Returns a new instance of the tool. If the tool has an configure(Map) method, the new instance will be initialized using the given properties combined with whatever "constant" properties have been put into this ToolInfo.- Parameters:
dynamicProperties- map of dynamic properties- Returns:
- newly created and configured object
-
configure
protected void configure(java.lang.Object tool, java.util.Map<java.lang.String,java.lang.Object> configuration)Actually performs configuration of the newly instantiated tool using the combined final set of configuration properties. First, if the class lacks theSkipSettersannotation, then any specific setters matching the configuration keys are called, then the general configure(Map) method (if any) is called.- Parameters:
tool- newly created tool to be configuredconfiguration- properties
-
getConfigure
protected java.lang.reflect.Method getConfigure()
Try to find aconfigure()method.- Returns:
configure()method if found,nullotherwise.
-
newInstance
protected java.lang.Object newInstance()
Creates a new instance for this tool.- Returns:
- newly created tool
- Throws:
java.lang.IllegalStateException- if creation failed
-
invoke
protected void invoke(java.lang.reflect.Method method, java.lang.Object tool, java.lang.Object param)Invoke a single argument method on a tool- Parameters:
method- the method to invoketool- the tool on which to invoke the methodparam- the method argument- Throws:
java.lang.IllegalStateException- if invocation failed
-
setProperty
protected void setProperty(java.lang.Object tool, java.lang.String name, java.lang.Object value) throws java.lang.ExceptionSet a property on a tool instance- Parameters:
tool- tool instancename- property namevalue- property value- Throws:
java.lang.Exception- if setting the property throwed
-
combine
protected java.util.Map<java.lang.String,java.lang.Object> combine(java.util.Map<java.lang.String,java.lang.Object>... maps)
Combine several property maps- Parameters:
maps- maps to combine- Returns:
- combined map
-
-