Java Doc for Classes.java in  » Ajax » zk » org » zkoss » 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 » Ajax » zk » org.zkoss.lang 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.zkoss.lang.Classes

Classes
public class Classes (Code)
Utilities to handle java.lang.Class
author:
   tomyeh

Inner Class :public static class MethodInfo

Field Summary
final public static  intB_GET
     Search the get method; not imply B_METHODONLY.
final public static  intB_METHOD_ONLY
     Only search for methods; excluding fields.
final public static  intB_PUBLIC_ONLY
     Only search for public methods or fields.
final public static  intB_SET
     Search the set method; not imply B_METHODONLY.


Method Summary
public static  Objectcoerce(Class cls, Object val)
     Converts an object to the specified class.
public static  Objectcoerce(Class cls, Object val, boolean nullable)
     Converts to the specified type.
Parameters:
  nullable - whether the result could be null.If false, 0 is used for number, the default constructor is usedfor others.
final public static  booleancontainsMethod(Class cls, String name, Class[] paramTypes)
     Tests whether a class contains the specified method.
final public static  StringcorrectFieldName(String name)
     Corrects a string to a valid Java name. Currently, it only removes '-' and capitalizes the succeeding character.
final public static  ClassforNameByThread(String clsName)
     Returns the Class object of the specified class name, using the current thread's context class loader.
final public static  AccessibleObjectgetAccessibleObject(Class cls, String name, Class[] argTypes, int flags)
     Gets the specified accessible object, either a method or a field, by searching the specified name.

The search sequence is: (assume field name is body)>
getBody(...)
isBody(...)
body(...)
body

If B_SET is specified, setBody(...) is searched instead of getBody(...) and isBody(...).

public static  Class[]getAllInterfaces(Class cls)
     Returns all interfaces that are implemented by the specified class.
final public static  FieldgetAnyField(Class cls, String name)
     Gets the specified field by searching all fields including any access control and any base class. The search sequence is: this class's fields, and then the superclass's fields.

Note: public fields don't be treated different.

final public static  MethodgetAnyMethod(Class cls, String name, Class[] argTypes)
     Gets the specified method by searching all methods including any access control and any base class. Note: you rarely need to call this metod.
final public static  MethodgetCloseMethod(Class cls, String name, Class[] argTypes)
     Gets one of the close methods -- a close method is a method with the same name and the compatible argument type. By compatiable we mean the real method's argument type is the same as or a superclass of the specified one.

It might not be the best fit one, unless there is a method whose argument types are exactly argTypes.

You might specify the exact number in argTypes.

final public static  MethodgetCloseMethodBySubclass(Class cls, String name, Class[] argTypes)
     Like Classes.getCloseMethod to get a 'close' method, but it look for subclass of the arguement (instead of superclass).
final public static  Method[]getCloseMethods(Class cls, String name, Class[] argTypes)
     Returns all close methods that match the specified condition, or a zero-length array if none is found.
final public static  Method[]getCloseMethodsBySubclass(Class cls, String name, Class[] argTypes)
     Like Classes.getCloseMethods to get all 'close' methods, but it look for subclass of the arguement (instead of superclass).
final public static  MethodgetMethodByObject(Class cls, String name, Object[] args)
     Gets one of the close method by specifying the arguments, rather than the argument types.
final public static  MethodgetMethodBySignature(Class cls, String signature, Collection params)
     Gets the method based on the signature.
final public static  MethodgetMethodInPublic(Class cls, String name, Class[] argTypes)
     Gets the method that is declared in a public class/interface.

Class.getMethod returns a public method but the class itself might not be public.

final public static  Class[]getSuperClasses(Class cls, Class[] clsToCheck)
     Searches thru each element of the specified array of classes, and returns classes that are super-classes (or equal) of the sepcified class.
public static  ClassgetTopmostInterface(Class cls, Class subIF)
     Gets the topmost interface of the specified class or interface that implements or extends the specified interface.
