/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource/EmptyTargetSource. Object target = getTarget(); return (target != null ? new SingletonTargetSource(target) : EmptyTargetSource.forClass(getTargetClass())); } catch (Exception ex) { String msg = "Cannot get target for disconnecting TargetSource [" + this + "]"; logger.error(msg, ex); throw new NotSerializableException(msg + ": " + ex); } }
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource. return new SingletonTargetSource(getTarget()); } catch (Exception ex) { logger.error("Cannot get target for disconnecting TargetSource [" + this + "]", ex); throw new NotSerializableException( "Cannot get target for disconnecting TargetSource [" + this + "]: " + ex); } }
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource/EmptyTargetSource. Object target = getTarget(); return (target != null ? new SingletonTargetSource(target) : EmptyTargetSource.forClass(getTargetClass())); } catch (Exception ex) { String msg = "Cannot get target for disconnecting TargetSource [" + this + "]"; logger.error(msg, ex); throw new NotSerializableException(msg + ": " + ex); } }