S-PLUS Connect/Java v1.0

com.insightful.splus.util
Class ClassUtilities

java.lang.Object
  extended by com.insightful.splus.util.ClassUtilities

public class ClassUtilities
extends Object

Class with static methods for doing Class, Method, and Field operations. If the class name is in JNI format such as "java/lang/Math" it will be converted to the Java format such as "java.lang.Math".

See Also:
ClientUtilities, ClientUtilitiesImpl, ClientUtilitiesReceiver

Field Summary
static boolean testFieldBoolean
          fields and methods for testing .JavaMethod and .JavaField
static boolean[] testFieldBooleanArray
           
static byte testFieldByte
           
static byte[] testFieldByteArray
           
static char testFieldChar
           
static char[] testFieldCharArray
           
static double testFieldDouble
           
static double[] testFieldDoubleArray
           
static float testFieldFloat
           
static float[] testFieldFloatArray
           
static int testFieldInt
           
static int[] testFieldIntArray
           
static long testFieldLong
           
static long[] testFieldLongArray
           
static Object testFieldObject
           
static Object[] testFieldObjectArray
           
static short testFieldShort
           
static short[] testFieldShortArray
           
static String testFieldString
           
static String[] testFieldStringArray
           
 
Method Summary
static void attachClassPath(String classPath)
          Add a class loader for the specified class path to the class loader search list.
static void attachClassPath(String[] classPaths)
          Add a class loader for the specified class paths to the class loader search list.
static void attachClassPath(URL[] urlList)
          Add a class loader for the specified URLs to the class loader search list.
static int availableProcessors()
           
static boolean classExists(String className)
          Test whether a class exists.
static boolean fieldExists(String className, String fieldName)
          Test whether a field exists.
static double freeMemory()
           
static Class getClassForName(String name)
          Return the class for a given class name, using the current classloader.
static ClassLoader getClassLoader()
          Return the current class loader used for mapping from names to classes.
static String[] getPropertiesAsStringArray()
           
static Object getStaticFieldValue(String className, String fieldName)
          Get the value of a static field.
static Object invokeStaticMethod(String className, String methodName)
          Invoke a static method that has no arguments.
static Object invokeStaticMethod(String className, String methodName, Class[] parameterTypes, Object[] args)
          Invoke a static method.
static double maxMemory()
          static methods to access Runtime instance mts from .JavaMethod
static boolean methodExists(String className, String methodName, Class[] parameterTypes)
          Test whether a method exists.
static Object newInstance(String className)
          Create a new instance of an object using the no-argument constructor.
static void setClassLoader(ClassLoader loader)
          Set the current class loader used for mapping from names to classes.
static double testLoop(int size, int size2, boolean useDoubles, boolean doYield)
           
static double testLoop(int size, int size2, int sleep, boolean useDoubles)
           
static double testLoopDouble(int size)
           
static double testLoopDouble2(int size, int size2)
           
static int testLoopInt(int size)
           
static int testLoopInt2(int size, int size2)
           
static boolean testMethodBoolean()
           
static boolean[] testMethodBooleanArray()
           
static byte testMethodByte()
           
static byte[] testMethodByteArray()
           
static char testMethodChar()
           
static char[] testMethodCharArray()
           
static double testMethodDouble()
           
static double[] testMethodDoubleArray()
           
static float testMethodFloat()
           
static float[] testMethodFloatArray()
           
static int testMethodInt()
           
static int[] testMethodIntArray()
           
static long testMethodLong()
           
static long[] testMethodLongArray()
           
static Object testMethodObject()
           
static Object[] testMethodObjectArray()
           
static void testMethodSetBoolean(boolean val)
           
static void testMethodSetBooleanArray(boolean[] val)
           
static void testMethodSetByte(byte val)
           
static void testMethodSetByteArray(byte[] val)
           
static void testMethodSetChar(char val)
           
static void testMethodSetCharArray(char[] val)
           
static void testMethodSetDouble(double val)
           
static void testMethodSetDoubleArray(double[] val)
           
static void testMethodSetFloat(float val)
           
static void testMethodSetFloatArray(float[] val)
           
static void testMethodSetInt(int val)
           
static void testMethodSetIntArray(int[] val)
           
static void testMethodSetLong(long val)
           
static void testMethodSetLongArray(long[] val)
           
static void testMethodSetShort(short val)
           
static void testMethodSetShortArray(short[] val)
           
static void testMethodSetString(String val)
           
static void testMethodSetStringArray(String[] val)
           
