KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > util > ConnectorRARClassLoader


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors.util;
25
26 import java.security.SecureClassLoader JavaDoc;
27
28 /**
29  * ConnectorRARClassLoader finds classes and resources from a
30  * JAR file without exploding it. This uses the JarResourceExtractor
31  * for finding classes and resources inside the archive
32  *
33  * This classloader is _used_ only by the admin GUI to retrieve resource
34  * adapter class properties without exploding the connector archive.
35  *
36  * @author Sivakumar Thyagarajan
37  */

38 public class ConnectorRARClassLoader extends SecureClassLoader JavaDoc{
39     private JarResourceExtractor jarResources;
40     
41     public ConnectorRARClassLoader(String JavaDoc jarName, ClassLoader JavaDoc parent) {
42         super(parent);
43         // Create the JarResource and suck in the .jar file.
44
jarResources = new JarResourceExtractor(jarName);
45     }
46     
47     protected byte[] loadClassBytes(String JavaDoc className) {
48         className = formatClassName(className);
49         return (jarResources.getResource(className));
50     }
51
52     public Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
53         byte[] b = loadClassBytes(name);
54         if (b == null) {
55             throw new ClassNotFoundException JavaDoc(name);
56         }
57         return defineClass(name, b, 0, b.length);
58     }
59
60     private String JavaDoc formatClassName(String JavaDoc className) {
61         return className.replace('.', '/') + ".class";
62     }
63
64     public String JavaDoc getResourceAsString(String JavaDoc raDeploymentDescPath) {
65         return new String JavaDoc(jarResources.getResource(raDeploymentDescPath));
66     }
67     
68 }
69
Popular Tags