KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > OC4JClassLoader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.oc4j;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.net.URLClassLoader JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import org.openide.ErrorManager;
31
32 /**
33  *
34  * @author Michal Mocnak
35  */

36 public class OC4JClassLoader extends URLClassLoader JavaDoc {
37     
38     private ClassLoader JavaDoc oldLoader;
39     private String JavaDoc serverRoot;
40     
41     private static Map JavaDoc<String JavaDoc, OC4JClassLoader> instances = new HashMap JavaDoc<String JavaDoc, OC4JClassLoader>();
42     
43     /**
44      *
45      * @param serverRoot
46      * @return
47      */

48     public static OC4JClassLoader getInstance(String JavaDoc serverRoot) {
49         OC4JClassLoader instance = instances.get(serverRoot);
50         if (instance == null) {
51             instance = new OC4JClassLoader(serverRoot);
52             instances.put(serverRoot, instance);
53         }
54         return instance;
55     }
56     
57     private OC4JClassLoader(String JavaDoc serverRoot) {
58         super(new URL JavaDoc[0], OC4JDeploymentFactory.class.getClassLoader());
59         
60         this.serverRoot = serverRoot;
61         
62         try{
63             URL JavaDoc[] urls = new URL JavaDoc[] {
64                 new File JavaDoc(serverRoot + "/j2ee/home/lib/adminclient.jar").toURI().toURL(), // NOI18N
65
new File JavaDoc(serverRoot + "/j2ee/home/oc4jclient.jar").toURI().toURL(), // NOI18N
66
new File JavaDoc(serverRoot + "/webservices/lib/wsserver.jar").toURI().toURL(), // NOI18N
67
new File JavaDoc(serverRoot + "/j2ee/home/lib/ejb.jar").toURI().toURL(), // NOI18N
68
new File JavaDoc(serverRoot + "/j2ee/home/lib/mx4j-jmx.jar").toURI().toURL(), // NOI18N
69
new File JavaDoc(serverRoot + "/j2ee/home/lib/jmxri.jar").toURI().toURL(), // NOI18N
70
new File JavaDoc(serverRoot + "/j2ee/home/lib/jmx_remote_api.jar").toURI().toURL(), // NOI18N
71
new File JavaDoc(serverRoot + "/j2ee/home/lib/jaas.jar").toURI().toURL(), // NOI18N
72
new File JavaDoc(serverRoot + "/lib/xmlparserv2.jar").toURI().toURL(), // NOI18N
73
new File JavaDoc(serverRoot + "/oracle/lib/xmlparserv2.jar").toURI().toURL(), // NOI18N
74
new File JavaDoc(serverRoot + "/j2ee/home/lib/javax77.jar").toURI().toURL(), // NOI18N
75
new File JavaDoc(serverRoot + "/j2ee/home/lib/javax88.jar").toURI().toURL(), // NOI18N
76
new File JavaDoc(serverRoot + "/diagnostics/lib/ojdl.jar").toURI().toURL(), // NOI18N
77
new File JavaDoc(serverRoot + "/oracle/lib/dms.jar").toURI().toURL(), // NOI18N
78
new File JavaDoc(serverRoot + "/oracle/jlib/dms.jar").toURI().toURL(), // NOI18N
79
new File JavaDoc(serverRoot + "/lib/dms.jar").toURI().toURL(), // NOI18N
80
new File JavaDoc(serverRoot + "/jlib/dms.jar").toURI().toURL(), // NOI18N
81
new File JavaDoc(serverRoot + "/j2ee/home/lib/jta.jar").toURI().toURL(), // NOI18N
82
new File JavaDoc(serverRoot + "/j2ee/home/lib/jms.jar").toURI().toURL(), // NOI18N
83
new File JavaDoc(serverRoot + "/j2ee/home/lib/connector.jar").toURI().toURL(), // NOI18N
84
new File JavaDoc(serverRoot + "/opmn/lib/optic.jar").toURI().toURL(), // NOI18N
85
new File JavaDoc(serverRoot + "/oracle/jlib/oraclepki.jar").toURI().toURL(), // NOI18N
86
new File JavaDoc(serverRoot + "/jlib/oraclepki.jar").toURI().toURL(), // NOI18N
87
new File JavaDoc(serverRoot + "/oracle/jlib/ojpse.jar").toURI().toURL(),
88                 new File JavaDoc(serverRoot + "/oracle/jdbc/lib/ojdbc14d ms.jar").toURI().toURL(), // NOI18N// NOI18N
89
new File JavaDoc(serverRoot + "/oracle/jdbc/lib/ocrs12.jar").toURI().toURL(), // NOI18N
90
new File JavaDoc(serverRoot + "/oracle/rdbms/jlib/aqapi.jar").toURI().toURL(), // NOI18N
91
new File JavaDoc(serverRoot + "/jlib/ojpse.jar").toURI().toURL() // NOI18N
92
};
93             for (int i = 0; i < urls.length; i++) {
94                 addURL(urls[i]);
95             }
96         }catch(Exception JavaDoc e) {
97             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
98         }
99     }
100     
101     public Enumeration JavaDoc<URL JavaDoc> getResources(String JavaDoc name) throws IOException JavaDoc {
102         // get rid of annoying warnings
103
if (name.indexOf("jndi.properties") != -1) { // NOI18N
104
return Collections.enumeration(Collections.<URL JavaDoc>emptyList());
105         }
106         
107         return super.getResources(name);
108     }
109     
110     public synchronized void updateLoader() {
111         if (!Thread.currentThread().getContextClassLoader().equals(this)) {
112             oldLoader = Thread.currentThread().getContextClassLoader();
113             Thread.currentThread().setContextClassLoader(this);
114         }
115     }
116     
117     public synchronized void restoreLoader() {
118         if (oldLoader != null) {
119             Thread.currentThread().setContextClassLoader(oldLoader);
120             oldLoader = null;
121         }
122     }
123 }
Popular Tags