final public static  booleanisAttribute(String methodName)
     Tests if a method name is an attribute, i.e., prefixing with is, get or set.
final public static  booleanisNumeric(Class cls, boolean extend)
     Checks whether the specified class is a numeric class.
final public static  booleanisPrimitiveWrapper(Class cls)
     Check whether the specified class is a primitive or a primitive wrapper.
final public static  ObjectnewInstance(Class cls, Class[] argTypes, Object[] args)
     Instantiates a new instance of the specified class with the specified arguments and argument types.
final public static  ObjectnewInstance(Class cls, Object[] args)
     Instantiates a new instance of the specified class with the specified argument.
final public static  ObjectnewInstance(String clsName, Class[] argTypes, Object[] args)
     Instantiates a new instance of the specified class name with the specified arguments.
final public static  ObjectnewInstanceByThread(String clsName, Class[] argTypes, Object[] args)
     Creates and initializes a new instance of the specified class name with the specified arguments, by use of Classes.forNameByThread .
final public static  ObjectnewInstanceByThread(String clsName)
     Creates and initializes a new instance of the specified class name with default constructor, by use of Classes.forNameByThread .
final public static  MethodInfoparseMethod(String signature)
     Gets the method information from a signature.
final public static  StringtoAttributeName(String methodName)
     Converts a method name to an attribute name by removing the prefix is, get or set, or null if it doesn't start with is, get or set.
