001: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.error;
007:
008: /**
009: * Error codes specific to the CError channel.
010: * @author andrew.petro@yale.edu
011: * @version $Revision: 35593 $ $Date: 2005-04-17 13:54:14 -0700 (Sun, 17 Apr 2005) $
012: * @since uPortal 2.5
013: */
014: public class ErrorCode {
015:
016: /** Generic error code */
017: public static final ErrorCode UNKNOWN_ERROR = new ErrorCode(
018: "unknown error", -1, true);
019:
020: /** Generic error code */
021: public static final ErrorCode GENERAL_ERROR = new ErrorCode(
022: "general error", 0, true);
023:
024: /** Error code for failure during rendering. */
025: public static final ErrorCode RENDER_TIME_EXCEPTION = new ErrorCode(
026: "Render time exception", 1, true);
027:
028: /** Error code for errors at time static data is set */
029: public static final ErrorCode SET_STATIC_DATA_EXCEPTION = new ErrorCode(
030: "Set static data exception", 2, false);
031:
032: /** Error code for errors at time runtime data is set. */
033: public static final ErrorCode SET_RUNTIME_DATA_EXCEPTION = new ErrorCode(
034: "Set runtime data", 3, true);
035:
036: /** Error code for channels that fail to complete rendering during
037: * allotted time.
038: */
039: public static final ErrorCode TIMEOUT_EXCEPTION = new ErrorCode(
040: "Rendering timeout", 4, true);
041:
042: /** Error code representing failure when framework attempts to set
043: * channel portal control structures.
044: */
045: public static final ErrorCode SET_PCS_EXCEPTION = new ErrorCode(
046: "Set PCS exception", 5, true);
047:
048: /**
049: * Error code representing failure to render due to lack of authorization.
050: */
051: public static final ErrorCode CHANNEL_AUTHORIZATION_EXCEPTION = new ErrorCode(
052: "Channel authorization exception", 6, false);
053:
054: /**
055: * Error code representing the channel being just plain missing.
056: */
057: public static final ErrorCode CHANNEL_MISSING_EXCEPTION = new ErrorCode(
058: "Channel missing", 7, false);
059:
060: private static ErrorCode[] codeArray = { GENERAL_ERROR,
061: RENDER_TIME_EXCEPTION, SET_STATIC_DATA_EXCEPTION,
062: SET_RUNTIME_DATA_EXCEPTION, TIMEOUT_EXCEPTION,
063: SET_PCS_EXCEPTION, CHANNEL_AUTHORIZATION_EXCEPTION,
064: CHANNEL_MISSING_EXCEPTION };
065:
066: /**
067: * Obtain the ErrorCode for the given code number, or null if the
068: * code number does not correspond to an error code.
069: * @param codeNum
070: * @return ErrorCode or null.
071: */
072: public static ErrorCode codeForInt(int codeNum) {
073: ErrorCode code = UNKNOWN_ERROR;
074: if (codeNum > -1 && codeNum < codeArray.length)
075: code = codeArray[codeNum];
076: return code;
077: }
078:
079: /**
080: * Integer representing error code.
081: */
082: private final int codeNumber;
083:
084: /**
085: * String label suggesting meaning of error code.
086: */
087: private final String label;
088:
089: /**
090: * True if channel refresh is an appropriate response to this error,
091: * false otherwise.
092: */
093: private boolean refreshable;
094:
095: /**
096: * Private constructor.
097: * @param label - briefly describes error type
098: * @param codeNumber - integer representing error type
099: * @param refreshable - whether refresh is appropriate response
100: */
101: private ErrorCode(final String label, final int codeNumber,
102: final boolean refreshable) {
103: this .label = label;
104: this .codeNumber = codeNumber;
105: this .refreshable = refreshable;
106: }
107:
108: public int getCode() {
109: return this .codeNumber;
110: }
111:
112: public String getLabel() {
113: return this .label;
114: }
115:
116: /**
117: * Is this ErrorCode representative of a problem to which
118: * channel refresh would be an appropriate response.
119: * Some ErrorCodes are representative of problems that refreshing just
120: * won't fix, such as a failure when setting static data.
121: * @return true if refresh is allowed, false otherwise
122: */
123: public boolean isRefreshAllowed() {
124: return this .refreshable;
125: }
126:
127: public String toString() {
128: return this.label;
129: }
130:
131: }
|