Package com.oracle.coherence.common.base
Class Classes
java.lang.Object
com.oracle.coherence.common.base.Classes
This abstract class contains dynamic (reflect-based) class, method, and
field manipulation methods.
Note: This class is primarily for supporting generated code.
- Version:
- 1.00, 11/22/96
- Author:
- Cameron Purdy
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoader
ensureClassLoader
(ClassLoader loader) Obtain a non-null ClassLoader.static Method
findMethod
(Class clz, String sName, Class[] aclzParam, boolean fStatic) Find a Method that matches the specified name and parameter types.static char
fromBoxedTypeField
(String sSig) Provide a boxed version of the given primitive in binary format.static Class[]
getClassArray
(Object[] aoParam) Calculate the class array based on the parameter array.static ClassLoader
Try to determine the ClassLoader that supports the current context.static ClassLoader
Try to determine the ClassLoader that supports the current context.static String
getSimpleName
(Class clz) Determine the simple (unqualified) name of a class.static String
getSimpleName
(String sName) Determine the simple (unqualified) name of a class.static Object
Invoke the specified method using the passed arguments.static Object
Invoke the specified instance method using the passed arguments.static Object
invokeStatic
(Class clz, String sName, Object[] aoParam) Invoke the specified static method using the passed arguments.static Class
loadClass
(String sClass, ClassLoader loader1, ClassLoader loader2) Attempt to load the specified class using sequentionally all of the specified loaders, the ContextClassLoader and the current class loader.static Object
newInstance
(Class clz, Object[] aoParam) Instantiate the specified class using the specified parameters.static String
toBoxedTypeField
(String sSig) Provide a boxed version of the given primitive in binary format.static String
Formats Class information for debug output purposes.static String[]
Parse the method signature into discrete return type and parameter signatures as they appear in Java .class structures.static String
toTypeStringField
(String sSig) Provide a Java source representation of a JVM type signature.static Class[]
Replace wrapper types with appropriate primitive types.
-
Field Details
-
VOID_PARAMS
Useful constant for methods with no parameters. -
VOID
Useful constant for methods with no arguments.
-
-
Constructor Details
-
Classes
public Classes()
-
-
Method Details
-
getSimpleName
Determine the simple (unqualified) name of a class.- Parameters:
clz
- the class to determine the simple name of- Returns:
- the simple name of the class
-
getSimpleName
Determine the simple (unqualified) name of a class.in out ------- ------- [blank] [blank] a a .a [blank] a. [blank] .a. [blank] a.b b .a.b b a.b. [blank] .a.b. [blank]
- Parameters:
sName
- the simple or qualified name of the class (or package)- Returns:
- the simple name of the class
-
newInstance
public static Object newInstance(Class clz, Object[] aoParam) throws InstantiationException, InvocationTargetException Instantiate the specified class using the specified parameters.- Parameters:
clz
- the class to instantiateaoParam
- the constructor parameters- Returns:
- a new instance of the specified class
- Throws:
InstantiationException
- if an exception is raised trying to instantiate the object, whether the exception is a security, method access, no such method, or instantiation exceptionInvocationTargetException
- if the constructor of the new object instance raises an exception
-
invokeStatic
public static Object invokeStatic(Class clz, String sName, Object[] aoParam) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException Invoke the specified static method using the passed arguments.- Parameters:
clz
- the class to invoke the static method ofsName
- the method nameaoParam
- the method arguments- Returns:
- the return value (if any) from the method
- Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException
-
invoke
public static Object invoke(Object obj, String sName, Object[] aoParam) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException Invoke the specified instance method using the passed arguments.- Parameters:
obj
- the object to invoke the instance method ofsName
- the method nameaoParam
- the method arguments- Returns:
- the return value (if any) from the method
- Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException
-
invoke
public static Object invoke(Class clz, Object obj, String sName, Object[] aoParam) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException Invoke the specified method using the passed arguments.- Parameters:
clz
- the class to invoke the method onobj
- the object to invoke the method onsName
- the method nameaoParam
- the method arguments- Returns:
- the return value (if any) from the method invocation
- Throws:
NoSuchMethodException
IllegalAccessException
InvocationTargetException
-
findMethod
Find a Method that matches the specified name and parameter types. If there are more than one matching methods, the first one will be returned.- Parameters:
clz
- the class referencesName
- the method nameaclzParam
- the parameter types (some array elements could be null)fStatic
- the method scope flag- Returns:
- the matching Method object or null if no match could be found
-
getClassArray
Calculate the class array based on the parameter array.- Returns:
- the class array based on the parameter array
-
unwrap
Replace wrapper types with appropriate primitive types.- Returns:
- the class array with primitive instead of wrapper types
-
toTypes
Parse the method signature into discrete return type and parameter signatures as they appear in Java .class structures.- Parameters:
sSig
- the JVM method signature- Returns:
- an array of JVM type signatures, where [0] is the return type and [1]..[c] are the parameter types.
-
toTypeStringField
Provide a Java source representation of a JVM type signature.- Parameters:
sSig
- the JVM type signature- Returns:
- the Java type name as found in Java source code
-
toBoxedTypeField
Provide a boxed version of the given primitive in binary format.- Parameters:
sSig
- the JVM type signature- Returns:
- the boxed version of the given primitive in binary format
-
fromBoxedTypeField
Provide a boxed version of the given primitive in binary format.- Parameters:
sSig
- the JVM type signature- Returns:
- the boxed version of the given primitive in binary format
-
ensureClassLoader
Obtain a non-null ClassLoader.- Parameters:
loader
- a ClassLoader (may be null)- Returns:
- the passed ClassLoader (if not null), or the ContextClassLoader
-
getContextClassLoader
Try to determine the ClassLoader that supports the current context.- Returns:
- a ClassLoader to use for the current context
-
getContextClassLoader
Try to determine the ClassLoader that supports the current context.- Parameters:
o
- the calling object, or any object out of the application that is requesting the class loader- Returns:
- a ClassLoader to use for the current context
-
loadClass
public static Class loadClass(String sClass, ClassLoader loader1, ClassLoader loader2) throws ClassNotFoundException Attempt to load the specified class using sequentionally all of the specified loaders, the ContextClassLoader and the current class loader.- Parameters:
sClass
- the class nameloader1
- first ClassLoader to tryloader2
- second ClassLoader to try- Returns:
- the Class for the specified name
- Throws:
ClassNotFoundException
- if all the attempts fail
-
toString
Formats Class information for debug output purposes.- Parameters:
clz
- the Class to print information for- Returns:
- a String describing the Class in detail
-