2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import java.io.IOException;
21 import java.security.CodeSource;
22 import java.security.PermissionCollection;
23 import java.security.SecureClassLoader;
24 import java.util.ArrayList;
25 import java.util.Enumeration;
26 import java.util.Vector;
27 import java.util.jar.Manifest;
30 * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
32 * Model class for java.net.URLClassLoader
34 public class URLClassLoader extends SecureClassLoader {
36 private ArrayList<URL> urls = new ArrayList<URL>(0);
38 public URLClassLoader(URL[] urls) {
43 public URLClassLoader(URL[] urls, ClassLoader parent) {
48 private void addURLs(URL[] urls) {
54 private native void addURL0(String url);
56 protected void addURL(URL url) {
57 addURL0(url.toString());
62 protected native Class<?> findClass(final String name) throws ClassNotFoundException;
64 private native String findResource0 (String rname);
67 public URL findResource(final String rname) {
69 String path = findResource0(rname);
73 } catch (MalformedURLException x){
80 private native String[] findResources0 (String rname);
83 public Enumeration<URL> findResources(String name) throws IOException {
84 String[] urls = findResources0(name);
85 Vector<URL> list = new Vector<URL>(0);
86 for(String url: urls) {
88 list.add(new URL(url));
89 } catch (MalformedURLException x){
94 return list.elements();
97 public URL[] getURLs() {
98 return urls.toArray(new URL[urls.size()]);
101 public static URLClassLoader newInstance(URL[] urls) {
102 return (new URLClassLoader(urls));
105 public static URLClassLoader newInstance(URL[] urls, ClassLoader parent) {
106 return (new URLClassLoader(urls, parent));
109 //--- unsupported methods
111 public URLClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
112 throw new UnsupportedOperationException();
115 public void close() throws IOException {
116 throw new UnsupportedOperationException();
119 protected Package definePackage(String name, Manifest man, URL url)
120 throws IllegalArgumentException {
121 throw new UnsupportedOperationException();
124 protected PermissionCollection getPermissions(CodeSource codesource) {
125 throw new UnsupportedOperationException();