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