Class FactoryConfiguration
- java.lang.Object
-
- org.apache.velocity.tools.config.Configuration
-
- org.apache.velocity.tools.config.CompoundConfiguration<ToolboxConfiguration>
-
- org.apache.velocity.tools.config.FactoryConfiguration
-
- All Implemented Interfaces:
java.lang.Comparable<Configuration>
- Direct Known Subclasses:
EasyFactoryConfiguration,FileFactoryConfiguration
public class FactoryConfiguration extends CompoundConfiguration<ToolboxConfiguration>
This class serves to define configuration info for a
ToolboxFactory. It contains theToolboxConfigurations for the factory as well as anyDatawhich is to be made available in the application scope by the factory and anyPropertys which you intend to be available to all tools managed by the factory, regardless of toolbox or scope.Most users will not find themselves directly using the API of this class, as its subclasses generally provide much simpler means of inputting the actual configuration info whether from XML, Java or a Properties files.
When combining any
Configurations via the variousaddConfiguration(org.apache.velocity.tools.config.FactoryConfiguration)methods in each class, it is essential to remember that subsequent configurations always override previous ones. This is a "last entry wins" approach to configuration!For debugging, this class tracks its "sources", keeping a chronological list of all sources for configuration data. When you add configuration info to this class via
addConfiguration(org.apache.velocity.tools.config.FactoryConfiguration), the source lists from thoseFactoryConfigurations is appended to this instance's list. The initial item in this list will typically be the name of the FactoryConfiguration class (or subclass) along with a caller-provided string identifying where this instance was created. This aids greatly in debugging combined, complex configurations. You may add further sources at any time viaaddSource(java.lang.String).The
toString()method of this class provides a complete and well-formatted listing of the configuration info contained within this instance and is also very useful for debugging.- Version:
- $Id: FactoryConfiguration.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna
-
-
Constructor Summary
Constructors Modifier Constructor Description FactoryConfiguration()protectedFactoryConfiguration(java.lang.Class clazz, java.lang.String source)Allows subclasses to construct an instance that uses their classname.FactoryConfiguration(java.lang.String source)Creates a new instance with the specified source name combined with this class's name as the initial source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConfiguration(FactoryConfiguration config)voidaddData(Data newDatum)voidaddSource(java.lang.String source)ToolboxConfigurationaddToolbox(ToolboxConfiguration toolbox)ToolboxFactorycreateFactory()booleanequals(java.lang.Object o)This will consider the object equal if it is a FactoryConfiguration and whosetoString(boolean)method, when passedfalse, returns a String equal to that returned by a call to toString(false) on this instance.java.util.SortedSet<Data>getData()DatagetData(java.lang.String key)Search for Data by keyDatagetData(Data findme)Search for Data by valuejava.lang.StringgetSource()Returns the original source of this particular instance.java.util.List<java.lang.String>getSources()Returns the list of sources for this configuration info in order starting from the source name given to this instance (if any) and going to the most recently added source.ToolboxConfigurationgetToolbox(java.lang.String scope)java.util.Collection<ToolboxConfiguration>getToolboxes()booleanhasData()inthashCode()booleanremoveData(Data datum)voidremoveToolbox(ToolboxConfiguration toolbox)voidsetData(java.util.Collection<Data> data)voidsetSource(java.lang.String source)Sets the name of the original source of this particular instance.voidsetToolboxes(java.util.Collection<ToolboxConfiguration> toolboxes)java.lang.StringtoString()java.lang.StringtoString(boolean includeSources)voidvalidate()-
Methods inherited from class org.apache.velocity.tools.config.CompoundConfiguration
addChild, addChildren, addConfiguration, appendChildren, getChild, getChildren, hasChildren, removeChild, setChildren
-
Methods inherited from class org.apache.velocity.tools.config.Configuration
addConfiguration, addProperty, appendProperties, compareTo, getProperties, getProperty, getPropertyMap, hasProperties, removeProperty, removeProperty, setProperties, setProperty, setPropertyMap
-
-
-
-
Constructor Detail
-
FactoryConfiguration
public FactoryConfiguration()
-
FactoryConfiguration
public FactoryConfiguration(java.lang.String source)
Creates a new instance with the specified source name combined with this class's name as the initial source.- Parameters:
source- configuration source name
-
FactoryConfiguration
protected FactoryConfiguration(java.lang.Class clazz, java.lang.String source)Allows subclasses to construct an instance that uses their classname.- Parameters:
clazz- FactoryConfiguration class namesource- configuration source name
-
-
Method Detail
-
getSource
public java.lang.String getSource()
Returns the original source of this particular instance.- Returns:
- configuration source
-
setSource
public void setSource(java.lang.String source)
Sets the name of the original source of this particular instance. This does not affect subsequently added sources.- Parameters:
source- configuration source name
-
getSources
public java.util.List<java.lang.String> getSources()
Returns the list of sources for this configuration info in order starting from the source name given to this instance (if any) and going to the most recently added source.- Returns:
- list of all configuration sources
-
addSource
public void addSource(java.lang.String source)
- Parameters:
source- source to add
-
addData
public void addData(Data newDatum)
- Parameters:
newDatum- data to add
-
removeData
public boolean removeData(Data datum)
- Parameters:
datum- data to remove- Returns:
trueif removed
-
getData
public Data getData(java.lang.String key)
Search for Data by key- Parameters:
key- key of data to get- Returns:
- found Data or null
-
getData
public Data getData(Data findme)
Search for Data by value- Parameters:
findme- value to find- Returns:
- found Data or null
-
hasData
public boolean hasData()
-
getData
public java.util.SortedSet<Data> getData()
-
setData
public void setData(java.util.Collection<Data> data)
-
addToolbox
public ToolboxConfiguration addToolbox(ToolboxConfiguration toolbox)
-
removeToolbox
public void removeToolbox(ToolboxConfiguration toolbox)
-
getToolbox
public ToolboxConfiguration getToolbox(java.lang.String scope)
-
getToolboxes
public java.util.Collection<ToolboxConfiguration> getToolboxes()
-
setToolboxes
public void setToolboxes(java.util.Collection<ToolboxConfiguration> toolboxes)
-
addConfiguration
public void addConfiguration(FactoryConfiguration config)
-
validate
public void validate()
- Overrides:
validatein classCompoundConfiguration<ToolboxConfiguration>
-
equals
public boolean equals(java.lang.Object o)
This will consider the object equal if it is a FactoryConfiguration and whosetoString(boolean)method, when passedfalse, returns a String equal to that returned by a call to toString(false) on this instance.toString(boolean)is used since that returns a String encompassing all relevant info about the configuration except for the source information. In other words, two FactoryConfigurations are considered equal if they have the same data, properties and toolboxes in String form.- Overrides:
equalsin classCompoundConfiguration<ToolboxConfiguration>- Parameters:
o- object to compare to- Returns:
- equality
-
hashCode
public int hashCode()
- Overrides:
hashCodein classCompoundConfiguration<ToolboxConfiguration>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(boolean includeSources)
-
createFactory
public ToolboxFactory createFactory()
-
-