KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > ModelVetoException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ModelVetoException.java
26  *
27  * Created on August 23, 2000, 10:50 PM
28  */

29
30 package com.sun.jdo.api.persistence.model;
31
32 import java.io.PrintStream JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35 import com.sun.jdo.spi.persistence.utility.StringHelper;
36
37 /**
38  *
39  * @author raccah
40  * @version %I%
41  */

42 public class ModelVetoException extends ModelException
43 {
44     /** This field holds the target if the
45      * ModelVetoException (Throwable target) constructor was
46      * used to instantiate the object
47      */

48     private Throwable JavaDoc _target;
49
50     /**
51      * Creates new <code>ModelVetoException</code> without detail message and
52      * <code>null</code> as the target exception.
53      */

54     public ModelVetoException ()
55     {
56     }
57
58     /**
59      * Constructs an <code>ModelVetoException</code> with the specified
60      * detail message and <code>null</code> as the target exception..
61      * @param msg the detail message.
62      */

63     public ModelVetoException (String JavaDoc msg)
64     {
65         super(msg);
66     }
67
68     /**
69      * Constructs a ModelVetoException with a target exception.
70      */

71     public ModelVetoException (Throwable JavaDoc target)
72     {
73         super();
74         _target = target;
75     }
76
77     /**
78      * Constructs a ModelVetoException with a target exception
79      * and a detail message.
80      */

81     public ModelVetoException (Throwable JavaDoc target, String JavaDoc s)
82     {
83         super(s);
84         _target = target;
85     }
86
87     /**
88      * Get the thrown target exception.
89      */

90     public Throwable JavaDoc getTargetException() { return _target; }
91
92     /**
93     * Returns the error message string of this throwable object.
94     * @return the error message string of this <code>ModelVetoException</code>
95     * object if it was created with an error message string, the error
96     * message of the target exception if it was not created a message
97     * but the target exception has a message, or <code>null</code> if
98     * neither has an error message.
99     *
100     */

101     public String JavaDoc getMessage()
102     {
103         String JavaDoc message = super.getMessage();
104
105         if (StringHelper.isEmpty(message))
106         {
107             Throwable JavaDoc target = getTargetException();
108
109             message = target.getMessage();
110         }
111
112         return message;
113     }
114
115     /**
116      * Prints the stack trace of the thrown target exception.
117      * @see java.lang.System#err
118      */

119     public void printStackTrace ()
120     {
121         printStackTrace(System.err);
122     }
123
124     /**
125      * Prints the stack trace of the thrown target exception to the specified
126      * print stream.
127      */

128     public void printStackTrace (PrintStream JavaDoc ps)
129     {
130         synchronized (ps)
131         {
132             Throwable JavaDoc target = getTargetException();
133
134             if (target != null)
135             {
136                 ps.print(getClass() + ": "); // NOI18N
137
target.printStackTrace(ps);
138             }
139             else
140                 super.printStackTrace(ps);
141         }
142     }
143
144     /**
145      * Prints the stack trace of the thrown target exception to the
146      * specified print writer.
147      */

148     public void printStackTrace (PrintWriter JavaDoc pw)
149     {
150         synchronized (pw)
151         {
152             Throwable JavaDoc target = getTargetException();
153
154             if (target != null)
155             {
156                 pw.print(getClass() + ": "); // NOI18N
157
target.printStackTrace(pw);
158             }
159             else
160                 super.printStackTrace(pw);
161         }
162     }
163 }
164
Popular Tags