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