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.admin.mbeans.tasks;
006:
007: import java.io.PrintWriter;
008:
009: /**
010: * A <code>ProfilerException</code> is thrown when there are errors related to
011: * amadmin operations.
012: */
013:
014: public class ProfilerException extends Exception {
015:
016: public static final String RESOURCE_BASE = "Profiler";
017:
018: protected static java.util.Locale locale = java.util.Locale
019: .getDefault();
020:
021: protected java.lang.Throwable origEx = null;
022: protected java.lang.String key = null;
023: protected java.lang.Object[] tokens = null;
024:
025: /*
026: * CONSTRUCTORS
027: */
028:
029: /**
030: * Constructs an instance of the <code>ProfilerException</code> class.
031: * @param key key string to index into resource bundle to retieve
032: * localized message
033: */
034: public ProfilerException(java.lang.String key) {
035: super (key);
036: this .key = key;
037: }
038:
039: /**
040: * Constructs an instance of the <code>ProfilerException</code> class.
041: * @param key key string to index into resource bundle to retieve
042: * localized message
043: * @param tokens array of tokens to be used by the exception message
044: */
045: public ProfilerException(java.lang.String key,
046: java.lang.Object[] tokens) {
047: super (key);
048: this .key = key;
049: this .tokens = tokens;
050: }
051:
052: /**
053: * Constructs an instance of the <code>ProfilerException</code> class.
054: * @param key key string to index into resource bundle to retieve
055: * localized message
056: * @param t Throwable object provided by the object which is throwing
057: */
058: public ProfilerException(java.lang.String key, java.lang.Throwable t) {
059: super (key);
060: origEx = t;
061: this .key = key;
062: }
063:
064: /**
065: * Constructs an instance of the <code>ProfilerException</code> class.
066: * @param key key string to index into resource bundle to retieve
067: * localized message
068: * @param t Throwable object provided by the object which is throwing
069: * @param tokens array of tokens to be used by the exception message
070: */
071: public ProfilerException(java.lang.String key,
072: java.lang.Throwable t, java.lang.Object[] tokens) {
073: super (key);
074: origEx = t;
075: this .key = key;
076: this .tokens = tokens;
077: }
078:
079: /**
080: * Constructs an instance of the <code>ProfilerException</code> class.
081: * @param t Throwable object provided by the object which is throwing
082: * the exception
083: */
084: public ProfilerException(java.lang.Throwable t) {
085: super (t.getMessage());
086: origEx = t;
087: }
088:
089: public static void setLocale(java.util.Locale loc) {
090: locale = loc;
091: }
092:
093: public String getMessage() {
094: // non-localized resource bundle
095: java.util.ResourceBundle rb = java.util.PropertyResourceBundle
096: .getBundle(RESOURCE_BASE, java.util.Locale.getDefault());
097: return getMessageFromRB(rb, key, tokens);
098: }
099:
100: public Throwable getWrapped() {
101: return origEx;
102: }
103:
104: public String getWrappedMessage() {
105: String msg = null;
106: if (origEx != null) {
107: msg = origEx.getMessage();
108: }
109: return msg;
110: }
111:
112: public String getLocalizedMessage() {
113: // localized resource bundle
114: java.util.ResourceBundle rb = java.util.PropertyResourceBundle
115: .getBundle(RESOURCE_BASE, locale);
116: String msg = null;
117: try {
118: msg = getMessageFromRB(rb, key, tokens);
119: } catch (java.util.MissingResourceException mrex) {
120: msg = key;
121: }
122: return msg;
123: }
124:
125: private String getMessageFromRB(java.util.ResourceBundle rb,
126: java.lang.String key, java.lang.Object[] tokens)
127: throws java.util.MissingResourceException {
128:
129: String msg = rb.getString(key);
130:
131: if (tokens != null && tokens.length > 0) {
132: java.text.MessageFormat mf = new java.text.MessageFormat("");
133: mf.setLocale(rb.getLocale());
134: mf.applyPattern(msg);
135: return mf.format(tokens);
136: } else {
137: return msg;
138: }
139: }
140:
141: public void printStackTrace() {
142: if (origEx != null) {
143: origEx.printStackTrace();
144: } else {
145: super .printStackTrace();
146: }
147: }
148:
149: public void printStackTrace(PrintWriter pw) {
150: if (origEx != null) {
151: origEx.printStackTrace(pw);
152: } else {
153: super .printStackTrace(pw);
154: }
155: }
156:
157: public String getKey() {
158: return key;
159: }
160:
161: public Object[] getTokens() {
162: return tokens;
163: }
164:
165: public Throwable getOrigEx() {
166: return origEx;
167: }
168:
169: }
|