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;
}