001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: ConfigException.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
022: */
023:
024: package com.lutris.util;
025:
026: /**
027: * Exception class thrown by class <code>Config</code>. If a syntax
028: * error is found in the configuration input stream, or if a component
029: * expects a data format for which a configuration element cannot be
030: * converted, then this exception is thrown to indicate the error.
031: *
032: * @see Config
033: * @version $Revision: 1.2 $
034: * @author John Marco
035: * @since Soda1.0
036: */
037: public class ConfigException extends KeywordValueException {
038: /**
039: * The <code>reason</code> field may contain this value to indicate
040: * that the cause of the current exception is unknown.
041: *
042: * @see ConfigException#reason
043: */
044: public static final int UNKNOWN = 0;
045:
046: /**
047: * The <code>reason</code> field may contain this value to indicate
048: * that a syntax error in the configuration input file or stream
049: * caused this exception.
050: *
051: * @see ConfigException#reason
052: */
053: public static final int NOT_FOUND = 1;
054:
055: /**
056: * The <code>reason</code> field may contain this value to indicate
057: * that a syntax error in the configuration input file or stream
058: * caused this exception.
059: *
060: * @see ConfigException#reason
061: */
062: public static final int SYNTAX = 2;
063:
064: /**
065: * The <code>reason</code> field may contain this value to indicate
066: * that a component expects a different number of elements than
067: * are provided in the configuration file for a particular key.
068: *
069: * @see ConfigException#reason
070: */
071: public static final int COUNT = 3;
072:
073: /**
074: * The <code>reason</code> field may contain this value to indicate
075: * that a configuration element could not be converted from its
076: * internal string form to the requested type.
077: *
078: * @see ConfigException#reason
079: */
080: public static final int FORMAT = 4;
081:
082: /**
083: * Internal constant to indicate the highest valid <code>reason</code>
084: * code.
085: *
086: * @see ConfigException#reason
087: */
088: private static final int MAX_REASON = 4;
089:
090: /**
091: * Indicates the cause (if known) of the current exception.
092: *
093: * @see ConfigException#UNKNOWN
094: * @see ConfigException#SYNTAX
095: * @see ConfigException#COUNT
096: * @see ConfigException#FORMAT
097: */
098: public int reason;
099:
100: /**
101: * Creates a new ConfigException object with no informational string
102: * and a <code>reason</code> field of <code>UNKNOWN</code>.
103: *
104: * @see ConfigException#reason
105: */
106: public ConfigException() {
107: super ("Unknown reason");
108: reason = UNKNOWN;
109: }
110:
111: /**
112: * Creates a new ConfigException object with the specified informational
113: * string and a <code>reason</code> field of <code>UNKNOWN</code>.
114: *
115: * @param s Informational string to store in the exception object.
116: *
117: * @see ConfigException#reason
118: */
119: public ConfigException(String s) {
120: super (s);
121: reason = UNKNOWN;
122: }
123:
124: /**
125: * Constructs a new exception with the specified cause.
126: *
127: * @param cause The cause (which is saved for later retrieval by the
128: * Throwable.getCause() method).
129: * A null value is permitted, and indicates that the cause is
130: * nonexistent or unknown.
131: */
132: public ConfigException(Throwable cause) {
133: super (cause);
134: }
135:
136: /**
137: * Constructs a new exception with the specified cause and a detail message.
138: *
139: * @param msg A detailed message describing the expection.
140: * @param cause The cause (which is saved for later retrieval by the
141: * Throwable.getCause() method).
142: * A null value is permitted, and indicates that the cause is
143: * nonexistent or unknown.
144: */
145: public ConfigException(String msg, Throwable cause) {
146: super (msg, cause);
147: }
148:
149: /**
150: * Creates a new ConfigException object with the specified informational
151: * string and the specified <code>reason</code> field.
152: *
153: * @param s Informational string to store in the exception object.
154: * @param r Reason code to store in the <code>reason</code> field.
155: *
156: * @see ConfigException#reason
157: */
158: public ConfigException(int r, String s) {
159: super (s);
160: if ((r < 0) || (r > MAX_REASON))
161: reason = UNKNOWN;
162: else
163: reason = r;
164: }
165: }
|