KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > DeleteDenyException


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne;
21
22 /**
23  * An exception thrown during an attempt to delete an object that has a relationship to a
24  * non-null related object, that has a DENY delete rule.
25  *
26  * @since 1.2
27  * @author Andrus Adamchik
28  */

29 public class DeleteDenyException extends CayenneRuntimeException {
30
31     protected Persistent object;
32     protected String JavaDoc relationship;
33
34     public DeleteDenyException() {
35     }
36
37     public DeleteDenyException(String JavaDoc message) {
38         super(message);
39     }
40
41     /**
42      * @since 1.2
43      */

44     public DeleteDenyException(Persistent object, String JavaDoc relationship, String JavaDoc reason) {
45         super(reason);
46
47         this.object = object;
48         this.relationship = relationship;
49     }
50
51     /**
52      * @since 1.2
53      */

54     public Persistent getObject() {
55         return object;
56     }
57
58     /**
59      * @since 1.2
60      */

61     public String JavaDoc getRelationship() {
62         return relationship;
63     }
64
65     public String JavaDoc getMessage() {
66         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
67         buffer.append("Can't delete object");
68
69         if (object != null && object.getObjectId() != null) {
70             buffer.append(" with OID ").append(object.getObjectId());
71         }
72
73         if (relationship != null) {
74             buffer.append(". Reason: relationship '").append(relationship).append(
75                     "' has 'deny' delete rule");
76         }
77
78         String JavaDoc message = super.getUnlabeledMessage();
79         if (message != null) {
80             buffer.append(". Details: ").append(message);
81         }
82
83         return buffer.toString();
84     }
85 }
86
Popular Tags