OK, here is the definition of CloneUtils as originally in my mind:
See PrototypeFactory in [collections].
It clones an object by
a) public method named cloned (called by reflection)
b) public copy constructor
c) serialization
(trying each in turn until one suceeds)
IMHO, this would now be written as ObjectUtils.clone(Object).
(serialization is merely a means to an end, otherwise it would sit with
[io])
Stephen
James Carman wrote:
The cloning code in beanutils is for cloning JavaBeans (or objects that
"look like" JavaBeans). This serialization cloning method doesn't place
that restriction. It only requires that the object be serializable. I
think this code is general enough to live in Commons Lang.
-----Original Message-----
From: Kyle Miller [mailto:[EMAIL PROTECTED]
Sent: Monday, June 06, 2005 2:20 PM
To: Jakarta Commons Developers List
Subject: Re: [lang] CloneUtils
I would think that cloning would go into BeanUtils,
which already has some cloning methods. If BeanUtils
already has cloning code, and so does
SerializationUtils, why would write yet another class?
--- Stephen Colebourne <[EMAIL PROTECTED]>
wrote:
Have a look in SerializationUtils. IIRC this code is
already there.
CloneUtils can wrap the code in SerializationUtils
to
achieve its aims, although I'd probably prefer to
just
add a method to ObjectUtils rather than creating a
new
class for one method.
Stephen
--- Shaun Kalley <[EMAIL PROTECTED]> wrote:
I've included my code below. I have another if
you're able to answer
it: why is the lang subproject home to classes
dealing with
serialization? Shouldn't they be part of the IO
subproject?
Thanks,
Shaun
/**
* <p>Clones a serializable object by
serializing and deserializing
it.</p>
*
* @param obj the object to clone.
* @return a clone of the object, or null if
the
object is null.
* @throws SerializationException if the
serialization process fails.
*/
public static Object
cloneSerializable(Serializable obj) throws
SerializationException {
if (obj == null) {
return null;
}
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
try {
ByteArrayOutputStream baos = new
ByteArrayOutputStream(512);
oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.flush();
ois = new ObjectInputStream(new
ByteArrayInputStream(baos.toByteArray()));
return ois.readObject();
} catch (Exception e) {
throw new
SerializationException("Failed
to clone
serializable object.", e);
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException ignored) {
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException ignored) {
}
}
}
}
Kevin Gessner wrote:
Thanks Shaun - I'd be happy to have the code if
you'll send it along.
Kevin
On 6/4/05, Shaun Kalley <[EMAIL PROTECTED]>
wrote:
The only substantial difference in my code is a
shortcut to return null
if the object is null. (Sorry to send two
replies!)
Shaun
James Carman wrote:
SerializationUtils already has a clone()
method.
Is your code different
from that?
-----Original Message-----
From: Shaun Kalley
[mailto:[EMAIL PROTECTED]
Sent: Saturday, June 04, 2005 4:31 PM
To: Jakarta Commons Developers List
Subject: Re: [lang] CloneUtils
Hi, Kevin and everyone,
I've got code for cloning serializable objects
that I'd be happy to
contribute to the project. Let me know if
you'd
like it as a starting
point.
Thanks,
Shaun Kalley
Kevin Gessner wrote:
Hello all,
In the interest of jumping feet first into
commons-lang, I'm hoping to
start work on CloneUtils (from the tasks
list).
Before I start any
serious design/coding, I'd like to ask for any
suggestions as to
features of the class (assuming, of course,
that
no one has anything
completed already). I was planning on
implementing serialization
cloning, and maybe super-simple public fields
cloning if it's worth
it. I would appreciate any
suggestions/tips/etc. anyone has to offer.
Thanks,
Kevin Gessner
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail:
=== message truncated ===
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]