final public static  StringtoInternalForm(String clsName)
     Change class name to internal form (e.g.
final public static  StringtoMethodName(String attrName, String prefix)
     Convert an attribute name, returned by toAttributeName, to a method name.

Field Detail
B_GET
final public static int B_GET(Code)
Search the get method; not imply B_METHODONLY.



B_METHOD_ONLY
final public static int B_METHOD_ONLY(Code)
Only search for methods; excluding fields.



B_PUBLIC_ONLY
final public static int B_PUBLIC_ONLY(Code)
Only search for public methods or fields.



B_SET
final public static int B_SET(Code)
Search the set method; not imply B_METHODONLY.





Method Detail
coerce
public static Object coerce(Class cls, Object val) throws ClassCastException(Code)
Converts an object to the specified class. It is the same as coerce(cls, val, true).

Future: use org.apache.commons.el.Coercions
Parameters:
  val - the value.
exception:
  ClassCastException - if failed to convert
See Also:   Classes.coerce(Class,Object,boolean)




coerce
public static Object coerce(Class cls, Object val, boolean nullable) throws ClassCastException(Code)
Converts to the specified type.
Parameters:
  nullable - whether the result could be null.If false, 0 is used for number, the default constructor is usedfor others. Classes.coerce(Class,Object) is a special case thatis equivalent to nullable=true.
exception:
  ClassCastException - if failed to convert



containsMethod
final public static boolean containsMethod(Class cls, String name, Class[] paramTypes)(Code)
Tests whether a class contains the specified method. Only public methods are tested.
Parameters:
  cls - the class to test
Parameters:
  name - the method name
Parameters:
  paramTypes - the list of parameter types true if it contains the method



correctFieldName
final public static String correctFieldName(String name)(Code)
Corrects a string to a valid Java name. Currently, it only removes '-' and capitalizes the succeeding character. Example, 'field-name' becomes 'fieldName'.



forNameByThread
final public static Class forNameByThread(String clsName) throws ClassNotFoundException(Code)
Returns the Class object of the specified class name, using the current thread's context class loader.

In additions, it handles the primitive types, such as int and double.
Parameters:
  clsName - fully qualified name of the desired class the Class object representing the desired class
exception:
  ClassNotFoundException - if the class cannot be located by the specified class loader




getAccessibleObject
final public static AccessibleObject getAccessibleObject(Class cls, String name, Class[] argTypes, int flags) throws NoSuchMethodException(Code)
Gets the specified accessible object, either a method or a field, by searching the specified name.

The search sequence is: (assume field name is body)>
getBody(...)
isBody(...)
body(...)
body

If B_SET is specified, setBody(...) is searched instead of getBody(...) and isBody(...). The field is searched only if argsType.length is 0 or 1.

Note: it uses Classes.getCloseMethod to get the method.

A cache mechanism is implemented, so you don't need to cache it again in the caller.
Parameters:
  cls - the class to find
Parameters:
  name - the name of the accessible object
Parameters:
  argTypes - the parameter type of the method to find
Parameters:
  flags - a combination of B_xxx or zero the accessible object; either Field or Method
exception:
  NoSuchMethodException - if neither the set method ofspecified field nor the field itself not found
exception:
  SecurityException - if access to the information is denied




getAllInterfaces
public static Class[] getAllInterfaces(Class cls)(Code)
Returns all interfaces that are implemented by the specified class.

Unlike Class.getInterfaces , it recursively searches for all derived classes.




getAnyField
final public static Field getAnyField(Class cls, String name) throws NoSuchFieldException(Code)
Gets the specified field by searching all fields including any access control and any base class. The search sequence is: this class's fields, and then the superclass's fields.

Note: public fields don't be treated different. If the caller wants to search public fields first, it has to call Class.getField first.
Parameters:
  cls - the class to search
Parameters:
  name - the field name the Field object
exception:
  NoSuchFieldException - if a matching field is not found.
exception:
  SecurityException - if access to the information is denied.
See Also:   Classes.getAccessibleObject(Class,String,Class[],int)
See Also:   Classes.getAnyMethod(Class,String,Class[])




getAnyMethod
final public static Method getAnyMethod(Class cls, String name, Class[] argTypes) throws NoSuchMethodException(Code)
Gets the specified method by searching all methods including any access control and any base class. Note: you rarely need to call this metod. In most cases, Class.getMethod, Classes.getCloseMethod , and Classes.getMethodInPublic are what you need.

The search sequence is: this class's methods, and then the superclass's methods.

Note: public methods don't be treated different. If the caller wants to search public methods first, it has to call Class.getMethod first.
Parameters:
  cls - the class to search
Parameters:
  name - the method name
Parameters:
  argTypes - the parameter array of types the Method object
exception:
  NoSuchMethodException - if a matching method is not found.
exception:
  SecurityException - if access to the information is denied.
See Also:   Classes.getAccessibleObject(Class,String,Class[],int)
See Also:   Classes.getAnyField(Class,String)




getCloseMethod
final public static Method getCloseMethod(Class cls, String name, Class[] argTypes) throws NoSuchMethodException(Code)
Gets one of the close methods -- a close method is a method with the same name and the compatible argument type. By compatiable we mean the real method's argument type is the same as or a superclass of the specified one.

It might not be the best fit one, unless there is a method whose argument types are exactly argTypes.

You might specify the exact number in argTypes. If any of them is unknwon, use null. Example, in the following, the first argument could be anything and the second is anything deriving from MyClass:
new Class[] {null, MyClass.class}

Note: if an argument accepts int, then Integer is considered as compatible (unlike Class.getMethod). So are long, byte...

A cache mechanism is implemented, so you don't need to cache it again in the caller.
Parameters:
  cls - the class to locate the method
Parameters:
  name - the method name
Parameters:
  argTypes - an array of the argument classes;null to denote no argument at all (i.e., exact match).Any argTypes[i] could be null to denote any class. the method
exception:
  NoSuchMethodException - if the method is not found




getCloseMethodBySubclass
final public static Method getCloseMethodBySubclass(Class cls, String name, Class[] argTypes) throws NoSuchMethodException(Code)
Like Classes.getCloseMethod to get a 'close' method, but it look for subclass of the arguement (instead of superclass). In other words, it looks for the method whose argument type is the same as or a subclass of the specified one.



getCloseMethods
final public static Method[] getCloseMethods(Class cls, String name, Class[] argTypes)(Code)
Returns all close methods that match the specified condition, or a zero-length array if none is found.

Unlike Classes.getCloseMethod , we don't cache the searched result, and it won't throw any exception.




getCloseMethodsBySubclass
final public static Method[] getCloseMethodsBySubclass(Class cls, String name, Class[] argTypes)(Code)
Like Classes.getCloseMethods to get all 'close' methods, but it look for subclass of the arguement (instead of superclass). In other words, it looks for the method whose argument type is the same as or a subclass of the specified one.



getMethodByObject
final public static Method getMethodByObject(Class cls, String name, Object[] args) throws NoSuchMethodException(Code)
Gets one of the close method by specifying the arguments, rather than the argument types. It actually calls Classes.getCloseMethod .



getMethodBySignature
final public static Method getMethodBySignature(Class cls, String signature, Collection params) throws NoSuchMethodException, ClassNotFoundException(Code)
Gets the method based on the signature. It also returns the parameter names to the params list.

Like Classes.getMethodInPublic(Class,String,Class[]) , it returns only public method in a public class/interface.

For example, "find(java.lang.String name)" will return the method with one String-typed argument and params will hold "name". The return type is optional (actualy ignored).

If params is null, the parameter names are not returned and the signature could be simplified as "find(java.lang.String)".

A cache mechanism is implemented, so you don't need to cache it again in the caller.
Parameters:
  cls - the class to look
Parameters:
  signature - the method signature; the return type is optional
Parameters:
  params - the collection to hold the parameter names returned;null means no parameter names to return




getMethodInPublic
final public static Method getMethodInPublic(Class cls, String name, Class[] argTypes) throws NoSuchMethodException(Code)
Gets the method that is declared in a public class/interface.

Class.getMethod returns a public method but the class itself might not be public. However, in many cases, that class also implements a public interface or class.

This method will search all its public classes to look for the method that is 'real' public.

NoSuchMethodException is thrown if no public class/interface is found to have the method.




getSuperClasses
final public static Class[] getSuperClasses(Class cls, Class[] clsToCheck)(Code)
Searches thru each element of the specified array of classes, and returns classes that are super-classes (or equal) of the sepcified class.
Parameters:
  cls - the specified class; null is not allowed
Parameters:
  clsToCheck - the class array to check; null is acceptable a subset of clsToCheck that are super-class of cls;null if no one qualified



getTopmostInterface
public static Class getTopmostInterface(Class cls, Class subIF)(Code)
Gets the topmost interface of the specified class or interface that implements or extends the specified interface. For example, if A extends B, and C implements A, then getTopInterface(C, B) returns A.

The interfaces implemented by the specified class is checked first, and then the subclass.
Parameters:
  cls - the class or interface
Parameters:
  subIF - the sub-interface the topmost interface extending subIF, or null if subIFis not implemented by cls




isAttribute
final public static boolean isAttribute(String methodName)(Code)
Tests if a method name is an attribute, i.e., prefixing with is, get or set. Caller could then test if it is a setter or getter by charAt(0)=='s'.

Note 'set' is considered as an attribute, whose name is an empty string.
Parameters:
  methodName - the method name to test true if it is setter or getter




isNumeric
final public static boolean isNumeric(Class cls, boolean extend)(Code)
Checks whether the specified class is a numeric class.
Parameters:
  extend - whether to consider Date, char, boolean, Characterand Boolean as a numeric object.



isPrimitiveWrapper
final public static boolean isPrimitiveWrapper(Class cls)(Code)
Check whether the specified class is a primitive or a primitive wrapper.



newInstance
final public static Object newInstance(Class cls, Class[] argTypes, Object[] args) throws NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalAccessException(Code)
Instantiates a new instance of the specified class with the specified arguments and argument types.

Note only public constructors are searched.
Parameters:
  cls - the class of the instance to create
Parameters:
  argTypes - the argument types of the constructor to inovke
Parameters:
  args - the arguments to initialize the instance the new instance
exception:
  NoSuchMethodException - if a matching method is not found
exception:
  InstantiationException - if the class that declares theunderlying constructor represents an abstract class
exception:
  InvocationTargetException - if the underlying constructorthrows an exception
See Also:   Classes.newInstance(String,Class[],Object[])




newInstance
final public static Object newInstance(Class cls, Object[] args) throws NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalAccessException(Code)
Instantiates a new instance of the specified class with the specified argument.

It searches all contructor for the first one that matches the specified arguments.
since:
   3.0.1




newInstance
final public static Object newInstance(String clsName, Class[] argTypes, Object[] args) throws NoSuchMethodException, InstantiationException, InvocationTargetException, ClassNotFoundException, IllegalAccessException(Code)
Instantiates a new instance of the specified class name with the specified arguments.

It uses Class.forName to get the class.
Parameters:
  clsName - the class name of the instance to create
Parameters:
  argTypes - the argument types of the constructor to inovke
Parameters:
  args - the arguments to initialize the instance the new instance
exception:
  NoSuchMethodException - if a matching method is not found
exception:
  InstantiationException - if the class that declares theunderlying constructor represents an abstract class
exception:
  InvocationTargetException - if the underlying constructorthrows an exception
exception:
  ClassNotFoundException - if the specified class name is not a class
See Also:   Classes.newInstance(Class,Class[],Object[])




newInstanceByThread
final public static Object newInstanceByThread(String clsName, Class[] argTypes, Object[] args) throws NoSuchMethodException, InstantiationException, InvocationTargetException, ClassNotFoundException, IllegalAccessException(Code)
Creates and initializes a new instance of the specified class name with the specified arguments, by use of Classes.forNameByThread .

It uses Classes.forNameByThread to get the class.
Parameters:
  clsName - the class name of the instance to create
Parameters:
  argTypes - the argument types of the constructor to inovke
Parameters:
  args - the arguments to initialize the instance the new instance
exception:
  NoSuchMethodException - if a matching method is not found
exception:
  InstantiationException - if the class that declares theunderlying constructor represents an abstract class
exception:
  InvocationTargetException - if the underlying constructorthrows an exception
exception:
  ClassNotFoundException - if the specified class name is not a class
See Also:   Classes.newInstance(Class,Class[],Object[])




newInstanceByThread
final public static Object newInstanceByThread(String clsName) throws NoSuchMethodException, InstantiationException, InvocationTargetException, ClassNotFoundException, IllegalAccessException(Code)
Creates and initializes a new instance of the specified class name with default constructor, by use of Classes.forNameByThread .



parseMethod
final public static MethodInfo parseMethod(String signature) throws IllegalSyntaxException(Code)
Gets the method information from a signature. It returns a method info with the return type, method name and two collections of arguments type and arguments name.
Parameters:
  signature - the method signature. MethodInfo The method information including return type, method nameand two collections for argument type annd arguments name.



toAttributeName
final public static String toAttributeName(String methodName)(Code)
Converts a method name to an attribute name by removing the prefix is, get or set, or null if it doesn't start with is, get or set.

The code is optimized for better performance.
Parameters:
  methodName - the method name the attribute name; null if it is not an attribute name
See Also:   Classes.toMethodName




toInternalForm
final public static String toInternalForm(String clsName)(Code)
Change class name to internal form (e.g. byte[] -> [B). If already in internal form, then just return it.



toMethodName
final public static String toMethodName(String attrName, String prefix)(Code)
Convert an attribute name, returned by toAttributeName, to a method name.

toMethodName("true", "is") => "isTrue"
toMethodName("true", "") => "true"
Parameters:
  attrName - the attribute name
Parameters:
  prefix - the prefix; one of is, get and set the method name
See Also:   Classes.toAttributeName




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.