1 19 20 package org.apache.cayenne.reflect.generic; 21 22 import org.apache.cayenne.DataObject; 23 import org.apache.cayenne.reflect.Accessor; 24 import org.apache.cayenne.reflect.PropertyException; 25 26 32 class DataObjectAccessor implements Accessor { 33 34 protected String propertyName; 35 36 DataObjectAccessor(String propertyName) { 37 38 if (propertyName == null) { 39 throw new IllegalArgumentException ("Null propertyName"); 40 } 41 42 this.propertyName = propertyName; 43 } 44 45 public String getName() { 46 return propertyName; 47 } 48 49 53 public Object getValue(Object object) throws PropertyException { 54 try { 55 56 DataObject dataObject = (DataObject) object; 57 return dataObject.readPropertyDirectly(propertyName); 58 } 59 catch (ClassCastException e) { 60 throw new PropertyException("Object is not a DataObject: '" 61 + object.getClass().getName() 62 + "'", this, object, e); 63 } 64 catch (Throwable th) { 65 throw new PropertyException("Error reading DataObject property: " 66 + propertyName, this, object, th); 67 } 68 69 } 71 72 75 public void setValue(Object object, Object newValue) throws PropertyException { 76 77 try { 78 ((DataObject) object).writePropertyDirectly(propertyName, newValue); 79 } 80 catch (ClassCastException e) { 81 throw new PropertyException("Object is not a DataObject: '" 82 + object.getClass().getName() 83 + "'", this, object, e); 84 } 85 catch (Throwable th) { 86 throw new PropertyException("Error reading DataObject property: " 87 + propertyName, this, object, th); 88 } 89 90 } 93 } 94 | Popular Tags |