KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ConflictException.java,v 1.7 2004/07/28 09:35:29 ib Exp $
3  * $Revision: 1.7 $
4  * $Date: 2004/07/28 09:35:29 $
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.common.SlideException;
31 import org.apache.slide.util.Messages;
32
33 /**
34  * The copy/move operation is in conflict, e.g. the path of the destination is not created (yet).
35  *
36  * @version $Revision: 1.7 $
37  */

38 public class ConflictException extends SlideException {
39
40
41     // ----------------------------------------------------------- Constructors
42

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

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

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

71
72     /**
73      * Object uri.
74      */

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

86
87     /**
88      * Object Uri accessor.
89      *
90      * @return String object uri
91      */

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

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

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