org.apache.tools.ant.types

Class EnumeratedAttribute

public abstract class EnumeratedAttribute extends Object

Helper class for attributes that can only take one of a fixed list of values.

See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an example.

Field Summary
protected Stringvalue
The selected value in this enumeration.
Constructor Summary
protected EnumeratedAttribute()
bean constructor
Method Summary
booleancontainsValue(String value)
Is this value included in the enumeration?
intgetIndex()
static EnumeratedAttributegetInstance(Class clazz, String value)
Factory method for instantiating EAs via API in a more developer friendly way.
StringgetValue()
abstract String[]getValues()
This is the only method a subclass needs to implement.
intindexOfValue(String value)
get the index of a value in this enumeration.
voidsetValue(String value)
Invoked by {@link org.apache.tools.ant.IntrospectionHelper IntrospectionHelper}.
StringtoString()
Convert the value to its string form.

Field Detail

value

protected String value
The selected value in this enumeration.

Constructor Detail

EnumeratedAttribute

protected EnumeratedAttribute()
bean constructor

Method Detail

containsValue

public final boolean containsValue(String value)
Is this value included in the enumeration?

Parameters: value the String value to look up

Returns: true if the value is valid

getIndex

public final int getIndex()

Returns: the index of the selected value in the array.

See Also: getValues

getInstance

public static EnumeratedAttribute getInstance(Class clazz, String value)
Factory method for instantiating EAs via API in a more developer friendly way.

Parameters: clazz Class, extending EA, which to instantiate value The value to set on that EA

Returns: Configured EA

Throws: BuildException If the class could not be found or the value is not valid for the given EA-class.

See Also: http://issues.apache.org/bugzilla/show_bug.cgi?id=14831

getValue

public final String getValue()

Returns: the selected value.

getValues

public abstract String[] getValues()
This is the only method a subclass needs to implement.

Returns: an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

indexOfValue

public final int indexOfValue(String value)
get the index of a value in this enumeration.

Parameters: value the string value to look for.

Returns: the index of the value in the array of strings or -1 if it cannot be found.

See Also: getValues

setValue

public final void setValue(String value)
Invoked by {@link org.apache.tools.ant.IntrospectionHelper IntrospectionHelper}.

Parameters: value the String value of the attribute

Throws: BuildException if the value is not valid for the attribute

toString

public String toString()
Convert the value to its string form.

Returns: the string form of the value.