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