/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The 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 { TargetSource disconnectedTargetSource = new SingletonTargetSource(getTarget()); return disconnectedTargetSource; } catch (Exception ex) { logger.error("Cannot get target for disconnecting TargetSource [" + this + "]", ex); throw new NotSerializableException( "Cannot get target for disconnecting TargetSource [" + this + "]: " + ex.getMessage()); } }