Search in sources :

Example 1 with EnableAttribute

use of org.apache.tools.ant.attribute.EnableAttribute in project ant by apache.

the class RuntimeConfigurable method isEnabled.

/**
 * Check if an UE is enabled.
 * This looks tru the attributes and checks if there
 * are any Ant attributes, and if so, the method calls the
 * isEnabled() method on them.
 * @param owner the UE that owns this RC.
 * @return true if enabled, false if any of the ant attributes return
 *              false.
 * @since 1.9.1
 */
public boolean isEnabled(UnknownElement owner) {
    if (!namespacedAttribute) {
        return true;
    }
    ComponentHelper componentHelper = ComponentHelper.getComponentHelper(owner.getProject());
    IntrospectionHelper ih = IntrospectionHelper.getHelper(owner.getProject(), EnableAttributeConsumer.class);
    for (int i = 0; i < attributeMap.keySet().size(); ++i) {
        String name = (String) attributeMap.keySet().toArray()[i];
        AttributeComponentInformation attributeComponentInformation = isRestrictedAttribute(name, componentHelper);
        if (!attributeComponentInformation.isRestricted()) {
            continue;
        }
        String value = (String) attributeMap.get(name);
        EnableAttribute enable = null;
        try {
            enable = (EnableAttribute) ih.createElement(owner.getProject(), new EnableAttributeConsumer(), attributeComponentInformation.getComponentName());
        } catch (BuildException ex) {
            throw new BuildException("Unsupported attribute " + attributeComponentInformation.getComponentName());
        }
        if (enable == null) {
            continue;
        }
        // FixMe: need to make config
        value = owner.getProject().replaceProperties(value);
        if (!enable.isEnabled(owner, value)) {
            return false;
        }
    }
    return true;
}
Also used : EnableAttribute(org.apache.tools.ant.attribute.EnableAttribute)

Aggregations

EnableAttribute (org.apache.tools.ant.attribute.EnableAttribute)1