Java Doc for MultiClassLoader.java in  » J2EE » Enhydra-Application-Framework » com » lutris » classloader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Application Framework » com.lutris.classloader 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.lang.ClassLoader
      com.lutris.classloader.MultiClassLoader

MultiClassLoader
public class MultiClassLoader extends ClassLoader (Code)

Summary:

A class loader that can load classes from class files and zip files residing in a specified class path.

This class loader can also load resources that reside on the class path and return them as is, as input streams, or as byte arrays.

Features:

  • Loads classes from class files and zip files.
  • Finds resources and can return them as is, as input streams and as byte arrays.
  • Loads classes and resources using the specified class path. Class path entries can be URLs, directories, zip files or jar files.

    A secondary classloader can be specified which is used to locate the class if its not found by this classloader.

  • A filter object can be supplied to determine if the current class loader should load the class or it should be passed to the parent or secondary class loader.

Class Path

If classes are to be loaded from a class path, it must be set by the setClassPath or addClassPath methods or by the constructor prior to calling loadClass. If the class path is not set, the class will be loaded with the system class loader.

The class path can consist of directories, files, and/or URLs.

Example valid class path entries are:

 Files and directories on the local file system
 ../../java/classes
 /users/kristen/java/classes
 /users/kristen/java/classes/
 /users/kristen/java/zipfiles/MyClasses.zip
 /users/kristen/java/jarfiles/MyClasses.jar
 file:///users/kristen/java/classes
 file://localhost/users/kristen/java/classes
 
Files and directories on a remote file system (must be in URL format) ftp://www.foo.com/pub/java/classes file://www.foo.com/pub/java/classes/ http://www.foo.com/web/java/classes/ file://www.foo.com:8080/pub/java/zipfiles/MyClasses.zip http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar

Note that the location of the entry includes the protocol, the host name, and the port while the file name is everything else. For example,

 http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar
 
