KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > modelmbean > XMLParseException


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
26
27
28 package javax.management.modelmbean;
29
30 import java.io.IOException JavaDoc;
31 import java.io.ObjectInputStream JavaDoc;
32 import java.io.ObjectOutputStream JavaDoc;
33 import java.io.ObjectStreamField JavaDoc;
34 import java.security.AccessController JavaDoc;
35 import java.security.PrivilegedAction JavaDoc;
36
37 import com.sun.jmx.mbeanserver.GetPropertyAction;
38
39 /**
40 * This exception is thrown when an XML formatted string is being parsed into ModelMBean objects
41 * or when XML formatted strings are being created from ModelMBean objects.
42 *
43 * It is also used to wrapper exceptions from XML parsers that may be used.
44 *
45 * @since 1.5
46 */

47 public class XMLParseException
48 extends Exception JavaDoc
49 {
50     // Serialization compatibility stuff:
51
// Two serial forms are supported in this class. The selected form depends
52
// on system property "jmx.serial.form":
53
// - "1.0" for JMX 1.0
54
// - any other value for JMX 1.1 and higher
55
//
56
// Serial version for old serial form
57
private static final long oldSerialVersionUID = -7780049316655891976L;
58     //
59
// Serial version for new serial form
60
private static final long newSerialVersionUID = 3176664577895105181L;
61     //
62
// Serializable fields in old serial form
63
private static final ObjectStreamField JavaDoc[] oldSerialPersistentFields =
64     {
65       new ObjectStreamField JavaDoc("msgStr", String JavaDoc.class)
66     };
67     //
68
// Serializable fields in new serial form
69
private static final ObjectStreamField JavaDoc[] newSerialPersistentFields = { };
70     //
71
// Actual serial version and serial form
72
private static final long serialVersionUID;
73     private static final ObjectStreamField JavaDoc[] serialPersistentFields;
74     private static boolean compat = false;
75     static {
76     try {
77         PrivilegedAction JavaDoc act = new GetPropertyAction("jmx.serial.form");
78         String JavaDoc form = (String JavaDoc) AccessController.doPrivileged(act);
79         compat = (form != null && form.equals("1.0"));
80     } catch (Exception JavaDoc e) {
81         // OK: No compat with 1.0
82
}
83     if (compat) {
84         serialPersistentFields = oldSerialPersistentFields;
85         serialVersionUID = oldSerialVersionUID;
86     } else {
87         serialPersistentFields = newSerialPersistentFields;
88         serialVersionUID = newSerialVersionUID;
89     }
90     }
91     //
92
// END Serialization compatibility stuff
93

94     /**
95      * Default constructor .
96      */

97     public XMLParseException ()
98     {
99       super("XML Parse Exception.");
100     }
101     
102     /**
103      * Constructor taking a string.
104      *
105      * @param s the detail message.
106      */

107     public XMLParseException (String JavaDoc s)
108     {
109       super("XML Parse Exception: " + s);
110     }
111     /**
112      * Constructor taking a string and an exception.
113      *
114      * @param e the nested exception.
115      * @param s the detail message.
116      */

117     public XMLParseException (Exception JavaDoc e, String JavaDoc s)
118     {
119       super("XML Parse Exception: " + s + ":" + e.toString());
120     }
121
122     /**
123      * Deserializes an {@link XMLParseException} from an {@link ObjectInputStream}.
124      */

125     private void readObject(ObjectInputStream JavaDoc in)
126         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
127       // New serial form ignores extra field "msgStr"
128
in.defaultReadObject();
129     }
130
131
132     /**
133      * Serializes an {@link XMLParseException} to an {@link ObjectOutputStream}.
134      */

135     private void writeObject(ObjectOutputStream JavaDoc out)
136         throws IOException JavaDoc {
137       if (compat)
138       {
139         // Serializes this instance in the old serial form
140
//
141
ObjectOutputStream.PutField JavaDoc fields = out.putFields();
142     fields.put("msgStr", getMessage());
143     out.writeFields();
144       }
145       else
146       {
147         // Serializes this instance in the new serial form
148
//
149
out.defaultWriteObject();
150       }
151     }
152 }
153
154
155
156
157
Popular Tags