001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.subscriptions.profiler;
006:
007: import java.io.PrintWriter;
008:
009: import com.sun.portal.desktop.DesktopError;
010:
011: /**
012: * @author pm95875
013: * @created September 2, 2003
014: */
015:
016: public class NotifierException extends Exception {
017:
018: /**
019: * Description of the Field
020: */
021: public final static String RESOURCE_BASE = "profiler";
022:
023: /**
024: * Description of the Field
025: */
026: protected static java.util.Locale locale = java.util.Locale
027: .getDefault();
028:
029: /**
030: * Description of the Field
031: */
032: protected java.lang.Throwable origEx = null;
033: /**
034: * Description of the Field
035: */
036: protected java.lang.String key = null;
037: /**
038: * Description of the Field
039: */
040: protected java.lang.Object[] tokens = null;
041:
042: /*
043: * CONSTRUCTORS
044: */
045: /**
046: *Constructor for the NotifierException object
047: *
048: * @param key Description of the Parameter
049: */
050: public NotifierException(java.lang.String key) {
051: super (key);
052: this .key = key;
053: }
054:
055: /**
056: *Constructor for the NotifierException object
057: *
058: * @param key Description of the Parameter
059: * @param tokens Description of the Parameter
060: */
061: public NotifierException(java.lang.String key,
062: java.lang.Object[] tokens) {
063: super (key);
064: this .key = key;
065: this .tokens = tokens;
066: }
067:
068: /**
069: *Constructor for the NotifierException object
070: *
071: * @param key Description of the Parameter
072: * @param t Description of the Parameter
073: */
074: public NotifierException(java.lang.String key, java.lang.Throwable t) {
075: super (key);
076: origEx = t;
077: this .key = key;
078: }
079:
080: /**
081: *Constructor for the NotifierException object
082: *
083: * @param key Description of the Parameter
084: * @param t Description of the Parameter
085: * @param tokens Description of the Parameter
086: */
087: public NotifierException(java.lang.String key,
088: java.lang.Throwable t, java.lang.Object[] tokens) {
089: super (key);
090: origEx = t;
091: this .key = key;
092: this .tokens = tokens;
093: }
094:
095: /**
096: *Constructor for the NotifierException object
097: *
098: * @param t Description of the Parameter
099: */
100: public NotifierException(java.lang.Throwable t) {
101: super (t.getMessage());
102: origEx = t;
103: }
104:
105: /**
106: * Sets the locale attribute of the NotifierException class
107: *
108: * @param loc The new locale value
109: */
110: public static void setLocale(java.util.Locale loc) {
111: locale = loc;
112: }
113:
114: /**
115: * Gets the message attribute of the NotifierException object
116: *
117: * @return The message value
118: */
119: public String getMessage() {
120: // non-localized resource bundle
121: java.util.ResourceBundle rb = java.util.PropertyResourceBundle
122: .getBundle(RESOURCE_BASE, java.util.Locale.getDefault());
123: return getMessageFromRB(rb, key, tokens);
124: }
125:
126: /**
127: * Gets the wrapped attribute of the NotifierException object
128: *
129: * @return The wrapped value
130: */
131: public Throwable getWrapped() {
132: return origEx;
133: }
134:
135: /**
136: * Gets the wrappedMessage attribute of the NotifierException object
137: *
138: * @return The wrappedMessage value
139: */
140: public String getWrappedMessage() {
141: String msg = null;
142: if (origEx != null) {
143: if (origEx instanceof DesktopError) {
144: Throwable wrapped = ((DesktopError) origEx).getCause();
145: if (wrapped != null) {
146: //msg = origEx.getMessage() + wrapped.getMessage();
147: msg = wrapped.getMessage();
148: } else {
149: msg = origEx.getMessage();
150: }
151: } else {
152: msg = origEx.getMessage();
153: }
154: }
155: return msg;
156: }
157:
158: /**
159: * Gets the localizedMessage attribute of the NotifierException object
160: *
161: * @return The localizedMessage value
162: */
163: public String getLocalizedMessage() {
164: // localized resource bundle
165: java.util.ResourceBundle rb = java.util.PropertyResourceBundle
166: .getBundle(RESOURCE_BASE, locale);
167: String msg = null;
168: try {
169: msg = getMessageFromRB(rb, key, tokens);
170: } catch (java.util.MissingResourceException mrex) {
171: msg = key;
172: }
173: return msg;
174: }
175:
176: /**
177: * Gets the messageFromRB attribute of the NotifierException object
178: *
179: * @param rb Description of the Parameter
180: * @param key Description of the Parameter
181: * @param tokens Description of the Parameter
182: * @return The messageFromRB value
183: * @exception java.util.MissingResourceException Description of the Exception
184: */
185: private String getMessageFromRB(java.util.ResourceBundle rb,
186: java.lang.String key, java.lang.Object[] tokens)
187: throws java.util.MissingResourceException {
188:
189: String msg = rb.getString(key);
190:
191: if (tokens != null && tokens.length > 0) {
192: java.text.MessageFormat mf = new java.text.MessageFormat("");
193: mf.setLocale(rb.getLocale());
194: mf.applyPattern(msg);
195: return mf.format(tokens);
196: } else {
197: return msg;
198: }
199: }
200:
201: /**
202: * Description of the Method
203: */
204: public void printStackTrace() {
205: if (origEx != null) {
206: origEx.printStackTrace();
207: } else {
208: super .printStackTrace();
209: }
210: }
211:
212: /**
213: * Description of the Method
214: *
215: * @param pw Description of the Parameter
216: */
217: public void printStackTrace(PrintWriter pw) {
218: if (origEx != null) {
219: origEx.printStackTrace(pw);
220: } else {
221: super.printStackTrace(pw);
222: }
223: }
224: }
|