Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.util
Class ClassHelper

`java.lang.Object
com.tangosol.util.ClassHelper`

      public abstract class ClassHelper

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
`static Object[]` | `VOID` Useful constant for methods with no arguments.
`static Class[]` | `VOID_PARAMS` Useful constant for methods with no parameters.

Constructor Summary
`ClassHelper()`

Method Summary
`static Method` | `findMethod(Class clz, String sName, Class[] aclzParam, boolean fStatic)` Find a Method that matches the specified name and parameter types.
`static String` | `getCompositeName(Class clz, String sName)` Build the composite name of a class based on an existing class and a second class name.
`static String` | `getCompositeName(String sName1, String sName2)` Build the composite name of a class based on an existing class name and a second class name.
`static String` | `getCompositePackage(String pkg1, String pkg2)` Build the composite name of a package based on two package names.
`static String` | `getDerivedName(Class clz, String sPrefix)` Build the name of a "derived" class based on an existing class and a "derived" class prefix.
`static String` | `getDerivedName(String sName, String sPrefix)` Build the name of a "derived" class based on the name of an existing class and a "derived" class prefix.
`static String` | `getPackageName(Class clz)` Determine the package name of a class.
`static String` | `getPackageName(String sName)` Determine the package name from a class (or package) name.
`static Resources` | `getPackageResources(Class clz)` Load the default package resources for the specified class.
`static Resources` | `getPackageResources(String sClass)` Load the default package resources for the specified class name.
`static String` | `getQualifiedName(String pkg, String sName)` Build the fully qualified name of a class based on a package name and a simple class name.
`static Resources` | `getResources(Class clz, String sName)` Load the named resources for the specified class.
`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 boolean` | `isInstanceOf(Object obj, Class clz)` Determine if the passed object is an instance of the specified class.
`static boolean` | `isInstanceOf(Object obj, String sClz)` Determine if the passed object is an instance of the specified class.
`static boolean` | `isPartialNameLegal(String sName)` Determine if a partial name (for example, a prefix, class name, package name, etc. as accepted by the above methods) is legal.
`static boolean` | `isQualifiedNameLegal(String sName)` Determine if the passed string is a legal dot-delimited identifier.
`static boolean` | `isSimpleNameLegal(String sName)` Determine if the passed string is a legal simple name.
`static Object` | `newInstance(Class clz, Object[] aoParam)` Instantiate the specified class using the specified parameters.

Field Detail

### 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 Detail

### ClassHelper

    public ClassHelper()

Method Detail

### isInstanceOf

    public static boolean isInstanceOf(Object obj,
                                       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(Object obj,
                                       Class clz)

  Determine if the passed object is an instance of the specified class.
  Parameters:
    `obj` - the object
    `clz` - the class

### getPackageName

    public static String getPackageName(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 String getPackageName(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 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

### getQualifiedName

    public static String getQualifiedName(String pkg,
                                          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 String getCompositePackage(String pkg1,
                                             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 String getCompositeName(Class clz,
                                          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 String getCompositeName(String sName1,
                                          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 String getDerivedName(Class clz,
                                        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 String getDerivedName(String sName,
                                        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(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(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(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(String sClass)
                                         throws 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:
    `MissingResourceException`
  See Also:
    `getResources(java.lang.Class, java.lang.String)`

### getPackageResources

    public static Resources getPackageResources(Class clz)
                                         throws 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:
    `MissingResourceException`
  See Also:
    `getResources(java.lang.Class, java.lang.String)`

### getResources

    public static Resources getResources(Class clz,
                                         String sName)
                                  throws 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:
    `MissingResourceException`

### 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

Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.