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