01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.jbossmx.implementation.server.support;
23:
24: import java.io.IOException;
25: import java.io.*;
26: import java.rmi.MarshalledObject;
27:
28: import org.apache.log4j.Category;
29:
30: /** The ContextCL standard MBean implementation.
31: *
32: * @author Scott.Stark@jboss.org
33: * @version $Revision: 57211 $
34: */
35: public class ContextCL implements ContextCLMBean {
36: private static Category log = Category.getInstance(ContextCL.class);
37: private TestData data0;
38:
39: /** The TestData.class ClassLoader will be the ClassLoader of the ContextCL
40: *mbean because we have a static reference to the TestData class. This
41: *causes the VM to call the ClassLoader.loadClassInternal method.
42: */
43: public ContextCL() throws IOException {
44: ClassLoader cl = Thread.currentThread().getContextClassLoader();
45: log.info("ContextCL ClassLoader: "
46: + getClass().getClassLoader());
47: log.info("ctor Context ClassLoader: " + cl);
48: data0 = new TestData();
49: log.info("TestData.class ProtectionDomain: "
50: + TestData.class.getProtectionDomain());
51: }
52:
53: /** An operation that load the TestData class using the current thread
54: *context class loader (TCL) and the Class.forName(String, boolean, ClassLoader)
55: *operation to validate that the class loader used to load TestData in
56: *the ctor is compatible with the operation TCL.
57: */
58: public void useTestData() throws Exception {
59: ClassLoader cl = Thread.currentThread().getContextClassLoader();
60: log.info("useTestData ClassLoader: " + cl);
61: Class c0 = data0.getClass();
62: log.info("TestData #0 ProtectionDomain: "
63: + c0.getProtectionDomain());
64: Class c1 = Class
65: .forName(
66: "org.jboss.test.jbossmx.implementation.server.support.TestData",
67: false, cl);
68: log.info("TestData #1 ProtectionDomain: "
69: + c1.getProtectionDomain());
70: if (c1.isInstance(data0) == false) {
71: log
72: .error("Assertion failed: data0 is NOT compatible with c1");
73: throw new IllegalStateException(
74: "data0 is NOT compatible with c1");
75: }
76: }
77: }
|