static short testMethodShort()
           
static short[] testMethodShortArray()
           
static String testMethodString()
           
static String[] testMethodStringArray()
           
static double totalMemory()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

testFieldBoolean

public static boolean testFieldBoolean
fields and methods for testing .JavaMethod and .JavaField


testFieldByte

public static byte testFieldByte

testFieldChar

public static char testFieldChar

testFieldShort

public static short testFieldShort

testFieldInt

public static int testFieldInt

testFieldLong

public static long testFieldLong

testFieldFloat

public static float testFieldFloat

testFieldDouble

public static double testFieldDouble

testFieldString

public static String testFieldString

testFieldObject

public static Object testFieldObject

testFieldBooleanArray

public static boolean[] testFieldBooleanArray

testFieldByteArray

public static byte[] testFieldByteArray

testFieldCharArray

public static char[] testFieldCharArray

testFieldShortArray

public static short[] testFieldShortArray

testFieldIntArray

public static int[] testFieldIntArray

testFieldLongArray

public static long[] testFieldLongArray

testFieldFloatArray

public static float[] testFieldFloatArray

testFieldDoubleArray

public static double[] testFieldDoubleArray

testFieldStringArray

public static String[] testFieldStringArray

testFieldObjectArray

public static Object[] testFieldObjectArray
Method Detail

getStaticFieldValue

public static Object getStaticFieldValue(String className,
                                         String fieldName)
                                  throws ClassNotFoundException,
                                         NoSuchFieldException,
                                         IllegalAccessException
Get the value of a static field.

Parameters:
className - The class containing the field of interest.
fieldName - The field of interest.
Throws:
ClassNotFoundException
NoSuchFieldException
IllegalAccessException
See Also:
Class.getField(String name)

invokeStaticMethod

public static Object invokeStaticMethod(String className,
                                        String methodName,
                                        Class[] parameterTypes,
                                        Object[] args)
                                 throws ClassNotFoundException,
                                        NoSuchMethodException,
                                        IllegalAccessException,
                                        InvocationTargetException
Invoke a static method.

If parameterTypes is null, the classes of args will be used to construct the Class [] array. This means that a method whose signature does not match the specific object types will not be found.

Parameters:
className - The class containing the method to invoke.
methodName - The method to invoke.
parameterTypes - Array of Class objects matching the arguments to the method. The class for a primitive argument such as "double" is obtained from the wrapper class "Double" using the static field "Double.TYPE".
args - Array of arguments to the method. Primitive arguments such as "double" must be wrapped in an object such as "Double".
Returns:
The Object returned by the method.
Throws:
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InvocationTargetException
See Also:
Method.invoke(Object obj, Object [] args)

invokeStaticMethod

public static Object invokeStaticMethod(String className,
                                        String methodName)
                                 throws ClassNotFoundException,
                                        NoSuchMethodException,
                                        IllegalAccessException,
                                        InvocationTargetException
Invoke a static method that has no arguments. Equivalent to specifying parameterTypes and args as null.

Throws:
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

newInstance

public static Object newInstance(String className)
                          throws ClassNotFoundException,
                                 IllegalAccessException,
                                 InstantiationException
Create a new instance of an object using the no-argument constructor.

Parameters:
className - Class of the object.
Returns:
A new object of the specified class.
Throws:
ClassNotFoundException
IllegalAccessException
InstantiationException
See Also:
Class.newInstance()

classExists

public static boolean classExists(String className)
Test whether a class exists. This is done by seeing whether the system ClassLoader can find the class.

Parameters:
className - Class to find.
Returns:
boolean indicating whether the class can be found.

fieldExists

public static boolean fieldExists(String className,
                                  String fieldName)
                           throws SecurityException
Test whether a field exists.

Parameters:
className - The class containing the field of interest.
fieldName - The field of interest.
Returns:
Returns true if the class exists and contains a public field with the specified name.
Throws:
SecurityException

methodExists

public static boolean methodExists(String className,
                                   String methodName,
                                   Class[] parameterTypes)
Test whether a method exists.

Parameters:
className - The class containing the method.
methodName - The method.
parameterTypes - Array of Class objects matching the arguments to the method. The class for a primitive argument such as "double" is obtained from the wrapper class "Double" using the static field "Double.TYPE".
Returns:
Returns true if the class exists and has a public method with the specified parameter types.

getClassForName

public static Class getClassForName(String name)
                             throws ClassNotFoundException
Return the class for a given class name, using the current classloader.

