1 package com.atlassian.plugin.servlet.util;
2
3 /**
4 * This utility provides a thread local stack of {@link ClassLoader}s.
5 * The current "top" of the stack is the thread's current context class loader.
6 * This can be used when implementing delegating plugin {@link java.util.logging.Filter}s or {@link javax.servlet.Servlet}s
7 * that need to set the {@link ClassLoader} to the {@link com.atlassian.plugin.classloader.PluginClassLoader} the filter
8 * or servlet is declared in.
9 *
10 * @deprecated Moved to atlassian-plugins-core: com.atlassian.plugin.util.ClassLoaderStack. This impl delegates to the new impl.
11 *
12 * @since 2.1.0
13 */
14 @Deprecated
15 public class ClassLoaderStack
16 {
17 /**
18 * Makes the given classLoader the new ContextClassLoader for this thread, and pushes the current ContextClassLoader
19 * onto a ThreadLocal stack so that we can do a {@link #pop} operation later to return to that ContextClassLoader.
20 *
21 * <p>
22 * Passing null is allowed and will act as a no-op. This means that you can safely {@link #pop} a ClassLoader and {@link #push} it back in
23 * and it will work safely whether the stack was empty at time of {@link #pop} or not.
24 *
25 * @param loader The new ClassLoader to set as ContextClassLoader.
26 */
27 public static void push(ClassLoader loader)
28 {
29 com.atlassian.plugin.util.ClassLoaderStack.push(loader);
30 }
31
32 /**
33 * Pops the current ContextClassLoader off the stack, setting the new ContextClassLoader to the previous one on the stack.
34 * <ul>
35 * <li>If the stack is not empty, then the current ClassLoader is replaced by the previous one on the stack, and then returned.</li>
36 * <li>If the stack is empty, then null is returned and the current ContextClassLoader is not changed.</li>
37 * </ul>
38 *
39 * @return the previous ContextClassLoader that was just replaced, or null if the stack is empty.
40 */
41 public static ClassLoader pop()
42 {
43 return com.atlassian.plugin.util.ClassLoaderStack.pop();
44 }
45 }