25
26 package javax.management.relation;
27
28
29 import com.sun.jmx.mbeanserver.GetPropertyAction;
30
31 import java.io.IOException;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34 import java.io.ObjectStreamField;
35 import java.io.Serializable;
36 import java.security.AccessController;
37
38 import javax.management.MBeanServer;
39
40 import javax.management.NotCompliantMBeanException;
41
42 /**
43 * A RoleInfo object summarises a role in a relation type.
44 *
45 * <p>The <b>serialVersionUID</b> of this class is <code>2504952983494636987L</code>.
46 *
47 * @since 1.5
48 */
49 @SuppressWarnings("serial") // serialVersionUID not constant
50 public class RoleInfo implements Serializable {
51
52 // Serialization compatibility stuff:
53 // Two serial forms are supported in this class. The selected form depends
54 // on system property "jmx.serial.form":
55 // - "1.0" for JMX 1.0
56 // - any other value for JMX 1.1 and higher
57 //
58 // Serial version for old serial form
59 private static final long oldSerialVersionUID = 7227256952085334351L;
60 //
61 // Serial version for new serial form
62 private static final long newSerialVersionUID = 2504952983494636987L;
63 //
64 // Serializable fields in old serial form
65 private static final ObjectStreamField[] oldSerialPersistentFields =
72 new ObjectStreamField("myMaxDegree", int.class),
73 new ObjectStreamField("myRefMBeanClassName", String.class)
74 };
75 //
76 // Serializable fields in new serial form
77 private static final ObjectStreamField[] newSerialPersistentFields =
78 {
79 new ObjectStreamField("name", String.class),
80 new ObjectStreamField("isReadable", boolean.class),
81 new ObjectStreamField("isWritable", boolean.class),
82 new ObjectStreamField("description", String.class),
83 new ObjectStreamField("minDegree", int.class),
84 new ObjectStreamField("maxDegree", int.class),
85 new ObjectStreamField("referencedMBeanClassName", String.class)
86 };
87 //
88 // Actual serial version and serial form
89 private static final long serialVersionUID;
90 /**
91 * @serialField name String Role name
92 * @serialField isReadable boolean Read access mode: <code>true</code> if role is readable
93 * @serialField isWritable boolean Write access mode: <code>true</code> if role is writable
94 * @serialField description String Role description
95 * @serialField minDegree int Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
96 * @serialField maxDegree int Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
97 * @serialField referencedMBeanClassName String Name of class of MBean(s) expected to be referenced in corresponding role
98 */
99 private static final ObjectStreamField[] serialPersistentFields;
100 private static boolean compat = false;
101 static {
102 try {
103 GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
104 String form = AccessController.doPrivileged(act);
105 compat = (form != null && form.equals("1.0"));
106 } catch (Exception e) {
107 // OK : Too bad, no compat with 1.0
108 }
109 if (compat) {
110 serialPersistentFields = oldSerialPersistentFields;
111 serialVersionUID = oldSerialVersionUID;
112 } else {
113 serialPersistentFields = newSerialPersistentFields;
119
120 //
121 // Public constants
122 //
123
124 /**
125 * To specify an unlimited cardinality.
126 */
127 public static final int ROLE_CARDINALITY_INFINITY = -1;
128
129 //
130 // Private members
131 //
132
133 /**
134 * @serial Role name
135 */
136 private String name = null;
137
138 /**
139 * @serial Read access mode: <code>true</code> if role is readable
140 */
141 private boolean isReadable;
142
143 /**
144 * @serial Write access mode: <code>true</code> if role is writable
145 */
146 private boolean isWritable;
147
148 /**
149 * @serial Role description
150 */
151 private String description = null;
152
153 /**
154 * @serial Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
155 */
156 private int minDegree;
157
158 /**
159 * @serial Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
160 */
161 private int maxDegree;
162
163 /**
164 * @serial Name of class of MBean(s) expected to be referenced in corresponding role
166 private String referencedMBeanClassName = null;
167
168 //
169 // Constructors
170 //
171
172 /**
173 * Constructor.
174 *
175 * @param roleName name of the role.
176 * @param mbeanClassName name of the class of MBean(s) expected to
177 * be referenced in corresponding role. If an MBean <em>M</em> is in
178 * this role, then the MBean server must return true for
179 * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
180 * @param read flag to indicate if the corresponding role
181 * can be read
182 * @param write flag to indicate if the corresponding role
183 * can be set
184 * @param min minimum degree for role, i.e. minimum number of
185 * MBeans to provide in corresponding role
186 * Must be less than or equal to <tt>max</tt>.
187 * (ROLE_CARDINALITY_INFINITY for unlimited)
188 * @param max maximum degree for role, i.e. maximum number of
189 * MBeans to provide in corresponding role
190 * Must be greater than or equal to <tt>min</tt>
191 * (ROLE_CARDINALITY_INFINITY for unlimited)
192 * @param descr description of the role (can be null)
193 *
194 * @exception IllegalArgumentException if null parameter
195 * @exception InvalidRoleInfoException if the minimum degree is
196 * greater than the maximum degree.
197 * @exception ClassNotFoundException As of JMX 1.2, this exception
198 * can no longer be thrown. It is retained in the declaration of
199 * this class for compatibility with existing code.
200 * @exception NotCompliantMBeanException if the class mbeanClassName
201 * is not a MBean class.
202 */
203 public RoleInfo(String roleName,
204 String mbeanClassName,
205 boolean read,
206 boolean write,
207 int min,
208 int max,
209 String descr)
210 throws IllegalArgumentException,
299
300 try {
301 init(roleName,
302 mbeanClassName,
303 true,
304 true,
305 1,
306 1,
307 null);
308 } catch (InvalidRoleInfoException exc) {
309 // OK : Can never happen as the minimum
310 // degree equals the maximum degree.
311 }
312
313 return;
314 }
315
316 /**
317 * Copy constructor.
318 *
319 * @param roleInfo the <tt>RoleInfo</tt> instance to be copied.
320 *
321 * @exception IllegalArgumentException if null parameter
322 */
323 public RoleInfo(RoleInfo roleInfo)
324 throws IllegalArgumentException {
325
326 if (roleInfo == null) {
327 // Revisit [cebro] Localize message
328 String excMsg = "Invalid parameter.";
329 throw new IllegalArgumentException(excMsg);
330 }
331
332 try {
333 init(roleInfo.getName(),
334 roleInfo.getRefMBeanClassName(),
335 roleInfo.isReadable(),
336 roleInfo.isWritable(),
337 roleInfo.getMinDegree(),
338 roleInfo.getMaxDegree(),
339 roleInfo.getDescription());
396 /**
397 * Returns maximum degree for corresponding role reference.
398 *
399 * @return the maximum degree.
400 */
401 public int getMaxDegree() {
402 return maxDegree;
403 }
404
405 /**
406 * <p>Returns name of type of MBean expected to be referenced in
407 * corresponding role.</p>
408 *
409 * @return the name of the referenced type.
410 */
411 public String getRefMBeanClassName() {
412 return referencedMBeanClassName;
413 }
414
415 /**
416 * Returns true if the <tt>value</tt> parameter is greater than or equal to
417 * the expected minimum degree, false otherwise.
418 *
419 * @param value the value to be checked
420 *
421 * @return true if greater than or equal to minimum degree, false otherwise.
422 */
423 public boolean checkMinDegree(int value) {
424 if (value >= ROLE_CARDINALITY_INFINITY &&
425 (minDegree == ROLE_CARDINALITY_INFINITY
426 || value >= minDegree)) {
427 return true;
428 } else {
429 return false;
430 }
431 }
432
433 /**
434 * Returns true if the <tt>value</tt> parameter is lower than or equal to
435 * the expected maximum degree, false otherwise.
436 *
437 * @param value the value to be checked
438 *
439 * @return true if lower than or equal to maximum degree, false otherwise.
440 */
441 public boolean checkMaxDegree(int value) {
442 if (value >= ROLE_CARDINALITY_INFINITY &&
443 (maxDegree == ROLE_CARDINALITY_INFINITY ||
444 (value != ROLE_CARDINALITY_INFINITY &&
445 value <= maxDegree))) {
446 return true;
447 } else {
448 return false;
449 }
450 }
451
452 /**
453 * Returns a string describing the role info.
454 *
|
25
26 package javax.management.relation;
27
28
29 import com.sun.jmx.mbeanserver.GetPropertyAction;
30
31 import java.io.IOException;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34 import java.io.ObjectStreamField;
35 import java.io.Serializable;
36 import java.security.AccessController;
37
38 import javax.management.MBeanServer;
39
40 import javax.management.NotCompliantMBeanException;
41
42 /**
43 * A RoleInfo object summarises a role in a relation type.
44 *
45 * <p>The <b>serialVersionUID</b> of this class is {@code 2504952983494636987L}.
46 *
47 * @since 1.5
48 */
49 @SuppressWarnings("serial") // serialVersionUID not constant
50 public class RoleInfo implements Serializable {
51
52 // Serialization compatibility stuff:
53 // Two serial forms are supported in this class. The selected form depends
54 // on system property "jmx.serial.form":
55 // - "1.0" for JMX 1.0
56 // - any other value for JMX 1.1 and higher
57 //
58 // Serial version for old serial form
59 private static final long oldSerialVersionUID = 7227256952085334351L;
60 //
61 // Serial version for new serial form
62 private static final long newSerialVersionUID = 2504952983494636987L;
63 //
64 // Serializable fields in old serial form
65 private static final ObjectStreamField[] oldSerialPersistentFields =
72 new ObjectStreamField("myMaxDegree", int.class),
73 new ObjectStreamField("myRefMBeanClassName", String.class)
74 };
75 //
76 // Serializable fields in new serial form
77 private static final ObjectStreamField[] newSerialPersistentFields =
78 {
79 new ObjectStreamField("name", String.class),
80 new ObjectStreamField("isReadable", boolean.class),
81 new ObjectStreamField("isWritable", boolean.class),
82 new ObjectStreamField("description", String.class),
83 new ObjectStreamField("minDegree", int.class),
84 new ObjectStreamField("maxDegree", int.class),
85 new ObjectStreamField("referencedMBeanClassName", String.class)
86 };
87 //
88 // Actual serial version and serial form
89 private static final long serialVersionUID;
90 /**
91 * @serialField name String Role name
92 * @serialField isReadable boolean Read access mode: {@code true} if role is readable
93 * @serialField isWritable boolean Write access mode: {@code true} if role is writable
94 * @serialField description String Role description
95 * @serialField minDegree int Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
96 * @serialField maxDegree int Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
97 * @serialField referencedMBeanClassName String Name of class of MBean(s) expected to be referenced in corresponding role
98 */
99 private static final ObjectStreamField[] serialPersistentFields;
100 private static boolean compat = false;
101 static {
102 try {
103 GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
104 String form = AccessController.doPrivileged(act);
105 compat = (form != null && form.equals("1.0"));
106 } catch (Exception e) {
107 // OK : Too bad, no compat with 1.0
108 }
109 if (compat) {
110 serialPersistentFields = oldSerialPersistentFields;
111 serialVersionUID = oldSerialVersionUID;
112 } else {
113 serialPersistentFields = newSerialPersistentFields;
119
120 //
121 // Public constants
122 //
123
124 /**
125 * To specify an unlimited cardinality.
126 */
127 public static final int ROLE_CARDINALITY_INFINITY = -1;
128
129 //
130 // Private members
131 //
132
133 /**
134 * @serial Role name
135 */
136 private String name = null;
137
138 /**
139 * @serial Read access mode: {@code true} if role is readable
140 */
141 private boolean isReadable;
142
143 /**
144 * @serial Write access mode: {@code true} if role is writable
145 */
146 private boolean isWritable;
147
148 /**
149 * @serial Role description
150 */
151 private String description = null;
152
153 /**
154 * @serial Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
155 */
156 private int minDegree;
157
158 /**
159 * @serial Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
160 */
161 private int maxDegree;
162
163 /**
164 * @serial Name of class of MBean(s) expected to be referenced in corresponding role
166 private String referencedMBeanClassName = null;
167
168 //
169 // Constructors
170 //
171
172 /**
173 * Constructor.
174 *
175 * @param roleName name of the role.
176 * @param mbeanClassName name of the class of MBean(s) expected to
177 * be referenced in corresponding role. If an MBean <em>M</em> is in
178 * this role, then the MBean server must return true for
179 * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
180 * @param read flag to indicate if the corresponding role
181 * can be read
182 * @param write flag to indicate if the corresponding role
183 * can be set
184 * @param min minimum degree for role, i.e. minimum number of
185 * MBeans to provide in corresponding role
186 * Must be less than or equal to {@code max}.
187 * (ROLE_CARDINALITY_INFINITY for unlimited)
188 * @param max maximum degree for role, i.e. maximum number of
189 * MBeans to provide in corresponding role
190 * Must be greater than or equal to {@code min}
191 * (ROLE_CARDINALITY_INFINITY for unlimited)
192 * @param descr description of the role (can be null)
193 *
194 * @exception IllegalArgumentException if null parameter
195 * @exception InvalidRoleInfoException if the minimum degree is
196 * greater than the maximum degree.
197 * @exception ClassNotFoundException As of JMX 1.2, this exception
198 * can no longer be thrown. It is retained in the declaration of
199 * this class for compatibility with existing code.
200 * @exception NotCompliantMBeanException if the class mbeanClassName
201 * is not a MBean class.
202 */
203 public RoleInfo(String roleName,
204 String mbeanClassName,
205 boolean read,
206 boolean write,
207 int min,
208 int max,
209 String descr)
210 throws IllegalArgumentException,
299
300 try {
301 init(roleName,
302 mbeanClassName,
303 true,
304 true,
305 1,
306 1,
307 null);
308 } catch (InvalidRoleInfoException exc) {
309 // OK : Can never happen as the minimum
310 // degree equals the maximum degree.
311 }
312
313 return;
314 }
315
316 /**
317 * Copy constructor.
318 *
319 * @param roleInfo the {@code RoleInfo} instance to be copied.
320 *
321 * @exception IllegalArgumentException if null parameter
322 */
323 public RoleInfo(RoleInfo roleInfo)
324 throws IllegalArgumentException {
325
326 if (roleInfo == null) {
327 // Revisit [cebro] Localize message
328 String excMsg = "Invalid parameter.";
329 throw new IllegalArgumentException(excMsg);
330 }
331
332 try {
333 init(roleInfo.getName(),
334 roleInfo.getRefMBeanClassName(),
335 roleInfo.isReadable(),
336 roleInfo.isWritable(),
337 roleInfo.getMinDegree(),
338 roleInfo.getMaxDegree(),
339 roleInfo.getDescription());
396 /**
397 * Returns maximum degree for corresponding role reference.
398 *
399 * @return the maximum degree.
400 */
401 public int getMaxDegree() {
402 return maxDegree;
403 }
404
405 /**
406 * <p>Returns name of type of MBean expected to be referenced in
407 * corresponding role.</p>
408 *
409 * @return the name of the referenced type.
410 */
411 public String getRefMBeanClassName() {
412 return referencedMBeanClassName;
413 }
414
415 /**
416 * Returns true if the {@code value} parameter is greater than or equal to
417 * the expected minimum degree, false otherwise.
418 *
419 * @param value the value to be checked
420 *
421 * @return true if greater than or equal to minimum degree, false otherwise.
422 */
423 public boolean checkMinDegree(int value) {
424 if (value >= ROLE_CARDINALITY_INFINITY &&
425 (minDegree == ROLE_CARDINALITY_INFINITY
426 || value >= minDegree)) {
427 return true;
428 } else {
429 return false;
430 }
431 }
432
433 /**
434 * Returns true if the {@code value} parameter is lower than or equal to
435 * the expected maximum degree, false otherwise.
436 *
437 * @param value the value to be checked
438 *
439 * @return true if lower than or equal to maximum degree, false otherwise.
440 */
441 public boolean checkMaxDegree(int value) {
442 if (value >= ROLE_CARDINALITY_INFINITY &&
443 (maxDegree == ROLE_CARDINALITY_INFINITY ||
444 (value != ROLE_CARDINALITY_INFINITY &&
445 value <= maxDegree))) {
446 return true;
447 } else {
448 return false;
449 }
450 }
451
452 /**
453 * Returns a string describing the role info.
454 *
|