Java Doc for ClassUtils.java in  » Library » Apache-common-lang » org » apache » commons » lang » 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 » Library » Apache common lang » org.apache.commons.lang 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.lang.ClassUtils

ClassUtils
public class ClassUtils (Code)

Operates on classes without using reflection.

This class handles invalid null inputs as best it can. Each method documents its behaviour in more detail.


author:
   Stephen Colebourne
author:
   Gary Gregory
author:
   Norm Deane
author:
   Alban Peignier
since:
   2.0
version:
   $Id: ClassUtils.java 437554 2006-08-28 06:21:41Z bayard $


Field Summary
final public static  StringINNER_CLASS_SEPARATOR
    
final public static  charINNER_CLASS_SEPARATOR_CHAR
    
final public static  StringPACKAGE_SEPARATOR
    
final public static  charPACKAGE_SEPARATOR_CHAR
    

Constructor Summary
public  ClassUtils()
    

ClassUtils instances should NOT be constructed in standard programming.


Method Summary
public static  ListconvertClassNamesToClasses(List classNames)
    

Given a List of class names, this method converts them into classes.

A new List is returned.

public static  ListconvertClassesToClassNames(List classes)
    

Given a List of Class objects, this method converts them into class names.

A new List is returned.

public static  ListgetAllInterfaces(Class cls)
    

Gets a List of all interfaces implemented by the given class and its superclasses.

The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up.

public static  ListgetAllSuperclasses(Class cls)
    
public static  ClassgetClass(ClassLoader classLoader, String className, boolean initialize)
     Returns the class represented by className using the classLoader.
public static  ClassgetClass(ClassLoader classLoader, String className)
     Returns the (initialized) class represented by className using the classLoader.
public static  ClassgetClass(String className)
     Returns the (initialized )class represented by className using the current thread's context class loader.
public static  ClassgetClass(String className, boolean initialize)
     Returns the class represented by className using the current thread's context class loader.
public static  StringgetPackageName(Object object, String valueIfNull)
    
public static  StringgetPackageName(Class cls)
    

Gets the package name of a Class.


Parameters:
  cls - the class to get the package name for, may be null.
public static  StringgetPackageName(String className)
    
public static  MethodgetPublicMethod(Class cls, String methodName, Class parameterTypes)
    

Returns the desired Method much like Class.getMethod, however it ensures that the returned Method is from a public class or interface and not from an anonymous inner class.

public static  StringgetShortClassName(Object object, String valueIfNull)
    
public static  StringgetShortClassName(Class cls)
    

Gets the class name minus the package name from a Class.


Parameters:
  cls - the class to get the short name for.
public static  StringgetShortClassName(String className)
    
public static  booleanisAssignable(Class[] classArray, Class[] toClassArray)
    

Checks if an array of Classes can be assigned to another array of Classes.

This method calls ClassUtils.isAssignable(Class,Class) isAssignable for each Class pair in the input arrays.

public static  booleanisAssignable(Class cls, Class toClass)
    

Checks if one Class can be assigned to a variable of another Class.

Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double.

public static  booleanisInnerClass(Class cls)
    
public static  ClassprimitiveToWrapper(Class cls)
    

Converts the specified primitive Class object to its corresponding wrapper Class object.

NOTE: From v2.2, this method handles Void.TYPE, returning Void.TYPE.


Parameters:
  cls - the class to convert, may be null the wrapper class for cls or cls ifcls is not a primitive.
public static  Class[]primitivesToWrappers(Class[] classes)
    

Converts the specified array of primitive Class objects to an array of its corresponding wrapper Class objects.


Parameters:
  classes - the class array to convert, may be null or empty an array which contains for each given class, the wrapper class orthe original class if class is not a primitive.

Field Detail
INNER_CLASS_SEPARATOR
final public static String INNER_CLASS_SEPARATOR(Code)

The inner class separator String: "$".




INNER_CLASS_SEPARATOR_CHAR
final public static char INNER_CLASS_SEPARATOR_CHAR(Code)

The inner class separator character: '$' == .




PACKAGE_SEPARATOR
final public static String PACKAGE_SEPARATOR(Code)

The package separator String: ".".




PACKAGE_SEPARATOR_CHAR
final public static char PACKAGE_SEPARATOR_CHAR(Code)

The package separator character: '.' == .





Constructor Detail
ClassUtils
public ClassUtils()(Code)

ClassUtils instances should NOT be constructed in standard programming. Instead, the class should be used as ClassUtils.getShortClassName(cls).

This constructor is public to permit tools that require a JavaBean instance to operate.





Method Detail
convertClassNamesToClasses
public static List convertClassNamesToClasses(List classNames)(Code)

Given a List of class names, this method converts them into classes.

A new List is returned. If the class name cannot be found, null is stored in the List. If the class name in the List is null, null is stored in the output List.


Parameters:
  classNames - the classNames to change a List of Class objects corresponding to the class names,null if null input
throws:
  ClassCastException - if classNames contains a non String entry



convertClassesToClassNames
public static List convertClassesToClassNames(List classes)(Code)

Given a List of Class objects, this method converts them into class names.

A new List is returned. null objects will be copied into the returned list as null.


Parameters:
  classes - the classes to change a List of class names corresponding to the Class objects,null if null input
throws:
  ClassCastException - if classes contains a non-Class entry



getAllInterfaces
public static List getAllInterfaces(Class cls)(Code)

Gets a List of all interfaces implemented by the given class and its superclasses.

The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order is maintained.


Parameters:
  cls - the class to look up, may be null the List of interfaces in order,null if null input



getAllSuperclasses
public static List getAllSuperclasses(Class cls)(Code)

Gets a List of superclasses for the given class.


Parameters:
  cls - the class to look up, may be null the List of superclasses in order going up from this onenull if null input



