package io.undertow.servlet.core;
import io.undertow.servlet.api.FilterInfo;
import io.undertow.servlet.api.LifecycleInterceptor;
import io.undertow.servlet.api.ServletInfo;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import java.util.List;
class LifecyleInterceptorInvocation implements LifecycleInterceptor.LifecycleContext {
private final List<LifecycleInterceptor> list;
private final ServletInfo servletInfo;
private final FilterInfo filterInfo;
private final Servlet servlet;
private final Filter filter;
private int i;
private final ServletConfig servletConfig;
private final FilterConfig filterConfig;
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, ServletInfo servletInfo, Servlet servlet, ServletConfig servletConfig) {
this.list = list;
this.servletInfo = servletInfo;
this.servlet = servlet;
this.servletConfig = servletConfig;
this.filter = null;
this.filterConfig = null;
this.filterInfo = null;
i = list.size();
}
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, ServletInfo servletInfo, Servlet servlet) {
this.list = list;
this.servlet = servlet;
this.servletInfo = servletInfo;
this.filterInfo = null;
this.servletConfig = null;
this.filter = null;
this.filterConfig = null;
i = list.size();
}
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter, FilterConfig filterConfig) {
this.list = list;
this.servlet = null;
this.servletConfig = null;
this.filter = filter;
this.filterConfig = filterConfig;
this.filterInfo = filterInfo;
this.servletInfo = null;
i = list.size();
}
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter) {
this.list = list;
this.servlet = null;
this.servletConfig = null;
this.filter = filter;
this.filterConfig = null;
this.filterInfo = filterInfo;
this.servletInfo = null;
i = list.size();
}
@Override
public void proceed() throws ServletException {
if (--i >= 0) {
final LifecycleInterceptor next = list.get(i);
if(filter != null) {
if(filterConfig == null) {
next.destroy(filterInfo, filter, this);
} else {
next.init(filterInfo, filter, this);
}
} else {
if(servletConfig == null) {
next.destroy(servletInfo, servlet, this);
} else {
next.init(servletInfo, servlet, this);
}
}
} else if (i == -1) {
if(filter != null) {
if(filterConfig == null) {
filter.destroy();
} else {
filter.init(filterConfig);
}
} else {
if(servletConfig == null) {
servlet.destroy();
} else {
servlet.init(servletConfig);
}
}
}
}
}