1 19 package org.apache.cayenne.reflect.generic; 20 21 import org.apache.cayenne.DataObject; 22 import org.apache.cayenne.reflect.Property; 23 import org.apache.cayenne.reflect.PropertyException; 24 import org.apache.cayenne.reflect.PropertyVisitor; 25 26 32 abstract class DataObjectBaseProperty implements Property { 33 34 public abstract String getName(); 35 36 public abstract void injectValueHolder(Object object) throws PropertyException; 37 38 public abstract boolean visit(PropertyVisitor visitor); 39 40 public Object readProperty(Object object) throws PropertyException { 41 try { 42 return toDataObject(object).readProperty(getName()); 43 } 44 catch (Throwable th) { 45 throw new PropertyException( 46 "Error reading DataObject property: " + getName(), 47 this, 48 object, 49 th); 50 } 51 } 52 53 public void writeProperty(Object object, Object oldValue, Object newValue) 54 throws PropertyException { 55 try { 56 toDataObject(object).writeProperty(getName(), newValue); 57 } 58 catch (Throwable th) { 59 throw new PropertyException( 60 "Error writing DataObject property: " + getName(), 61 this, 62 object, 63 th); 64 } 65 } 66 67 public Object readPropertyDirectly(Object object) throws PropertyException { 68 try { 69 return toDataObject(object).readPropertyDirectly(getName()); 70 } 71 catch (Throwable th) { 72 throw new PropertyException( 73 "Error reading DataObject property: " + getName(), 74 this, 75 object, 76 th); 77 } 78 } 79 80 public void writePropertyDirectly(Object object, Object oldValue, Object newValue) 81 throws PropertyException { 82 try { 83 toDataObject(object).writePropertyDirectly(getName(), newValue); 84 } 85 catch (Throwable th) { 86 throw new PropertyException( 87 "Error writing DataObject property: " + getName(), 88 this, 89 object, 90 th); 91 } 92 } 93 94 protected final DataObject toDataObject(Object object) throws PropertyException { 95 try { 96 return (DataObject) object; 97 } 98 catch (ClassCastException e) { 99 throw new PropertyException("Object is not a DataObject: '" 100 + object.getClass().getName() 101 + "'", this, object, e); 102 } 103 } 104 } 105 | Popular Tags |