KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > io > MalformedByteSequenceException


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.xerces.impl.io;
18
19 import java.io.CharConversionException JavaDoc;
20 import java.util.Locale JavaDoc;
21 import org.apache.xerces.util.MessageFormatter;
22
23 /**
24  * <p>Signals that a malformed byte sequence was detected
25  * by a <code>java.io.Reader</code> that decodes bytes
26  * of a given encoding into characters.</p>
27  *
28  * @xerces.internal
29  *
30  * @author Michael Glavassevich, IBM
31  *
32  * @version $Id: MalformedByteSequenceException.java,v 1.4 2004/10/04 22:07:41 mrglavas Exp $
33  */

34 public class MalformedByteSequenceException extends CharConversionException JavaDoc {
35
36     /** Serialization version. */
37     static final long serialVersionUID = 8436382245048328739L;
38     
39     //
40
// Data
41
//
42

43     /** message formatter **/
44     private MessageFormatter fFormatter;
45     
46     /** locale for error message **/
47     private Locale JavaDoc fLocale;
48     
49     /** error domain **/
50     private String JavaDoc fDomain;
51     
52     /** key for the error message **/
53     private String JavaDoc fKey;
54     
55     /** replacement arguements for the error message **/
56     private Object JavaDoc[] fArguments;
57     
58     /** message text for this message, initially null **/
59     private String JavaDoc fMessage;
60     
61     //
62
// Constructors
63
//
64

65     /**
66      * Constructs a MalformedByteSequenceException with the given
67      * parameters which may be passed to an error reporter to
68      * generate a localized string for this exception.
69      *
70      * @param formatter The MessageFormatter used for building the
71      * message text for this exception.
72      * @param locale The Locale for which messages are to be reported.
73      * @param domain The error domain.
74      * @param key The key of the error message.
75      * @param arguments The replacement arguments for the error message,
76      * if needed.
77      */

78     public MalformedByteSequenceException(MessageFormatter formatter,
79         Locale JavaDoc locale, String JavaDoc domain, String JavaDoc key, Object JavaDoc[] arguments) {
80         fFormatter = formatter;
81         fLocale = locale;
82         fDomain = domain;
83         fKey = key;
84         fArguments = arguments;
85     } // <init>(MessageFormatter, Locale, String, String, Object[])
86

87     //
88
// Public methods
89
//
90

91     /**
92      * <p>Returns the error domain of the error message.</p>
93      *
94      * @return the error domain
95      */

96     public String JavaDoc getDomain () {
97         return fDomain;
98     } // getDomain
99

100     /**
101      * <p>Returns the key of the error message.</p>
102      *
103      * @return the error key of the error message
104      */

105     public String JavaDoc getKey () {
106         return fKey;
107     } // getKey()
108

109     /**
110      * <p>Returns the replacement arguments for the error
111      * message or <code>null</code> if none exist.</p>
112      *
113      * @return the replacement arguments for the error message
114      * or <code>null</code> if none exist
115      */

116     public Object JavaDoc[] getArguments () {
117         return fArguments;
118     } // getArguments();
119

120     /**
121      * <p>Returns the localized message for this exception.</p>
122      *
123      * @return the localized message for this exception.
124      */

125     public String JavaDoc getMessage() {
126         if (fMessage == null) {
127             fMessage = fFormatter.formatMessage(fLocale, fKey, fArguments);
128             // The references to the message formatter and locale
129
// aren't needed anymore so null them.
130
fFormatter = null;
131             fLocale = null;
132         }
133         return fMessage;
134      } // getMessage()
135

136 } // MalformedByteSequenceException
137
Popular Tags