001: package com.sun.portal.taskadmin;
002:
003: import java.io.PrintWriter;
004: import java.io.IOException;
005: import java.io.BufferedReader;
006: import java.io.FileInputStream;
007: import java.io.PrintStream;
008: import java.io.PrintWriter;
009:
010: import javax.servlet.http.HttpServletResponse;
011:
012: import com.sun.portal.util.UnicodeInputStreamReader;
013:
014: public class TaskAdminException extends Exception {
015:
016: public static final String UNKNOWN = "unknown";
017:
018: public static final String[] errorKeys = {
019: //0 - Error, Operation was unsuccessful
020: "generic.error.message",
021: //1 - Invlid channel or channel does not exist
022: "message.nochannel",
023: //2 - Invlid provider or provider does not exist
024: "message.noprovider",
025: //3 - unknown property type
026: "message.typeunknown",
027: //4 Channel Exists error
028: "message.channelexists",
029: //5 DP Store error
030: "message.store",
031: //6 channel not a container
032: "message.notcontainer",
033: //7 property doesn't exist
034: "message.noproperty",
035: //8 error in assignRole method
036: "message.role.assign.error",
037: //9 error in removeRole method
038: "message.role.remove.error",
039: //10 error in retriving user roles.
040: "message.user.roles.error",
041: //11 error in changing user status.
042: "message.userstatus.error",
043: //12 error in resetting user password.
044: "message.resetpassword.error",
045: //13 error in getting the users
046: "message.users.error",
047: //14 error in getting the assignable roles
048: "message.assignable.roles.error",
049: //15 error in getting the assignable roles
050: "message.DNName.error",
051: //16 error in retrieving baseDN
052: "message.invalidDN.error",
053: //17 invalid search string
054: "message.invalidpattern.error",
055: //18 create users error
056: "message.createusers.error",
057: //19 delete users error
058: "message.deleteusers.error",
059: //20 null password
060: "message.nullpassword",
061: //21 invalid portlet preference
062: "message.invalidpreference",
063: //22 null channel name
064: "message.nullchannelname",
065: //23 Invalid user DN.
066: "message.invaliduserdn",
067: //24 Invalid role DN.
068: "message.invalidroledn",
069: //25 error in retrieving the produers ids list.
070: "message.producers.id.list",
071: //26 error in retrieving the porlets handlers (ids) list.
072: "message.porlets.handler.list",
073: //27 Error while retrieving WSRP produer name.
074: "message.producer.name.error",
075: //28 Error while retrieving WSRP portlet name.
076: "message.porlet.name.error",
077: //29 Invalid new user information.
078: "message.createuser.error",
079: //30 Invalid role information
080: "message.invalidrole.error",
081: //31 Create role error
082: "message.createrole.error",
083: //32 Search Users Time Limit error
084: "message.searchtimelimit.error",
085: //33 Search Users Size Limit error
086: "message.searchsizelimit.error",
087: //34 dp is modified before store
088: "message.store.dpmodified.error",
089: //35 error deleting channel
090: "message.delete.channel.error",
091: // 36 empty dp document
092: "error.empty.dp.document" };
093:
094: private int errorCode = 0;
095:
096: protected Throwable wrapped = null;
097: protected String exceptionType = UNKNOWN;
098: protected java.lang.Object[] tokens = null;
099:
100: private TaskAdminException() {
101: // nothing
102: }
103:
104: public TaskAdminException(String msg) {
105: super (msg);
106: }
107:
108: public TaskAdminException(String msg, String type) {
109: super (msg);
110: exceptionType = type;
111: }
112:
113: public TaskAdminException(String msg, Throwable e) {
114: super (msg);
115: wrapped = e;
116: }
117:
118: public TaskAdminException(int errorCode, Throwable e,
119: java.lang.Object[] tokens) {
120: super (e.getMessage());
121: wrapped = e;
122: this .errorCode = validateErrorCode(errorCode);
123: this .tokens = tokens;
124:
125: }
126:
127: public TaskAdminException(int errorCode, String msg,
128: java.lang.Object[] tokens) {
129: super (msg);
130: this .errorCode = validateErrorCode(errorCode);
131: this .tokens = tokens;
132: }
133:
134: public TaskAdminException(int errorCode, java.lang.Object[] tokens) {
135: this .errorCode = validateErrorCode(errorCode);
136: this .tokens = tokens;
137: }
138:
139: public Throwable getWrapped() {
140: return wrapped;
141: }
142:
143: public String getExceptionType() {
144: return exceptionType;
145: }
146:
147: public String toString() {
148: StringBuffer b = new StringBuffer();
149:
150: b.append(super .toString());
151: if (getWrapped() != null) {
152: b.append(wrapped.toString());
153: }
154:
155: return b.toString();
156: }
157:
158: public void printStackTrace() {
159: super .printStackTrace();
160: if (getWrapped() != null) {
161: wrapped.printStackTrace();
162: }
163: }
164:
165: public void printStackTrace(PrintStream s) {
166: super .printStackTrace(s);
167: if (getWrapped() != null) {
168: wrapped.printStackTrace(s);
169: }
170: }
171:
172: public void printStackTrace(PrintWriter s) {
173: super .printStackTrace(s);
174: if (getWrapped() != null) {
175: wrapped.printStackTrace(s);
176: }
177: }
178:
179: public int getErrorCode() {
180: return errorCode;
181: }
182:
183: public String getErrorKey() {
184: return errorKeys[errorCode];
185: }
186:
187: public Object[] getTokens() {
188: return tokens;
189: }
190:
191: public String getMessageFromRB(java.util.ResourceBundle rb,
192: java.lang.String key, java.lang.Object[] tokens) {
193:
194: String msg = rb.getString(key);
195:
196: if (tokens != null && tokens.length > 0) {
197: java.text.MessageFormat mf = new java.text.MessageFormat("");
198: mf.setLocale(rb.getLocale());
199: mf.applyPattern(msg);
200: return mf.format(tokens);
201: } else {
202: return msg;
203: }
204: }
205:
206: public String getLocalizedMessage(java.util.ResourceBundle rb) {
207: return getMessageFromRB(rb, getErrorKey(), getTokens());
208: }
209:
210: private int validateErrorCode(int code) {
211: if (code < errorKeys.length) {
212: return code;
213: } else {
214: return 0;
215: }
216: }
217: }
|