Example usage for org.apache.commons.collections ClosureUtils chainedClosure

List of usage examples for org.apache.commons.collections ClosureUtils chainedClosure

Introduction

In this page you can find the example usage for org.apache.commons.collections ClosureUtils chainedClosure.

Prototype

public static Closure chainedClosure(Collection closures) 

Source Link

Document

Create a new Closure that calls each closure in turn, passing the result into the next closure.

Usage

From source file:gov.nih.nci.caarray.security.SecurityPolicy.java

/**
 * Returns a Closure mutator to be applied to the given property on the given entity, given the set
 * of applicable policies. If multiple Closures are to be applied, then the returned Closure
 * represents a chaining of those Closure. If no Closures are to be applied,
 * returns null/* w ww . ja v  a 2 s .co  m*/
 *
 * @param policies the active policies
 * @param propertyAccessor accessor for the property on the object
 * @return the Closure to be applied, or null if none should be applied
 */
private static Closure getPropertyMutator(Set<SecurityPolicy> policies, PropertyAccessor propAccessor) {
    AttributePolicy attributePolicy = getAttributePolicy(propAccessor);
    if (attributePolicy == null) {
        return null;
    }
    List<Closure> mutators = new ArrayList<Closure>();
    for (AttributeMutator attrMutator : attributePolicy.mutators()) {
        if (policiesMatch(attrMutator.policies(), policies)) {
            try {
                mutators.add(attrMutator.mutator().newInstance());
            } catch (InstantiationException e) {
                LOG.warn("Could not instantiate closure of class " + attrMutator.mutator().getName(), e);
            } catch (IllegalAccessException e) {
                LOG.warn("Could not instantiate closure of class " + attrMutator.mutator().getName(), e);
            }
        }
    }
    return mutators.isEmpty() ? null : ClosureUtils.chainedClosure(mutators);
}