1 56 57 package org.objectstyle.cayenne.access; 58 59 import org.objectstyle.cayenne.CayenneRuntimeException; 60 import org.objectstyle.cayenne.DataObject; 61 import org.objectstyle.cayenne.map.DeleteRule; 62 import org.objectstyle.cayenne.map.ObjRelationship; 63 64 70 public class DeleteDenyException extends CayenneRuntimeException { 71 72 protected DataObject object; 73 protected ObjRelationship relationship; 74 75 78 public DeleteDenyException() { 79 super(); 80 } 81 82 87 public DeleteDenyException(String message) { 88 super(message); 89 } 90 91 94 public DeleteDenyException(DataObject object, ObjRelationship relationship, 95 String reason) { 96 super(reason); 97 this.object = object; 98 this.relationship = relationship; 99 } 100 101 104 public DataObject getObject() { 105 return object; 106 } 107 108 111 public ObjRelationship getRelationship() { 112 return relationship; 113 } 114 115 public String getMessage() { 116 StringBuffer buffer = new StringBuffer (); 117 buffer.append("Can't delete object"); 118 119 if (object != null && object.getObjectId() != null) { 120 buffer.append(" with OID ").append(object.getObjectId()); 121 } 122 123 if (relationship != null) { 124 buffer 125 .append(". Reason: relationship '") 126 .append(relationship.getName()) 127 .append("' has ") 128 .append(DeleteRule.deleteRuleName(relationship.getDeleteRule())); 129 } 130 131 String message = super.getUnlabeledMessage(); 132 if (message != null) { 133 buffer.append(". Details: ").append(message); 134 } 135 136 return buffer.toString(); 137 } 138 } | Popular Tags |