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 Details

    • VOID_PARAMS

      public static final Class[] VOID_PARAMS
      Useful constant for methods with no parameters.
    • VOID

      public static final Object[] VOID
      Useful constant for methods with no arguments.
  • Constructor Details

    • Classes

      public Classes()
  • Method Details

    • 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 instantiate
      aoParam - 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 exception
      InvocationTargetException - 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 of
      sName - the method name
      aoParam - 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 of
      sName - the method name
      aoParam - 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 on
      obj - the object to invoke the method on
      sName - the method name
      aoParam - 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 reference
      sName - the method name
      aclzParam - 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 name
      loader1 - first ClassLoader to try
      loader2 - second ClassLoader to try
      Returns:
      the Class for the specified name
      Throws:
      ClassNotFoundException - if all the attempts fail
    • toString

      public static String toString(Class clz)
      Formats Class information for debug output purposes.
      Parameters:
      clz - the Class to print information for
      Returns:
      a String describing the Class in detail