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

org.jboss.resteasy.reactive.common.model.InterceptorContainer Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package org.jboss.resteasy.reactive.common.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

import org.jboss.resteasy.reactive.spi.BeanFactory;

public class InterceptorContainer {

    private final List> globalResourceInterceptors = new ArrayList<>();
    private final List> nameResourceInterceptors = new ArrayList<>();

    public void addGlobalRequestInterceptor(ResourceInterceptor interceptor) {
        this.globalResourceInterceptors.add(interceptor);
    }

    public void addNameRequestInterceptor(ResourceInterceptor interceptor) {
        this.nameResourceInterceptors.add(interceptor);
    }

    public List> getGlobalResourceInterceptors() {
        return globalResourceInterceptors;
    }

    public List> getNameResourceInterceptors() {
        return nameResourceInterceptors;
    }

    public void sort() {
        Collections.sort(globalResourceInterceptors);
        Collections.sort(nameResourceInterceptors);
    }

    public boolean isEmpty() {
        return globalResourceInterceptors.isEmpty() && nameResourceInterceptors.isEmpty();
    }

    public ResourceInterceptor create() {
        return new ResourceInterceptor<>();
    }

    public void initializeDefaultFactories(Function> factoryCreator) {
        for (ResourceInterceptor i : globalResourceInterceptors) {
            if (i.getFactory() == null) {
                i.setFactory((BeanFactory) factoryCreator.apply(i.getClassName()));
            }
        }
        for (ResourceInterceptor i : nameResourceInterceptors) {
            if (i.getFactory() == null) {
                i.setFactory((BeanFactory) factoryCreator.apply(i.getClassName()));
            }
        }
    }

    public static class Reversed extends InterceptorContainer {

        public ResourceInterceptor create() {
            return new ResourceInterceptor.Reversed();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy