All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.indeed.proctor.common.el.MulticontextReadOnlyVariableMapper Maven / Gradle / Ivy

There is a newer version: 1.9.118-1950c8a
Show newest version
package com.indeed.proctor.common.el;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
import java.util.Map;

/**
 * Provides services for the Unified Expression Language to look up variables in priority order
 * given the input contexts.
 *
 * @author ketan
 */
public class MulticontextReadOnlyVariableMapper extends VariableMapper {
    @Nonnull private final Map[] contexts;

    public MulticontextReadOnlyVariableMapper(
            @Nonnull final Map... contexts) {
        this.contexts = contexts;
    }

    @Nullable
    @Override
    public ValueExpression resolveVariable(final String name) {
        //noinspection unchecked
        return MulticontextReadOnlyVariableMapper.resolve(name, contexts);
    }

    @Nonnull
    @Override
    public ValueExpression setVariable(final String name, final ValueExpression expression) {
        throw new IllegalStateException("Setting variables is not allowed");
    }

    @Nullable
    public static ValueExpression resolve(
            final String variableName, @Nonnull final Map... contexts) {
        for (final Map context : contexts) {
            final ValueExpression ve = context.get(variableName);
            if (ve != null) {
                return ve;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy