This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 161284
Collapse All | Expand All

(-)j2ee.websphere6/src/org/netbeans/modules/j2ee/websphere6/WSClassLoader.java (-13 / +90 lines)
Lines 46-57 Link Here
46
46
47
import java.io.File;
47
import java.io.File;
48
import java.io.FileFilter;
48
import java.io.FileFilter;
49
import java.io.IOException;
49
50
50
import java.net.MalformedURLException;
51
import java.net.MalformedURLException;
51
import java.net.URL;
52
import java.net.URL;
52
import java.net.URLClassLoader;
53
import java.net.URLClassLoader;
54
import java.security.AllPermission;
55
import java.security.CodeSource;
56
import java.security.PermissionCollection;
57
import java.security.Permissions;
58
import java.util.ArrayList;
59
import java.util.Collections;
60
import java.util.Enumeration;
53
61
54
import java.util.HashMap;
62
import java.util.HashMap;
63
import java.util.List;
55
import java.util.Map;
64
import java.util.Map;
56
import java.util.logging.Level;
65
import java.util.logging.Level;
57
import java.util.logging.Logger;
66
import java.util.logging.Logger;
Lines 73-78 Link Here
73
     * loader
82
     * loader
74
     */
83
     */
75
    private static Map instances = new HashMap();
84
    private static Map instances = new HashMap();
85
    private Map urlMap = new HashMap();
76
86
77
    /**
87
    /**
78
     * A factory method.
88
     * A factory method.
Lines 82-88 Link Here
82
     * @param serverRoot path to the server installation directory
92
     * @param serverRoot path to the server installation directory
83
     * @param domainRoot path to the profile root directory
93
     * @param domainRoot path to the profile root directory
84
     */
94
     */
85
    public static WSClassLoader getInstance(String serverRoot,
95
    public static WSClassLoader getInstance(URL[] urls,String serverRoot,
86
            String domainRoot) {
96
            String domainRoot) {
87
        if (LOGGER.isLoggable(Level.FINEST)) {
97
        if (LOGGER.isLoggable(Level.FINEST)) {
88
            LOGGER.log(Level.FINEST, "getInstance(" + serverRoot + ", " + domainRoot + ")"); // NOI18N
98
            LOGGER.log(Level.FINEST, "getInstance(" + serverRoot + ", " + domainRoot + ")"); // NOI18N
Lines 93-99 Link Here
93
103
94
        // if it's not, create a new one and register
104
        // if it's not, create a new one and register
95
        if (instance == null) {
105
        if (instance == null) {
96
            instance = new WSClassLoader(serverRoot, domainRoot);
106
            instance = new WSClassLoader(urls,serverRoot, domainRoot);
97
            instances.put(domainRoot, instance);
107
            instances.put(domainRoot, instance);
98
        }
108
        }
99
109
Lines 118-128 Link Here
118
     * @param serverRoot path to the server installation directory
128
     * @param serverRoot path to the server installation directory
119
     * @param domainRoot path to the profile root directory
129
     * @param domainRoot path to the profile root directory
120
     */
130
     */
121
    private WSClassLoader(String serverRoot, String domainRoot) {
131
    private WSClassLoader(URL[] urls,String serverRoot, String domainRoot) {
122
        // we have to isolate the loader from the netbeans main loader in order
132
        // we have to isolate the loader from the netbeans main loader in order
123
        // to avoid conflicts with SOAP classes implementations
133
        // to avoid conflicts with SOAP classes implementations
124
134
125
        super(new URL[0], Thread.currentThread().getContextClassLoader());
135
        super(urls, WSClassLoader.class.getClassLoader());
136
        this.urlMap.put("urls", urls);
126
137
127
        System.out.println("serverRoot:" + serverRoot);
138
        System.out.println("serverRoot:" + serverRoot);
128
        System.out.println("domainRoot:" + domainRoot);
139
        System.out.println("domainRoot:" + domainRoot);
Lines 130-136 Link Here
130
        // save the instance variables
141
        // save the instance variables
131
        this.serverRoot = serverRoot;
142
        this.serverRoot = serverRoot;
132
        this.domainRoot = domainRoot;
143
        this.domainRoot = domainRoot;
133
144
    }
145
    public static URL[] loadClassesToURLs(String serverRoot, String domainRoot) {
134
        // following is to identify whether it is 6.0 or 6.1
146
        // following is to identify whether it is 6.0 or 6.1
135
        // 6.0 has cloudscape dir and 6.1 has derby
147
        // 6.0 has cloudscape dir and 6.1 has derby
136
        String dbDir = "derby";
148
        String dbDir = "derby";
Lines 168-179 Link Here
168
                    new File(serverRoot + "/derby/lib/locales/"),
180
                    new File(serverRoot + "/derby/lib/locales/"),
169
                    new File(serverRoot + "/deploytool/itp/"),
181
                    new File(serverRoot + "/deploytool/itp/"),
170
                    new File(serverRoot + "/deploytool/itp/plugins/"),
182
                    new File(serverRoot + "/deploytool/itp/plugins/"),
183
                    new File(serverRoot + "/runtimes/"),
171
                    //added plugins
184
                    //added plugins
172
                    new File(serverRoot + "/plugins/"),
185
                    new File(serverRoot + "/plugins/"),
173
                    new File(serverRoot + "/etc/"),
186
                    new File(serverRoot + "/etc/"),
174
                    new File(serverRoot + "/optionalLibraries/Apache/Struts/1.1/")};
187
                    new File(serverRoot + "/optionalLibraries/Apache/Struts/1.1/")};
175
        }
188
        }
176
189
         List files = new ArrayList();
177
        // for each directory add all the .jar files to the class path
190
        // for each directory add all the .jar files to the class path
178
        // and finally add the directory itself
191
        // and finally add the directory itself
179
        for (int i = 0; i < directories.length; i++) {
192
        for (int i = 0; i < directories.length; i++) {
Lines 181-201 Link Here
181
            if (directory.exists() && directory.isDirectory()) {
194
            if (directory.exists() && directory.isDirectory()) {
182
                File[] children = directory.listFiles(new JarFileFilter());
195
                File[] children = directory.listFiles(new JarFileFilter());
183
                for (int j = 0; j < children.length; j++) {
196
                for (int j = 0; j < children.length; j++) {
184
                    try {
197
                        files.add(children[j]);                   
185
                        addURL(children[j].toURL());
186
                    } catch (MalformedURLException e) {
187
                        // do nothing just skip this jar file
188
                    }
198
                    }
189
                }
199
                }
200
            files.add(directory);
190
            }
201
            }
202
        
203
           URL[] urls = new URL[files.size()];
204
205
        for (int i = 0; i < files.size(); i++) {
206
            File file = (File) files.get(i);
191
            try {
207
            try {
192
                addURL(directory.toURL());
208
                urls[i] = file.toURI().toURL();
193
            } catch (MalformedURLException e) {
209
            } catch (MalformedURLException e) {
194
                // do nothing just skip this directory
195
            }
210
            }
196
        }
211
        }
212
213
         return urls;
197
    }
214
    }
