KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > servermgmt > RepositoryException


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  * RepositoryException.java
26  *
27  * Created on August 22, 2003, 11:21 AM
28  */

29
30 package com.sun.enterprise.admin.servermgmt;
31
32 /**
33  *
34  * @author kebbs
35  */

36 public class RepositoryException extends java.lang.Exception JavaDoc {
37     
38        /** Constructs a new InstanceException object.
39      * @param message
40      */

41     public RepositoryException(String JavaDoc message)
42     {
43         super(message);
44     }
45
46     /** Constructs a new InstanceException object.
47      * @param cause
48      */

49     public RepositoryException(Throwable JavaDoc cause)
50     {
51         //When created without a message, we take the message of our cause
52
this(cause.getLocalizedMessage(), cause);
53     }
54
55     /** Constructs a new InstanceException object.
56      * @param message
57      * @param cause
58      */

59     public RepositoryException(String JavaDoc message, Throwable JavaDoc cause)
60     {
61         super(message, cause);
62     }
63
64     private final String JavaDoc PREFIX = "( ";
65     private final String JavaDoc POSTFIX = " )";
66    
67     private String JavaDoc format(String JavaDoc msg, String JavaDoc causeMsg, Throwable JavaDoc cause)
68     {
69         if (cause != null) {
70             if (msg != null) {
71                 if (causeMsg != null) {
72                     msg = causeMsg;
73                 } else {
74                     msg = cause.toString();
75                 }
76             } else if (causeMsg != null && !msg.equals(causeMsg)) {
77                 msg += PREFIX + causeMsg + POSTFIX;
78             } else if (causeMsg == null) {
79                 msg += PREFIX + cause.toString() + POSTFIX;
80             }
81         }
82         return msg;
83     }
84
85     /** If there is a cause, appends the getCause().getMessage()
86      * to the original message.
87      */

88     public String JavaDoc getMessage()
89     {
90         String JavaDoc msg = super.getMessage();
91         Throwable JavaDoc cause = super.getCause();
92         if (cause != null) {
93             msg = format(msg, cause.getMessage(), cause);
94         }
95         return msg;
96     }
97     
98     /** If there is a cause, appends the getCause().getMessage()
99      * to the original message.
100      */

101     public String JavaDoc getLocalizedMessage()
102     {
103         String JavaDoc msg = super.getLocalizedMessage();
104         Throwable JavaDoc cause = super.getCause();
105         if (cause != null) {
106             msg = format(msg, cause.getLocalizedMessage(), cause);
107         }
108         return msg;
109     }
110 }
111
Popular Tags