Java Doc for ClassUtil.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.ClassUtil

ClassUtil
public class ClassUtil (Code)
Utility class for loading classes and creating instances. It decides which JDK version to use as the loader. Class instances are put into a Hashtable, based on URL and classname. When the Java-Doc defines a jarName, as in ClassUtil.getClass(String,String) , the jarName may be a filename loadable from the java.io.File class, or a proper URL loadable from the java.net.URL class. If the jarName does not have a protocol, then it is assumed to be a file, otherwise, it is used as a URL.

Note that this class is not thread safe. It is assumed that applications will use the ClassUtil only during initialization times, since dynamic class loading can be very expensive. If you need thread safety, then you will need to ensure that either all class loading is done in a single thread, or that your application properly synchronizes the method calls.

Update v0.9.1: the constructor will now check for jdk2 first like before, but now if it is not found, it will try to use jdk0 compatibility - before, it would just fail out. This allows the libraries to be repackaged to contain only the jdk0 classes if so desired.
author:
   Matt Albrecht groboclown@users.sourceforge.net
version:
   $Date: 2003/02/10 22:52:36 $
since:
   November 13, 2000 (GroboUtils Alpha 0.9.0)



Field Summary
protected static  ClassUtils_instance
     Subclasses must instantiate themselves in this variable in their static initialization block, and overload the ClassUtil.getInstance() static method.

Constructor Summary
protected  ClassUtil()
    

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, String jarName)
     Creates a new instance of the class with the given className using the default constructor, from the given URL.
public  ObjectcreateObject(Class c)
     Creates an Object from the given Class, using its default constructor. All creation exceptions are swallowed.
public  voidflush()
     Call this to flush out the cache.
public  ClassgetClass(String name)
     Either finds or loads from cache the given class, using the default class loader.
Parameters:
  name - the name of the class to load.
public  ClassgetClass(String name, String jarName)
     Either finds or loads from cache the given class.
Parameters:
  name - the name of the class to load.
Parameters:
  jarName - the URL to load the class from - it may be null.
protected  StringgetClassHashName(String name, String jarName)
     Creates the name of the class for the hashtable lookup, which is a junction of the jar name and the class name.
public  StringgetClassPackage(Class c)
     Discovers the package name for the given class.
public static  ClassUtilgetInstance()
     Retrieve the shared instance of the utility class.
public  booleanisJdk2Compatible()
     Checks if the current JVM version is 1.2 compatible.
protected  ClassloadClass(String className, String baseJar)
     Attempts to load the class from the current classpath if baseJar is null, or from the appropriate class loader if it is not null.

Field Detail
s_instance
protected static ClassUtil s_instance(Code)
Subclasses must instantiate themselves in this variable in their static initialization block, and overload the ClassUtil.getInstance() static method.




Constructor Detail
ClassUtil
protected ClassUtil()(Code)
Default constructor - made protected so users won't instantiate the utility




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:   ClassUtil.getClass(String)
See Also:   ClassUtil.createObject(String,String)



createObject
public Object createObject(String className, String jarName)(Code)
Creates a new instance of the class with the given className using the default constructor, from the given URL. 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.
Parameters:
  jarName - the URL to load the class from - it may be null. the new instance, or null if there was a problem.
See Also:   ClassUtil.getClass(String,String)
See Also:   ClassUtil.createObject(String)



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.



flush
public void flush()(Code)
Call this to flush out the cache. The cache may be huge, depending on the Jar files loaded, as well as the Class instances. This should be called whenever a mass class instantiation process is finished.



getClass
public Class getClass(String name)(Code)
Either finds or loads from cache the given class, using the default class loader.
Parameters:
  name - the name of the class to load. the discovered Class, or null if it could not be found.
See Also:   ClassUtil.getClass(String,String)



getClass
public Class getClass(String name, String jarName)(Code)
Either finds or loads from cache the given class.
Parameters:
  name - the name of the class to load.
Parameters:
  jarName - the URL to load the class from - it may be null. the discovered Class, or null if it could not be found.
See Also:   ClassUtil.getClass(String)



getClassHashName
protected String getClassHashName(String name, String jarName)(Code)
Creates the name of the class for the hashtable lookup, which is a junction of the jar name and the class name. It allows for multiple classes with the same name.
Parameters:
  name - the class name
Parameters:
  jarName - the jar name - may be null. the name for the hashtable lookup.



getClassPackage
public String getClassPackage(Class c)(Code)
Discovers the package name for the given class. The package name will not have a final '.'.
Parameters:
  c - the class to find the package name. the package name, or null if c isnull.



getInstance
public static ClassUtil getInstance()(Code)
Retrieve the shared instance of the utility class. the utility instance



isJdk2Compatible
public boolean isJdk2Compatible()(Code)
Checks if the current JVM version is 1.2 compatible. We check by seeing if java.net.URLClassLoader exists. true if java.net.URLClassLoader existsin the classpath, or false otherwise.



loadClass
protected Class loadClass(String className, String baseJar)(Code)
Attempts to load the class from the current classpath if baseJar is null, or from the appropriate class loader if it is not null. If the class is not found, then this returns null. This never throws an exception.
Parameters:
  className - name of the class to load
Parameters:
  baseJar - the URL file to load the class from - may benull. the Class instance, or null if it was not found.



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.