KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > macro > ForbiddenException


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ForbiddenException.java,v 1.6 2004/07/28 09:35:28 ib Exp $
3  * $Revision: 1.6 $
4  * $Date: 2004/07/28 09:35:28 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.macro;
25
26
27 import java.io.StringWriter JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29
30 import org.apache.slide.util.Messages;
31 import org.apache.slide.common.SlideException;
32
33
34 /**
35  * The copy/move operation is forbidden, e.g. source and destination uri are identical.
36  *
37  * @version $Revision: 1.6 $
38  */

39 public class ForbiddenException extends SlideException {
40     
41     
42     // ----------------------------------------------------------- Constructors
43

44     
45     
46     /**
47      * Constructor.
48      *
49      * @param objectUri Uri of the forbidden operation
50      */

51     public ForbiddenException(String JavaDoc objectUri) {
52         this(objectUri, new SlideException("no cause given", false));
53     }
54     
55     
56     /**
57      * Constructor.
58      *
59      * @param objectUri Uri of the forbidden operation
60      * @param t Throwable containing the reason
61      */

62     public ForbiddenException(String JavaDoc objectUri, Throwable JavaDoc t) {
63         super(Messages.format(ConflictException.class.getName(), objectUri, computeCause(t)), t!=null);
64         this.objectUri = objectUri;
65         this.nestedException = t;
66     }
67     
68     
69     
70     
71     // ----------------------------------------------------- Instance Variables
72

73     
74     /**
75      * Object uri.
76      */

77     private String JavaDoc objectUri;
78     
79
80     /* hold the cause exception, if supplied */
81     private Throwable JavaDoc nestedException = null;
82
83     
84     
85     
86     // ------------------------------------------------------------- Properties
87

88     
89     /**
90      * Object Uri accessor.
91      *
92      * @return String object uri
93      */

94     public String JavaDoc getObjectUri() {
95         return objectUri;
96     }
97     
98     
99     
100     /**
101      * computeCause.
102      *
103      * @param e if getMessage is empty the stack trace of e is used
104      */

105     private static String JavaDoc computeCause(Throwable JavaDoc e) {
106         return computeCause(e==null?"":e.getMessage(), e);
107     }
108     
109     /**
110      * computeCause.
111      *
112      * @param delieveredCause the cause as a string, if null or empty e is used
113      * @param e the exception stacktrace is shown, if cause is not supplied
114      */

115     private static String JavaDoc computeCause(String JavaDoc delieveredCause, Throwable JavaDoc e) {
116         String JavaDoc result = delieveredCause;
117         if (delieveredCause == null || delieveredCause.equals("")) {
118             StringWriter JavaDoc sw = new StringWriter JavaDoc();
119             e.printStackTrace( new PrintWriter JavaDoc(sw, true) ); //autoFlush=true
120
result = sw.toString();
121         }
122         return result;
123     }
124     
125     
126 }
127
Popular Tags