Oracle® Coherence Java API Reference
v3.5

E14977-01

com.tangosol.util
Class ClassHelper

java.lang.Object
  extended by com.tangosol.util.ClassHelper

public abstract class ClassHelper
extends java.lang.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
static java.lang.Object[] VOID
          Useful constant for methods with no arguments.
static java.lang.Class[] VOID_PARAMS
          Useful constant for methods with no parameters.
 
Constructor Summary
ClassHelper()
           
 
Method Summary
static java.lang.reflect.Method findMethod(java.lang.Class clz, java.lang.String sName, java.lang.Class[] aclzParam, boolean fStatic)
          Find a Method that matches the specified name and parameter types.
static java.lang.String getCompositeName(java.lang.Class clz, java.lang.String sName)
          Build the composite name of a class based on an existing class and a second class name.
static java.lang.String getCompositeName(java.lang.String sName1, java.lang.String sName2)
          Build the composite name of a class based on an existing class name and a second class name.
static java.lang.String getCompositePackage(java.lang.String pkg1, java.lang.String pkg2)
          Build the composite name of a package based on two package names.
static java.lang.String getDerivedName(java.lang.Class clz, java.lang.String sPrefix)
          Build the name of a "derived" class based on an existing class and a "derived" class prefix.
static java.lang.String getDerivedName(java.lang.String sName, java.lang.String sPrefix)
          Build the name of a "derived" class based on the name of an existing class and a "derived" class prefix.
static java.lang.String getPackageName(java.lang.Class clz)
          Determine the package name of a class.
static java.lang.String getPackageName(java.lang.String sName)
          Determine the package name from a class (or package) name.
static Resources getPackageResources(java.lang.Class clz)
          Load the default package resources for the specified class.
static Resources getPackageResources(java.lang.String sClass)
          Load the default package resources for the specified class name.
static java.lang.String getQualifiedName(java.lang.String pkg, java.lang.String sName)
          Build the fully qualified name of a class based on a package name and a simple class name.
static Resources getResources(java.lang.Class clz, java.lang.String sName)
          Load the named resources for the specified class.
static java.lang.String getSimpleName(java.lang.Class clz)
          Determine the simple (unqualified) name of a class.
static java.lang.String getSimpleName(java.lang.String sName)
          Determine the simple (unqualified) name of a class.
static java.lang.Object invoke(java.lang.Class clz, java.lang.Object obj, java.lang.String sName, java.lang.Object[] aoParam)
          Invoke the specified method using the passed arguments.
static java.lang.Object invoke(java.lang.Object obj, java.lang.String sName, java.lang.Object[] aoParam)
          Invoke the specified instance method using the passed arguments.
static java.lang.Object invokeStatic(java.lang.Class clz, java.lang.String sName, java.lang.Object[] aoParam)
          Invoke the specified static method using the passed arguments.
static boolean isInstanceOf(java.lang.Object obj, java.lang.Class clz)
          Determine if the passed object is an instance of the specified class.
static boolean isInstanceOf(java.lang.Object obj, java.lang.String sClz)
          Determine if the passed object is an instance of the specified class.
