001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.ws.scout.registry;
017:
018: import org.apache.ws.scout.uddi.DispositionReport;
019: import org.apache.ws.scout.uddi.DispositionReportDocument;
020: import org.apache.ws.scout.uddi.ErrInfo;
021: import org.apache.ws.scout.uddi.Result;
022:
023: /**
024: * Thrown to indicate that a UDDI Exception was encountered.
025: *
026: * <i>Borrowed from jUDDI project.</i>
027: *
028: * @author Steve Viens (sviens@apache.org)
029: */
030: public class RegistryException extends Exception {
031: private static final long serialVersionUID = 1L;
032: public static final int E_ASSERTION_NOT_FOUND = 30000;
033: public static final int E_AUTH_TOKEN_EXPIRED = 10110;
034: public static final int E_AUTH_TOKEN_REQUIRED = 10120;
035: public static final int E_ACCOUNT_LIMIT_EXCEEDED = 10160;
036: public static final int E_BUSY = 10400;
037: public static final int E_CATEGORIZATION_NOT_ALLOWED = 20100;
038: public static final int E_FATAL_ERROR = 10500;
039: public static final int E_INVALID_KEY_PASSED = 10210;
040: public static final int E_INVALID_PROJECTION = 20230;
041: public static final int E_INVALID_CATEGORY = 20000;
042: public static final int E_INVALID_COMPLETION_STATUS = 30100;
043: public static final int E_INVALID_URL_PASSED = 10220;
044: public static final int E_INVALID_VALUE = 20200;
045: public static final int E_KEY_RETIRED = 10310;
046: public static final int E_LANGUAGE_ERROR = 10060;
047: public static final int E_MESSAGE_TOO_LARGE = 30110;
048: public static final int E_NAME_TOO_LONG = 10020;
049: public static final int E_OPERATOR_MISMATCH = 10130;
050: public static final int E_PUBLISHER_CANCELLED = 30220;
051: public static final int E_REQUEST_DENIED = 30210;
052: public static final int E_SECRET_UNKNOWN = 30230;
053: public static final int E_SUCCESS = 0;
054: public static final int E_TOO_MANY_OPTIONS = 10030;
055: public static final int E_TRANSFER_ABORTED = 30200;
056: public static final int E_UNRECOGNIZED_VERSION = 10040;
057: public static final int E_UNKNOWN_USER = 10150;
058: public static final int E_UNSUPPORTED = 10050;
059: public static final int E_USER_MISMATCH = 10140;
060: public static final int E_VALUE_NOT_ALLOWED = 20210;
061: public static final int E_UNVALIDATABLE = 20220;
062: public static final int E_REQUEST_TIMEOUT = 20240;
063: public static final int E_INVALID_TIME = 40030;
064: public static final int E_RESULT_SET_TOO_LARGE = 40300;
065:
066: // SOAP SOAPFault Actor
067: private String faultActor;
068:
069: // SOAP SOAPFault Code
070: private String faultCode;
071:
072: // SOAP SOAPFault SOAPMessage
073: private String faultString;
074:
075: // UDDI DispositionReport
076: private DispositionReport dispReport;
077:
078: /**
079: * Constructs a RegistryException instance.
080: * @param msg additional error information
081: */
082: public RegistryException(String msg) {
083: super (msg);
084:
085: setFaultCode(null);
086: setFaultString(msg);
087: setFaultActor(null);
088: }
089:
090: /**
091: * Constructs a RegistryException instance.
092: * @param ex the original exception
093: */
094: public RegistryException(Exception ex) {
095: super (ex);
096:
097: if (ex != null) {
098: // Not sure why this would ever happen but
099: // just in case we are asked to create a new
100: // RegistryException using values from another
101: // let's be sure to grab all relevant values.
102: //
103: if (ex instanceof RegistryException) {
104: RegistryException regex = (RegistryException) ex;
105: setFaultCode(regex.getFaultCode());
106: setFaultString(regex.getFaultString());
107: setFaultActor(regex.getFaultActor());
108: setDispositionReport(regex.getDispositionReport());
109: } else // Not a RegistryException (or subclass)
110: {
111: setFaultString(ex.getMessage());
112: }
113: }
114: }
115:
116: /**
117: * Constructs a RegistryException instance.
118: * @param ex the original exception
119: */
120: public RegistryException(String fCode, String fString,
121: String fActor, DispositionReport dispRpt) {
122: super (fString);
123:
124: setFaultCode(fCode);
125: setFaultString(fString);
126: setFaultActor(fActor);
127: setDispositionReport(dispRpt);
128: }
129:
130: /**
131: * Constructs a RegistryException instance.
132: * @param ex the original exception
133: */
134: RegistryException(String fCode, int errno, String msg) {
135: super (buildMessage(errno, msg));
136:
137: String errCode = lookupErrCode(errno);
138:
139: if (fCode != null) {
140: setFaultCode(fCode);
141: }
142:
143: setFaultString(getMessage());
144:
145: Result r = Result.Factory.newInstance();
146: ErrInfo ei = ErrInfo.Factory.newInstance();
147:
148: if (errCode != null) {
149: ei.setErrCode(errCode);
150: }
151:
152: ei.setStringValue(getMessage());
153:
154: r.setErrno(errno);
155:
156: if (ei != null) {
157: r.setErrInfo(ei);
158: }
159:
160: addResult(r);
161: }
162:
163: /**
164: * Sets the fault actor of this SOAP SOAPFault to the given value.
165: * @param actor The new actor value for this SOAP SOAPFault.
166: */
167: public void setFaultActor(String actor) {
168: this .faultActor = actor;
169: }
170:
171: /**
172: * Returns the fault actor of this SOAP SOAPFault.
173: * @return The fault actor of this SOAP SOAPFault.
174: */
175: public String getFaultActor() {
176: return this .faultActor;
177: }
178:
179: /**
180: * Sets the fault code of this SOAP SOAPFault to the given value.
181: * @param code The new code number for this SOAP SOAPFault.
182: */
183: public void setFaultCode(String code) {
184: this .faultCode = code;
185: }
186:
187: /**
188: * Returns the fault code of this SOAP SOAPFault.
189: * @return The fault code of this SOAP SOAPFault.
190: */
191: public String getFaultCode() {
192: return this .faultCode;
193: }
194:
195: /**
196: * Sets the fault string of this SOAP SOAPFault to the given value.
197: * @param value The new fault string for this SOAP SOAPFault.
198: */
199: public void setFaultString(String value) {
200: this .faultString = value;
201: }
202:
203: /**
204: * Returns the fault string of this SOAP SOAPFault.
205: * @return The fault string of this SOAP SOAPFault.
206: */
207: public String getFaultString() {
208: return this .faultString;
209: }
210:
211: /**
212: * Sets the UDDI DispositionReport value to the instance
213: * specified
214: * @param dispRpt The new UDDI DispositionReport instance for
215: * this SOAP Fault.
216: */
217: public void setDispositionReport(DispositionReport dispRpt) {
218: this .dispReport = dispRpt;
219: }
220:
221: /**
222: * Returns the disposition report associated with this jUDDI exception. It
223: * uses the results Vector to determine if a disposition report is present
224: * and should be returned.
225: * @return The disposition report associated with this jUDDI exception.
226: */
227: public DispositionReport getDispositionReport() {
228: return this .dispReport;
229: }
230:
231: /**
232: * Adds a result instance to this Exception. Multiple result objects
233: * may exist within a DispositionReport
234: */
235: public void addResult(Result result) {
236: if (this .dispReport == null) {
237: DispositionReportDocument doc = DispositionReportDocument.Factory
238: .newInstance();
239: this .dispReport = doc.addNewDispositionReport();
240: }
241:
242: Result r = this .dispReport.addNewResult();
243:
244: if (result.getErrInfo() != null)
245: r.setErrInfo(result.getErrInfo());
246: if (result.getKeyType() != null)
247: r.setKeyType(result.getKeyType());
248: r.setErrno(result.getErrno());
249: }
250:
251: /**
252: *
253: */
254: public String toString() {
255: String msg = getMessage();
256: if (msg == null)
257: return "";
258: else
259: return getMessage();
260: }
261:
262: private static final String buildMessage(int errno, String msg) {
263: StringBuffer buffer = new StringBuffer();
264:
265: String errCode = lookupErrCode(errno);
266: if (errCode != null) {
267: buffer.append(errCode);
268: buffer.append(" ");
269: }
270:
271: buffer.append("(");
272: buffer.append(errno);
273: buffer.append(") ");
274:
275: //String errText = lookupErrText(errno);
276: // FIXME: What should error text be?
277: String errText = "";
278: if (errText != null) {
279: buffer.append(errText);
280: buffer.append(" ");
281: }
282:
283: if ((msg != null) && (msg.trim().length() > 0)) {
284: buffer.append(msg);
285: }
286:
287: return buffer.toString();
288: }
289:
290: public static final String lookupErrCode(int errno) {
291: switch (errno) {
292: case E_ACCOUNT_LIMIT_EXCEEDED:
293: return "E_accountLimitExceeded";
294: case E_ASSERTION_NOT_FOUND:
295: return "E_assertionNotFound";
296: case E_AUTH_TOKEN_EXPIRED:
297: return "E_authTokenExpired";
298: case E_AUTH_TOKEN_REQUIRED:
299: return "E_authTokenRequired";
300: case E_BUSY:
301: return "E_busy";
302: case E_CATEGORIZATION_NOT_ALLOWED:
303: return "E_categorizationNotAllowed";
304: case E_FATAL_ERROR:
305: return "E_fatalError";
306: case E_INVALID_CATEGORY:
307: return "E_invalidCategory";
308: case E_INVALID_COMPLETION_STATUS:
309: return "E_invalidCompletionStatus";
310: case E_INVALID_KEY_PASSED:
311: return "E_invalidKeyPassed";
312: case E_INVALID_PROJECTION:
313: return "E_invalidProjection";
314: case E_INVALID_TIME:
315: return "E_invalidTime";
316: case E_INVALID_URL_PASSED:
317: return "E_invalidURLPassed";
318: case E_INVALID_VALUE:
319: return "E_invalidValue";
320: case E_KEY_RETIRED:
321: return "E_keyRetired";
322: case E_LANGUAGE_ERROR:
323: return "E_languageError";
324: case E_MESSAGE_TOO_LARGE:
325: return "E_messageTooLarge";
326: case E_NAME_TOO_LONG:
327: return "E_nameTooLong";
328: case E_OPERATOR_MISMATCH:
329: return "E_operatorMismatch";
330: case E_PUBLISHER_CANCELLED:
331: return "E_publisherCancelled";
332: case E_REQUEST_DENIED:
333: return "E_requestDenied";
334: case E_REQUEST_TIMEOUT:
335: return "E_requestTimeout";
336: case E_RESULT_SET_TOO_LARGE:
337: return "E_resultSetTooLarge";
338: case E_SECRET_UNKNOWN:
339: return "E_secretUnknown";
340: case E_SUCCESS:
341: return "E_success";
342: case E_TOO_MANY_OPTIONS:
343: return "E_tooManyOptions";
344: case E_TRANSFER_ABORTED:
345: return "E_transferAborted";
346: case E_UNKNOWN_USER:
347: return "E_unknownUser";
348: case E_UNRECOGNIZED_VERSION:
349: return "E_unrecognizedVersion";
350: case E_UNSUPPORTED:
351: return "E_unsupported";
352: case E_UNVALIDATABLE:
353: return "E_unvalidatable";
354: case E_USER_MISMATCH:
355: return "E_userMismatch";
356: case E_VALUE_NOT_ALLOWED:
357: return "E_valueNotAllowed";
358: default:
359: return null;
360: }
361: }
362: }
|