KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)file InvalidTargetObjectTypeException.java
3  * @(#)author IBM Corp.
4  * @(#)version 1.26
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  * Exception thrown when an invalid target object type is specified.
41  *
42  *
43  * @since 1.5
44  */

45
46 public class InvalidTargetObjectTypeException extends Exception JavaDoc
47 {
48
49     // Serialization compatibility stuff:
50
// Two serial forms are supported in this class. The selected form depends
51
// on system property "jmx.serial.form":
52
// - "1.0" for JMX 1.0
53
// - any other value for JMX 1.1 and higher
54
//
55
// Serial version for old serial form
56
private static final long oldSerialVersionUID = 3711724570458346634L;
57     //
58
// Serial version for new serial form
59
private static final long newSerialVersionUID = 1190536278266811217L;
60     //
61
// Serializable fields in old serial form
62
private static final ObjectStreamField JavaDoc[] oldSerialPersistentFields =
63     {
64       new ObjectStreamField JavaDoc("msgStr", String JavaDoc.class),
65       new ObjectStreamField JavaDoc("relatedExcept", Exception JavaDoc.class)
66     };
67     //
68
// Serializable fields in new serial form
69
private static final ObjectStreamField JavaDoc[] newSerialPersistentFields =
70     {
71       new ObjectStreamField JavaDoc("exception", Exception JavaDoc.class)
72     };
73     //
74
// Actual serial version and serial form
75
private static final long serialVersionUID;
76     /**
77      * @serialField exception Exception Encapsulated {@link Exception}
78      */

79     private static final ObjectStreamField JavaDoc[] serialPersistentFields;
80     private static boolean compat = false;
81     static {
82     try {
83         PrivilegedAction JavaDoc act = new GetPropertyAction("jmx.serial.form");
84         String JavaDoc form = (String JavaDoc) AccessController.doPrivileged(act);
85         compat = (form != null && form.equals("1.0"));
86     } catch (Exception JavaDoc e) {
87         // OK: No compat with 1.0
88
}
89     if (compat) {
90         serialPersistentFields = oldSerialPersistentFields;
91         serialVersionUID = oldSerialVersionUID;
92     } else {
93         serialPersistentFields = newSerialPersistentFields;
94         serialVersionUID = newSerialVersionUID;
95     }
96     }
97     //
98
// END Serialization compatibility stuff
99

100     /**
101      * @serial Encapsulated {@link Exception}
102      */

103     Exception JavaDoc exception;
104
105
106     /**
107      * Default constructor.
108      */

109     public InvalidTargetObjectTypeException ()
110     {
111       super("InvalidTargetObjectTypeException: ");
112       exception = null;
113     }
114
115
116     /**
117      * Constructor from a string.
118      *
119      * @param s String value that will be incorporated in the message for
120      * this exception.
121      */

122
123     public InvalidTargetObjectTypeException (String JavaDoc s)
124     {
125       super("InvalidTargetObjectTypeException: " + s);
126       exception = null;
127     }
128
129
130     /**
131      * Constructor taking an exception and a string.
132      *
133      * @param e Exception that we may have caught to reissue as an
134      * InvalidTargetObjectTypeException. The message will be used, and we may want to
135      * consider overriding the printStackTrace() methods to get data
136      * pointing back to original throw stack.
137      * @param s String value that will be incorporated in message for
138      * this exception.
139      */

140
141     public InvalidTargetObjectTypeException (Exception JavaDoc e, String JavaDoc s)
142     {
143       super("InvalidTargetObjectTypeException: " +
144             s +
145             ((e != null)?("\n\t triggered by:" + e.toString()):""));
146       exception = e;
147     }
148
149     /**
150      * Deserializes an {@link InvalidTargetObjectTypeException} from an {@link ObjectInputStream}.
151      */

152     private void readObject(ObjectInputStream JavaDoc in)
153         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
154       if (compat)
155       {
156         // Read an object serialized in the old serial form
157
//
158
ObjectInputStream.GetField JavaDoc fields = in.readFields();
159     exception = (Exception JavaDoc) fields.get("relatedExcept", null);
160     if (fields.defaulted("relatedExcept"))
161         {
162           throw new NullPointerException JavaDoc("relatedExcept");
163         }
164       }
165       else
166       {
167         // Read an object serialized in the new serial form
168
//
169
in.defaultReadObject();
170       }
171     }
172
173
174     /**
175      * Serializes an {@link InvalidTargetObjectTypeException} to an {@link ObjectOutputStream}.
176      */

177     private void writeObject(ObjectOutputStream JavaDoc out)
178         throws IOException JavaDoc {
179       if (compat)
180       {
181         // Serializes this instance in the old serial form
182
//
183
ObjectOutputStream.PutField JavaDoc fields = out.putFields();
184     fields.put("relatedExcept", exception);
185     fields.put("msgStr", ((exception != null)?exception.getMessage():""));
186     out.writeFields();
187       }
188       else
189       {
190         // Serializes this instance in the new serial form
191
//
192
out.defaultWriteObject();
193       }
194     }
195 }
196
197
Popular Tags