1 19 package org.apache.cayenne.reflect; 20 21 import org.apache.cayenne.ObjectContext; 22 import org.apache.cayenne.Persistent; 23 import org.apache.cayenne.map.ObjAttribute; 24 25 31 public class SimpleAttributeProperty extends BaseProperty implements AttributeProperty { 32 33 private ObjAttribute attribute; 34 35 public SimpleAttributeProperty(ClassDescriptor owner, Accessor accessor, 36 ObjAttribute attribute) { 37 super(owner, accessor); 38 this.attribute = attribute; 39 } 40 41 public boolean visit(PropertyVisitor visitor) { 42 return visitor.visitAttribute(this); 43 } 44 45 public ObjAttribute getAttribute() { 46 return attribute; 47 } 48 49 public Object readProperty(Object object) throws PropertyException { 50 resolveFault(object); 51 return super.readProperty(object); 52 } 53 54 public void writeProperty(Object object, Object oldValue, Object newValue) 55 throws PropertyException { 56 resolveFault(object); 57 super.writeProperty(object, oldValue, newValue); 58 } 59 60 protected void resolveFault(Object object) throws PropertyException { 61 try { 62 Persistent persistent = (Persistent) object; 63 ObjectContext context = persistent.getObjectContext(); 64 if (context != null) { 65 context.prepareForAccess(persistent, getName(), false); 66 } 67 } 68 catch (ClassCastException e) { 69 throw new PropertyException("Object is not a Persistent: '" 70 + object.getClass().getName() 71 + "'", this, object, e); 72 } 73 } 74 } | Popular Tags |