org.ow2.jonas.lib.util
Class JNDIUtils

java.lang.Object
  extended by org.ow2.jonas.lib.util.JNDIUtils

public class JNDIUtils
extends Object

JNDIUtils groups all commonly used methods for JNDI.

Author:
Guillaume Sauthier

Method Summary
static
<T> T
extractObjectFrom(Reference ref, String key, Class<T> type)
          Extract an Object from the Reference.
static String extractStringFrom(Reference ref, String key)
          Extract a String value with the given key, from the Reference.
static byte[] getBytesFromObject(Object obj)
          Return an array of byte from a given object
static byte[] getBytesFromObject(Object obj, org.objectweb.util.monolog.api.Logger logger)
          Return an array of byte from a given object
static Object getObjectFromBytes(byte[] bytes)
          Return an object from an array of bytes.
static Object getObjectFromBytes(byte[] bytes, org.objectweb.util.monolog.api.Logger logger)
          Return an object from an array of bytes.
static void insertInto(Reference ref, String key, Object value)
          Insert a key/value String/Object couple in the given Reference after serialization of the value.
static void insertInto(Reference ref, String key, String value)
          Insert a key/value String/String couple in the given Reference as a StringRefAddr.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBytesFromObject

public static byte[] getBytesFromObject(Object obj)
Return an array of byte from a given object

Parameters:
obj - the object from which we must extract the bytes.
Returns:
the byte[] from an object

getBytesFromObject

public static byte[] getBytesFromObject(Object obj,
                                        org.objectweb.util.monolog.api.Logger logger)
Return an array of byte from a given object

Parameters:
obj - the object from which we must extract the bytes.
logger - logger to log exceptions
Returns:
the byte[] from an object

getObjectFromBytes

public static Object getObjectFromBytes(byte[] bytes)
Return an object from an array of bytes. Useful for BinaryRefAddr Useful for BinaryRefAddr

Parameters:
bytes - an array of bytes
Returns:
an object or null if there is an error of if it's empty

getObjectFromBytes

public static Object getObjectFromBytes(byte[] bytes,
                                        org.objectweb.util.monolog.api.Logger logger)
Return an object from an array of bytes. Useful for BinaryRefAddr

Parameters:
bytes - an array of bytes
logger - logger to log exceptions
Returns:
an object or null if there is an error of if it's empty

insertInto

public static void insertInto(Reference ref,
                              String key,
                              String value)
Insert a key/value String/String couple in the given Reference as a StringRefAddr.

Parameters:
ref - Reference to be modified
key - Address' key
value - Address' value

insertInto

public static void insertInto(Reference ref,
                              String key,
                              Object value)
Insert a key/value String/Object couple in the given Reference after serialization of the value.

Parameters:
ref - Reference to be modified
key - Address' key
value - Object value (will be serialized)

extractStringFrom

public static String extractStringFrom(Reference ref,
                                       String key)
Extract a String value with the given key, from the Reference.

Parameters:
ref - Reference that holds the value within
key - Key of the value
Returns:
the String value

extractObjectFrom

public static <T> T extractObjectFrom(Reference ref,
                                      String key,
                                      Class<T> type)
Extract an Object from the Reference. Notice that this object have to be castable to the given Class parameter. The ClassLoader where this class live is used to deserialize the object. If it cannot load the requested class, a ClassLoading error will probably occur.

Parameters:
ref - Reference that holds the serialized version of the requested object
key - Object's key
type - Object's type (may be an interface)
Returns:
an Object casted with Class


Copyright © 2010 OW2 Consortium. All Rights Reserved.