Package com.oracle.coherence.common.base
Class Classes
- java.lang.Object
-
- com.oracle.coherence.common.base.Classes
-
public abstract class Classes extends Object
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
Fields Modifier and Type Field Description static Object[]
VOID
Useful constant for methods with no arguments.static Class[]
VOID_PARAMS
Useful constant for methods with no parameters.
-
Constructor Summary
Constructors Constructor Description Classes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
getContextClassLoader()
Try to determine the ClassLoader that supports the current context.static ClassLoader
getContextClassLoader(Object o)
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(Class clz, Object obj, String sName, Object[] aoParam)
Invoke the specified method using the passed arguments.static Object
invoke(Object obj, String sName, Object[] aoParam)
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
toString(Class clz)
Formats Class information for debug output purposes.static String[]
toTypes(String sSig)
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[]
unwrap(Class[] aClasses)
Replace wrapper types with appropriate primitive types.
-
-
-
Method Detail
-
getSimpleName
public static String getSimpleName(Class clz)
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
public static String getSimpleName(String sName)
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
public static Method findMethod(Class clz, String sName, Class[] aclzParam, boolean fStatic)
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
public static Class[] getClassArray(Object[] aoParam)
Calculate the class array based on the parameter array.- Returns:
- the class array based on the parameter array
-
unwrap
public static Class[] unwrap(Class[] aClasses)
Replace wrapper types with appropriate primitive types.- Returns:
- the class array with primitive instead of wrapper types
-
toTypes
public static String[] toTypes(String sSig)
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
public static String toTypeStringField(String sSig)
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
public static String toBoxedTypeField(String sSig)
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
public static char fromBoxedTypeField(String sSig)
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
public static ClassLoader ensureClassLoader(ClassLoader loader)
Obtain a non-null ClassLoader.- Parameters:
loader
- a ClassLoader (may be null)- Returns:
- the passed ClassLoader (if not null), or the ContextClassLoader
-
getContextClassLoader
public static ClassLoader getContextClassLoader()
Try to determine the ClassLoader that supports the current context.- Returns:
- a ClassLoader to use for the current context
-
getContextClassLoader
public static ClassLoader getContextClassLoader(Object o)
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
-
-