1 7 8 package javax.management.relation; 9 10 import javax.management.ObjectName ; 11 12 import java.util.ArrayList ; 13 import java.util.List ; 14 import java.util.Iterator ; 15 16 import java.security.AccessController ; 17 import java.security.PrivilegedAction ; 18 19 import java.io.IOException ; 20 import java.io.ObjectInputStream ; 21 import java.io.ObjectOutputStream ; 22 import java.io.ObjectStreamField ; 23 import java.io.Serializable ; 24 25 import com.sun.jmx.mbeanserver.GetPropertyAction; 26 27 35 public class RoleUnresolved implements Serializable { 36 37 private static final long oldSerialVersionUID = -9026457686611660144L; 45 private static final long newSerialVersionUID = -48350262537070138L; 48 private static final ObjectStreamField [] oldSerialPersistentFields = 51 { 52 new ObjectStreamField ("myRoleName", String .class), 53 new ObjectStreamField ("myRoleValue", ArrayList .class), 54 new ObjectStreamField ("myPbType", int.class) 55 }; 56 private static final ObjectStreamField [] newSerialPersistentFields = 59 { 60 new ObjectStreamField ("roleName", String .class), 61 new ObjectStreamField ("roleValue", List .class), 62 new ObjectStreamField ("problemType", int.class) 63 }; 64 private static final long serialVersionUID; 67 71 private static final ObjectStreamField [] serialPersistentFields; 72 private static boolean compat = false; 73 static { 74 try { 75 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 76 String form = (String ) AccessController.doPrivileged(act); 77 compat = (form != null && form.equals("1.0")); 78 } catch (Exception e) { 79 } 81 if (compat) { 82 serialPersistentFields = oldSerialPersistentFields; 83 serialVersionUID = oldSerialVersionUID; 84 } else { 85 serialPersistentFields = newSerialPersistentFields; 86 serialVersionUID = newSerialVersionUID; 87 } 88 } 89 92 96 99 private String roleName = null; 100 101 104 private List roleValue = null; 105 106 109 private int problemType; 110 111 115 127 public RoleUnresolved(String theRoleName, 128 List theRoleValue, 129 int thePbType) 130 throws IllegalArgumentException { 131 132 if (theRoleName == null) { 133 String excMsg = "Invalid parameter."; 135 throw new IllegalArgumentException (excMsg); 136 } 137 138 setRoleName(theRoleName); 139 setRoleValue(theRoleValue); 140 setProblemType(thePbType); 142 return; 143 } 144 145 149 156 public String getRoleName() { 157 return roleName; 158 } 159 160 169 public List getRoleValue() { 170 return roleValue; 171 } 172 173 181 public int getProblemType() { 182 return problemType; 183 } 184 185 194 public void setRoleName(String theRoleName) 195 throws IllegalArgumentException { 196 197 if (theRoleName == null) { 198 String excMsg = "Invalid parameter."; 200 throw new IllegalArgumentException (excMsg); 201 } 202 203 roleName = theRoleName; 204 return; 205 } 206 207 215 public void setRoleValue(List theRoleValue) { 216 217 if (theRoleValue != null) { 218 roleValue = new ArrayList (theRoleValue); 219 } else { 220 roleValue = null; 221 } 222 return; 223 } 224 225 235 public void setProblemType(int thePbType) 236 throws IllegalArgumentException { 237 238 if (!(RoleStatus.isRoleStatus(thePbType))) { 239 String excMsg = "Incorrect problem type."; 241 throw new IllegalArgumentException (excMsg); 242 } 243 problemType = thePbType; 244 return; 245 } 246 247 252 public Object clone() { 253 try { 254 return new RoleUnresolved (roleName, roleValue, problemType); 255 } catch (IllegalArgumentException exc) { 256 return null; } 258 } 259 260 265 public String toString() { 266 StringBuffer result = new StringBuffer (); 267 result.append("role name: " + roleName); 268 if (roleValue != null) { 269 result.append("; value: "); 270 for (Iterator objNameIter = roleValue.iterator(); 271 objNameIter.hasNext();) { 272 ObjectName currObjName = (ObjectName )(objNameIter.next()); 273 result.append(currObjName.toString()); 274 if (objNameIter.hasNext()) { 275 result.append(", "); 276 } 277 } 278 } 279 result.append("; problem type: " + problemType); 280 return result.toString(); 281 } 282 283 286 private void readObject(ObjectInputStream in) 287 throws IOException , ClassNotFoundException { 288 if (compat) 289 { 290 ObjectInputStream.GetField fields = in.readFields(); 293 roleName = (String ) fields.get("myRoleName", null); 294 if (fields.defaulted("myRoleName")) 295 { 296 throw new NullPointerException ("myRoleName"); 297 } 298 roleValue = (List ) fields.get("myRoleValue", null); 299 if (fields.defaulted("myRoleValue")) 300 { 301 throw new NullPointerException ("myRoleValue"); 302 } 303 problemType = fields.get("myPbType", (int)0); 304 if (fields.defaulted("myPbType")) 305 { 306 throw new NullPointerException ("myPbType"); 307 } 308 } 309 else 310 { 311 in.defaultReadObject(); 314 } 315 } 316 317 318 321 private void writeObject(ObjectOutputStream out) 322 throws IOException { 323 if (compat) 324 { 325 ObjectOutputStream.PutField fields = out.putFields(); 328 fields.put("myRoleName", roleName); 329 fields.put("myRoleValue", (ArrayList )roleValue); 330 fields.put("myPbType", problemType); 331 out.writeFields(); 332 } 333 else 334 { 335 out.defaultWriteObject(); 338 } 339 } 340 } 341 | Popular Tags |