1 7 8 package javax.management.relation; 9 10 import java.util.Iterator ; 11 12 import java.io.IOException ; 13 import java.io.ObjectInputStream ; 14 import java.io.ObjectOutputStream ; 15 import java.io.ObjectStreamField ; 16 import java.io.Serializable ; 17 18 import java.security.AccessController ; 19 import java.security.PrivilegedAction ; 20 21 import com.sun.jmx.mbeanserver.GetPropertyAction; 22 23 29 public class RoleResult implements Serializable { 30 31 private static final long oldSerialVersionUID = 3786616013762091099L; 39 private static final long newSerialVersionUID = -6304063118040985512L; 42 private static final ObjectStreamField [] oldSerialPersistentFields = 45 { 46 new ObjectStreamField ("myRoleList", RoleList .class), 47 new ObjectStreamField ("myRoleUnresList", RoleUnresolvedList .class) 48 }; 49 private static final ObjectStreamField [] newSerialPersistentFields = 52 { 53 new ObjectStreamField ("roleList", RoleList .class), 54 new ObjectStreamField ("unresolvedRoleList", RoleUnresolvedList .class) 55 }; 56 private static final long serialVersionUID; 59 63 private static final ObjectStreamField [] serialPersistentFields; 64 private static boolean compat = false; 65 static { 66 try { 67 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 68 String form = (String ) AccessController.doPrivileged(act); 69 compat = (form != null && form.equals("1.0")); 70 } catch (Exception e) { 71 } 73 if (compat) { 74 serialPersistentFields = oldSerialPersistentFields; 75 serialVersionUID = oldSerialVersionUID; 76 } else { 77 serialPersistentFields = newSerialPersistentFields; 78 serialVersionUID = newSerialVersionUID; 79 } 80 } 81 84 88 91 private RoleList roleList = null; 92 93 96 private RoleUnresolvedList unresolvedRoleList = null; 97 98 102 109 public RoleResult(RoleList theRoleList, 110 RoleUnresolvedList theRoleUnresList) { 111 112 setRoles(theRoleList); 113 setRolesUnresolved(theRoleUnresList); 114 return; 115 } 116 117 121 128 public RoleList getRoles() { 129 return roleList; 130 } 131 132 139 public RoleUnresolvedList getRolesUnresolved() { 140 return unresolvedRoleList; 141 } 142 143 150 public void setRoles(RoleList theRoleList) { 151 if (theRoleList != null) { 152 153 roleList = new RoleList (); 154 155 for (Iterator roleIter = theRoleList.iterator(); 156 roleIter.hasNext();) { 157 Role currRole = (Role )(roleIter.next()); 158 roleList.add((Role )(currRole.clone())); 159 } 160 } else { 161 roleList = null; 162 } 163 return; 164 } 165 166 173 public void setRolesUnresolved(RoleUnresolvedList theRoleUnresList) { 174 if (theRoleUnresList != null) { 175 176 unresolvedRoleList = new RoleUnresolvedList (); 177 178 for (Iterator roleUnresIter = theRoleUnresList.iterator(); 179 roleUnresIter.hasNext();) { 180 RoleUnresolved currRoleUnres = 181 (RoleUnresolved )(roleUnresIter.next()); 182 unresolvedRoleList.add((RoleUnresolved )(currRoleUnres.clone())); 183 } 184 } else { 185 unresolvedRoleList = null; 186 } 187 return; 188 } 189 190 193 private void readObject(ObjectInputStream in) 194 throws IOException , ClassNotFoundException { 195 if (compat) 196 { 197 ObjectInputStream.GetField fields = in.readFields(); 200 roleList = (RoleList ) fields.get("myRoleList", null); 201 if (fields.defaulted("myRoleList")) 202 { 203 throw new NullPointerException ("myRoleList"); 204 } 205 unresolvedRoleList = (RoleUnresolvedList ) fields.get("myRoleUnresList", null); 206 if (fields.defaulted("myRoleUnresList")) 207 { 208 throw new NullPointerException ("myRoleUnresList"); 209 } 210 } 211 else 212 { 213 in.defaultReadObject(); 216 } 217 } 218 219 220 223 private void writeObject(ObjectOutputStream out) 224 throws IOException { 225 if (compat) 226 { 227 ObjectOutputStream.PutField fields = out.putFields(); 230 fields.put("myRoleList", roleList); 231 fields.put("myRoleUnresList", unresolvedRoleList); 232 out.writeFields(); 233 } 234 else 235 { 236 out.defaultWriteObject(); 239 } 240 } 241 } 242 | Popular Tags |