01: /*
02: * Copyright 1999-2001,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:
17: package org.apache.catalina.startup;
18:
19: import java.lang.reflect.Method;
20: import org.apache.catalina.Container;
21: import org.apache.commons.digester.Rule;
22: import org.xml.sax.Attributes;
23:
24: /**
25: * <p>Rule that copies the <code>parentClassLoader</code> property from the
26: * next-to-top item on the stack (which must be a <code>Container</code>)
27: * to the top item on the stack (which must also be a
28: * <code>Container</code>).</p>
29: *
30: * @author Craig R. McClanahan
31: * @version $Revision: 1.4 $ $Date: 2004/05/26 16:16:31 $
32: */
33:
34: public class CopyParentClassLoaderRule extends Rule {
35:
36: // ----------------------------------------------------------- Constructors
37:
38: /**
39: * Construct a new instance of this Rule.
40: */
41: public CopyParentClassLoaderRule() {
42: }
43:
44: // --------------------------------------------------------- Public Methods
45:
46: /**
47: * Handle the beginning of an XML element.
48: *
49: * @param attributes The attributes of this element
50: *
51: * @exception Exception if a processing error occurs
52: */
53: public void begin(String namespace, String name,
54: Attributes attributes) throws Exception {
55:
56: if (digester.getLogger().isDebugEnabled())
57: digester.getLogger().debug("Copying parent class loader");
58: Container child = (Container) digester.peek(0);
59: Object parent = digester.peek(1);
60: Method method = parent.getClass().getMethod(
61: "getParentClassLoader", new Class[0]);
62: ClassLoader classLoader = (ClassLoader) method.invoke(parent,
63: new Object[0]);
64: child.setParentClassLoader(classLoader);
65:
66: }
67:
68: }
|