org.jboss.resteasy.reactive.common.model.InterceptorContainer Maven / Gradle / Ivy
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();
}
}
}