01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.catalina.startup;
19:
20: import java.lang.reflect.Method;
21: import org.apache.catalina.Container;
22: import org.apache.tomcat.util.digester.Rule;
23: import org.xml.sax.Attributes;
24:
25: /**
26: * <p>Rule that copies the <code>parentClassLoader</code> property from the
27: * next-to-top item on the stack (which must be a <code>Container</code>)
28: * to the top item on the stack (which must also be a
29: * <code>Container</code>).</p>
30: *
31: * @author Craig R. McClanahan
32: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
33: */
34:
35: public class CopyParentClassLoaderRule extends Rule {
36:
37: // ----------------------------------------------------------- Constructors
38:
39: /**
40: * Construct a new instance of this Rule.
41: */
42: public CopyParentClassLoaderRule() {
43: }
44:
45: // --------------------------------------------------------- Public Methods
46:
47: /**
48: * Handle the beginning of an XML element.
49: *
50: * @param attributes The attributes of this element
51: *
52: * @exception Exception if a processing error occurs
53: */
54: public void begin(String namespace, String name,
55: Attributes attributes) throws Exception {
56:
57: if (digester.getLogger().isDebugEnabled())
58: digester.getLogger().debug("Copying parent class loader");
59: Container child = (Container) digester.peek(0);
60: Object parent = digester.peek(1);
61: Method method = parent.getClass().getMethod(
62: "getParentClassLoader", new Class[0]);
63: ClassLoader classLoader = (ClassLoader) method.invoke(parent,
64: new Object[0]);
65: child.setParentClassLoader(classLoader);
66:
67: }
68:
69: }
|