01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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,
54: useContextClassLoader, getClass());
55: }
56:
57: /**
58: * Set the class loader to be used for instantiating application objects
59: * when required.
60: *
61: * @param classLoader The new class loader to use, or <code>null</code>
62: * to revert to the standard rules
63: */
64: public void setClassLoader(ClassLoader classLoader) {
65: this .classLoader = classLoader;
66: }
67:
68: /**
69: * Return the boolean as to whether the context classloader should be used.
70: */
71: public boolean getUseContextClassLoader() {
72: return useContextClassLoader;
73: }
74:
75: /**
76: * Determine whether to use the Context ClassLoader (the one found by
77: * calling <code>Thread.currentThread().getContextClassLoader()</code>)
78: * to resolve/load classes. If not
79: * using Context ClassLoader, then the class-loading defaults to
80: * using the calling-class' ClassLoader.
81: *
82: * @param boolean determines whether to use JellyContext ClassLoader.
83: */
84: public void setUseContextClassLoader(boolean use) {
85: useContextClassLoader = use;
86: }
87: }
|