io.atlassian.util.adapter.javax.JavaXAdapters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jakarta-adapters Show documentation
Show all versions of jakarta-adapters Show documentation
A collection of classes for adapting Servlet API 4.0 objects to Servlet API 5.0 and vice versa.
package io.atlassian.util.adapter.javax;
import io.atlassian.util.adapter.javax.servlet.JavaXFilterAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXFilterChainAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXFilterConfigAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletConfigAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletContextAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletContextListenerAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletRequestAdapter;
import io.atlassian.util.adapter.javax.servlet.JavaXServletResponseAdapter;
import io.atlassian.util.adapter.javax.servlet.http.JavaXHttpServletRequestAdapter;
import io.atlassian.util.adapter.javax.servlet.http.JavaXHttpServletResponseAdapter;
import static io.atlassian.util.adapter.util.WrapperUtil.applyIfNonNull;
public class JavaXAdapters {
private JavaXAdapters() {
}
/**
* Converts a potential Jakarta object to its corresponding JavaX object. Only supports:
*
* - {@link jakarta.servlet.http.HttpServletRequest}
* - {@link jakarta.servlet.ServletRequest}
* - {@link jakarta.servlet.http.HttpServletResponse}
* - {@link jakarta.servlet.ServletResponse}
* - {@link jakarta.servlet.ServletContext}
* - {@link jakarta.servlet.Servlet}
* - {@link jakarta.servlet.Filter}
*
*/
public static Object asJavaXIfJakarta(Object delegate) {
if (delegate instanceof jakarta.servlet.ServletRequest cast) {
return asJavaX(cast);
} else if (delegate instanceof jakarta.servlet.ServletResponse cast) {
return asJavaX(cast);
} else if (delegate instanceof jakarta.servlet.ServletContext cast) {
return asJavaX(cast);
} else if (delegate instanceof jakarta.servlet.Servlet cast) {
return asJavaX(cast);
} else if (delegate instanceof jakarta.servlet.Filter cast) {
return asJavaX(cast);
}
return delegate;
}
public static javax.servlet.Filter asJavaX(jakarta.servlet.Filter delegate) {
return applyIfNonNull(delegate, JavaXFilterAdapter::from);
}
public static javax.servlet.FilterChain asJavaX(jakarta.servlet.FilterChain delegate) {
return applyIfNonNull(delegate, JavaXFilterChainAdapter::from);
}
public static javax.servlet.FilterConfig asJavaX(jakarta.servlet.FilterConfig delegate) {
return applyIfNonNull(delegate, JavaXFilterConfigAdapter::from);
}
public static javax.servlet.Servlet asJavaX(jakarta.servlet.Servlet delegate) {
return applyIfNonNull(delegate, JavaXServletAdapter::from);
}
public static javax.servlet.ServletConfig asJavaX(jakarta.servlet.ServletConfig delegate) {
return applyIfNonNull(delegate, JavaXServletConfigAdapter::from);
}
public static javax.servlet.http.HttpServletRequest asJavaX(jakarta.servlet.http.HttpServletRequest delegate) {
return applyIfNonNull(delegate, JavaXHttpServletRequestAdapter::from);
}
public static javax.servlet.ServletRequest asJavaX(jakarta.servlet.ServletRequest delegate) {
return applyIfNonNull(delegate, JavaXServletRequestAdapter::from);
}
public static javax.servlet.http.HttpServletResponse asJavaX(jakarta.servlet.http.HttpServletResponse delegate) {
return applyIfNonNull(delegate, JavaXHttpServletResponseAdapter::from);
}
public static javax.servlet.ServletResponse asJavaX(jakarta.servlet.ServletResponse delegate) {
return applyIfNonNull(delegate, JavaXServletResponseAdapter::from);
}
public static javax.servlet.ServletContext asJavaX(jakarta.servlet.ServletContext delegate) {
return applyIfNonNull(delegate, JavaXServletContextAdapter::from);
}
public static javax.servlet.ServletContextListener asJavaX(jakarta.servlet.ServletContextListener delegate) {
return applyIfNonNull(delegate, JavaXServletContextListenerAdapter::from);
}
}