1 19 package org.apache.cayenne.reflect.pojo; 20 21 import org.apache.cayenne.Fault; 22 import org.apache.cayenne.Persistent; 23 import org.apache.cayenne.reflect.Accessor; 24 import org.apache.cayenne.reflect.BaseToOneProperty; 25 import org.apache.cayenne.reflect.ClassDescriptor; 26 import org.apache.cayenne.reflect.PropertyException; 27 28 36 class EnhancedPojoToOneProperty extends BaseToOneProperty { 37 38 protected EnhancedPojoPropertyFaultHandler faultHandler; 39 40 EnhancedPojoToOneProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor, 41 Accessor accessor, String reverseName) { 42 super(owner, targetDescriptor, accessor, reverseName); 43 this.faultHandler = new EnhancedPojoPropertyFaultHandler( 44 owner.getObjectClass(), 45 getName()); 46 } 47 48 public boolean isFault(Object source) { 49 return faultHandler.isFaultProperty(source); 50 } 51 52 public void invalidate(Object object) { 53 faultHandler.setFaultProperty(object, true); 54 } 55 56 void resolveFault(Object object) { 57 if (isFault(object)) { 58 Object target = Fault.getToOneFault().resolveFault( 59 (Persistent) object, 60 getName()); 61 writePropertyDirectly(object, null, target); 62 faultHandler.setFaultProperty(object, false); 63 } 64 } 65 66 public Object readProperty(Object object) throws PropertyException { 67 resolveFault(object); 68 return super.readProperty(object); 69 } 70 } 71 | Popular Tags |