|
|
@@ -54,6 +54,32 @@ public abstract class EnumeratedAttribute { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Factory method for instantiating EAs via API in a more |
|
|
|
* developer friendly way. |
|
|
|
* @param clazz Class, extending EA, which to instantiate |
|
|
|
* @param value The value to set on that EA |
|
|
|
* @return Configured EA |
|
|
|
* @throws BuildException If the class could not be found or the value |
|
|
|
* is not valid for the given EA-class. |
|
|
|
* @see Bug-14831 |
|
|
|
*/ |
|
|
|
public static EnumeratedAttribute getInstance( |
|
|
|
Class/*<? extends EnumeratedAttribute>*/ clazz, |
|
|
|
String value) throws BuildException { |
|
|
|
if (!EnumeratedAttribute.class.isAssignableFrom(clazz)) { |
|
|
|
throw new BuildException("You have to provide a subclass from EnumeratedAttribut as clazz-parameter."); |
|
|
|
} |
|
|
|
EnumeratedAttribute ea = null; |
|
|
|
try { |
|
|
|
ea = (EnumeratedAttribute)clazz.newInstance(); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new BuildException(e); |
|
|
|
} |
|
|
|
ea.setValue(value); |
|
|
|
return ea; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Invoked by {@link org.apache.tools.ant.IntrospectionHelper IntrospectionHelper}. |
|
|
|
* @param value the <code>String</code> value of the attribute |
|
|
|
* @throws BuildException if the value is not valid for the attribute |
|
|
@@ -111,7 +137,6 @@ public abstract class EnumeratedAttribute { |
|
|
|
return index; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Convert the value to its string form. |
|
|
|
* |
|
|
@@ -121,4 +146,4 @@ public abstract class EnumeratedAttribute { |
|
|
|
return getValue(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |