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

io.atlassian.util.adapter.javax.el.JavaXExpressionFactoryAdapter Maven / Gradle / Ivy

Go to download

A collection of classes for adapting Servlet API 4.0 objects to Servlet API 5.0 and vice versa.

There is a newer version: 0.1.0
Show newest version
package io.atlassian.util.adapter.javax.el;

import io.atlassian.util.adapter.jakarta.el.JakartaExpressionFactoryAdapter;

import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import java.lang.reflect.Method;
import java.util.Map;

import static io.atlassian.util.adapter.jakarta.JakartaJspAdapters.asJakartaJsp;
import static io.atlassian.util.adapter.util.WrapperUtil.applyIfNonNull;
import static java.util.Objects.requireNonNull;

public class JavaXExpressionFactoryAdapter extends ExpressionFactory {

    private final jakarta.el.ExpressionFactory delegate;

    public static ExpressionFactory from(jakarta.el.ExpressionFactory delegate) {
        if (delegate instanceof JakartaExpressionFactoryAdapter castDelegate) {
            return castDelegate.getDelegate();
        }
        return applyIfNonNull(delegate, JavaXExpressionFactoryAdapter::new);
    }

    JavaXExpressionFactoryAdapter(jakarta.el.ExpressionFactory delegate) {
        this.delegate = requireNonNull(delegate);
    }

    public jakarta.el.ExpressionFactory getDelegate() {
        return delegate;
    }

    @Override
    public ELResolver getStreamELResolver() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public Map getInitFunctionMap() {
        return delegate.getInitFunctionMap();
    }

    @Override
    public ValueExpression createValueExpression(ELContext context, String expression, Class expectedType) {
        return JavaXValueExpressionAdapter.from(delegate.createValueExpression(asJakartaJsp(context), expression, expectedType));
    }

    @Override
    public ValueExpression createValueExpression(Object instance, Class expectedType) {
        return JavaXValueExpressionAdapter.from(delegate.createValueExpression(instance, expectedType));
    }

    @Override
    public MethodExpression createMethodExpression(ELContext context,
                                                   String expression,
                                                   Class expectedReturnType,
                                                   Class[] expectedParamTypes) {
        return JavaXMethodExpressionAdapter.from(delegate.createMethodExpression(asJakartaJsp(context), expression, expectedReturnType, expectedParamTypes));
    }

    @Override
    public Object coerceToType(Object obj, Class targetType) {
        return delegate.coerceToType(obj, targetType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy