Android
java.net
public class

java.net.URLClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader

This class loader is responsible for loading classes and resources from a list of URLs which can refer to either directories or JAR files. Classes loaded by this URLClassLoader are granted permission to access the URLs contained in the URL search list.

Summary

Public Constructors

            URLClassLoader(URL[] urls)
Constructs a new instance of this class.
            URLClassLoader(URL[] urls, ClassLoader parent)
Constructs a new instance of this class.
            URLClassLoader(URL[] searchUrls, ClassLoader parent, URLStreamHandlerFactory factory)
Constructs a new instance of this class.

Public Methods

          URL  findResource(String name)
Returns a URL referencing the specified resource or null if no resource could be found.
          Enumeration<URL findResources(String name)
Returns an enumeration of URLs that contain the specified resource.
          URL[]  getURLs()
Returns the search list of this URLClassLoader
      static    URLClassLoader  newInstance(URL[] urls, ClassLoader parentCl)
Returns an instance of URLClassLoader.
      static    URLClassLoader  newInstance(URL[] urls)
Returns an instance of URLClassLoader.

Protected Methods

          void  addURL(URL url)
Adds the specified URL to the search list.
          Package  definePackage(String packageName, Manifest manifest, URL url)
Define a new Package using information extracted from the specified Manifest.
          Class<?>  findClass(String clsName)
Locates and loads the specified class, searching this URLClassLoader's list of URLS.
          PermissionCollection  getPermissions(CodeSource codesource)
Returns the permissions for the given code source.
Methods inherited from class java.security.SecureClassLoader
Methods inherited from class java.lang.ClassLoader
Methods inherited from class java.lang.Object

Details

Public Constructors

public URLClassLoader(URL[] urls)

Constructs a new instance of this class. The newly created instance will have the system ClassLoader as its parent. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters

urls the URLs to search

Throws

SecurityException if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders

public URLClassLoader(URL[] urls, ClassLoader parent)

Constructs a new instance of this class. The newly created instance will have the specified ClassLoader as its parent. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters

urls the URLs to search
parent the ClassLoader to assign as this loader's parent.

Throws

SecurityException if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders

public URLClassLoader(URL[] searchUrls, ClassLoader parent, URLStreamHandlerFactory factory)

Constructs a new instance of this class. The newly created instance will have the specified ClassLoader as its parent and use the specified factory to create stream handlers. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters

searchUrls java.net.URL[] the URLs that will be searched in the order they were specified for resource
parent ClassLoader the ClassLoader name of the resource to find.
factory java.net.URLStreamHandlerFactory the factory that will used to create stream (protocol) handlers

Throws

SecurityException if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders

Public Methods

public URL findResource(String name)

Returns a URL referencing the specified resource or null if no resource could be found.

Parameters

name java.lang.String the name of the requested resource

Returns

  • URL URL for the resource.

public Enumeration<URL> findResources(String name)

Returns an enumeration of URLs that contain the specified resource.

Parameters

name java.lang.String the name of the requested resource

Returns

  • Enumeration the enumeration of URLs that contain the specified resource.

Throws

IOException thrown if an IO Exception occurs while attempting to connect

public URL[] getURLs()

Returns the search list of this URLClassLoader

Returns

  • java.net.URL[]

public static URLClassLoader newInstance(URL[] urls, ClassLoader parentCl)

Returns an instance of URLClassLoader. loadClass() of the new instance will call security manager's checkPackageAccess() before loading a class.

Parameters

urls URL[] the list of URLs that is passed to the new URLClassloader
parentCl ClassLoader the parent class loader that is passed to the new URLClassloader

Returns

  • URLClassLoader the new instance of URLClassLoader

public static URLClassLoader newInstance(URL[] urls)

Returns an instance of URLClassLoader. loadClass() of the new instance will call the SecurityManager's checkPackageAccess() before loading a class.

Parameters

urls java.net.URL[] a list of URLs that is passed to the new URLClassloader

Returns

  • java.net.URLClassLoader the new instance of URLClassLoader

Protected Methods

protected void addURL(URL url)

Adds the specified URL to the search list.

Parameters

url java.net.URL the new URL

protected Package definePackage(String packageName, Manifest manifest, URL url)

Define a new Package using information extracted from the specified Manifest.

Parameters

packageName The name of the package
manifest The Manifest for the Package
url The code source for the Package

Returns

  • The Package created

Throws

IllegalArgumentException if the Package already exists

protected Class<?> findClass(String clsName)

Locates and loads the specified class, searching this URLClassLoader's list of URLS.

Parameters

clsName String the name of the class.

Returns

  • Class the class that has been loaded.

Throws

ClassNotFoundException if the class cannot be loaded

protected PermissionCollection getPermissions(CodeSource codesource)

Returns the permissions for the given code source. First this method retrieves the permissions from the system policy. If the protocol is "file:/" then a new permission, FilePermission, granting the read permission to the file is added to the permission collection. Otherwise, connecting to and accepting connections from the URL is granted.

Parameters

codesource CodeSource

Returns

  • PermissionCollection
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56