1 7 package java.beans; 8 9 70 71 public abstract class PersistenceDelegate { 72 73 93 public void writeObject(Object oldInstance, Encoder out) { 94 Object newInstance = out.get(oldInstance); 95 if (!mutatesTo(oldInstance, newInstance)) { 96 out.remove(oldInstance); 97 out.writeExpression(instantiate(oldInstance, out)); 98 } 99 else { 100 initialize(oldInstance.getClass(), oldInstance, newInstance, out); 101 } 102 } 103 104 123 protected boolean mutatesTo(Object oldInstance, Object newInstance) { 124 return (newInstance != null && oldInstance != null && 125 oldInstance.getClass() == newInstance.getClass()); 126 } 127 128 146 protected abstract Expression instantiate(Object oldInstance, Encoder out); 147 148 184 protected void initialize(Class <?> type, 185 Object oldInstance, Object newInstance, 186 Encoder out) 187 { 188 Class superType = type.getSuperclass(); 189 PersistenceDelegate info = out.getPersistenceDelegate(superType); 190 info.initialize(superType, oldInstance, newInstance, out); 191 } 192 } 193 | Popular Tags |