Java Doc for ClassLoadHelper.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » util » classes » v1 » 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 » Test Coverage » GroboUtils » net.sourceforge.groboutils.util.classes.v1 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sourceforge.groboutils.util.classes.v1.ClassLoadHelper

ClassLoadHelper
public class ClassLoadHelper (Code)
Utility class for loading classes and creating instances. Much of the basic operation have been ripped from net.groboutils.util.classes.v1.ClassUtil in the GroboUtils package. If the helper's class loader is null, then it will use the Thread's context ClassLoader.

Note that resource loading is very tricky. Finding the right classloader and right methods to invoke is JDK dependent.
author:
   Matt Albrecht groboclown@users.sourceforge.net
version:
   $Date: 2003/02/10 22:52:36 $
since:
   March 16, 2002




Constructor Summary
public  ClassLoadHelper()
     Default constructor - will use the Thread's context class loader for each class discovery.
public  ClassLoadHelper(Class clazz)
     Use the given class's classloader.
public  ClassLoadHelper(ClassLoader cl)
     Loads the helper with the given class loader.

Method Summary
public  ObjectcreateObject(String className)
     Creates a new instance of the class with the given className using the default constructor.
public  ObjectcreateObject(String className, boolean swallowExceptions)
     Creates a new instance of the class with the given className using the default constructor.
public  ObjectcreateObject(Class c)
     Creates an Object from the given Class, using its default constructor. All creation exceptions are swallowed.
public  ObjectcreateObject(Class c, boolean swallowExceptions)
     Creates an Object from the given Class, using its default constructor. If there was an error during the creation, such as the class was not found, the class does not have a default constructor, or the constructor threw an exception, then an IllegalStateException will be thrown only if swallowExceptions is false; otherwise, null will be returned.
Parameters:
  c - the Class object from which a new instance will be createdusing its default constructor.
Parameters:
  swallowExceptions - true if this method is to returnnull on any exceptions, or false if it shouldthrow an IllegalStateException on any error.
public  ObjectcreateObjectFromProperty(String propertyClassName, Class defaultClass, boolean swallowExceptions)
     Loads an object using the ClassLoadHelper.createObject(String,boolean) method above, using the given System property's value as the class name.
public  ObjectcreateObjectFromProperty(String propertyClassName, Class defaultClass, Hashtable properties, boolean swallowExceptions)
     Loads an object using the ClassLoadHelper.createObject(String,boolean) method above, using the given Hashtable's property's value as the class name.
protected static  MethoddiscoverContextClassloaderMethod()
    
protected static  MethoddiscoverGetResourcesMethod()
    
protected static  MethoddiscoverGetSystemResourcesMethod()
    
protected  StringgetAbsoluteResourceName(String name)
    
public  ClassgetClass(String name)
     Loads the requested class from the helper's classloader, and returns the Class instance, or null if the class could not be found.
Parameters:
  name - the name of the class to load.
public  ClassgetClass(String name, boolean swallowExceptions)
     Loads the requested class from the helper's classloader, and returns the Class instance, or null if the class could not be found.
protected  ClassLoadergetClassLoader()
     Gets the correct class loader.
public  URLgetResource(String name)
     Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions.
public  URLgetResource(String name, ClassLoader cl)
     Loads a resource with the given name, using the given ClassLoader. Does not swallow exceptions.
public  InputStreamgetResourceAsStream(String name)
     Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions.
public  EnumerationgetResources(String name)
     Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions.
public  EnumerationgetResources(String name, ClassLoader cl)
     Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions.
public  URLgetSystemResource(String name)
     Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions.
public  EnumerationgetSystemResources(String name)
     Get the resource associated with the given name from the System classloader.
protected static  ClassLoadergetThreadClassLoader(Thread t)
     Use reflection to get the thread (context) class loader.
protected  ClassloadClass(String name)
     Loads a class with the given name, using the correct ClassLoader.


Constructor Detail
ClassLoadHelper
public ClassLoadHelper()(Code)
Default constructor - will use the Thread's context class loader for each class discovery.



