FileDocCategorySizeDatePackage
NamingUtils.javaAPI DocGlassfish v2 API3401Fri May 04 22:35:08 BST 2007com.sun.enterprise.naming

NamingUtils

public class NamingUtils extends Object
This is a utils class for refactoring the following method.

Fields Summary
static Logger
_logger
Constructors Summary
Methods Summary
public static java.lang.ObjectmakeCopyOfObject(java.lang.Object obj)
method to make a copy of the object.


                 

       

       
	if ( obj instanceof Serializable ) {
	    try {
		// first serialize the object
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(obj);
		oos.flush();
		byte[] data = bos.toByteArray();
		oos.close();
		bos.close();
		
		// now deserialize it
		ByteArrayInputStream bis = new ByteArrayInputStream(data);
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		ObjectInputStream ois = new ObjectInputStreamWithLoader(bis,cl);
             
                               
		return ois.readObject();
	    } catch ( Exception ex ) {
         
                _logger.log(Level.SEVERE,
                            "enterprise_naming.excep_in_copymutableobj", ex);

                RuntimeException re = 
                    new RuntimeException("Cant copy Serializable object:");
                re.initCause(ex);
                throw re;
	    }
	}
	else {
	    // XXX no copy ?
	    return obj;
	}