WebObjects 5.2.3

com.webobjects.eoapplication
Class EOURLClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended bycom.webobjects.eoapplication.EOURLClassLoader

public class EOURLClassLoader
extends URLClassLoader

EOURLClassLoader is an URLClassLoader that can be used to add classes to your program at runtime. Provided a url or set of urls to search through, and a class to load, the class loader will look for the class in the set of classes available at the URLs it knows of. Once a matching class is found the class is registered with the WebObjects frameworks so that other classes in the WebObjects runtime will know about it.

This is useful specifically for Java Client applications so that classes needed by the client application can be downloaded on demand. EOApplication uses the shared class loader if the bindings of the WOJavaClientApplet that application connects to specifies classes for the client to download. Developers can also use this class to add classes to the running Java Client application.

Example: First, add the NSArray of url(s) for the class loader to search through using EOURLClassLoader.sharedURLClassLoader().addURLs(). Then call EOURLClassLoader.sharedURLClassLoader().loadClass() to load an individual class, or EOURLClassLoader.sharedURLClassLoader().loadClasses() to load an array of classes. The classes are then registered with the WebObjects frameworks using the static registerClass method.

To use your custom subclass of EOURLClassLoader in an EOApplication, make sure that you set your class loader as the default class loader with setSharedURLClassLoader before EOApplication's startApplication method is invoked (write your own main function which prepares the class loader and then jumps into EOApplication's main function).

See Also:
URLClassLoader

Constructor Summary
EOURLClassLoader(URL[] urls)
          Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes.
EOURLClassLoader(URL[] urls, ClassLoader parentClassLoader)
          Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes.
EOURLClassLoader(URL[] urls, ClassLoader parentClassLoader, URLStreamHandlerFactory streamHandlerFactory)
          Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes.
 
Method Summary
 void addURLs(NSArray urls)
          Adds the URLs specified by String in the array urls to the list of urls for the class loader to search when trying to load a class.
 NSArray allLoadedClasses()
          Returns all of the class objects that have been loaded through the class loader instance.
protected  Class loadClass(String className, boolean resolveClass)
          Tries to load the class named className and registers it with the WebObjects frameworks.
 void loadClasses(NSArray classNames)
          Tries to load the classes specified by name in the array classNames and registers them with the WebObjects frameworks.
static void registerClass(Class objectClass)
          Registers a class loaded with an EOURLClassLoader with the WebObjects frameworks.
static void setSharedURLClassLoader(EOURLClassLoader classLoader)
          Sets the class loader object to use as the shared EOURLClassLoader class loader.
static EOURLClassLoader sharedURLClassLoader()
          Returns the shared EOURLClassLoader class loader instance.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EOURLClassLoader

public EOURLClassLoader(URL[] urls)
Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes. The parent class loader will be the default parent class loader.

Parameters:
urls - array of URL objects

EOURLClassLoader

public EOURLClassLoader(URL[] urls,
                        ClassLoader parentClassLoader)
Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes. The parent class loader will be parentClassLoader.

Parameters:
urls - array of URL objects
parentClassLoader - the parent class loader for the new EOURLClassLoader

EOURLClassLoader

public EOURLClassLoader(URL[] urls,
                        ClassLoader parentClassLoader,
                        URLStreamHandlerFactory streamHandlerFactory)
Creates a new EOURLClassLoader object initialized to search at the URLs urls for classes. The parent class loader will be parentClassLoader and the stream handler factory will be streamHandlerFactory.

Parameters:
urls - array of URL objects
parentClassLoader - the parent class loader for the new EOURLClassLoader
streamHandlerFactory - the stream handler factory for the new EOURLClassLoader
Method Detail

addURLs

public void addURLs(NSArray urls)
             throws MalformedURLException
Adds the URLs specified by String in the array urls to the list of urls for the class loader to search when trying to load a class.

Parameters:
urls - array of String's representing URLs
Throws:
MalformedURLException

allLoadedClasses

public NSArray allLoadedClasses()
Returns all of the class objects that have been loaded through the class loader instance.

Returns:
array of all the classes loaded by the class loader

loadClass

protected Class loadClass(String className,
                          boolean resolveClass)
                   throws ClassNotFoundException
Tries to load the class named className and registers it with the WebObjects frameworks. If the class loader (or one of its parent class loaders) cannot find the class, this method throws a ClassNotFoundException.

Parameters:
className - the fully specified name of the class to load
resolveClass - true if the class loader will try to resolve the class immediately; false otherwise
Returns:
the class object if found
Throws:
ClassNotFoundException

loadClasses

public void loadClasses(NSArray classNames)
                 throws ClassNotFoundException
Tries to load the classes specified by name in the array classNames and registers them with the WebObjects frameworks. If the class loader (or one of its parent class loaders) cannot find one of the classes, this method throws a ClassNotFoundException.

Parameters:
classNames - array of fully specified class names to load
Throws:
ClassNotFoundException

registerClass

public static void registerClass(Class objectClass)
Registers a class loaded with an EOURLClassLoader with the WebObjects frameworks.

Parameters:
objectClass - Class object to register

setSharedURLClassLoader

public static void setSharedURLClassLoader(EOURLClassLoader classLoader)
Sets the class loader object to use as the shared EOURLClassLoader class loader.

Parameters:
classLoader - the EOURLClassLoader (or subclass) instance to use as the shared class loader

sharedURLClassLoader

public static EOURLClassLoader sharedURLClassLoader()
Returns the shared EOURLClassLoader class loader instance.

Returns:
the shared class loader instance

Last updated Thu Oct 21 15:04:16 PDT 2004.

Copyright © 2004 Apple Computer, Inc.