1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.core;
17
18 import org.apache.commons.jelly.TagSupport;
19 import org.apache.commons.jelly.util.ClassLoaderUtils;
20
21 /*** Abstract base tag providing {@link ClassLoader} support.
22 *
23 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
24 * @author Rodney Waldhoff
25 * @version $Revision: 155420 $
26 */
27 public abstract class BaseClassLoaderTag extends TagSupport {
28 /***
29 * The class loader to use for instantiating application objects.
30 * If not specified, the context class loader, or the class loader
31 * used to load XMLParser itself, is used, based on the value of the
32 * <code>useContextClassLoader</code> variable.
33 */
34 protected ClassLoader classLoader = null;
35
36 /***
37 * Do we want to use the Context ClassLoader when loading classes
38 * for instantiating new objects? Default is <code>false</code>.
39 */
40 protected boolean useContextClassLoader = false;
41
42 /***
43 * Return the class loader to be used for instantiating application objects
44 * when required. This is determined based upon the following rules:
45 * <ul>
46 * <li>The class loader set by <code>setClassLoader()</code>, if any</li>
47 * <li>The thread context class loader, if it exists and the
48 * <code>useContextClassLoader</code> property is set to true</li>
49 * <li>The class loader used to load the XMLParser class itself.
50 * </ul>
51 */
52 public ClassLoader getClassLoader() {
53 return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
54 }
55
56 /***
57 * Set the class loader to be used for instantiating application objects
58 * when required.
59 *
60 * @param classLoader The new class loader to use, or <code>null</code>
61 * to revert to the standard rules
62 */
63 public void setClassLoader(ClassLoader classLoader) {
64 this.classLoader = classLoader;
65 }
66
67 /***
68 * Return the boolean as to whether the context classloader should be used.
69 */
70 public boolean getUseContextClassLoader() {
71 return useContextClassLoader;
72 }
73
74 /***
75 * Determine whether to use the Context ClassLoader (the one found by
76 * calling <code>Thread.currentThread().getContextClassLoader()</code>)
77 * to resolve/load classes. If not
78 * using Context ClassLoader, then the class-loading defaults to
79 * using the calling-class' ClassLoader.
80 *
81 * @param boolean determines whether to use JellyContext ClassLoader.
82 */
83 public void setUseContextClassLoader(boolean use) {
84 useContextClassLoader = use;
85 }
86 }