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.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.JPF;
21 import java.net.MalformedURLException;
24 import gov.nasa.jpf.annotation.MJI;
25 import gov.nasa.jpf.util.JPFLogger;
28 * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
30 * Native peer for java.net.URLClassLoader
32 public class JPF_java_net_URLClassLoader extends JPF_java_lang_ClassLoader{
34 static JPFLogger log = JPF.getLogger("class");
37 public void addURL0__Ljava_lang_String_2__V (MJIEnv env, int objRef, int urlRef) throws MalformedURLException {
38 ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
39 String url = env.getStringObject(urlRef);
43 String protocol = u.getProtocol();
44 if(protocol.equals("file")) {
46 } else if(protocol.equals("jar")){
47 path = url.substring(url.lastIndexOf(':')+1, url.indexOf('!'));
49 // we don't support other protocols for now!
50 log.warning("unknown path element specification: ", url);
54 cl.addClassPathElement(path);
58 public int findClass__Ljava_lang_String_2__Ljava_lang_Class_2 (MJIEnv env, int objRef, int nameRef) {
59 String typeName = env.getStringObject(nameRef);
60 ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
61 ThreadInfo ti = env.getThreadInfo();
64 ClassInfo ci = cl.getResolvedClassInfo( typeName);
65 if(!ci.isRegistered()) {
66 ci.registerClass(env.getThreadInfo());
68 // note that we don't initialize yet
69 return ci.getClassObjectRef();
71 } catch (LoadOnJPFRequired rre) { // this classloader has a overridden loadClass
72 env.repeatInvocation();
75 } catch (ClassInfoException cix){
76 if (cix.getCause() instanceof ClassParseException){
77 env.throwException("java.lang.ClassFormatError", typeName);
79 env.throwException("java.lang.ClassNotFoundException", typeName);
86 public int findResource0__Ljava_lang_String_2__Ljava_lang_String_2 (MJIEnv env, int objRef, int resRef){
87 String rname = env.getStringObject(resRef);
89 ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
91 String resourcePath = cl.findResource(rname);
93 return env.newString(resourcePath);
97 public int findResources0__Ljava_lang_String_2___3Ljava_lang_String_2 (MJIEnv env, int objRef, int resRef) {
98 String rname = env.getStringObject(resRef);
100 ClassLoaderInfo cl = env.getClassLoaderInfo(objRef);
102 String[] resources = cl.findResources(rname);
104 return env.newStringArray(resources);