How to clone JRDesignXXX objects

How do you clone the JRDesignXXX objects like JRDesignTextField?
barry@guild1.com's picture
Joined: Jul 19 2006 - 4:02am
Last seen: 16 years 10 months ago

3 Answers:

All else fails, I guess I can use something like the following since it is Serializable

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class CloneSerialized {
public final static <T extends Serializable> T cloneObject(T o) throws Exception
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);

oos.writeObject(o);
oos.close();

ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);

T ret = (T)ois.readObject();

return ret;
}
}
barry@guild1.com's picture
Joined: Jul 19 2006 - 4:02am
Last seen: 16 years 10 months ago
Turns out this is very slow; works but slow; likely because it is having to follow object references that get serialized as well
barry@guild1.com's picture
Joined: Jul 19 2006 - 4:02am
Last seen: 16 years 10 months ago
JasperReports version 2.0.3 and later now includes clone support for JRDesign objects. This is exactly the right solution to the problem of dynamically generating templates with multiple columns not known until runtime.
Way to go JR guys!
dsteck's picture
15
Joined: Dec 3 2007 - 8:26am
Last seen: 15 years 5 months ago
Feedback