ClassLoadHelper
public ClassLoadHelper(Class clazz)(Code)
Use the given class's classloader.
Parameters:
  clazz - the class to pull the classloader from.
exception:
  NullPointerException - if clazz is null.



ClassLoadHelper
public ClassLoadHelper(ClassLoader cl)(Code)
Loads the helper with the given class loader. If the given class loader is null, then it will use the Thread's context class loader.
Parameters:
  cl - the classloader to pull all requested classes from, orit will use the thread's context class loader if cl isnull.
See Also:   java.lang.Thread.getContextClassLoader




Method Detail
createObject
public Object createObject(String className)(Code)
Creates a new instance of the class with the given className using the default constructor. If there was an error during the creation, such as the class was not found, the class does not have a default constructor, or the constructor threw an exception, then null is returned.
Parameters:
  className - the name of the class to create an instance. the new instance, or null if there was a problem.
See Also:   ClassLoadHelper.getClass(String)
See Also:   ClassLoadHelper.createObject(String,boolean)
See Also:   ClassLoadHelper.createObject(Class)
See Also:   ClassLoadHelper.createObject(Class,boolean)



createObject
public Object createObject(String className, boolean swallowExceptions)(Code)
Creates a new instance of the class with the given className using the default constructor. If there was an error during the creation, such as the class was not found, the class does not have a default constructor, or the constructor threw an exception, then an IllegalStateException will be thrown only if swallowExceptions is false; otherwise, null will be returned.
Parameters:
  className - the name of the class to create an instance.
Parameters:
  swallowExceptions - true if this method is to returnnull on any exceptions, or false if it shouldthrow an IllegalStateException on any error. the new instance.
exception:
  IllegalStateException - if there was an error duringinitialization and swallowExceptions is false.
See Also:   ClassLoadHelper.getClass(String)
See Also:   ClassLoadHelper.createObject(String)
See Also:   ClassLoadHelper.createObject(Class)
See Also:   ClassLoadHelper.createObject(Class,boolean)



createObject
public Object createObject(Class c)(Code)
Creates an Object from the given Class, using its default constructor. All creation exceptions are swallowed. If the object could not be created, then null is returned.
Parameters:
  c - the Class object from which a new instance will be createdusing its default constructor. the instantiated object, or null if c isnull, or if there was an error during initialization.



createObject
public Object createObject(Class c, boolean swallowExceptions)(Code)
Creates an Object from the given Class, using its default constructor. If there was an error during the creation, such as the class was not found, the class does not have a default constructor, or the constructor threw an exception, then an IllegalStateException will be thrown only if swallowExceptions is false; otherwise, null will be returned.
Parameters:
  c - the Class object from which a new instance will be createdusing its default constructor.
Parameters:
  swallowExceptions - true if this method is to returnnull on any exceptions, or false if it shouldthrow an IllegalStateException on any error. the instantiated object, or null if c isnull, or if there was an error during initialization andswallowExceptions is true.
exception:
  IllegalStateException - if there was an error duringinitialization and swallowExceptions is false.



createObjectFromProperty
public Object createObjectFromProperty(String propertyClassName, Class defaultClass, boolean swallowExceptions)(Code)
Loads an object using the ClassLoadHelper.createObject(String,boolean) method above, using the given System property's value as the class name. If the System property is not defined, then it resorts to the default class.
Parameters:
  propertyClassName - the System Property name, whose value will beused as a fully-qualified Class name to load and instantiate andreturn.
Parameters:
  defaultClass - if the System Property propertyClassNameis not defined, then this will be the class to instantiate andreturn.
Parameters:
  swallowExceptions - true if this method is to returnnull on any exceptions, or false if it shouldthrow an IllegalStateException on any error. the instantiated class.
exception:
  IllegalStateException - if there was an error duringinitialization and swallowExceptions is false.



createObjectFromProperty
public Object createObjectFromProperty(String propertyClassName, Class defaultClass, Hashtable properties, boolean swallowExceptions)(Code)
Loads an object using the ClassLoadHelper.createObject(String,boolean) method above, using the given Hashtable's property's value as the class name. If the Hashtable property is not defined, then it resorts to the default class. If the Hashtable is null, then the System property will be used instead.
Parameters:
  propertyClassName - the System Property name, whose value will beused as a fully-qualified Class name to load and instantiate andreturn.
