/** Returns the old values of any changed properties. */ public List<Object> getOldValues() { List<Object> oldValues = new ArrayList<Object>(); for (String propertyName : getDirtyProperties()) { if (oldCollectionValues().containsKey(propertyName)) { oldValues.add(oldCollectionValues.get(propertyName)); } else { try { Method g = getter(propertyName); if (g == null) { throw new IllegalArgumentException("No such property: " + propertyName); } oldValues.add(g.invoke(proxyObject, null)); } catch (Exception e) { throw new RuntimeException(e); } } } return oldValues; }
/** Flag which indicates whether any properties of the object being proxied are changed. */ public boolean isDirty() { boolean dirty = false; for (Iterator i = properties().entrySet().iterator(); i.hasNext() && !dirty; ) { Map.Entry e = (Map.Entry) i.next(); if (e.getValue() instanceof Proxy) { ModificationProxy h = handler(e.getValue()); if (h != null && !h.isDirty()) { continue; } } else { try { Object orig = unwrap(getter((String) e.getKey()).invoke(proxyObject, null)); if (orig == null) { if (e.getValue() == null) { continue; } } else if (e.getValue() != null && orig.equals(e.getValue())) { continue; } } catch (Exception ex) { throw new RuntimeException(ex); } } dirty = true; } return dirty; }
List<String> getDirtyProperties() { List<String> propertyNames = new ArrayList<String>(); for (String propertyName : properties().keySet()) { // in the case this property is another proxy, check that it is actually dirty Object value = properties.get(propertyName); if (value instanceof Proxy) { ModificationProxy h = handler(value); if (h != null && !h.isDirty()) { // proxy reports it is not dirty, only return this property if the underling // value is not the same as the current value of the property on the object Object curr = unwrap(value); try { Object orig = unwrap(getter(propertyName).invoke(proxyObject, null)); if (curr == orig) { continue; } } catch (Exception e) { throw new RuntimeException(e); } } } propertyNames.add(propertyName); } return propertyNames; }
Method g = getter(p);