KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > JarClassLoader


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 package com.sun.enterprise.util;
24
25 // import java.util.zip.*;
26
// import java.util.*;
27
// import java.io.InputStream;
28
// import java.io.BufferedInputStream;
29

30 import java.io.IOException JavaDoc;
31 import java.io.File JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.HashSet JavaDoc;
34
35 import java.net.URL JavaDoc;
36 import com.sun.enterprise.util.FileUtil;
37
38 //START OF IASRI 4660742
39
import java.util.logging.*;
40 import com.sun.logging.*;
41 //END OF IASRI 4660742
42

43 // IASRI 4709925 - updated ejb class loader
44
import com.sun.enterprise.loader.EJBClassLoader;
45
46 public class JarClassLoader extends EJBClassLoader {
47
48     // START OF IASRI 4660742
49
static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER);
50     // END OF IASRI 4660742
51

52     // START OF IASRI 4679641
53
// private static final boolean debug = false;
54
private static final boolean debug = com.sun.enterprise.util.logging.Debug.enabled;
55     // END OF IASRI 4679641
56

57     public JarClassLoader() {
58         super(ConnectorClassLoader.getInstance());
59     }
60
61     public JarClassLoader(String JavaDoc jarName) throws IOException JavaDoc {
62         super(ConnectorClassLoader.getInstance());
63         addJar(jarName);
64     }
65     
66     /**
67      * Add a JAR to the list of JARs we search for a class's bytecodes.
68      */

69     
70     public synchronized void addJar(String JavaDoc jarName) throws IOException JavaDoc {
71     // The URL is OS specific. On Solaris, file:/xyz and file:///xyz work.
72
// On NT, file://c:/xyz and file:/c:/xyz work.
73
// So we let the java.io.File create a URL for us.
74
File JavaDoc file = new File JavaDoc(FileUtil.getAbsolutePath(jarName));
75     /** IASRI 4660742
76     if(debug)
77         System.err.println("JarClassLoader.addJar: url=" + file.toURL());
78     **/

79     //START OF IASRI 4660742
80
if(debug && _logger.isLoggable(Level.FINE)) {
81         _logger.log(Level.FINE,"JarClassLoader.addJar: url=" + file.toURL());
82   }
83     //END OF IASRI 4660742
84

85     appendURL(file);
86     }
87
88     public void addDir(URL JavaDoc url) throws IOException JavaDoc {
89     /** IASRI 4660742
90     if(debug)
91         System.err.println("JarClassLoader.addDir: url=" + url);
92     **/

93     //START OF IASRI 4660742
94
if(debug && _logger.isLoggable(Level.FINE)) {
95         _logger.log(Level.INFO,"JarClassLoader.addDir: url=" + url);
96   }
97     //END OF IASRI 4660742
98
appendURL(url);
99     }
100
101     public String JavaDoc getClassPath() {
102     String JavaDoc cpath = "";
103     URL JavaDoc[] urls = getURLs();
104     String JavaDoc sep = File.pathSeparator;
105
106     for(int i=0; i < urls.length; ++i) {
107         cpath = cpath + sep + urls[i].getFile();
108     }
109
110     return cpath;
111     }
112 }
113
114
115
116
117
118
Popular Tags