|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.tools.ant.ProjectComponent | +--org.apache.tools.ant.types.DataType | +--org.apache.tools.ant.types.selectors.BaseSelector | +--org.apache.tools.ant.types.selectors.BaseExtendSelector | +--org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector
Selector class that uses Algorithm, Cache and Comparator for its work. The Algorithm is used for computing a hashvalue for a file. The Comparator decides whether to select or not. The Cache stores the other value for comparison by the Comparator in a persistent manner.
The ModifiedSelector is implemented as a CoreSelector and uses default values for all its attributes therefore the simpliest example is
The same example rewritten as CoreSelector with setting the all values (same as defaults are) would be
And the same rewritten as CustomSelector would be
All these three examples copy the files from src to dest using the ModifiedSelector. The ModifiedSelector uses the PropertyfileCache , the DigestAlgorithm and the EqualComparator for its work. The PropertyfileCache stores key-value-pairs in a simple java properties file. The filename is cache.properties. The update flag lets the selector update the values in the cache (and on first call creates the cache). The DigestAlgorithm computes a hashvalue using the java.security.MessageDigest class with its MD5-Algorithm and its standard provider. The new computed hashvalue and the stored one are compared by the EqualComparator which returns 'true' (more correct a value not equals zero (1)) if the values are not the same using simple String comparison.
A useful scenario for this selector is inside a build environment for homepage generation (e.g. with Apache Forrest).
Here all changed files are uploaded to the server. The ModifiedSelector saves therefore much upload time.generate the site using forrest upload the changed files
This selector supports the following nested param's:
name | values | description | required |
---|---|---|---|
cache | propertyfile | which cache implementation should be used
|
no, defaults to 'propertyfile' |
algorithm | hashvalue | digest | which algorithm implementation should be used
|
no, defaults to digest |
comparator | equal | role | which comparator implementation should be used
|
no, defaults to equal |
update | true | false | If set to true, the cache will be stored, otherwise the values will be lost. | no, defaults to true |
seldirs | true | false | If set to true, directories will be selected otherwise not | no, defaults to true |
cache.* | depends on used cache | value is stored and given to the Cache-Object for initialisation | depends on used cache |
algorithm.* | depends on used algorithm | value is stored and given to the Algorithm-Object for initialisation | depends on used algorithm |
comparator.* | depends on used comparator | value is stored and given to the Comparator-Object for initialisation | depends on used comparator |
This selector uses reflection for setting the values of its three interfaces (using org.apache.tools.ant.IntrospectionHelper) therefore no special 'configuration interfaces' has to be implemented by new caches, algorithms or comparators. All present setXX methods can be used. E.g. the DigestAlgorithm can use a specified provider for computing its value. For selecting this there is a setProvider(String providername) method. So you can use a nested .
Nested Class Summary | |
static class |
ModifiedSelector.AlgorithmName
|
static class |
ModifiedSelector.CacheName
|
static class |
ModifiedSelector.ComparatorName
|
Field Summary |
Fields inherited from class org.apache.tools.ant.types.selectors.BaseExtendSelector |
parameters |
Fields inherited from class org.apache.tools.ant.types.DataType |
checked, description, ref |
Fields inherited from class org.apache.tools.ant.ProjectComponent |
project |
Constructor Summary | |
ModifiedSelector()
Bean-Constructor. |
Method Summary | |
void |
addParam(Parameter parameter)
Support for nested <param> tags. |
void |
addParam(java.lang.String key,
java.lang.Object value)
Support for nested <param> tags. |
void |
configure()
Configures this Selector. |
Algorithm |
getAlgorithm()
|
Cache |
getCache()
|
java.util.Comparator |
getComparator()
|
boolean |
isSelected(java.io.File basedir,
java.lang.String filename,
java.io.File file)
Implementation of BaseExtendSelector.isSelected(). |
void |
setAlgorithm(ModifiedSelector.AlgorithmName name)
|
void |
setCache(ModifiedSelector.CacheName name)
|
void |
setComparator(ModifiedSelector.ComparatorName name)
|
void |
setParameters(Parameter[] parameters)
Defined in org.apache.tools.ant.types.Parameterizable. |
void |
setSeldirs(boolean seldirs)
Support for seldirs attribute. |
void |
setUpdate(boolean update)
Support for update attribute. |
java.lang.String |
toString()
Override Object.toString(). |
protected void |
tryToSetAParameter(java.lang.Object obj,
java.lang.String name,
java.lang.String value)
Try to set a value on an object using reflection. |
void |
useParameter(Parameter parameter)
Support for nested tags. |
void |
verifySettings()
Overrides BaseSelector.verifySettings(). |
Methods inherited from class org.apache.tools.ant.types.selectors.BaseExtendSelector |
getParameters |
Methods inherited from class org.apache.tools.ant.types.selectors.BaseSelector |
getError, setError, validate |
Methods inherited from class org.apache.tools.ant.types.DataType |
checkAttributesAllowed, checkChildrenAllowed, circularReference, dieOnCircularReference, getCheckedRef, getDescription, getRefid, isChecked, isReference, noChildrenAllowed, setChecked, setDescription, setRefid, tooManyAttributes |
Methods inherited from class org.apache.tools.ant.ProjectComponent |
getProject, log, log, setProject |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ModifiedSelector()
Method Detail |
public void verifySettings()
verifySettings
in class BaseSelector
public void configure()
Because some problems while configuring from
This configuration algorithm is needed because you don't know the order of arriving config-data. E.g. if you first set the cache.cachefilename and after that the cache itself, the default value for cachefilename is used, because setting the cache implies creating a new Cache instance - with its defaults.
public boolean isSelected(java.io.File basedir, java.lang.String filename, java.io.File file)
isSelected
in interface FileSelector
isSelected
in class BaseExtendSelector
basedir
- as described in BaseExtendSelectorfilename
- as described in BaseExtendSelectorfile
- as described in BaseExtendSelector
public void setUpdate(boolean update)
update
- new valuepublic void setSeldirs(boolean seldirs)
seldirs
- new valuepublic void addParam(java.lang.String key, java.lang.Object value)
key
- the key of the parametervalue
- the value of the parameterpublic void addParam(Parameter parameter)
parameter
- the parameter objectpublic void setParameters(Parameter[] parameters)
setParameters
in interface Parameterizable
setParameters
in class BaseExtendSelector
parameters
- the complete set of parameters for this selectoraddParam(String,Object).
public void useParameter(Parameter parameter)
parameter
- Key and value as parameter objectprotected void tryToSetAParameter(java.lang.Object obj, java.lang.String name, java.lang.String value)
obj
- the object on which the attribute should be setname
- the attributenamevalue
- the new valuepublic java.lang.String toString()
toString
in class java.lang.Object
public Cache getCache()
public void setCache(ModifiedSelector.CacheName name)
public Algorithm getAlgorithm()
public void setAlgorithm(ModifiedSelector.AlgorithmName name)
public java.util.Comparator getComparator()
public void setComparator(ModifiedSelector.ComparatorName name)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |