[lang] CloneUtils

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

[lang] CloneUtils

Kevin Gessner
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Shaun Kalley
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: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [lang] CloneUtils

James Carman
SerializationUtils already has a clone() method.  Is your code different
from that?

-----Original Message-----
From: Shaun Kalley [mailto:[hidden email]]
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: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Shaun Kalley
Pretty much the same, except contained in a single method rather than
split among several.

Shaun


James Carman wrote:

>SerializationUtils already has a clone() method.  Is your code different
>from that?
>
>-----Original Message-----
>From: Shaun Kalley [mailto:[hidden email]]
>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: [hidden email]
>>For additional commands, e-mail: [hidden email]
>>
>>
>>
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>
>  
>

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Shaun Kalley
In reply to this post by James Carman
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:[hidden email]]
>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: [hidden email]
>>For additional commands, e-mail: [hidden email]
>>
>>
>>
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>
>  
>

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Kevin Gessner
Thanks Shaun - I'd be happy to have the code if you'll send it along.

Kevin

On 6/4/05, Shaun Kalley <[hidden email]> 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:[hidden email]]
> >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: [hidden email]
> >>For additional commands, e-mail: [hidden email]
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [hidden email]
> >For additional commands, e-mail: [hidden email]
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [hidden email]
> >For additional commands, e-mail: [hidden email]
> >
> >
> >
> >
> >
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Shaun Kalley
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 <[hidden email]> 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:[hidden email]]
>>>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: [hidden email]
>>>>For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [hidden email]
>>>For additional commands, e-mail: [hidden email]
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [hidden email]
>>>For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>>
>>>
>>>      
>>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>
>  
>

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Stephen Colebourne
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 <[hidden email]> 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 <[hidden email]>
> 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:[hidden email]]
> >>>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:
> [hidden email]
> >>>>For additional commands, e-mail:
> [hidden email]
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>        
> >>>>
> >>>
>
>>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail:
> [hidden email]
> >>>For additional commands, e-mail:
> [hidden email]
> >>>
> >>>
>
>>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail:
> [hidden email]
> >>>For additional commands, e-mail:
> [hidden email]
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>      
> >>>
> >>
> >>    
> >>
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> [hidden email]
> >For additional commands, e-mail:
> [hidden email]
> >
> >
> >
> >  
> >
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Kyle Miller
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 <[hidden email]>
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 <[hidden email]> 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 <[hidden email]>
> > 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:[hidden email]]
> > >>>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:
> > [hidden email]
> > >>>>For additional commands, e-mail:
> > [hidden email]
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>        
> > >>>>
> > >>>
> >
>
>>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail:
> > [hidden email]
> > >>>For additional commands, e-mail:
> > [hidden email]
> > >>>
> > >>>
> >
>
>>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail:
> > [hidden email]
> > >>>For additional commands, e-mail:
> > [hidden email]
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>      
> > >>>
> > >>
> > >>    
> > >>
> > >
> >
>
>---------------------------------------------------------------------
> > >To unsubscribe, e-mail:
>
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [lang] CloneUtils

James Carman
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:[hidden email]]
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 <[hidden email]>
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 <[hidden email]> 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 <[hidden email]>
> > 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:[hidden email]]
> > >>>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:
> > [hidden email]
> > >>>>For additional commands, e-mail:
> > [hidden email]
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>        
> > >>>>
> > >>>
> >
>
>>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail:
> > [hidden email]
> > >>>For additional commands, e-mail:
> > [hidden email]
> > >>>
> > >>>
> >
>
>>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail:
> > [hidden email]
> > >>>For additional commands, e-mail:
> > [hidden email]
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>      
> > >>>
> > >>
> > >>    
> > >>
> > >
> >
>
>---------------------------------------------------------------------
> > >To unsubscribe, e-mail:
>
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Stephen Colebourne
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:[hidden email]]
> 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 <[hidden email]>
> 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 <[hidden email]> 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 <[hidden email]>
>>>
>>>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:[hidden email]]
>>>
>>>>>>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:
>>>
>>>[hidden email]
>>>
>>>>>>>For additional commands, e-mail:
>>>
>>>[hidden email]
>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>      
>>>>>>>
>>>>>>
>>>>---------------------------------------------------------------------
>>>>
>>>>>>To unsubscribe, e-mail:
>>>
>>>[hidden email]
>>>
>>>>>>For additional commands, e-mail:
>>>
>>>[hidden email]
>>>
>>>>>>
>>>>---------------------------------------------------------------------
>>>>
>>>>>>To unsubscribe, e-mail:
>>>
>>>[hidden email]
>>>
>>>>>>For additional commands, e-mail:
>>>
>>>[hidden email]
>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>    
>>>>>>
>>>>>
>>>>>  
>>>>>
>>>>
>>---------------------------------------------------------------------
>>
>>>>To unsubscribe, e-mail:
>>
> === message truncated ===
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Kevin Gessner
Kind of what I had in mind, but I'm not sure why serialization would
be the last-attempted method.  It's guaranteed to work for any
Serializable without mucking about with reflection, so it should
probably go first.  We should also add support for Externalizables (as
rare as they often are).  I hacked up some code based on Serialization
cloning, which I could send along.

I don't think this should nec'ly go in with ObjectUtils.  Each of the
techniques of cloning would be its own method, with something like a
cloneAll(Object o) that would try each in turn.  I think this would
make ObjectUtils messy, and CloneUtils would tie it together nicely.

Kevin

On 6/6/05, Stephen Colebourne <[hidden email]> wrote:

> 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:[hidden email]]
> > 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 <[hidden email]>
> > 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 <[hidden email]> 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 <[hidden email]>
> >>>
> >>>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:[hidden email]]
> >>>
> >>>>>>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:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>>For additional commands, e-mail:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>---------------------------------------------------------------------
> >>>>
> >>>>>>To unsubscribe, e-mail:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>For additional commands, e-mail:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>
> >>>>---------------------------------------------------------------------
> >>>>
> >>>>>>To unsubscribe, e-mail:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>For additional commands, e-mail:
> >>>
> >>>[hidden email]
> >>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>---------------------------------------------------------------------
> >>
> >>>>To unsubscribe, e-mail:
> >>
> > === message truncated ===
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Stephen Colebourne
I like the idea of multiple methods with nice names. I'm not averse to a
CloneUtils class (it could be argued that StringUtils is too big as one
class, or that it is most convenient as one class...) Perhaps others can
comment on the location of the new methods.

Stephen


Kevin Gessner wrote:

> Kind of what I had in mind, but I'm not sure why serialization would
> be the last-attempted method.  It's guaranteed to work for any
> Serializable without mucking about with reflection, so it should
> probably go first.  We should also add support for Externalizables (as
> rare as they often are).  I hacked up some code based on Serialization
> cloning, which I could send along.
>
> I don't think this should nec'ly go in with ObjectUtils.  Each of the
> techniques of cloning would be its own method, with something like a
> cloneAll(Object o) that would try each in turn.  I think this would
> make ObjectUtils messy, and CloneUtils would tie it together nicely.
>
> Kevin
>
> On 6/6/05, Stephen Colebourne <[hidden email]> wrote:
>
>>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
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang] CloneUtils

Steven Caswell
I generally like small classes with few methods, but a significant exception
to that is utility classes. In this case I prefer the kind of thing we've
done with StringUtils. That way, when there is string manipulation to be
done, I know exactly where to go to look, without having to drag out sveral
classes hunting the right method. So I'm +1 on multiple methods with nice
names.

On 6/7/05, Stephen Colebourne <[hidden email]> wrote:

>
> I like the idea of multiple methods with nice names. I'm not averse to a
> CloneUtils class (it could be argued that StringUtils is too big as one
> class, or that it is most convenient as one class...) Perhaps others can
> comment on the location of the new methods.
>
> Stephen
>
>
> Kevin Gessner wrote:
> > Kind of what I had in mind, but I'm not sure why serialization would
> > be the last-attempted method. It's guaranteed to work for any
> > Serializable without mucking about with reflection, so it should
> > probably go first. We should also add support for Externalizables (as
> > rare as they often are). I hacked up some code based on Serialization
> > cloning, which I could send along.
> >
> > I don't think this should nec'ly go in with ObjectUtils. Each of the
> > techniques of cloning would be its own method, with something like a
> > cloneAll(Object o) that would try each in turn. I think this would
> > make ObjectUtils messy, and CloneUtils would tie it together nicely.
> >
> > Kevin
> >
> > On 6/6/05, Stephen Colebourne <[hidden email]> wrote:
> >
> >>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
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Steven Caswell
[hidden email]

Take back the web - http://www.mozilla.org
Reply | Threaded
Open this post in threaded view
|

RE: [lang] CloneUtils

James Carman
I like the idea of these methods being in a class which specializes in
cloning.  I think it will make it more obvious where to look.  If a person
wants to find a method which will help them clone their objects, where would
they naturally look?  If there is no CloneUtils, they might look in
ObjectUtils, since the clone() method is defined in the Object class.  It's
not exactly obvious that they should look in SerializationUtils, since not
everyone knows about that little trick.  So, I'm +1 for moving that stuff
into a new class, CloneUtils.

-----Original Message-----
From: Steven Caswell [mailto:[hidden email]]
Sent: Wednesday, June 08, 2005 6:27 AM
To: Jakarta Commons Developers List
Subject: Re: [lang] CloneUtils

I generally like small classes with few methods, but a significant exception

to that is utility classes. In this case I prefer the kind of thing we've
done with StringUtils. That way, when there is string manipulation to be
done, I know exactly where to go to look, without having to drag out sveral
classes hunting the right method. So I'm +1 on multiple methods with nice
names.

On 6/7/05, Stephen Colebourne <[hidden email]> wrote:

>
> I like the idea of multiple methods with nice names. I'm not averse to a
> CloneUtils class (it could be argued that StringUtils is too big as one
> class, or that it is most convenient as one class...) Perhaps others can
> comment on the location of the new methods.
>
> Stephen
>
>
> Kevin Gessner wrote:
> > Kind of what I had in mind, but I'm not sure why serialization would
> > be the last-attempted method. It's guaranteed to work for any
> > Serializable without mucking about with reflection, so it should
> > probably go first. We should also add support for Externalizables (as
> > rare as they often are). I hacked up some code based on Serialization
> > cloning, which I could send along.
> >
> > I don't think this should nec'ly go in with ObjectUtils. Each of the
> > techniques of cloning would be its own method, with something like a
> > cloneAll(Object o) that would try each in turn. I think this would
> > make ObjectUtils messy, and CloneUtils would tie it together nicely.
> >
> > Kevin
> >
> > On 6/6/05, Stephen Colebourne <[hidden email]> wrote:
> >
> >>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
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Steven Caswell
[hidden email]

Take back the web - http://www.mozilla.org


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]