Package org.apache.commons.jexl2

Examples of org.apache.commons.jexl2.MapContext


     * @param attributes the set of attributes against which evaluate this derived attribute
     * @return the value of this derived attribute
     */
    public String getValue(final Collection<? extends AbstractAttr> attributes) {
        // Prepare context using user attributes
        final JexlContext jexlContext = new MapContext();
        JexlUtil.addAttrsToContext(attributes, jexlContext);
        JexlUtil.addFieldsToContext(getOwner(), jexlContext);

        // Evaluate expression using the context prepared before
        return JexlUtil.evaluate(getSchema().getExpression(), jexlContext);
View Full Code Here


                    if (role.getResourceNames().contains(task.getResource().getName())
                            && StringUtils.isNotBlank(task.getResource().getRmapping().getAccountLink())) {

                        LOG.debug("Evaluating accountLink for {}", role);

                        final JexlContext jexlContext = new MapContext();
                        JexlUtil.addFieldsToContext(role, jexlContext);
                        JexlUtil.addAttrsToContext(role.getAttrs(), jexlContext);
                        JexlUtil.addDerAttrsToContext(role.getDerAttrs(), role.getAttrs(), jexlContext);

                        final String roleAccountLink =
View Full Code Here

        return result;
    }

    public static JexlContext addFieldsToContext(final Object attributable, final JexlContext jexlContext) {
        JexlContext context = jexlContext == null ? new MapContext() : jexlContext;

        try {
            for (PropertyDescriptor desc : Introspector.getBeanInfo(attributable.getClass()).getPropertyDescriptors()) {
                final Class<?> type = desc.getPropertyType();
                final String fieldName = desc.getName();
View Full Code Here

    public static JexlContext addAttrsToContext(final Collection<? extends AbstractAttr> attrs,
            final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractAttr attr : attrs) {
            if (attr.getSchema() != null) {
                List<String> attrValues = attr.getValuesAsStrings();
View Full Code Here

    public static JexlContext addDerAttrsToContext(final Collection<? extends AbstractDerAttr> derAttrs,
            final Collection<? extends AbstractAttr> attrs, final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractDerAttr derAttr : derAttrs) {
            if (derAttr.getSchema() != null) {
                String expressionValue = derAttr.getValue(attrs);
View Full Code Here

    public static JexlContext addVirAttrsToContext(final Collection<? extends AbstractVirAttr> virAttrs,
            final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractVirAttr virAttr : virAttrs) {
            if (virAttr.getSchema() != null) {
                List<String> attrValues = virAttr.getValues();
View Full Code Here

        return context;
    }

    public static String evaluate(final String expression, final AbstractAttributableTO attributableTO) {
        final JexlContext context = new MapContext();

        addFieldsToContext(attributableTO, context);

        for (AttributeTO attr : attributableTO.getAttrs()) {
            List<String> values = attr.getValues();
            String expressionValue = values.isEmpty()
                    ? ""
                    : values.get(0);

            LOG.debug("Add attribute {} with value {}", attr.getSchema(), expressionValue);

            context.set(attr.getSchema(), expressionValue);
        }
        for (AttributeTO derAttr : attributableTO.getDerAttrs()) {
            List<String> values = derAttr.getValues();
            String expressionValue = values.isEmpty()
                    ? ""
                    : values.get(0);

            LOG.debug("Add derived attribute {} with value {}", derAttr.getSchema(), expressionValue);

            context.set(derAttr.getSchema(), expressionValue);
        }
        for (AttributeTO virAttr : attributableTO.getVirAttrs()) {
            List<String> values = virAttr.getValues();
            String expressionValue = values.isEmpty()
                    ? ""
                    : values.get(0);

            LOG.debug("Add virtual attribute {} with value {}", virAttr.getSchema(), expressionValue);

            context.set(virAttr.getSchema(), expressionValue);
        }

        // Evaluate expression using the context prepared before
        return evaluate(expression, context);
    }
View Full Code Here

    }

    public static boolean evaluateMandatoryCondition(final String mandatoryCondition,
            final AbstractAttributable attributable) {

        JexlContext jexlContext = new MapContext();
        addAttrsToContext(attributable.getAttrs(), jexlContext);
        addDerAttrsToContext(attributable.getDerAttrs(), attributable.getAttrs(), jexlContext);
        addVirAttrsToContext(attributable.getVirAttrs(), jexlContext);

        return Boolean.parseBoolean(evaluate(mandatoryCondition, jexlContext));
View Full Code Here

public class ELUtil {
    public static Object invoke(String expression, Map<String, Object> context) {
        JexlEngine jexl = new JexlEngine();
        Expression el = jexl.createExpression(expression);
        JexlContext elContext = new MapContext();
        for (String property : context.keySet()) {
            elContext.set(property, context.get(property));
        }
        return el.evaluate(elContext);
    }
View Full Code Here

    public JexlExpressionParser(final Map<String, Object> vars) {
        if (vars == null) {
            throw new IllegalArgumentException("vars: " + vars);
        }
        engine = new JexlEngine();
        context = new MapContext(vars);

        LOGGER.trace("Using variables: {}", vars);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.MapContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.