KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > relation > RoleResult


1 /*
2  * @(#)RoleResult.java 1.23 04/02/10
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.relation;
9
10 import java.util.Iterator JavaDoc;
11
12 import java.io.IOException JavaDoc;
13 import java.io.ObjectInputStream JavaDoc;
14 import java.io.ObjectOutputStream JavaDoc;
15 import java.io.ObjectStreamField JavaDoc;
16 import java.io.Serializable JavaDoc;
17
18 import java.security.AccessController JavaDoc;
19 import java.security.PrivilegedAction JavaDoc;
20
21 import com.sun.jmx.mbeanserver.GetPropertyAction;
22
23 /**
24  * Represents the result of a multiple access to several roles of a relation
25  * (either for reading or writing).
26  *
27  * @since 1.5
28  */

29 public class RoleResult implements Serializable JavaDoc {
30
31     // Serialization compatibility stuff:
32
// Two serial forms are supported in this class. The selected form depends
33
// on system property "jmx.serial.form":
34
// - "1.0" for JMX 1.0
35
// - any other value for JMX 1.1 and higher
36
//
37
// Serial version for old serial form
38
private static final long oldSerialVersionUID = 3786616013762091099L;
39     //
40
// Serial version for new serial form
41
private static final long newSerialVersionUID = -6304063118040985512L;
42     //
43
// Serializable fields in old serial form
44
private static final ObjectStreamField JavaDoc[] oldSerialPersistentFields =
45     {
46       new ObjectStreamField JavaDoc("myRoleList", RoleList JavaDoc.class),
47       new ObjectStreamField JavaDoc("myRoleUnresList", RoleUnresolvedList JavaDoc.class)
48     };
49     //
50
// Serializable fields in new serial form
51
private static final ObjectStreamField JavaDoc[] newSerialPersistentFields =
52     {
53       new ObjectStreamField JavaDoc("roleList", RoleList JavaDoc.class),
54       new ObjectStreamField JavaDoc("unresolvedRoleList", RoleUnresolvedList JavaDoc.class)
55     };
56     //
57
// Actual serial version and serial form
58
private static final long serialVersionUID;
59     /**
60      * @serialField roleList RoleList List of roles successfully accessed
61      * @serialField unresolvedRoleList RoleUnresolvedList List of roles unsuccessfully accessed
62      */

63     private static final ObjectStreamField JavaDoc[] serialPersistentFields;
64     private static boolean compat = false;
65     static {
66     try {
67         PrivilegedAction JavaDoc act = new GetPropertyAction("jmx.serial.form");
68         String JavaDoc form = (String JavaDoc) AccessController.doPrivileged(act);
69         compat = (form != null && form.equals("1.0"));
70     } catch (Exception JavaDoc e) {
71         // OK : Too bad, no compat with 1.0
72
}
73     if (compat) {
74         serialPersistentFields = oldSerialPersistentFields;
75         serialVersionUID = oldSerialVersionUID;
76     } else {
77         serialPersistentFields = newSerialPersistentFields;
78         serialVersionUID = newSerialVersionUID;
79     }
80     }
81     //
82
// END Serialization compatibility stuff
83

84     //
85
// Private members
86
//
87

88     /**
89      * @serial List of roles successfully accessed
90      */

91     private RoleList JavaDoc roleList = null;
92
93     /**
94      * @serial List of roles unsuccessfully accessed
95      */

96     private RoleUnresolvedList JavaDoc unresolvedRoleList = null;
97
98     //
99
// Constructor
100
//
101

102     /**
103      * Constructor.
104      *
105      * @param theRoleList list of roles successfully accessed.
106      * @param theRoleUnresList list of roles not accessed (with problem
107      * descriptions).
108      */

109     public RoleResult(RoleList JavaDoc theRoleList,
110               RoleUnresolvedList JavaDoc theRoleUnresList) {
111
112     setRoles(theRoleList);
113     setRolesUnresolved(theRoleUnresList);
114     return;
115     }
116
117     //
118
// Accessors
119
//
120

121     /**
122      * Retrieves list of roles successfully accessed.
123      *
124      * @return a RoleList
125      *
126      * @see #setRoles
127      */

128     public RoleList JavaDoc getRoles() {
129     return roleList;
130     }
131
132     /**
133      * Retrieves list of roles unsuccessfully accessed.
134      *
135      * @return a RoleUnresolvedList.
136      *
137      * @see #setRolesUnresolved
138      */

139     public RoleUnresolvedList JavaDoc getRolesUnresolved() {
140     return unresolvedRoleList;
141     }
142
143     /**
144      * Sets list of roles successfully accessed.
145      *
146      * @param theRoleList list of roles successfully accessed
147      *
148      * @see #getRoles
149      */

150     public void setRoles(RoleList JavaDoc theRoleList) {
151     if (theRoleList != null) {
152
153         roleList = new RoleList JavaDoc();
154
155         for (Iterator JavaDoc roleIter = theRoleList.iterator();
156          roleIter.hasNext();) {
157         Role JavaDoc currRole = (Role JavaDoc)(roleIter.next());
158         roleList.add((Role JavaDoc)(currRole.clone()));
159         }
160     } else {
161         roleList = null;
162     }
163     return;
164     }
165
166     /**
167      * Sets list of roles unsuccessfully accessed.
168      *
169      * @param theRoleUnresList list of roles unsuccessfully accessed
170      *
171      * @see #getRolesUnresolved
172      */

173     public void setRolesUnresolved(RoleUnresolvedList JavaDoc theRoleUnresList) {
174     if (theRoleUnresList != null) {
175
176         unresolvedRoleList = new RoleUnresolvedList JavaDoc();
177
178         for (Iterator JavaDoc roleUnresIter = theRoleUnresList.iterator();
179          roleUnresIter.hasNext();) {
180         RoleUnresolved JavaDoc currRoleUnres =
181             (RoleUnresolved JavaDoc)(roleUnresIter.next());
182         unresolvedRoleList.add((RoleUnresolved JavaDoc)(currRoleUnres.clone()));
183         }
184     } else {
185         unresolvedRoleList = null;
186     }
187     return;
188     }
189
190     /**
191      * Deserializes a {@link RoleResult} from an {@link ObjectInputStream}.
192      */

193     private void readObject(ObjectInputStream JavaDoc in)
194         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
195       if (compat)
196       {
197         // Read an object serialized in the old serial form
198
//
199
ObjectInputStream.GetField JavaDoc fields = in.readFields();
200     roleList = (RoleList JavaDoc) fields.get("myRoleList", null);
201     if (fields.defaulted("myRoleList"))
202         {
203           throw new NullPointerException JavaDoc("myRoleList");
204         }
205     unresolvedRoleList = (RoleUnresolvedList JavaDoc) fields.get("myRoleUnresList", null);
206     if (fields.defaulted("myRoleUnresList"))
207         {
208           throw new NullPointerException JavaDoc("myRoleUnresList");
209         }
210       }
211       else
212       {
213         // Read an object serialized in the new serial form
214
//
215
in.defaultReadObject();
216       }
217     }
218
219
220     /**
221      * Serializes a {@link RoleResult} to an {@link ObjectOutputStream}.
222      */

223     private void writeObject(ObjectOutputStream JavaDoc out)
224         throws IOException JavaDoc {
225       if (compat)
226       {
227         // Serializes this instance in the old serial form
228
//
229
ObjectOutputStream.PutField JavaDoc fields = out.putFields();
230     fields.put("myRoleList", roleList);
231     fields.put("myRoleUnresList", unresolvedRoleList);
232     out.writeFields();
233       }
234       else
235       {
236         // Serializes this instance in the new serial form
237
//
238
out.defaultWriteObject();
239       }
240     }
241 }
242
Popular Tags