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. package com.sun.org.apache.xerces.internal.impl.io;
  17. import java.io.CharConversionException;
  18. import java.util.Locale;
  19. import com.sun.org.apache.xerces.internal.util.MessageFormatter;
  20. /**
  21. * <p>Signals that a malformed byte sequence was detected
  22. * by a <code>java.io.Reader</code> that decodes bytes
  23. * of a given encoding into characters.</p>
  24. *
  25. * @author Michael Glavassevich, IBM
  26. *
  27. * @version $Id: MalformedByteSequenceException.java,v 1.1.1.1 2004/05/04 10:22:02 vk112360 Exp $
  28. */
  29. public class MalformedByteSequenceException extends CharConversionException {
  30. //
  31. // Data
  32. //
  33. /** message formatter **/
  34. private MessageFormatter fFormatter;
  35. /** locale for error message **/
  36. private Locale fLocale;
  37. /** error domain **/
  38. private String fDomain;
  39. /** key for the error message **/
  40. private String fKey;
  41. /** replacement arguements for the error message **/
  42. private Object[] fArguments;
  43. /** message text for this message, initially null **/
  44. private String fMessage;
  45. //
  46. // Constructors
  47. //
  48. /**
  49. * Constructs a MalformedByteSequenceException with the given
  50. * parameters which may be passed to an error reporter to
  51. * generate a localized string for this exception.
  52. *
  53. * @param formatter The MessageFormatter used for building the
  54. * message text for this exception.
  55. * @param locale The Locale for which messages are to be reported.
  56. * @param domain The error domain.
  57. * @param key The key of the error message.
  58. * @param arguments The replacement arguments for the error message,
  59. * if needed.
  60. */
  61. public MalformedByteSequenceException(MessageFormatter formatter,
  62. Locale locale, String domain, String key, Object[] arguments) {
  63. fFormatter = formatter;
  64. fLocale = locale;
  65. fDomain = domain;
  66. fKey = key;
  67. fArguments = arguments;
  68. } // <init>(MessageFormatter, Locale, String, String, Object[])
  69. //
  70. // Public methods
  71. //
  72. /**
  73. * <p>Returns the error domain of the error message.</p>
  74. *
  75. * @return the error domain
  76. */
  77. public String getDomain () {
  78. return fDomain;
  79. } // getDomain
  80. /**
  81. * <p>Returns the key of the error message.</p>
  82. *
  83. * @return the error key of the error message
  84. */
  85. public String getKey () {
  86. return fKey;
  87. } // getKey()
  88. /**
  89. * <p>Returns the replacement arguments for the error
  90. * message or <code>null</code> if none exist.</p>
  91. *
  92. * @return the replacement arguments for the error message
  93. * or <code>null</code> if none exist
  94. */
  95. public Object[] getArguments () {
  96. return fArguments;
  97. } // getArguments();
  98. /**
  99. * <p>Returns the localized message for this exception.</p>
  100. *
  101. * @return the localized message for this exception.
  102. */
  103. public String getMessage() {
  104. if (fMessage == null) {
  105. fMessage = fFormatter.formatMessage(fLocale, fKey, fArguments);
  106. // The references to the message formatter and locale
  107. // aren't needed anymore so null them.
  108. fFormatter = null;
  109. fLocale = null;
  110. }
  111. return fMessage;
  112. } // getMessage()
  113. } // MalformedByteSequenceException