clone.content = null;
contentLock.lock();
try {
for (Iterator seItr = getContent().iterator(); seItr.hasNext();) {
StyleEntry styleEntry = (StyleEntry) seItr.next();
StyleEntry styleEntryClone = ProjectFactory.eINSTANCE.createStyleEntry();
// clone the entry by copying the id + memento over
final String ID = styleEntry.getID();
styleEntryClone.setID(ID);
styleEntryClone.setMemento(styleEntry.getMemento());
Object style = styleEntry.getStyle();
if (style instanceof String) {
styleEntryClone.setStyle(style); // immutable
} else if (style instanceof Serializable) {
try {
Serializable serializable = (Serializable) style;
ByteArrayOutputStream save = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(save);
out.writeObject(style);
out.close();
byte data[] = save.toByteArray();
ByteArrayInputStream restore = new ByteArrayInputStream(data);
ObjectInputStream in = new ObjectInputStream(restore);
Object copy = in.readObject();
in.close();
styleEntryClone.setStyle(copy);
} catch (Throwable t) {
ProjectPlugin.trace(StyleBlackboardImpl.class, "Unable to copy style " + ID
+ ":" + style, t);
}
} else {
// unable to preserve independence of this style object
styleEntryClone.setStyle(style); // warning!
ProjectPlugin.trace(StyleBlackboardImpl.class, "Unable to copy style " + ID
+ ":" + style, null);
}
clone.getContent().add(styleEntryClone);
}