1 7 25 26 27 28 package javax.management.modelmbean; 29 30 import java.io.IOException ; 31 import java.io.ObjectInputStream ; 32 import java.io.ObjectOutputStream ; 33 import java.io.ObjectStreamField ; 34 import java.security.AccessController ; 35 import java.security.PrivilegedAction ; 36 37 import com.sun.jmx.mbeanserver.GetPropertyAction; 38 39 45 46 public class InvalidTargetObjectTypeException extends Exception 47 { 48 49 private static final long oldSerialVersionUID = 3711724570458346634L; 57 private static final long newSerialVersionUID = 1190536278266811217L; 60 private static final ObjectStreamField [] oldSerialPersistentFields = 63 { 64 new ObjectStreamField ("msgStr", String .class), 65 new ObjectStreamField ("relatedExcept", Exception .class) 66 }; 67 private static final ObjectStreamField [] newSerialPersistentFields = 70 { 71 new ObjectStreamField ("exception", Exception .class) 72 }; 73 private static final long serialVersionUID; 76 79 private static final ObjectStreamField [] serialPersistentFields; 80 private static boolean compat = false; 81 static { 82 try { 83 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 84 String form = (String ) AccessController.doPrivileged(act); 85 compat = (form != null && form.equals("1.0")); 86 } catch (Exception e) { 87 } 89 if (compat) { 90 serialPersistentFields = oldSerialPersistentFields; 91 serialVersionUID = oldSerialVersionUID; 92 } else { 93 serialPersistentFields = newSerialPersistentFields; 94 serialVersionUID = newSerialVersionUID; 95 } 96 } 97 100 103 Exception exception; 104 105 106 109 public InvalidTargetObjectTypeException () 110 { 111 super("InvalidTargetObjectTypeException: "); 112 exception = null; 113 } 114 115 116 122 123 public InvalidTargetObjectTypeException (String s) 124 { 125 super("InvalidTargetObjectTypeException: " + s); 126 exception = null; 127 } 128 129 130 140 141 public InvalidTargetObjectTypeException (Exception e, String s) 142 { 143 super("InvalidTargetObjectTypeException: " + 144 s + 145 ((e != null)?("\n\t triggered by:" + e.toString()):"")); 146 exception = e; 147 } 148 149 152 private void readObject(ObjectInputStream in) 153 throws IOException , ClassNotFoundException { 154 if (compat) 155 { 156 ObjectInputStream.GetField fields = in.readFields(); 159 exception = (Exception ) fields.get("relatedExcept", null); 160 if (fields.defaulted("relatedExcept")) 161 { 162 throw new NullPointerException ("relatedExcept"); 163 } 164 } 165 else 166 { 167 in.defaultReadObject(); 170 } 171 } 172 173 174 177 private void writeObject(ObjectOutputStream out) 178 throws IOException { 179 if (compat) 180 { 181 ObjectOutputStream.PutField fields = out.putFields(); 184 fields.put("relatedExcept", exception); 185 fields.put("msgStr", ((exception != null)?exception.getMessage():"")); 186 out.writeFields(); 187 } 188 else 189 { 190 out.defaultWriteObject(); 193 } 194 } 195 } 196 197 | Popular Tags |