List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T object)
Deep clone an Object using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:com.link_intersystems.lang.reflect.SerializablePackageTest.java
@Test(expected = SerializationException.class) public void classNotFound() throws Exception { Package packageObject = SerializablePackageTest.class.getPackage(); String name = packageObject.getName(); Whitebox.setInternalState(packageObject, String.class, "packagepath.that.does.not.exists", Package.class); try {//ww w .j a v a2s. c om SerializablePackage serializablePackage = new SerializablePackage(packageObject); SerializablePackage deserialized = (SerializablePackage) SerializationUtils.clone(serializablePackage); deserialized.get(); } finally { Whitebox.setInternalState(packageObject, String.class, name, Package.class); } }
From source file:com.eldar.models.templates.Layout.java
@Override public LayoutVersion cloneCurrentVersion() { LayoutVersion clone = SerializationUtils.clone(currentVersion); clone.setId(0); return clone; }
From source file:com.link_intersystems.lang.reflect.SerializableFieldTest.java
@Test(expected = SerializationException.class) public void classNotFound() throws Exception { Field field = SerializableFieldTest.class.getDeclaredField("testField"); String name = field.getName(); Whitebox.setInternalState(field, "name", "noSuchField"); try {// w w w . j a v a 2 s .c om SerializableField serializableField = new SerializableField(field); SerializableField deserialized = (SerializableField) SerializationUtils.clone(serializableField); deserialized.get(); } finally { /* * Restore original state */ Whitebox.setInternalState(field, "name", name); } }
From source file:com.link_intersystems.lang.reflect.SerializableConstructorTest.java
@Test public void securityException() throws Throwable { Constructor<ConstructorSerializationTestClass> constructor = ConstructorSerializationTestClass.class .getDeclaredConstructor(String.class); final SerializableConstructor serializableConstructor = new SecurityExceptionSerializableConstructor( constructor);/* w w w . j a va 2s. co m*/ Assertion.assertCause(SecurityException.class, new Callable<Object>() { public Object call() throws Exception { return SerializationUtils.clone(serializableConstructor); } }); }
From source file:com.eldar.models.Page.java
@Override public PageVersion cloneCurrentVersion() { PageVersion clone = SerializationUtils.clone(currentVersion); clone.setId(0);/*from ww w . ja v a 2s .c o m*/ clone.setKey(""); return null; //To change body of implemented methods use File | Settings | File Templates. }
From source file:com.link_intersystems.lang.reflect.SerializableFieldTest.java
@Test(expected = SerializationException.class) public void modifierChanged() throws SecurityException, NoSuchFieldException { Field field = SerializableFieldTest.class.getDeclaredField("testField"); SerializableField serializableField = new SerializationExceptionSerializableField(field); SerializationUtils.clone(serializableField); }
From source file:com.eldar.models.elements.HtmlElement.java
@Override public HtmlElementVersion cloneCurrentVersion() { HtmlElementVersion clone = SerializationUtils.clone(version); clone.setId(0); return clone; }
From source file:be.error.rpi.heating.RoomTemperature.java
public RoomTemperature clone() { return SerializationUtils.clone(this); }
From source file:com.mirth.connect.plugins.serverlog.ServerLogProvider.java
public LinkedList<String[]> getServerLogs(String sessionId) { // work with deep copied clone of the static server logs object in // order to avoid multiple threads ConcurrentModificationException. LinkedList<String[]> serverLogsCloned = new LinkedList<String[]>(); try {// ww w . j av a 2s .c o m serverLogsCloned = (LinkedList<String[]>) SerializationUtils.clone(serverLogs); } catch (SerializationException e) { // ignore } if (lastDisplayedServerLogIdBySessionId.containsKey(sessionId)) { // client exist with the sessionId. // -> only display new log entries. long lastDisplayedServerLogId = lastDisplayedServerLogIdBySessionId.get(sessionId); LinkedList<String[]> newServerLogEntries = new LinkedList<String[]>(); // FYI, channelLog.size() will never be larger than LOG_SIZE = // 100. for (String[] aServerLog : serverLogsCloned) { if (lastDisplayedServerLogId < Long.parseLong(aServerLog[0])) { newServerLogEntries.addLast(aServerLog); } } if (newServerLogEntries.size() > 0) { // put the lastDisplayedLogId into the HashMap. index 0 is // the most recent entry, and index0 of that entry contains // the logId. lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(newServerLogEntries.get(0)[0])); } try { return SerializationUtils.clone(newServerLogEntries); } catch (SerializationException e) { logger.error(e); } } else { // brand new client. i.e. brand new session id, and all log // entries are new. // -> display all log entries. if (serverLogsCloned.size() > 0) { lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(serverLogsCloned.get(0)[0])); } else { // no log exist at all. put the currentLogId-1, which is the // very latest logId. lastDisplayedServerLogIdBySessionId.put(sessionId, logId - 1); } try { return SerializationUtils.clone(serverLogsCloned); } catch (SerializationException e) { logger.error(e); } } return null; }
From source file:com.eldar.models.templates.Template.java
/** * Clones the current version using apache commons SerializationUtils. * * @return - the clone.//from w w w . j a va 2 s .co m */ @Override public TemplateVersion cloneCurrentVersion() { TemplateVersion clone = SerializationUtils.clone(getVersion()); //reset all the ids of the clones so they save. clone.setId(0); return clone; }