Parameters:
name - The class containing the method.
Returns:
Returns the class for the name.
Throws:
ClassNotFoundException

attachClassPath

public static void attachClassPath(String classPath)
                            throws Exception
Add a class loader for the specified class path to the class loader search list.

Parameters:
classPath - a jar file or a directory containing classes.
Throws:
Exception

attachClassPath

public static void attachClassPath(String[] classPaths)
                            throws Exception
Add a class loader for the specified class paths to the class loader search list.

Parameters:
classPaths - an array of jar files and class directories.
Throws:
Exception

attachClassPath

public static void attachClassPath(URL[] urlList)
                            throws Exception
Add a class loader for the specified URLs to the class loader search list.

Parameters:
urlList - an array of URLs for jar files and class directories.
Throws:
Exception

getClassLoader

public static ClassLoader getClassLoader()
Return the current class loader used for mapping from names to classes. This may be null, if the system classloader is being used.

Returns:
Returns the current class loader.

setClassLoader

public static void setClassLoader(ClassLoader loader)
Set the current class loader used for mapping from names to classes.

Parameters:
loader - the new class loader.

testMethodBoolean

public static boolean testMethodBoolean()

testMethodByte

public static byte testMethodByte()

testMethodChar

public static char testMethodChar()

testMethodShort

public static short testMethodShort()

testMethodInt

public static int testMethodInt()

testMethodLong

public static long testMethodLong()

testMethodFloat

public static float testMethodFloat()

testMethodDouble

public static double testMethodDouble()

testMethodString

public static String testMethodString()

testMethodObject

public static Object testMethodObject()

testMethodBooleanArray

public static boolean[] testMethodBooleanArray()

testMethodByteArray

public static byte[] testMethodByteArray()

testMethodCharArray

public static char[] testMethodCharArray()

testMethodShortArray

public static short[] testMethodShortArray()

testMethodIntArray

public static int[] testMethodIntArray()

testMethodLongArray

public static long[] testMethodLongArray()

testMethodFloatArray

public static float[] testMethodFloatArray()

testMethodDoubleArray

public static double[] testMethodDoubleArray()

testMethodStringArray

public static String[] testMethodStringArray()

testMethodObjectArray

public static Object[] testMethodObjectArray()

testMethodSetInt

public static void testMethodSetInt(int val)

testMethodSetBoolean

public static void testMethodSetBoolean(boolean val)

testMethodSetByte

public static void testMethodSetByte(byte val)

testMethodSetChar

public static void testMethodSetChar(char val)

testMethodSetShort

public static void testMethodSetShort(short val)

testMethodSetLong

public static void testMethodSetLong(long val)

testMethodSetFloat

public static void testMethodSetFloat(float val)

testMethodSetDouble

public static void testMethodSetDouble(double val)

testMethodSetString

public static void testMethodSetString(String val)

testMethodSetBooleanArray

public static void testMethodSetBooleanArray(boolean[] val)

testMethodSetByteArray

public static void testMethodSetByteArray(byte[] val)

testMethodSetCharArray

public static void testMethodSetCharArray(char[] val)

testMethodSetShortArray

public static void testMethodSetShortArray(short[] val)

testMethodSetIntArray

public static void testMethodSetIntArray(int[] val)

testMethodSetLongArray

public static void testMethodSetLongArray(long[] val)

testMethodSetFloatArray

public static void testMethodSetFloatArray(float[] val)

testMethodSetDoubleArray

public static void testMethodSetDoubleArray(double[] val)

testMethodSetStringArray

public static void testMethodSetStringArray(String[] val)

getPropertiesAsStringArray

public static String[] getPropertiesAsStringArray()

testLoopInt

public static int testLoopInt(int size)

testLoopInt2

public static int testLoopInt2(int size,
                               int size2)

testLoopDouble

public static double testLoopDouble(int size)

testLoopDouble2

public static double testLoopDouble2(int size,
                                     int size2)

testLoop

public static double testLoop(int size,
                              int size2,
                              boolean useDoubles,
                              boolean doYield)

testLoop

public static double testLoop(int size,
                              int size2,
                              int sleep,
                              boolean useDoubles)

maxMemory

public static double maxMemory()
static methods to access Runtime instance mts from .JavaMethod


totalMemory

public static double totalMemory()

freeMemory

public static double freeMemory()

availableProcessors

public static int availableProcessors()

S-PLUS Connect/Java v1.0

Copyright © 2000, 2002 Insightful Corporation
Warning: Classes not documented in the S-PLUS Programmer's Guide may change in future releases.