01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package javax.microedition.content;
28:
29: import java.io.IOException;
30:
31: /**
32: * A <tt>ContentHandlerException</tt> is thrown to report errors
33: * specific to registration and invocation of content handlers.
34: * Instances are immutable and thread safe.
35: */
36: public class ContentHandlerException extends IOException {
37: /** The error code. */
38: private int errcode;
39:
40: /**
41: * The reason is <CODE>NO_REGISTERED_HANDLER</CODE> in a
42: * ContentHandlerException when there is no content handler
43: * registered of the requested combination of
44: * ID, type, suffix, and action.
45: */
46: public final static int NO_REGISTERED_HANDLER = 1;
47:
48: /**
49: * The reason is <code>TYPE_UNKNOWN</code> in a
50: * ContentHandlerException when the type is not available.
51: */
52: public final static int TYPE_UNKNOWN = 2;
53:
54: /**
55: * The reason is <CODE>AMBIGUOUS</CODE> in a
56: * ContentHandlerException when an ID does not
57: * uniquely identify a single content handler application.
58: */
59: public final static int AMBIGUOUS = 3;
60:
61: /**
62: * Constructs a <code>ContentHandlerException</code> with a reason
63: * and error code.
64: * The error message string <code>reason</code> can later be
65: * retrieved by the
66: * {@link java.lang.Throwable#getMessage java.lang.Throwable.getMessage}
67: * method.
68: * @param reason the reason for the exception
69: * @param errcode the error code; one of
70: * {@link #NO_REGISTERED_HANDLER}, {@link #AMBIGUOUS},
71: * or {@link #TYPE_UNKNOWN}
72: * @exception IllegalArgumentException if <code>errcode</code> is not
73: * one of
74: * {@link #NO_REGISTERED_HANDLER}, {@link #AMBIGUOUS},
75: * or {@link #TYPE_UNKNOWN}
76: */
77: public ContentHandlerException(String reason, int errcode) {
78: super (reason);
79: if (errcode < NO_REGISTERED_HANDLER || errcode > AMBIGUOUS) {
80: throw new IllegalArgumentException();
81: }
82: this .errcode = errcode;
83: }
84:
85: /**
86: * Returns the error code for the exception.
87: * @return the error code; one of
88: * {@link #NO_REGISTERED_HANDLER}, {@link #AMBIGUOUS},
89: * or {@link #TYPE_UNKNOWN}
90: */
91: public int getErrorCode() {
92: return errcode;
93: }
94: }
|