01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.jmeter;
19:
20: import java.net.URL;
21: import java.net.URLClassLoader;
22: import java.net.URLStreamHandlerFactory;
23:
24: /**
25: * @author pete
26: *
27: * This is a basic URL classloader for loading new resources
28: * dynamically.
29: *
30: * It allows public access to the addURL() method.
31: *
32: * It also adds a convenience method to update the current thread classloader
33: *
34: */
35: public class DynamicClassLoader extends URLClassLoader {
36:
37: public DynamicClassLoader(URL[] urls) {
38: super (urls);
39: }
40:
41: public DynamicClassLoader(URL[] urls, ClassLoader parent) {
42: super (urls, parent);
43: }
44:
45: public DynamicClassLoader(URL[] urls, ClassLoader parent,
46: URLStreamHandlerFactory factory) {
47: super (urls, parent, factory);
48: }
49:
50: // Make the addURL method visible
51: public void addURL(URL url) {
52: super .addURL(url);
53: }
54:
55: /**
56: *
57: * @param urls - list of URLs to add to the thread's classloader
58: */
59: public static void updateLoader(URL[] urls) {
60: DynamicClassLoader loader = (DynamicClassLoader) Thread
61: .currentThread().getContextClassLoader();
62: for (int i = 0; i < urls.length; i++) {
63: loader.addURL(urls[i]);
64: }
65: }
66: }
|