Example usage for org.apache.commons.collections TransformerUtils chainedTransformer

List of usage examples for org.apache.commons.collections TransformerUtils chainedTransformer

Introduction

In this page you can find the example usage for org.apache.commons.collections TransformerUtils chainedTransformer.

Prototype

public static Transformer chainedTransformer(Collection transformers) 

Source Link

Document

Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.

Usage

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

/**
 * Returns a transformer to be applied to the given property on the given entity, given the set
 * of applicable policies. If multiple Transformers are to be applied, then the returned
 * Transformer represents a chaining of those Transformers. If no Transformers are to be applied,
 * returns null//  ww w  .  j ava  2s.com
 *
 * @param policies the active policies
 * @param propertyAccessor accessor for the property on the object
 * @return the Transformer to be applied, or null if none should be applied
 */
private static Transformer getPropertyTransformer(Set<SecurityPolicy> policies, PropertyAccessor propAccessor) {
    AttributePolicy attributePolicy = getAttributePolicy(propAccessor);
    if (attributePolicy == null) {
        return null;
    }
    List<Transformer> transformers = new ArrayList<Transformer>();
    for (AttributeTransformer attrTransformer : attributePolicy.transformers()) {
        if (policiesMatch(attrTransformer.policies(), policies)) {
            try {
                transformers.add(attrTransformer.transformer().newInstance());
            } catch (InstantiationException e) {
                LOG.warn(
                        "Could not instantiate transformer of class " + attrTransformer.transformer().getName(),
                        e);
            } catch (IllegalAccessException e) {
                LOG.warn(
                        "Could not instantiate transformer of class " + attrTransformer.transformer().getName(),
                        e);
            }
        }
    }
    return transformers.isEmpty() ? null : TransformerUtils.chainedTransformer(transformers);
}