198
215
216
199
    /**
217
    /**
200
     * Handle for the clasloader that was the context loader for the current
218
     * Handle for the clasloader that was the context loader for the current
201
     * thread before update
219
     * thread before update
Lines 217-222 Link Here
217
        System.setProperty("was.install.root", serverRoot); // NOI18N
235
        System.setProperty("was.install.root", serverRoot); // NOI18N
218
        System.setProperty("was.repository.root", domainRoot // NOI18N
236
        System.setProperty("was.repository.root", domainRoot // NOI18N
219
                + File.separator + "config"); // NOI18N
237
                + File.separator + "config"); // NOI18N
238
        System.setProperty("com.ibm.ssl.performURLHostNameVerification", "true");
220
239
221
        try {
240
        try {
222
            System.setProperty("com.ibm.SOAP.ConfigURL", new File(domainRoot // NOI18N
241
            System.setProperty("com.ibm.SOAP.ConfigURL", new File(domainRoot // NOI18N
Lines 224-231 Link Here
224
                    + "soap.client.props").toURI().toURL().toString()); // NOI18N
243
                    + "soap.client.props").toURI().toURL().toString()); // NOI18N
225
        } catch (MalformedURLException ex) {
244
        } catch (MalformedURLException ex) {
226
            LOGGER.log(Level.INFO, null, ex);
245
            LOGGER.log(Level.INFO, null, ex);
246
        } catch (Exception e) {
247
           LOGGER.log(Level.INFO, null, e);
227
        }
248
        }
228
229
        // if debugging is enabled set the system property pointing to the WS
249
        // if debugging is enabled set the system property pointing to the WS
230
        // debug properties file
250
        // debug properties file
231
        if (LOGGER.isLoggable(Level.FINEST)) {
251
        if (LOGGER.isLoggable(Level.FINEST)) {
Lines 276-279 Link Here
276
            }
296
            }
277
        }
297
        }
278
    }
298
    }
299
    
300
     @Override
301
    protected Class<?> findClass(String name) throws ClassNotFoundException {
302
        Class<?> clazz = super.findClass(name);
303
304
305
        if (LOGGER.isLoggable(Level.FINEST)) {
306
            String filename = name.replace('.', '/'); // NOI18N
307
308
309
            int index = filename.indexOf('$'); // NOI18N
310
311
312
            if (index > 0) {
313
                filename = filename.substring(0, index);
314
315
279
}
316
}
317
            filename = filename + ".class"; // NOI18N
318
319
            URL url = this.getResource(filename);
320
            LOGGER.log(Level.FINEST, "Websphere classloader asked for {0}", name);
321
322
323
            if (url != null) {
324
                LOGGER.log(Level.FINEST, "Websphere classloader found {0} at {1}", new Object[]{name, url});
325
326
327
            }
328
        }
329
        return clazz;
330
331
332
    }
333
334
    @Override
335
    protected PermissionCollection getPermissions(CodeSource codeSource) {
336
        Permissions p = new Permissions();
337
        p.add(new AllPermission());       
338
        return p;
339
340
341
    }
342
343
    @Override
344
    public Enumeration<URL> getResources(String name) throws IOException {
345
        // get rid of annoying warnings
346
        if (name.indexOf("jndi.properties") != -1 || name.indexOf("i18n_user.properties") != -1) { // NOI18N
347
            return Collections.enumeration(Collections.<URL>emptyList());
348
349
350
        }
351
352
        return super.getResources(name);
353
354
355
    }
356
}

Return to bug 161284