001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.io;
019:
020: import java.io.CharConversionException;
021: import java.util.Locale;
022: import org.apache.xerces.util.MessageFormatter;
023:
024: /**
025: * <p>Signals that a malformed byte sequence was detected
026: * by a <code>java.io.Reader</code> that decodes bytes
027: * of a given encoding into characters.</p>
028: *
029: * @xerces.internal
030: *
031: * @author Michael Glavassevich, IBM
032: *
033: * @version $Id: MalformedByteSequenceException.java 539931 2007-05-20 20:27:43Z mrglavas $
034: */
035: public class MalformedByteSequenceException extends
036: CharConversionException {
037:
038: /** Serialization version. */
039: static final long serialVersionUID = 8436382245048328739L;
040:
041: //
042: // Data
043: //
044:
045: /** message formatter **/
046: private MessageFormatter fFormatter;
047:
048: /** locale for error message **/
049: private Locale fLocale;
050:
051: /** error domain **/
052: private String fDomain;
053:
054: /** key for the error message **/
055: private String fKey;
056:
057: /** replacement arguements for the error message **/
058: private Object[] fArguments;
059:
060: /** message text for this message, initially null **/
061: private String fMessage;
062:
063: //
064: // Constructors
065: //
066:
067: /**
068: * Constructs a MalformedByteSequenceException with the given
069: * parameters which may be passed to an error reporter to
070: * generate a localized string for this exception.
071: *
072: * @param formatter The MessageFormatter used for building the
073: * message text for this exception.
074: * @param locale The Locale for which messages are to be reported.
075: * @param domain The error domain.
076: * @param key The key of the error message.
077: * @param arguments The replacement arguments for the error message,
078: * if needed.
079: */
080: public MalformedByteSequenceException(MessageFormatter formatter,
081: Locale locale, String domain, String key, Object[] arguments) {
082: fFormatter = formatter;
083: fLocale = locale;
084: fDomain = domain;
085: fKey = key;
086: fArguments = arguments;
087: } // <init>(MessageFormatter, Locale, String, String, Object[])
088:
089: //
090: // Public methods
091: //
092:
093: /**
094: * <p>Returns the error domain of the error message.</p>
095: *
096: * @return the error domain
097: */
098: public String getDomain() {
099: return fDomain;
100: } // getDomain
101:
102: /**
103: * <p>Returns the key of the error message.</p>
104: *
105: * @return the error key of the error message
106: */
107: public String getKey() {
108: return fKey;
109: } // getKey()
110:
111: /**
112: * <p>Returns the replacement arguments for the error
113: * message or <code>null</code> if none exist.</p>
114: *
115: * @return the replacement arguments for the error message
116: * or <code>null</code> if none exist
117: */
118: public Object[] getArguments() {
119: return fArguments;
120: } // getArguments();
121:
122: /**
123: * <p>Returns the localized message for this exception.</p>
124: *
125: * @return the localized message for this exception.
126: */
127: public synchronized String getMessage() {
128: if (fMessage == null) {
129: fMessage = fFormatter.formatMessage(fLocale, fKey,
130: fArguments);
131: // The references to the message formatter and locale
132: // aren't needed anymore so null them.
133: fFormatter = null;
134: fLocale = null;
135: }
136: return fMessage;
137: } // getMessage()
138:
139: } // MalformedByteSequenceException
|