KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > implementation > server > support > ContextCL


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import java.io.*;
26 import java.rmi.MarshalledObject JavaDoc;
27
28 import org.jboss.logging.Logger;
29
30 /** The ContextCL standard MBean implementation.
31  *
32  * @author Scott.Stark@jboss.org
33  * @version $Revision: 58115 $
34  */

35 public class ContextCL implements ContextCLMBean
36 {
37    private static Logger log = Logger.getLogger(ContextCL.class);
38    private TestData data0;
39
40    /** The TestData.class ClassLoader will be the ClassLoader of the ContextCL
41     *mbean because we have a static reference to the TestData class. This
42     *causes the VM to call the ClassLoader.loadClassInternal method.
43     */

44    public ContextCL() throws IOException JavaDoc
45    {
46       ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
47       log.info("ContextCL ClassLoader: "+getClass().getClassLoader());
48       log.info("ctor Context ClassLoader: "+cl);
49       data0 = new TestData();
50       log.info("TestData.class ProtectionDomain: "+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 JavaDoc
59    {
60       ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
61       log.info("useTestData ClassLoader: "+cl);
62       Class JavaDoc c0 = data0.getClass();
63       log.info("TestData #0 ProtectionDomain: "+c0.getProtectionDomain());
64       Class JavaDoc c1 = Class.forName("org.jboss.test.jbossmx.implementation.server.support.TestData",
65          false, cl);
66       log.info("TestData #1 ProtectionDomain: "+c1.getProtectionDomain());
67       if( c1.isInstance(data0) == false )
68       {
69          log.error("Assertion failed: data0 is NOT compatible with c1");
70          throw new IllegalStateException JavaDoc("data0 is NOT compatible with c1");
71       }
72    }
73 }
74
Popular Tags