1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.xerces.impl.io; 19 20 import java.io.CharConversionException; 21 import java.util.Locale; 22 import org.apache.xerces.util.MessageFormatter; 23 24 /** 25 * <p>Signals that a malformed byte sequence was detected 26 * by a <code>java.io.Reader</code> that decodes bytes 27 * of a given encoding into characters.</p> 28 * 29 * @xerces.internal 30 * 31 * @author Michael Glavassevich, IBM 32 * 33 * @version $Id: MalformedByteSequenceException.java 539931 2007-05-20 20:27:43Z mrglavas $ 34 */ 35 public class MalformedByteSequenceException extends CharConversionException { 36 37 /** Serialization version. */ 38 static final long serialVersionUID = 8436382245048328739L; 39 40 // 41 // Data 42 // 43 44 /** message formatter **/ 45 private MessageFormatter fFormatter; 46 47 /** locale for error message **/ 48 private Locale fLocale; 49 50 /** error domain **/ 51 private String fDomain; 52 53 /** key for the error message **/ 54 private String fKey; 55 56 /** replacement arguements for the error message **/ 57 private Object[] fArguments; 58 59 /** message text for this message, initially null **/ 60 private String fMessage; 61 62 // 63 // Constructors 64 // 65 66 /** 67 * Constructs a MalformedByteSequenceException with the given 68 * parameters which may be passed to an error reporter to 69 * generate a localized string for this exception. 70 * 71 * @param formatter The MessageFormatter used for building the 72 * message text for this exception. 73 * @param locale The Locale for which messages are to be reported. 74 * @param domain The error domain. 75 * @param key The key of the error message. 76 * @param arguments The replacement arguments for the error message, 77 * if needed. 78 */ 79 public MalformedByteSequenceException(MessageFormatter formatter, 80 Locale locale, String domain, String key, Object[] arguments) { 81 fFormatter = formatter; 82 fLocale = locale; 83 fDomain = domain; 84 fKey = key; 85 fArguments = arguments; 86 } // <init>(MessageFormatter, Locale, String, String, Object[]) 87 88 // 89 // Public methods 90 // 91 92 /** 93 * <p>Returns the error domain of the error message.</p> 94 * 95 * @return the error domain 96 */ 97 public String getDomain () { 98 return fDomain; 99 } // getDomain 100 101 /** 102 * <p>Returns the key of the error message.</p> 103 * 104 * @return the error key of the error message 105 */ 106 public String getKey () { 107 return fKey; 108 } // getKey() 109 110 /** 111 * <p>Returns the replacement arguments for the error 112 * message or <code>null</code> if none exist.</p> 113 * 114 * @return the replacement arguments for the error message 115 * or <code>null</code> if none exist 116 */ 117 public Object[] getArguments () { 118 return fArguments; 119 } // getArguments(); 120 121 /** 122 * <p>Returns the localized message for this exception.</p> 123 * 124 * @return the localized message for this exception. 125 */ 126 public synchronized String getMessage() { 127 if (fMessage == null) { 128 fMessage = fFormatter.formatMessage(fLocale, fKey, fArguments); 129 // The references to the message formatter and locale 130 // aren't needed anymore so null them. 131 fFormatter = null; 132 fLocale = null; 133 } 134 return fMessage; 135 } // getMessage() 136 137 } // MalformedByteSequenceException