Android
dalvik.system
public class

dalvik.system.PathClassLoader

java.lang.Object
java.lang.ClassLoader
dalvik.system.PathClassLoader

Simple ClassLoader implementation. This loads classes from a colon-separated list.

Summary

Public Constructors

            PathClassLoader(String path, ClassLoader parent)
Create a ClassLoader that finds files in the specified path.
            PathClassLoader(String path, String libPath, ClassLoader parent)
Create a ClassLoader that finds files in the specified path.

Protected Methods

          Class<?>  findClass(String name)
Find the class with the specified name.
          String  findLibrary(String libname)
Find a native library.
          URL  findResource(String name)
Returns an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.
          Package  getPackage(String name)
Returns package information for the given package.
Methods inherited from class java.lang.ClassLoader
Methods inherited from class java.lang.Object

Details

Public Constructors

public PathClassLoader(String path, ClassLoader parent)

Create a ClassLoader that finds files in the specified path.

public PathClassLoader(String path, String libPath, ClassLoader parent)

Create a ClassLoader that finds files in the specified path. The path is a colon-separated list of files and directories. For Dalvik, this is usually a list of .jar and .apk filenames.

Parameters

path A colon-separated class path.
libPath A colon-separated list of directories where native libraries can be found.
parent The parent class loader.

Protected Methods

protected Class<?> findClass(String name)

Find the class with the specified name. None of our ancestors were able to find it, so it's up to us now. "name" is a "binary name", e.g. "java.lang.String" or "java.net.URLClassLoader$3$1". This method will either return a valid Class object or throw an exception. Does not return null.

Parameters

name The name of the class to search for.

Returns

  • The class or null.

protected String findLibrary(String libname)

Find a native library. Return the full pathname of the first appropriate-looking file we find.

Parameters

libname The name of the library to find.

Returns

  • The library file name or null.

protected URL findResource(String name)

Returns an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm. The default behavior is just to return null. This should be implemented by a ClassLoader.

Parameters

name The name of the resource to find.

Returns

  • The location of the resource.

protected Package getPackage(String name)

Returns package information for the given package. Unfortunately, the PathClassLoader doesn't really have this information, and as a non-secure ClassLoader, it isn't even required to, according to the spec. Yet, we want to provide it, in order to make all those hopeful callers of myClass.getPackage().getName() happy. Thus we construct a Package object the first time it is being requested and fill most of the fields with dummy values. The Package object is then put into the ClassLoader's Package cache, so we see the same one next time. We don't create Package objects for null arguments or for the default package.

There a limited chance that we end up with multiple Package objects representing the same package: It can happen when when a package is scattered across different JAR files being loaded by different ClassLoaders. Rather unlikely, and given that this whole thing is more or less a workaround, probably not worth the effort.

Parameters

name The name of the package to find

Returns

  • The package requested, or null
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56