getClass
public static Class getClass(ClassLoader classLoader, String className, boolean initialize) throws ClassNotFoundException(Code)
Returns the class represented by className using the classLoader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
Parameters:
  classLoader - the class loader to use to load the class
Parameters:
  className - the class name
Parameters:
  initialize - whether the class must be initialized the class represented by className using the classLoader
throws:
  ClassNotFoundException - if the class is not found



getClass
public static Class getClass(ClassLoader classLoader, String className) throws ClassNotFoundException(Code)
Returns the (initialized) class represented by className using the classLoader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
Parameters:
  classLoader - the class loader to use to load the class
Parameters:
  className - the class name the class represented by className using the classLoader
throws:
  ClassNotFoundException - if the class is not found



getClass
public static Class getClass(String className) throws ClassNotFoundException(Code)
Returns the (initialized )class represented by className using the current thread's context class loader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
Parameters:
  className - the class name the class represented by className using the current thread's context class loader
throws:
  ClassNotFoundException - if the class is not found



getClass
public static Class getClass(String className, boolean initialize) throws ClassNotFoundException(Code)
Returns the class represented by className using the current thread's context class loader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
Parameters:
  className - the class name
Parameters:
  initialize - whether the class must be initialized the class represented by className using the current thread's context class loader
throws:
  ClassNotFoundException - if the class is not found



getPackageName
public static String getPackageName(Object object, String valueIfNull)(Code)

Gets the package name of an Object.


Parameters:
  object - the class to get the package name for, may be null
Parameters:
  valueIfNull - the value to return if null the package name of the object, or the null value



getPackageName
public static String getPackageName(Class cls)(Code)

Gets the package name of a Class.


Parameters:
  cls - the class to get the package name for, may be null. the package name or an empty string



getPackageName
public static String getPackageName(String className)(Code)

Gets the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

If the class is unpackaged, return an empty string.


Parameters:
  className - the className to get the package name for, may be null the package name or an empty string



getPublicMethod
public static Method getPublicMethod(Class cls, String methodName, Class parameterTypes) throws SecurityException, NoSuchMethodException(Code)

Returns the desired Method much like Class.getMethod, however it ensures that the returned Method is from a public class or interface and not from an anonymous inner class. This means that the Method is invokable and doesn't fall foul of Java bug 4071957).

Set set = Collections.unmodifiableSet(...);
 Method method = ClassUtils.getPublicMethod(set.getClass(), "isEmpty",  new Class[0]);
 Object result = method.invoke(set, new Object[]);


Parameters:
  cls - the class to check, not null
Parameters:
  methodName - the name of the method
Parameters:
  parameterTypes - the list of parameters the method
throws:
  NullPointerException - if the class is null
throws:
  SecurityException - if a a security violation occured
throws:
  NoSuchMethodException - if the method is not found in the given classor if the metothod doen't conform with the requirements



getShortClassName
public static String getShortClassName(Object object, String valueIfNull)(Code)

Gets the class name minus the package name for an Object.


Parameters:
  object - the class to get the short name for, may be null
Parameters:
  valueIfNull - the value to return if null the class name of the object without the package name, or the null value



getShortClassName
public static String getShortClassName(Class cls)(Code)

Gets the class name minus the package name from a Class.


Parameters:
  cls - the class to get the short name for. the class name without the package name or an empty string



getShortClassName
public static String getShortClassName(String className)(Code)

Gets the class name minus the package name from a String.

The string passed in is assumed to be a class name - it is not checked.


Parameters:
  className - the className to get the short name for the class name of the class without the package name or an empty string



isAssignable
public static boolean isAssignable(Class[] classArray, Class[] toClassArray)(Code)

Checks if an array of Classes can be assigned to another array of Classes.

This method calls ClassUtils.isAssignable(Class,Class) isAssignable for each Class pair in the input arrays. It can be used to check if a set of arguments (the first parameter) are suitably compatible with a set of method parameter types (the second parameter).

Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.

Null may be assigned to any reference type. This method will return true if null is passed in and the toClass is non-primitive.

Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.


Parameters:
  classArray - the array of Classes to check, may be null
Parameters:
  toClassArray - the array of Classes to try to assign into, may be null true if assignment possible



isAssignable
public static boolean isAssignable(Class cls, Class toClass)(Code)

Checks if one Class can be assigned to a variable of another Class.

Unlike the Class.isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double. This method returns the correct result for these cases.

Null may be assigned to any reference type. This method will return true if null is passed in and the toClass is non-primitive.

Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion widening primitive or widening reference conversion. See The Java Language Specification, sections 5.1.1, 5.1.2 and 5.1.4 for details.


Parameters:
  cls - the Class to check, may be null
Parameters:
  toClass - the Class to try to assign into, returns false if null true if assignment possible



isInnerClass
public static boolean isInnerClass(Class cls)(Code)

Is the specified class an inner class or static nested class.


Parameters:
  cls - the class to check, may be null true if the class is an inner or static nested class,false if not or null



primitiveToWrapper
public static Class primitiveToWrapper(Class cls)(Code)

Converts the specified primitive Class object to its corresponding wrapper Class object.

NOTE: From v2.2, this method handles Void.TYPE, returning Void.TYPE.


Parameters:
  cls - the class to convert, may be null the wrapper class for cls or cls ifcls is not a primitive. null if null input.
since:
   2.1



primitivesToWrappers
public static Class[] primitivesToWrappers(Class[] classes)(Code)

Converts the specified array of primitive Class objects to an array of its corresponding wrapper Class objects.


Parameters:
  classes - the class array to convert, may be null or empty an array which contains for each given class, the wrapper class orthe original class if class is not a primitive. null if null input.Empty array if an empty array passed in.
since:
   2.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.