has the form [location][name] or
 [http://www.foo.com:8080/][/web/java/jarfiles/MyClasses.jar]
 
so the location is "http://www.foo.com:8080/" and the name is "/web/java/jarfiles/MyClasses.jar".

Note that the two references

 /users/kristen/java/classes/
 file:///users/kristen/java/classes/
 
represent the same directory on a Unix machine, and
 C|/windows/java/classes/
 file:///C|/windows/java/classes/
 
are equivalent directories on a Windows box.

But the two references

 /users/kristen/java/classes/
 file://monet.lutris.com/users/kristen/java/classes/
 
are not equivalent even if the directory /users/kristen/java/classes/ lives on the machine named monet.lutris.com and all development is on this machine. Why? Because the web (browser?) protocol is different for URLs with host information and those without. If no host is specified, the file is assumed to be on the local machine and the path is determined from the ROOT of the machine. If the host is specified, then the ftp protocol is used and the path is determined from the ftp ROOT (e.g. /users/ftp/) rather than the machine's ROOT. Thus, on a machine that support's anonymous ftp, the following two directories are the same:
 /users/ftp/pub/classes/
 file://picasso.lutris.com/pub/classes/
 
assuming the development is being done on picasso.lutris.com.

System Class Path

The system class path is the system-dependent path of directories and files (e.g. CLASSPATH on Unix and Windows) used by the system class loader to load classes. This class path is usually configured prior to executing a Java program but can be dynamically configured during runtime if desired. If you want to use the system class path for this class loader, the convenience method getSystemClassPath has been provided.

Valid system class path entries are directories and zip files, specified by absolute path or relative path on the system. Any valid system class path entry is also valid for this class loader.

Example

Here is an example of how to use this class loader:

 MultiClassLoader loader = new MultiClassLoader();
 loader.setClassPath("/web/java/lutris.jar");
 loader.addClassPath("/users/kristen/java/");
 loader.addClassPath("/usr/local/lib/graphics.zip");
 try {
 Class c = loader.loadClass("com.lutris.util.MyClass");
 System.out.println("My loader is " + c.getClassLoader());
 Object o = (Object) c.newInstance();
 System.out.println("My class is " + o.getClass());
 } catch (ClassNotFoundException e) {
 Throwable t = new Throwable();
 t.printStackTrace();
 }
 

Warning: This class loader is not yet fully compliant with Java 1.2. It maybe used on 1.2, but not all features are available. The parent loader, secondary loader, and filter may change in a future release without maintaining compatibility.
author:
   Kristen Pol, Lutris Technologies
version:
   $Revision : 1.0 $
See Also:   java.lang.ClassLoader
See Also:   com.lutris.classloader.Resource
See Also:   java.net.URL


Inner Class :public interface ClassFilter
Inner Class :public static class ClassResource

Field Summary
final public static  StringLOG_LEVEL
    

Constructor Summary
public  MultiClassLoader(ClassLoader parent, ClassLoader secondary, LogChannel loadLogChannel)
     Constructs class loader with no initial class path and a specified parent class loader.
public  MultiClassLoader(LogChannel loadLogChannel)
     Constructs class loader with no initial class path and the system class loader as the secondary.
public  MultiClassLoader(String path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.
public  MultiClassLoader(String[] path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.
public  MultiClassLoader(File path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.
public  MultiClassLoader(File[] path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.
public  MultiClassLoader(URL path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.
public  MultiClassLoader(URL[] path, LogChannel loadLogChannel)
     Constructs class loader with specified class path.

Method Summary
public synchronized  voidaddClassFilter(ClassFilter filter)
     Add a filter to the list of filters that check if a class maybe loaded by this class loader.
public  voidaddClassPath(String path)
     Adds specified class path to beginning of existing path.
public synchronized  voidaddClassPath(String[] path)
     Adds specified class path to beginning of existing path.
public  voidaddClassPath(File path)
     Adds specified class path to beginning of existing path.
public synchronized  voidaddClassPath(File[] path)
     Adds specified class path to beginning of existing path.
public  voidaddClassPath(URL path)
     Adds specified class path to beginning of existing path.
public synchronized  voidaddClassPath(URL[] path)
     Adds specified class path to beginning of existing path.
public synchronized  voidclearClassPath()
     Clears class path entries.
public  voidenableAutoReloadForSecLoader(boolean enable)
     Sets flag to enable Auto Reloading possibility when Secondary ClassLoader usage is forced (refer to forceSecondaryLoader() method for more help).
public  voidforceSecondaryLoader(boolean force)
     Sets flag to indicate forsing of Secondary ClassLoader usage or not.
Parameters:
  force - true when the MultiClassLoader is used as utility wrapperclass for passed secondary ClassLoader.
public  URL[]getClassPath()
     Gets class path for class loader defined previously by constructor and setClassPath/addClassPath methods.
public  ResourcegetClassResource(String className)
     Get the resource for a class loaded by this class loader.
public  LogChannelgetLogChannel()
     Get the log channel associated this class loader.
public  URLgetResource(String name)
     Gets specified resource as URL.
public  byte[]getResourceAsByteArray(String name)
     Gets specified resource as array of bytes.
Parameters:
  name - The name of the resource.
public  ResourcegetResourceAsIs(String name)
     Gets specified resource object.
public  InputStreamgetResourceAsStream(String name)
     Gets specified resource as input stream.
Parameters:
  name - The name of the resource.
public  ResourcegetResourceObject(String name)
     Gets specified resource object.
Parameters:
  name - The name of the resource.
public  ClassLoadergetSecondary()
     Get the secondary class loader.
public static  URL[]getSystemClassPath()
     Gets class path from system.
public  ClassloadClass(String className, boolean resolve)
     Loads and, optionally, resolves the specified class.
public  ClassloadClass(String className)
    
public static  String[]parseClassPath(String path)
     Parse a class-path string using the system path separator.
public  voidremoveLoadedClass()
    
public  voidsetClassPath(String path)
     Sets class loader with specified class path.
public synchronized  voidsetClassPath(String[] path)
     Sets class loader with specified class path.
public  voidsetClassPath(File path)
     Sets class loader with specified class path.
public synchronized  voidsetClassPath(File[] path)
     Sets class loader with specified class path.
public  voidsetClassPath(URL path)
     Sets class loader with specified class path.
public synchronized  voidsetClassPath(URL[] path)
     Sets class loader with specified class path.
public  voidsetParent(ClassLoader parent)
     Set the parent class loader for delegation.
public  voidsetSecondary(ClassLoader secondary)
     Set the secondary class loader.
public  booleanshouldReload()
     Determine if the classes loaded by this class loader have been modified. If any file associated with loaded in the class loader's class path has changed, the classes should be reloaded.

Field Detail
LOG_LEVEL
final public static String LOG_LEVEL(Code)
Log level symbolic name




Constructor Detail
MultiClassLoader
public MultiClassLoader(ClassLoader parent, ClassLoader secondary, LogChannel loadLogChannel)(Code)
Constructs class loader with no initial class path and a specified parent class loader.
Parameters:
  parent - The parent class loader for delegation,or null if no parent is defined.
Parameters:
  secondary - The secondary class loader.Use getSysClassLoader to get the system class loaderto specify as the secondary.
Parameters:
  loadLogChannel - The log channel, maybe null.
See Also:   getSysClassLoader



MultiClassLoader
public MultiClassLoader(LogChannel loadLogChannel)(Code)
Constructs class loader with no initial class path and the system class loader as the secondary.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(String path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is assumed to be either a directory, URL, or zip file.
Parameters:
  path - The class path represented by a String.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(String[] path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is assumed to be an array of directories, URLs, and/or zip files.
Parameters:
  path - The class path represented by a String array.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(File path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is assumed to be either a zip file or directory.
Parameters:
  path - The class path represented by a File.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(File[] path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is assumed to be an array of zip files and/or directories.
Parameters:
  path - The class path represented by a File array.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(URL path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is represent a directory or zip file on the local machine or a remote machine.
Parameters:
  path - The class path represented by a URL.
Parameters:
  loadLogChannel - The log channel, maybe null.



MultiClassLoader
public MultiClassLoader(URL[] path, LogChannel loadLogChannel)(Code)
Constructs class loader with specified class path. The parameter is represent directories and/or zip files on the local machine and/or on remote machines.
Parameters:
  path - The class path represented by a URL array.
Parameters:
  loadLogChannel - The log channel, maybe null.




Method Detail
addClassFilter
public synchronized void addClassFilter(ClassFilter filter)(Code)
Add a filter to the list of filters that check if a class maybe loaded by this class loader.



addClassPath
public void addClassPath(String path)(Code)
Adds specified class path to beginning of existing path. The parameter is assumed to be either a directory, URL, or zip file.
Parameters:
  path - The class path to be added to current class path.



addClassPath
public synchronized void addClassPath(String[] path)(Code)
Adds specified class path to beginning of existing path. The parameter is assumed to be an array of directories, URLs, and/or zip files.
Parameters:
  path - The class path to be added to current class path.



addClassPath
public void addClassPath(File path)(Code)
Adds specified class path to beginning of existing path. The parameter is assumed to be either a zip file or directory.
Parameters:
  path - The class path to be added to current class path.



addClassPath
public synchronized void addClassPath(File[] path)(Code)
Adds specified class path to beginning of existing path. The parameter is assumed to be an array of zip files and/or directories.
Parameters:
  path - The class path to be added to current class path.



addClassPath
public void addClassPath(URL path)(Code)
Adds specified class path to beginning of existing path. The parameter is represent a directory or zip file on the local machine or a remote machine.
Parameters:
  path - The class path to be added to current class path.



addClassPath
public synchronized void addClassPath(URL[] path)(Code)
Adds specified class path to beginning of existing path. The parameter is represent directories and/or zip files on the local machine and/or on remote machines.
Parameters:
  path - The class path to be added to current class path.



clearClassPath
public synchronized void clearClassPath()(Code)
Clears class path entries.
See Also:   MultiClassLoader.setClassPath



enableAutoReloadForSecLoader
public void enableAutoReloadForSecLoader(boolean enable)(Code)
Sets flag to enable Auto Reloading possibility when Secondary ClassLoader usage is forced (refer to forceSecondaryLoader() method for more help). This flag has no efect when MultiClassLoader is used in standard maner (as realy ClassLoader, not only as wrapper class for external ClassLoader)
Parameters:
  enable - true when the AutoReloading should be used.



forceSecondaryLoader
public void forceSecondaryLoader(boolean force)(Code)
Sets flag to indicate forsing of Secondary ClassLoader usage or not.
Parameters:
  force - true when the MultiClassLoader is used as utility wrapperclass for passed secondary ClassLoader. All resource loads will be forcedvia passed Secondary ClassLoader. If parameter is set to false, then theMultyClassLoader will work in standard maner.



getClassPath
public URL[] getClassPath()(Code)
Gets class path for class loader defined previously by constructor and setClassPath/addClassPath methods. the class path represented by an Enumerationof URL objects.
See Also:   MultiClassLoader.setClassPath
See Also:   MultiClassLoader.addClassPath
See Also:   



getClassResource
public Resource getClassResource(String className) throws ClassNotFoundException(Code)
Get the resource for a class loaded by this class loader.



getLogChannel
public LogChannel getLogChannel()(Code)
Get the log channel associated this class loader.



getResource
public URL getResource(String name)(Code)
Gets specified resource as URL. Doing a getContent() on the URL may return an Image, an AudioClip, or an InputStream.
Parameters:
  name - The name of the resource. the resource represented by a URL, or null if not found.



getResourceAsByteArray
public byte[] getResourceAsByteArray(String name)(Code)
Gets specified resource as array of bytes.
Parameters:
  name - The name of the resource. an array of bytes representing the specified resource ornull if the resource is not found.



getResourceAsIs
public Resource getResourceAsIs(String name)(Code)
Gets specified resource object.
See Also:   deprecated
See Also:    Use getResourceObject()
See Also:   getResourceObject



getResourceAsStream
public InputStream getResourceAsStream(String name)(Code)
Gets specified resource as input stream.
Parameters:
  name - The name of the resource. an input stream representing the specified resource ornull if the resource is not found.



getResourceObject
public Resource getResourceObject(String name)(Code)
Gets specified resource object.
Parameters:
  name - The name of the resource. the resource if found, null if not.
See Also:   Resource



getSecondary
public ClassLoader getSecondary()(Code)
Get the secondary class loader.



getSystemClassPath
public static URL[] getSystemClassPath()(Code)
Gets class path from system. the system class path represented by anarray of URL objects.



loadClass
public Class loadClass(String className, boolean resolve) throws ClassNotFoundException(Code)
Loads and, optionally, resolves the specified class. If the class needs to be instantiated, the class must be resolved. If only the existence of the class needs verification, class resolution is unnecessary. Calling loadClass(String className) is equivalent to calling this method with resolve set to true. Purposely not synchronized. If class is not found in loadedClasses table, then doLoadClass will do the operation in a synchronized manner.
Parameters:
  className - The name of the class to be loaded, e.g."com.lutris.util.Table".
Parameters:
  resolve - Set to true for class resolution,false for no resolution. the loaded Class.
exception:
  ClassNotFoundException - if the class could not be load.
See Also:   MultiClassLoader.setClassPath
See Also:   MultiClassLoader.addClassPath



loadClass
public Class loadClass(String className) throws ClassNotFoundException(Code)



parseClassPath
public static String[] parseClassPath(String path)(Code)
Parse a class-path string using the system path separator.



removeLoadedClass
public void removeLoadedClass()(Code)
Removes stored data about already loaded classes



setClassPath
public void setClassPath(String path)(Code)
Sets class loader with specified class path. The parameter is assumed to be either a directory, URL, or zip file.
Parameters:
  path - The class path to be used when loading classes.



setClassPath
public synchronized void setClassPath(String[] path)(Code)
Sets class loader with specified class path. The parameter is assumed to be an array of directories, URLs, and/or zip files.
Parameters:
  path - The class path to be used when loading classes.



setClassPath
public void setClassPath(File path)(Code)
Sets class loader with specified class path. The parameter is assumed to be either a zip file or directory.
Parameters:
  path - The class path to be used when loading classes.



setClassPath
public synchronized void setClassPath(File[] path)(Code)
Sets class loader with specified class path. The parameter is assumed to be an array of zip files and/or directories.
Parameters:
  path - The class path to be used when loading classes.



setClassPath
public void setClassPath(URL path)(Code)
Sets class loader with specified class path. The parameter is represent a directory or zip file on the local machine or a remote machine.
Parameters:
  path - The class path to be used when loading classes.



setClassPath
public synchronized void setClassPath(URL[] path)(Code)
Sets class loader with specified class path. The parameter is represent directories and/or zip files on the local machine and/or on remote machines.
Parameters:
  path - The class path to be used when loading classes.



setParent
public void setParent(ClassLoader parent)(Code)
Set the parent class loader for delegation.



setSecondary
public void setSecondary(ClassLoader secondary)(Code)
Set the secondary class loader.



shouldReload
public boolean shouldReload()(Code)
Determine if the classes loaded by this class loader have been modified. If any file associated with loaded in the class loader's class path has changed, the classes should be reloaded. If the classes need to be reloaded, a new instance of this class loader must be created because a particular class loader instance can only load classes once. true if the classes should be reloaded,false if not.



Methods inherited from java.lang.ClassLoader
public synchronized void clearAssertionStatus()(Code)(Java Doc)
final protected Class defineClass(byte[] b, int off, int len) throws ClassFormatError(Code)(Java Doc)
final protected Class defineClass(String name, byte[] b, int off, int len) throws ClassFormatError(Code)(Java Doc)
final protected Class defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) throws ClassFormatError(Code)(Java Doc)
final protected Class defineClass(String name, java.nio.ByteBuffer b, ProtectionDomain protectionDomain) throws ClassFormatError(Code)(Java Doc)
protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException(Code)(Java Doc)
protected Class findClass(String name) throws ClassNotFoundException(Code)(Java Doc)
protected String findLibrary(String libname)(Code)(Java Doc)
final protected Class findLoadedClass(String name)(Code)(Java Doc)
protected URL findResource(String name)(Code)(Java Doc)
protected Enumeration<URL> findResources(String name) throws IOException(Code)(Java Doc)
final protected Class findSystemClass(String name) throws ClassNotFoundException(Code)(Java Doc)
protected Package getPackage(String name)(Code)(Java Doc)
protected Package[] getPackages()(Code)(Java Doc)
final public ClassLoader getParent()(Code)(Java Doc)
public URL getResource(String name)(Code)(Java Doc)
public InputStream getResourceAsStream(String name)(Code)(Java Doc)
public Enumeration<URL> getResources(String name) throws IOException(Code)(Java Doc)
public static ClassLoader getSystemClassLoader()(Code)(Java Doc)
public static URL getSystemResource(String name)(Code)(Java Doc)
public static InputStream getSystemResourceAsStream(String name)(Code)(Java Doc)
public static Enumeration<URL> getSystemResources(String name) throws IOException(Code)(Java Doc)
public Class loadClass(String name) throws ClassNotFoundException(Code)(Java Doc)
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException(Code)(Java Doc)
final protected void resolveClass(Class c)(Code)(Java Doc)
public synchronized void setClassAssertionStatus(String className, boolean enabled)(Code)(Java Doc)
public synchronized void setDefaultAssertionStatus(boolean enabled)(Code)(Java Doc)
public synchronized void setPackageAssertionStatus(String packageName, boolean enabled)(Code)(Java Doc)
final protected void setSigners(Class c, Object[] signers)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.