Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / gnu / gcj / runtime / SharedLibLoader.java
blobb8e6a57de536f94fccf9ed7c56fbedf4f6ffe44d
1 /* Copyright (C) 2001, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.gcj.runtime;
10 import java.io.IOException;
11 import java.net.MalformedURLException;
12 import java.net.URL;
13 import java.security.CodeSource;
14 import java.util.Enumeration;
15 import java.util.Vector;
17 /**
18 * A ClassLoader backed by a gcj-compiled shared library.
19 * @author Per Bothner <per@bothner.com>, Brainfood Inc.
22 public class SharedLibLoader extends ClassLoader
24 /** Load a shared library, and associate a ClassLoader with it.
25 * @param libname named of shared library (passed to dlopen)
26 * @param parent the parent ClassLoader
27 * @parem flags passed to dlopen
29 public SharedLibLoader(String libname, ClassLoader parent, int flags)
31 super(parent);
32 URL url;
33 try
35 url = new URL("file", "", libname);
37 catch (MalformedURLException _)
39 url = null;
41 helper = SharedLibHelper.findHelper(this, libname,
42 new CodeSource(url, null), true);
45 /** Load a shared library, and asociate a ClassLoader with it.
46 * @param libname named of shared library (passed to dlopen)
48 public SharedLibLoader(String libname)
50 this(libname, getSystemClassLoader(), 0);
53 public Class findClass(String name)
54 throws ClassNotFoundException
56 Class cls = helper.findClass(name);
57 if (cls == null)
58 throw new ClassNotFoundException(name);
59 return cls;
62 public URL findResource (String name)
64 return helper.findResource(name);
67 public Enumeration findResources (String name) throws IOException
69 URL url = findResource(name);
70 if (url == null)
71 return null;
72 Vector v = new Vector(1);
73 v.add(url);
74 return v.elements();
77 /** The helper that does the work for us. */
78 SharedLibHelper helper;