1. /*
  2. * @(#)file XMLParseException.java
  3. * @(#)author IBM Corp.
  4. * @(#)version 1.23
  5. * @(#)lastedit 03/12/19
  6. */
  7. /*
  8. * Copyright IBM Corp. 1999-2000. All rights reserved.
  9. *
  10. * The program is provided "as is" without any warranty express or implied,
  11. * including the warranty of non-infringement and the implied warranties of
  12. * merchantibility and fitness for a particular purpose. IBM will not be
  13. * liable for any damages suffered by you or any third party claim against
  14. * you regarding the Program.
  15. *
  16. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  17. * This software is the proprietary information of Sun Microsystems, Inc.
  18. * Use is subject to license terms.
  19. *
  20. * Copyright 2004 Sun Microsystems, Inc. Tous droits reserves.
  21. * Ce logiciel est propriete de Sun Microsystems, Inc.
  22. * Distribue par des licences qui en restreignent l'utilisation.
  23. *
  24. */
  25. package javax.management.modelmbean;
  26. import java.io.IOException;
  27. import java.io.ObjectInputStream;
  28. import java.io.ObjectOutputStream;
  29. import java.io.ObjectStreamField;
  30. import java.security.AccessController;
  31. import java.security.PrivilegedAction;
  32. import com.sun.jmx.mbeanserver.GetPropertyAction;
  33. /**
  34. * This exception is thrown when an XML formatted string is being parsed into ModelMBean objects
  35. * or when XML formatted strings are being created from ModelMBean objects.
  36. *
  37. * It is also used to wrapper exceptions from XML parsers that may be used.
  38. *
  39. * @since 1.5
  40. */
  41. public class XMLParseException
  42. extends Exception
  43. {
  44. // Serialization compatibility stuff:
  45. // Two serial forms are supported in this class. The selected form depends
  46. // on system property "jmx.serial.form":
  47. // - "1.0" for JMX 1.0
  48. // - any other value for JMX 1.1 and higher
  49. //
  50. // Serial version for old serial form
  51. private static final long oldSerialVersionUID = -7780049316655891976L;
  52. //
  53. // Serial version for new serial form
  54. private static final long newSerialVersionUID = 3176664577895105181L;
  55. //
  56. // Serializable fields in old serial form
  57. private static final ObjectStreamField[] oldSerialPersistentFields =
  58. {
  59. new ObjectStreamField("msgStr", String.class)
  60. };
  61. //
  62. // Serializable fields in new serial form
  63. private static final ObjectStreamField[] newSerialPersistentFields = { };
  64. //
  65. // Actual serial version and serial form
  66. private static final long serialVersionUID;
  67. private static final ObjectStreamField[] serialPersistentFields;
  68. private static boolean compat = false;
  69. static {
  70. try {
  71. PrivilegedAction act = new GetPropertyAction("jmx.serial.form");
  72. String form = (String) AccessController.doPrivileged(act);
  73. compat = (form != null && form.equals("1.0"));
  74. } catch (Exception e) {
  75. // OK: No compat with 1.0
  76. }
  77. if (compat) {
  78. serialPersistentFields = oldSerialPersistentFields;
  79. serialVersionUID = oldSerialVersionUID;
  80. } else {
  81. serialPersistentFields = newSerialPersistentFields;
  82. serialVersionUID = newSerialVersionUID;
  83. }
  84. }
  85. //
  86. // END Serialization compatibility stuff
  87. /**
  88. * Default constructor .
  89. */
  90. public XMLParseException ()
  91. {
  92. super("XML Parse Exception.");
  93. }
  94. /**
  95. * Constructor taking a string.
  96. *
  97. * @param s the detail message.
  98. */
  99. public XMLParseException (String s)
  100. {
  101. super("XML Parse Exception: " + s);
  102. }
  103. /**
  104. * Constructor taking a string and an exception.
  105. *
  106. * @param e the nested exception.
  107. * @param s the detail message.
  108. */
  109. public XMLParseException (Exception e, String s)
  110. {
  111. super("XML Parse Exception: " + s + ":" + e.toString());
  112. }
  113. /**
  114. * Deserializes an {@link XMLParseException} from an {@link ObjectInputStream}.
  115. */
  116. private void readObject(ObjectInputStream in)
  117. throws IOException, ClassNotFoundException {
  118. // New serial form ignores extra field "msgStr"
  119. in.defaultReadObject();
  120. }
  121. /**
  122. * Serializes an {@link XMLParseException} to an {@link ObjectOutputStream}.
  123. */
  124. private void writeObject(ObjectOutputStream out)
  125. throws IOException {
  126. if (compat)
  127. {
  128. // Serializes this instance in the old serial form
  129. //
  130. ObjectOutputStream.PutField fields = out.putFields();
  131. fields.put("msgStr", getMessage());
  132. out.writeFields();
  133. }
  134. else
  135. {
  136. // Serializes this instance in the new serial form
  137. //
  138. out.defaultWriteObject();
  139. }
  140. }
  141. }