Parameters:
  defaultClass - if the System Property propertyClassNameis not defined, then this will be the class to instantiate andreturn.
Parameters:
  properties - a Hashtable of String -> String mappings.
Parameters:
  swallowExceptions - true if this method is to returnnull on any exceptions, or false if it shouldthrow an IllegalStateException on any error. the instantiated class.
exception:
  IllegalStateException - if there was an error duringinitialization and swallowExceptions is false.



discoverContextClassloaderMethod
protected static Method discoverContextClassloaderMethod()(Code)



discoverGetResourcesMethod
protected static Method discoverGetResourcesMethod()(Code)



discoverGetSystemResourcesMethod
protected static Method discoverGetSystemResourcesMethod()(Code)



getAbsoluteResourceName
protected String getAbsoluteResourceName(String name)(Code)



getClass
public Class getClass(String name)(Code)
Loads the requested class from the helper's classloader, and returns the Class instance, or null if the class could not be found.
Parameters:
  name - the name of the class to load. the discovered Class, or null if it could not be found.



getClass
public Class getClass(String name, boolean swallowExceptions)(Code)
Loads the requested class from the helper's classloader, and returns the Class instance, or null if the class could not be found.
Parameters:
  name - the name of the class to load.
Parameters:
  swallowExceptions - true if this method is to return the discovered Class, or null if it could not be foundand swallowExceptions is true.
exception:
  IllegalStateException - if there was an error duringinitialization and swallowExceptions is false.



getClassLoader
protected ClassLoader getClassLoader()(Code)
Gets the correct class loader. May return null. the ClassLoader



getResource
public URL getResource(String name) throws IOException(Code)
Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource. the resource name as an URL, which may possibly benull.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getResource
public URL getResource(String name, ClassLoader cl) throws IOException(Code)
Loads a resource with the given name, using the given ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource.
Parameters:
  cl - the classloader to load the reference from. the resource name as an URL, which may possibly benull.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getResourceAsStream
public InputStream getResourceAsStream(String name) throws IOException(Code)
Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource. the resource as an InputStream, which may possibly benull.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getResources
public Enumeration getResources(String name) throws IOException(Code)
Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource. the list of resource URLs, which may NOT be null(implementation ensures it is not null).
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResources(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getResources
public Enumeration getResources(String name, ClassLoader cl) throws IOException(Code)
Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource.
Parameters:
  cl - the classloader to load the references from. a non-null list of resource URLs for the resource name.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResources(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getSystemResource
public URL getSystemResource(String name) throws IOException(Code)
Loads a resource with the given name, using the correct ClassLoader. Does not swallow exceptions. See the JDK documentation on resources (they are pretty much files that are in the classpath of the classloader). Yes, this can be used successfully to get a class file (well, JDK 1.1 throws a SecurityException if this is attempted).
Parameters:
  name - absolute referece to the expected resource. the resource name as an URL, which may possibly benull.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getSystemResources
public Enumeration getSystemResources(String name) throws IOException(Code)
Get the resource associated with the given name from the System classloader. This will never return null.
Parameters:
  name - absolute referece to the expected resource. a non-null list of URLs matching the resource.
exception:
  IOException - if an I/O error occurs.
See Also:   java.lang.ClassLoader.getResource(String)
See Also:   java.lang.ClassLoader.getResources(String)
See Also:   java.lang.ClassLoader.getResourceAsStream(String)



getThreadClassLoader
protected static ClassLoader getThreadClassLoader(Thread t)(Code)
Use reflection to get the thread (context) class loader.



loadClass
protected Class loadClass(String name) throws ClassNotFoundException, LinkageError, IllegalArgumentException(Code)
Loads a class with the given name, using the correct ClassLoader. Does not swallow exceptions.
exception:
  ClassNotFoundException - if the class name is not known by theclass loader.
exception:
  LinkageError - if there was a basic class loader error.
exception:
  IllegalArgumentException - if the class doesn't smell right toJDK 1.1.



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.