static boolean isPartialNameLegal(java.lang.String sName)
          Determine if a partial name (for example, a prefix, class name, package name, etc.
static boolean isQualifiedNameLegal(java.lang.String sName)
          Determine if the passed string is a legal dot-delimited identifier.
static boolean isSimpleNameLegal(java.lang.String sName)
          Determine if the passed string is a legal simple name.
static java.lang.Object newInstance(java.lang.Class clz, java.lang.Object[] aoParam)
          Instantiate the specified class using the specified parameters.
 

Field Detail

VOID_PARAMS

public static final java.lang.Class[] VOID_PARAMS
Useful constant for methods with no parameters.


VOID

public static final java.lang.Object[] VOID
Useful constant for methods with no arguments.

Constructor Detail

ClassHelper

public ClassHelper()
Method Detail

isInstanceOf

public static boolean isInstanceOf(java.lang.Object obj,
                                   java.lang.String sClz)
Determine if the passed object is an instance of the specified class.

Parameters:
obj - the object
sClz - the class name

isInstanceOf

public static boolean isInstanceOf(java.lang.Object obj,
                                   java.lang.Class clz)
Determine if the passed object is an instance of the specified class.

Parameters:
obj - the object
clz - the class

getPackageName

public static java.lang.String getPackageName(java.lang.Class clz)
Determine the package name of a class.

Parameters:
clz - the class to determine the package of
Returns:
the name of the package, including a trailing dot (which signifies that the string is a package name)

getPackageName

public static java.lang.String getPackageName(java.lang.String sName)
Determine the package name from a class (or package) name.
   in      out
   ------- -------
   [blank] [blank]
   a       [blank]
   .a      .a.
   a.      a.
   .a.     .a.
   a.b     a.
   .a.b    .a.
   a.b.    a.b.
   .a.b.   .a.b.
 

Parameters:
sName - the class name to determine the package of
Returns:
the name of the package, including a trailing dot (which signifies that the string is a package name)

getSimpleName

public static java.lang.String getSimpleName(java.lang.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 java.lang.String getSimpleName(java.lang.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

getQualifiedName

public static java.lang.String getQualifiedName(java.lang.String pkg,
                                                java.lang.String sName)
Build the fully qualified name of a class based on a package name and a simple class name.

Parameters:
pkg - package name
sName - simple class name
Returns:
fully qualified class name

getCompositePackage

public static java.lang.String getCompositePackage(java.lang.String pkg1,
                                                   java.lang.String pkg2)
Build the composite name of a package based on two package names. If there is a conflict, the second package name over-rides the first.
   pkg1        pkg2            composite
   ----------- --------------  ----------------------
   [blank]     [blank]         [blank]
   [blank]     yourpkg.        yourpkg.
   [blank]     .yourpkg.       .yourpkg.
   mypkg.      [blank]         mypkg.
   .mypkg.     [blank]         .mypkg.
   mypkg.      yourpkg.        yourpkg.
   mypkg.      .yourpkg.       mypkg.yourpkg.
   .mypkg.     .yourpkg.       .mypkg.yourpkg.
 

Parameters:
pkg1 - the first (base) package
pkg2 - the second (extending/overriding) package
Returns:
the composite package name, including a trailing dot

getCompositeName

public static java.lang.String getCompositeName(java.lang.Class clz,
                                                java.lang.String sName)
Build the composite name of a class based on an existing class and a second class name.

Parameters:
clz - the existing class
sName - the name to use to build the composite class name
Returns:
the composite name of the class

getCompositeName

public static java.lang.String getCompositeName(java.lang.String sName1,
                                                java.lang.String sName2)
Build the composite name of a class based on an existing class name and a second class name. For example:
   Class       Name           Derived
   ----------- -------------- ----------------------
   Test        Net            Net
   mypkg.Test  Net            mypkg.Net
   mypkg.Test  yourpkg.       yourpkg.Test
   mypkg.Test  .yourpkg       mypkg.yourpkg.Test
   mypkg.Test  .yourpkg.      mypkg.yourpkg.Test
   mypkg.Test  yourpkg.Net    yourpkg.Net
   mypkg.Test  .yourpkg.Net   mypkg.yourpkg.Net
   mypkg.Test  .yourpkg.Net.  mypkg.yourpkg.Net.Test
 

Parameters:
sName1 - the existing class name
sName2 - the name to use to build the composite class name
Returns:
the composite name of the class

getDerivedName

public static java.lang.String getDerivedName(java.lang.Class clz,
                                              java.lang.String sPrefix)
Build the name of a "derived" class based on an existing class and a "derived" class prefix.

Parameters:
clz - the existing class
sPrefix - the prefix to apply to the existing class to determine the name of the "derived" class
Returns:
the expected name of the "derived" class

getDerivedName

public static java.lang.String getDerivedName(java.lang.String sName,
                                              java.lang.String sPrefix)
Build the name of a "derived" class based on the name of an existing class and a "derived" class prefix. For example:
   Class       Prefix        Derived
   ----------- ------------- ----------------------
   Test        Net           NetTest
   mypkg.Test  Net           mypkg.NetTest
   mypkg.Test  yourpkg.      yourpkg.Test
   mypkg.Test  .yourpkg      mypkg.yourpkg.Test
   mypkg.Test  .yourpkg.     mypkg.yourpkg.Test
   mypkg.Test  yourpkg.Net   yourpkg.NetTest
   mypkg.Test  .yourpkg.Net  mypkg.yourpkg.NetTest
   mypkg.Test  .yourpkg.Net. mypkg.yourpkg.Net.Test
 

Parameters:
sName - the existing class name
sPrefix - the prefix to apply to the existing class to determine the name of the "derived" class
Returns:
the expected name of the "derived" class

isPartialNameLegal

public static boolean isPartialNameLegal(java.lang.String sName)
Determine if a partial name (for example, a prefix, class name, package name, etc. as accepted by the above methods) is legal.

Parameters:
sName - the partial name
Returns:
true if the name is a legal partial name

isSimpleNameLegal

public static boolean isSimpleNameLegal(java.lang.String sName)
Determine if the passed string is a legal simple name. This does not check if the name is reserved by the Java language.

Parameters:
sName - the string containing the name
Returns:
true if a legal name, false otherwise

isQualifiedNameLegal

public static boolean isQualifiedNameLegal(java.lang.String sName)
Determine if the passed string is a legal dot-delimited identifier.

Parameters:
sName - the string containing the dot-delimited identifier
Returns:
true if a legal identifier, false otherwise

getPackageResources

public static Resources getPackageResources(java.lang.String sClass)
                                     throws java.util.MissingResourceException
Load the default package resources for the specified class name.

Parameters:
sClass - the class name (fully qualified) to get the resources for
Returns:
the resource bundle for the class's package
Throws:
java.util.MissingResourceException
See Also:
getResources(java.lang.Class, java.lang.String)

getPackageResources

public static Resources getPackageResources(java.lang.Class clz)
                                     throws java.util.MissingResourceException
Load the default package resources for the specified class.

Parameters:
clz - the class to get the resources for
Returns:
the resource bundle for the class's package
Throws:
java.util.MissingResourceException
See Also:
getResources(java.lang.Class, java.lang.String)

getResources

public static Resources getResources(java.lang.Class clz,
                                     java.lang.String sName)
                              throws java.util.MissingResourceException
Load the named resources for the specified class.

Parameters:
clz - the class to get the resources for
sName - the name of the resource class
Returns:
the resource bundle for the class's package
Throws:
java.util.MissingResourceException

newInstance

public static java.lang.Object newInstance(java.lang.Class clz,
                                           java.lang.Object[] aoParam)
                                    throws java.lang.InstantiationException,
                                           java.lang.reflect.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:
java.lang.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
java.lang.reflect.InvocationTargetException - if the constructor of the new object instance raises an exception

invokeStatic

public static java.lang.Object invokeStatic(java.lang.Class clz,
                                            java.lang.String sName,
                                            java.lang.Object[] aoParam)
                                     throws java.lang.NoSuchMethodException,
                                            java.lang.IllegalAccessException,
                                            java.lang.reflect.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:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

invoke

public static java.lang.Object invoke(java.lang.Object obj,
                                      java.lang.String sName,
                                      java.lang.Object[] aoParam)
                               throws java.lang.NoSuchMethodException,
                                      java.lang.IllegalAccessException,
                                      java.lang.reflect.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:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

invoke

public static java.lang.Object invoke(java.lang.Class clz,
                                      java.lang.Object obj,
                                      java.lang.String sName,
                                      java.lang.Object[] aoParam)
                               throws java.lang.NoSuchMethodException,
                                      java.lang.IllegalAccessException,
                                      java.lang.reflect.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:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class clz,
                                                  java.lang.String sName,
                                                  java.lang.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

Oracle® Coherence Java API Reference
v3.5

E14977-01

Copyright © 2000, 2009, Oracle. All rights reserved.