de.root1.simon.utils
Class Utils

java.lang.Object
  extended by de.root1.simon.utils.Utils

public class Utils
extends java.lang.Object

A class with some static helper-methods

Author:
ACHR

Field Summary
static boolean DEBUG
          Deprecated. use JVM argument "java.util.logging.config.file=./log/mylogconfig.properties"
 
Constructor Summary
Utils()
           
 
Method Summary
static byte booleanToByte(boolean bool)
          Converts a boolean value to a byte value.
static boolean byteToBoolean(byte b)
          Converts a byte value to a boolean value.
static long computeMethodHash(java.lang.reflect.Method m)
          Compute the "method hash" of a remote method.
static java.lang.Class<?>[] findAllRemoteInterfaces(java.lang.Class<?> clazz)
          Method that returns an Class
static SimonRemoteMarker getMarker(java.lang.Object o)
          Returns the related instance of SimonRemoteMarker of the given object.
static SimonProtocolCodecFactory getProtocolFactoryInstance(java.lang.String protocolFactory)
          Loads a protocol codec factory by a given classname
static java.lang.Class<?>[] getRemoteAnnotationValue(java.lang.Object remoteObject)
          Checks whether the object is annotated with SimonRemote or not
static java.lang.Throwable getRootCause(java.lang.Throwable th)
          Looks up and returns the root cause of an exception.
static java.lang.String getStackTraceAsString(java.lang.Throwable e)
          Returns the stacktrace of the given throwable as a string.
static boolean isRemoteAnnotated(java.lang.Object remoteObject)
          Checks whether the object is annotated with SimonRemote or not
static boolean isSimonProxy(java.lang.Object o)
          Checks if given object is a simon proxy.
static boolean isValidRemote(java.lang.Object remoteObject)
          Checks if the given remote object is a valid remote object
static java.lang.String longToHexString(long l)
          Converts a long value to a hex string, i.e. 0xF923
static void putAllInterfaceNames(java.lang.Object object, java.util.List<java.lang.String> interfaceNames)
          Reads all interfaces and subinterfaces of the given object and add the names to the provided interface name list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Deprecated. use JVM argument "java.util.logging.config.file=./log/mylogconfig.properties"
if this flag is set to TRUE, SIMON tries to load the java.util.logging properties and enabled the debug-mode

Constructor Detail

Utils

public Utils()
Method Detail

computeMethodHash

public static long computeMethodHash(java.lang.reflect.Method m)
Compute the "method hash" of a remote method. The method hash is a long containing the first 64 bits of the SHA digest from the bytes representing the complete method signature.

Parameters:
m - the method for which the hash has to be computed
Returns:
the computed hash

getProtocolFactoryInstance

public static SimonProtocolCodecFactory getProtocolFactoryInstance(java.lang.String protocolFactory)
                                                            throws java.lang.ClassNotFoundException,
                                                                   java.lang.InstantiationException,
                                                                   java.lang.IllegalAccessException
Loads a protocol codec factory by a given classname

Parameters:
protocolFactory - a class name like "com.mydomain.myproject.codec.mySimonProtocolCodecFactory" which points to a class, that extends SimonProtocolCodecFactory. The important thing is, that this class correctly overrides SimonProtocolCodecFactory.setup(boolean). For further details, look at SimonProtocolCodecFactory!
Returns:
the protocolcodecfactory instance according to the given protocol factory class name
Throws:
java.lang.IllegalAccessException - if the class or its nullary constructor is not accessible.
java.lang.InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
java.lang.ClassNotFoundException - if the class is not found by the classloader. if so, please check your classpath.
java.lang.ClassCastException - if the given class is no instance of SimonProtocolCodecFactory

longToHexString

public static java.lang.String longToHexString(long l)
Converts a long value to a hex string, i.e. 0xF923

Parameters:
l -
Returns:
return a string showing the hex value of parameter l

booleanToByte

public static byte booleanToByte(boolean bool)
Converts a boolean value to a byte value.

Parameters:
bool -
Returns:
0xFF if true, 0x00 if false

byteToBoolean

public static boolean byteToBoolean(byte b)
                             throws java.lang.IllegalArgumentException
Converts a byte value to a boolean value.

Parameters:
b -
Returns:
0xFF if true, 0x00 if false
Throws:
java.lang.IllegalArgumentException - if byte value not 0xFF or 0x00

findAllRemoteInterfaces

public static java.lang.Class<?>[] findAllRemoteInterfaces(java.lang.Class<?> clazz)
Method that returns an Class array containing all remote interfaces of a given class

Parameters:
clazz - the class to analyse for remote interfaces
Returns:
the array with all known remote interfaces

isRemoteAnnotated

public static boolean isRemoteAnnotated(java.lang.Object remoteObject)
Checks whether the object is annotated with SimonRemote or not

Parameters:
remoteObject - the object to check
Returns:
true, if object is annotated, false if not

getRemoteAnnotationValue

public static java.lang.Class<?>[] getRemoteAnnotationValue(java.lang.Object remoteObject)
Checks whether the object is annotated with SimonRemote or not

Parameters:
remoteObject - the object to check
Returns:
true, if object is annotated, false if not

isValidRemote

public static boolean isValidRemote(java.lang.Object remoteObject)
Checks if the given remote object is a valid remote object

Parameters:
remoteObject - the object to check
Returns:
true, if remote object is valid, false if not
Throws:
IllegalRemoteObjectException - thrown in case of a faulty remote object (ie. missing interfaces)

isSimonProxy

public static boolean isSimonProxy(java.lang.Object o)
Checks if given object is a simon proxy.

Parameters:
o - object to check
Returns:
true, if object is a simon proxy, false if not

getMarker

public static SimonRemoteMarker getMarker(java.lang.Object o)
Returns the related instance of SimonRemoteMarker of the given object. if the specified object isn't marked, null is returned.

Parameters:
o -
Returns:
the related instance of SimonRemoteMarker, or null if given object is not marked

putAllInterfaceNames

public static void putAllInterfaceNames(java.lang.Object object,
                                        java.util.List<java.lang.String> interfaceNames)
Reads all interfaces and subinterfaces of the given object and add the names to the provided interface name list

Parameters:
object - the object to search for interfaces
interfaceNames - the list to which found interfaces names are added

getStackTraceAsString

public static java.lang.String getStackTraceAsString(java.lang.Throwable e)
Returns the stacktrace of the given throwable as a string. String will be the same as "e.printStackTrace();" woulld print to console

Parameters:
e -
Returns:
the exceptions stacktrace as a string

getRootCause

public static java.lang.Throwable getRootCause(java.lang.Throwable th)
Looks up and returns the root cause of an exception. If none is found, returns supplied Throwable object unchanged. If root is found, recursively "unwraps" it, and returns the result to the caller.

Parameters:
th -
Returns:
the exceptions root-cause, if available, otherwise th will be returned unchanged


Copyright © 2011. All Rights Reserved.