1 19 20 package org.apache.cayenne.reflect.generic; 21 22 import org.apache.cayenne.Fault; 23 import org.apache.cayenne.map.ObjRelationship; 24 import org.apache.cayenne.reflect.ArcProperty; 25 import org.apache.cayenne.reflect.ClassDescriptor; 26 import org.apache.cayenne.reflect.PropertyException; 27 import org.apache.cayenne.reflect.PropertyVisitor; 28 import org.apache.cayenne.reflect.ToOneProperty; 29 30 36 class DataObjectToOneProperty extends DataObjectBaseProperty implements ToOneProperty { 37 38 protected ObjRelationship relationship; 39 protected String reverseName; 40 protected ClassDescriptor targetDescriptor; 41 42 DataObjectToOneProperty(ObjRelationship relationship, ClassDescriptor targetDescriptor) { 43 this.relationship = relationship; 44 this.targetDescriptor = targetDescriptor; 45 this.reverseName = relationship.getReverseRelationshipName(); 46 } 47 48 public ArcProperty getComplimentaryReverseArc() { 49 return reverseName != null ? (ArcProperty) targetDescriptor 50 .getProperty(reverseName) : null; 51 } 52 53 public ClassDescriptor getTargetDescriptor() { 54 return targetDescriptor; 55 } 56 57 public String getName() { 58 return relationship.getName(); 59 } 60 61 public ObjRelationship getRelationship() { 62 return relationship; 63 } 64 65 public void injectValueHolder(Object object) throws PropertyException { 66 } 67 68 public void setTarget(Object source, Object target, boolean setReverse) { 69 try { 70 toDataObject(source).setToOneTarget( 71 getName(), 72 toDataObject(target), 73 setReverse); 74 } 75 catch (Throwable th) { 76 throw new PropertyException("Error setting to-one DataObject property: " 77 + getName(), this, source, th); 78 } 79 } 80 81 public boolean visit(PropertyVisitor visitor) { 82 return visitor.visitToOne(this); 83 } 84 85 public boolean isFault(Object object) { 86 return readPropertyDirectly(object) instanceof Fault; 87 } 88 89 public void invalidate(Object object) { 90 writePropertyDirectly(object, null, Fault.getToOneFault()); 91 } 92 } 93 | Popular Tags |