com.sun.enterprise.util
Class Utility

java.lang.Object
  extended by com.sun.enterprise.util.Utility

public final class Utility
extends Object

Handy class full of static functions.


Constructor Summary
Utility()
           
 
Method Summary
static int bytesToInt(byte[] array, int offset)
          Unmarshal a byte array to an integer.
static long bytesToLong(byte[] array, int offset)
          Unmarshal a byte array to an long.
static void checkJVMVersion()
           
static char[] convertByteArrayToCharArray(byte[] byteArray, String charset)
          Convert the byte array to char array with respect to given charset.
static byte[] convertCharArrayToByteArray(char[] charArray, String strCharset)
          Convert the char array to byte array with respect to given charset.
static ClassLoader getClassLoader()
          Get the current thread's context class loader which is set to the CommonClassLoader by ApplicationServer
static String getEnvOrProp(String name)
          Return the value for a given name from the System Properties or the Environmental Variables.
static String getLocalAddress()
          Return the hostname of the local machine.
static String getLocalHost()
          Return the hostname of the local machine.
static Properties getPropertiesFromFile(String file)
           
static void intToBytes(int value, byte[] array, int offset)
          Marshal an integer to a byte array.
static short intToShort(int value)
           
static void invokeApplicationMain(Class mainClass, String[] args)
          Verify and invoke main if present in the specified class.
static void invokeSetMethod(Object obj, String prop, String value)
           
static void invokeSetMethodCaseInsensitive(Object obj, String prop, String value)
           
static Class loadClass(String className)
          Loads the class with the common class loader.
static void longToBytes(long value, byte[] array, int offset)
          Marshal an long to a byte array.
static Remote lookupObject(String publishedName, Class anInterface)
          This is a convenience method to lookup a remote object by name within the naming context.
static ClassLoader setContextClassLoader(ClassLoader newClassLoader)
          Utility routine for setting the context class loader.
static void setEnvironment()
           
static int shortToInt(short value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

checkJVMVersion

public static void checkJVMVersion()

getPropertiesFromFile

public static Properties getPropertiesFromFile(String file)
                                        throws IOException
Throws:
IOException

getLocalHost

public static String getLocalHost()
Return the hostname of the local machine.


getLocalAddress

public static String getLocalAddress()
Return the hostname of the local machine.


lookupObject

public static Remote lookupObject(String publishedName,
                                  Class anInterface)
                           throws NamingException
This is a convenience method to lookup a remote object by name within the naming context.

Throws:
NamingException - if the object with that name could not be found.

bytesToInt

public static int bytesToInt(byte[] array,
                             int offset)
Unmarshal a byte array to an integer. Assume the bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+3] is the least-significant-byte.

Parameters:
array - The array of bytes.
offset - The offset from which to start unmarshalling.

intToBytes

public static void intToBytes(int value,
                              byte[] array,
                              int offset)
Marshal an integer to a byte array. The bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+3] is the least-significant-byte.

Parameters:
array - The array of bytes.
offset - The offset from which to start marshalling.

bytesToLong

public static long bytesToLong(byte[] array,
                               int offset)
Unmarshal a byte array to an long. Assume the bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+7] is the least-significant-byte.

Parameters:
array - The array of bytes.
offset - The offset from which to start unmarshalling.

longToBytes

public static void longToBytes(long value,
                               byte[] array,
                               int offset)
Marshal an long to a byte array. The bytes are in BIGENDIAN order. i.e. array[offset] is the most-significant-byte and array[offset+7] is the least-significant-byte.

Parameters:
array - The array of bytes.
offset - The offset from which to start marshalling.

invokeApplicationMain

public static void invokeApplicationMain(Class mainClass,
                                         String[] args)
                                  throws InvocationTargetException,
                                         IllegalAccessException,
                                         ClassNotFoundException
Verify and invoke main if present in the specified class.

Throws:
InvocationTargetException
IllegalAccessException
ClassNotFoundException

invokeSetMethod

public static void invokeSetMethod(Object obj,
                                   String prop,
                                   String value)
                            throws NoSuchMethodException,
                                   InvocationTargetException,
                                   IllegalAccessException
Throws:
NoSuchMethodException
InvocationTargetException
IllegalAccessException

invokeSetMethodCaseInsensitive

public static void invokeSetMethodCaseInsensitive(Object obj,
                                                  String prop,
                                                  String value)
                                           throws NoSuchMethodException,
                                                  InvocationTargetException,
                                                  IllegalAccessException
Throws:
NoSuchMethodException
InvocationTargetException
IllegalAccessException

intToShort

public static short intToShort(int value)

shortToInt

public static int shortToInt(short value)

getClassLoader

public static ClassLoader getClassLoader()
Get the current thread's context class loader which is set to the CommonClassLoader by ApplicationServer

Returns:
the thread's context classloader if it exists; else the system class loader.

loadClass

public static Class loadClass(String className)
                       throws ClassNotFoundException
Loads the class with the common class loader.

Parameters:
className - the class name
Returns:
the loaded class
Throws:
if - the class is not found.
ClassNotFoundException

setContextClassLoader

public static ClassLoader setContextClassLoader(ClassLoader newClassLoader)
Utility routine for setting the context class loader. Returns previous class loader.


setEnvironment

public static void setEnvironment()

getEnvOrProp

public static String getEnvOrProp(String name)
Return the value for a given name from the System Properties or the Environmental Variables. The former overrides the latter.

Parameters:
name - - the name of the System Property or Environmental Variable
Returns:
the value of the variable or null if it was not found

convertByteArrayToCharArray

public static char[] convertByteArrayToCharArray(byte[] byteArray,
                                                 String charset)
                                          throws CharacterCodingException
Convert the byte array to char array with respect to given charset.

Parameters:
byteArray -
charset - null or "" means default charset
Throws:
CharacterCodingException

convertCharArrayToByteArray

public static byte[] convertCharArrayToByteArray(char[] charArray,
                                                 String strCharset)
                                          throws CharacterCodingException
Convert the char array to byte array with respect to given charset.

Parameters:
charArray -
strCharset - null or "" means default charset
Throws:
CharacterCodingException


Copyright © 2012 GlassFish Community. All Rights Reserved.