org.apache.velocity.tools.config
Class EasyFactoryConfiguration
java.lang.Object
org.apache.velocity.tools.config.Configuration<C>
org.apache.velocity.tools.config.CompoundConfiguration<ToolboxConfiguration>
org.apache.velocity.tools.config.FactoryConfiguration
org.apache.velocity.tools.config.EasyFactoryConfiguration
public class EasyFactoryConfiguration
- extends FactoryConfiguration
FactoryConfiguration
subclass that simplifies the process of
configuration a ToolboxFactory
in Java without the use of an
xml or properties configuration file. Below is an example:
EasyFactoryConfiguration config = new EasyFactoryConfiguration();
config.toolbox("request").property("locale", Locale.US)
.tool(DateTool.class)
.tool("myTool", MyTool.class);
config.toolbox("application")
.tool(NumberTool.class).property("locale", Locale.FR);
ToolboxFactory factory = config.createFactory();
Doing the above without this class would require the following to
create an equivalent FactoryConfiguration
in Java:
FactoryConfiguration factoryConfig = new FactoryConfiguration();
ToolboxConfiguration toolbox = new ToolboxConfiguration();
toolbox.setScope("request");
toolbox.setProperty("locale", Locale.US);
ToolConfiguration tool = new ToolConfiguration();
tool.setClassname(DateTool.class.getName());
tool = new ToolConfiguration();
tool.setKey("myTool");
tool.setClassname(MyTool.class.getName());
toolbox.addTool(tool);
toolbox = new ToolboxConfiguration();
toolbox.setScope("application");
tool = new ToolConfiguration();
tool.setClassname(NumberTool.class.getName());
tool.setProperty("locale", Locale.FR);
toolbox.addTool(tool);
factoryConfig.addToolbox(toolbox);
ToolboxFactory factory = factoryConfig.createFactory();
Of course, you could directly configure a ToolboxFactory
with relatively little effort as well:
ToolboxFactory factory = new ToolboxFactory();
factory.putProperty("request", "locale", Locale.US);
factory.addToolInfo("request", new ToolInfo("date", DateTool.class));
factory.addToolInfo("request", new ToolInfo("render", ViewRenderTool.class));
ToolInfo info = new ToolInfo("number", NumberTool.class);
info.setProperty("locale", Locale.FR);
factory.addToolInfo("application", info);
But this is not reusable. Why does that matter? Well, it doesn't matter
for application developers. But, if another framework wishes to provide
a common VelocityTools configuration for application developers, this may
come in handy. Or it may not. In any case, it was mildly fun to write. :)
- Version:
- $Id: EasyFactoryConfiguration.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna
Methods inherited from class org.apache.velocity.tools.config.FactoryConfiguration |
addConfiguration, addData, addToolbox, createDefaultFactory, createFactory, findMatchingChild, getData, getDefault, getToolboxes, removeData, removeToolbox, toString, validate |
Methods inherited from class org.apache.velocity.tools.config.Configuration |
addConfiguration, addProperty, appendProperties, getConvertableProperties, getProperties, getSimpleProperties, hasProperties, removeProperty, removeProperty, setProperty, setProperty |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
addedDefault
private boolean addedDefault
toolbox
private EasyFactoryConfiguration.EasyWrap<ToolboxConfiguration> toolbox
EasyFactoryConfiguration
public EasyFactoryConfiguration()
EasyFactoryConfiguration
public EasyFactoryConfiguration(boolean startWithDefault)
- Parameters:
startWithDefault
- Sets whether this instance should start with the
FactoryConfiguration.getDefault()
configuration or not.
addDefault
public EasyFactoryConfiguration addDefault()
- Adds the
FactoryConfiguration.getDefault()
configuration to this
the current configuration.
toolbox
public EasyFactoryConfiguration.EasyWrap<ToolboxConfiguration> toolbox(java.lang.String scope)
tool
public EasyFactoryConfiguration.EasyWrap<ToolConfiguration> tool(java.lang.String classname)
tool
public EasyFactoryConfiguration.EasyWrap<ToolConfiguration> tool(java.lang.Class clazz)
tool
public EasyFactoryConfiguration.EasyWrap<ToolConfiguration> tool(java.lang.String key,
java.lang.String classname)
tool
public EasyFactoryConfiguration.EasyWrap<ToolConfiguration> tool(java.lang.String key,
java.lang.Class clazz)
property
public EasyFactoryConfiguration property(java.lang.String name,
java.lang.Object value)
Copyright (c) 2003-2007 Apache Software Foundation