author | prr |
Mon, 04 Nov 2019 10:01:55 -0800 | |
changeset 59176 | f5adbf111424 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
43235 | 2 |
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
/* |
|
26 |
* @author IBM Corp. |
|
27 |
* |
|
28 |
* Copyright IBM Corp. 1999-2000. All rights reserved. |
|
29 |
*/ |
|
30 |
||
31 |
package javax.management.modelmbean; |
|
32 |
||
33 |
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER; |
|
34 |
import com.sun.jmx.mbeanserver.GetPropertyAction; |
|
35 |
||
36 |
import java.io.IOException; |
|
37 |
import java.io.ObjectInputStream; |
|
38 |
import java.io.ObjectOutputStream; |
|
39 |
import java.io.ObjectStreamField; |
|
40 |
import java.lang.reflect.Constructor; |
|
41 |
import java.security.AccessController; |
|
43235 | 42 |
import java.lang.System.Logger.Level; |
2 | 43 |
|
44 |
import javax.management.Descriptor; |
|
45 |
import javax.management.DescriptorAccess; |
|
46 |
import javax.management.DescriptorKey; |
|
47 |
import javax.management.MBeanConstructorInfo; |
|
48 |
import javax.management.MBeanParameterInfo; |
|
49 |
import javax.management.RuntimeOperationsException; |
|
50 |
||
51 |
/** |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
52 |
* <p>The ModelMBeanConstructorInfo object describes a constructor of the ModelMBean. |
2 | 53 |
* It is a subclass of MBeanConstructorInfo with the addition of an associated Descriptor |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
54 |
* and an implementation of the DescriptorAccess interface.</p> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
55 |
* |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
56 |
* <P id="descriptor"> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
57 |
* The fields in the descriptor are defined, but not limited to, the following. |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
58 |
* Note that when the Type in this table is Number, a String that is the decimal |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
59 |
* representation of a Long can also be used.</P> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
60 |
* |
45130
469dceb426cc
8179631: Fix Html5 errors in java.management, jdk.management, jdk.jdi and jdk.attach
ksrini
parents:
44858
diff
changeset
|
61 |
* <table class="striped"> |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
43235
diff
changeset
|
62 |
* <caption style="display:none">ModelMBeanConstructorInfo Fields</caption> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
63 |
* <thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
64 |
* <tr><th scope="col">Name</th><th scope="col">Type</th><th scope="col">Meaning</th></tr> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
65 |
* </thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
66 |
* <tbody style="text-align:left"> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
67 |
* <tr><th scope="row">name</th><td>String</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
68 |
* <td>Constructor name.</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
69 |
* <tr><th scope="row">descriptorType</th><td>String</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
70 |
* <td>Must be "operation".</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
71 |
* <tr><th scope="row">role</th><td>String</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
72 |
* <td>Must be "constructor".</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
73 |
* <tr><th scope="row">displayName</th><td>String</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
74 |
* <td>Human readable name of constructor.</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
75 |
* <tr><th scope="row">visibility</th><td>Number</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
76 |
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
77 |
* <tr><th scope="row">presentationString</th><td>String</td> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
78 |
* <td>XML formatted string to describe how to present operation</td></tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
79 |
* </tbody> |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
80 |
* </table> |
2 | 81 |
* |
82 |
* <p>The {@code persistPolicy} and {@code currencyTimeLimit} fields |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
83 |
* are meaningless for constructors, but are not considered invalid.</p> |
2 | 84 |
* |
85 |
* <p>The default descriptor will have the {@code name}, {@code |
|
4156 | 86 |
* descriptorType}, {@code displayName} and {@code role} fields. |
2 | 87 |
* |
88 |
* <p>The <b>serialVersionUID</b> of this class is <code>3862947819818064362L</code>. |
|
89 |
* |
|
90 |
* @since 1.5 |
|
91 |
*/ |
|
92 |
||
93 |
@SuppressWarnings("serial") // serialVersionUID is not constant |
|
94 |
public class ModelMBeanConstructorInfo |
|
95 |
extends MBeanConstructorInfo |
|
96 |
implements DescriptorAccess { |
|
97 |
||
98 |
// Serialization compatibility stuff: |
|
99 |
// Two serial forms are supported in this class. The selected form depends |
|
100 |
// on system property "jmx.serial.form": |
|
101 |
// - "1.0" for JMX 1.0 |
|
102 |
// - any other value for JMX 1.1 and higher |
|
103 |
// |
|
104 |
// Serial version for old serial form |
|
105 |
private static final long oldSerialVersionUID = -4440125391095574518L; |
|
106 |
// |
|
107 |
// Serial version for new serial form |
|
108 |
private static final long newSerialVersionUID = 3862947819818064362L; |
|
109 |
// |
|
110 |
// Serializable fields in old serial form |
|
111 |
private static final ObjectStreamField[] oldSerialPersistentFields = |
|
112 |
{ |
|
113 |
new ObjectStreamField("consDescriptor", Descriptor.class), |
|
114 |
new ObjectStreamField("currClass", String.class) |
|
115 |
}; |
|
116 |
// |
|
117 |
// Serializable fields in new serial form |
|
118 |
private static final ObjectStreamField[] newSerialPersistentFields = |
|
119 |
{ |
|
120 |
new ObjectStreamField("consDescriptor", Descriptor.class) |
|
121 |
}; |
|
122 |
// |
|
123 |
// Actual serial version and serial form |
|
124 |
private static final long serialVersionUID; |
|
125 |
/** |
|
126 |
* @serialField consDescriptor Descriptor The {@link Descriptor} containing the metadata for this instance |
|
127 |
*/ |
|
128 |
private static final ObjectStreamField[] serialPersistentFields; |
|
129 |
private static boolean compat = false; |
|
130 |
static { |
|
131 |
try { |
|
132 |
GetPropertyAction act = new GetPropertyAction("jmx.serial.form"); |
|
133 |
String form = AccessController.doPrivileged(act); |
|
134 |
compat = (form != null && form.equals("1.0")); |
|
135 |
} catch (Exception e) { |
|
136 |
// OK: No compat with 1.0 |
|
137 |
} |
|
138 |
if (compat) { |
|
139 |
serialPersistentFields = oldSerialPersistentFields; |
|
140 |
serialVersionUID = oldSerialVersionUID; |
|
141 |
} else { |
|
142 |
serialPersistentFields = newSerialPersistentFields; |
|
143 |
serialVersionUID = newSerialVersionUID; |
|
144 |
} |
|
145 |
} |
|
146 |
// |
|
147 |
// END Serialization compatibility stuff |
|
148 |
||
149 |
/** |
|
150 |
* @serial The {@link Descriptor} containing the metadata for this instance |
|
151 |
*/ |
|
152 |
private Descriptor consDescriptor = validDescriptor(null); |
|
153 |
||
154 |
private final static String currClass = "ModelMBeanConstructorInfo"; |
|
155 |
||
156 |
||
157 |
/** |
|
158 |
* Constructs a ModelMBeanConstructorInfo object with a default |
|
159 |
* descriptor. The {@link Descriptor} of the constructed |
|
160 |
* object will include fields contributed by any annotations on |
|
161 |
* the {@code Constructor} object that contain the {@link |
|
162 |
* DescriptorKey} meta-annotation. |
|
163 |
* |
|
164 |
* @param description A human readable description of the constructor. |
|
165 |
* @param constructorMethod The java.lang.reflect.Constructor object |
|
166 |
* describing the MBean constructor. |
|
167 |
*/ |
|
168 |
public ModelMBeanConstructorInfo(String description, |
|
1510 | 169 |
Constructor<?> constructorMethod) |
2 | 170 |
{ |
171 |
super(description, constructorMethod); |
|
43235 | 172 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
173 |
MODELMBEAN_LOGGER.log(Level.TRACE, |
|
174 |
"ModelMBeanConstructorInfo(String,Constructor) " + |
|
2 | 175 |
"Entry"); |
176 |
} |
|
177 |
consDescriptor = validDescriptor(null); |
|
178 |
||
179 |
// put getter and setter methods in constructors list |
|
180 |
// create default descriptor |
|
181 |
||
182 |
} |
|
183 |
||
184 |
/** |
|
185 |
* Constructs a ModelMBeanConstructorInfo object. The {@link |
|
186 |
* Descriptor} of the constructed object will include fields |
|
187 |
* contributed by any annotations on the {@code Constructor} |
|
188 |
* object that contain the {@link DescriptorKey} |
|
189 |
* meta-annotation. |
|
190 |
* |
|
191 |
* @param description A human readable description of the constructor. |
|
192 |
* @param constructorMethod The java.lang.reflect.Constructor object |
|
193 |
* describing the ModelMBean constructor. |
|
194 |
* @param descriptor An instance of Descriptor containing the |
|
195 |
* appropriate metadata for this instance of the |
|
196 |
* ModelMBeanConstructorInfo. If it is null, then a default |
|
197 |
* descriptor will be created. If the descriptor does not |
|
4156 | 198 |
* contain the field "displayName" this field is added in the |
199 |
* descriptor with its default value. |
|
2 | 200 |
* |
201 |
* @exception RuntimeOperationsException Wraps an |
|
202 |
* IllegalArgumentException. The descriptor is invalid, or |
|
4156 | 203 |
* descriptor field "name" is not equal to name |
204 |
* parameter, or descriptor field "descriptorType" is |
|
205 |
* not equal to "operation" or descriptor field "role" is |
|
2 | 206 |
* present but not equal to "constructor". |
207 |
*/ |
|
208 |
||
209 |
public ModelMBeanConstructorInfo(String description, |
|
1510 | 210 |
Constructor<?> constructorMethod, |
2 | 211 |
Descriptor descriptor) |
212 |
{ |
|
213 |
||
214 |
super(description, constructorMethod); |
|
215 |
// put getter and setter methods in constructors list |
|
43235 | 216 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
217 |
MODELMBEAN_LOGGER.log(Level.TRACE, |
|
2 | 218 |
"ModelMBeanConstructorInfo(" + |
43235 | 219 |
"String,Constructor,Descriptor) Entry"); |
2 | 220 |
} |
221 |
consDescriptor = validDescriptor(descriptor); |
|
222 |
} |
|
223 |
/** |
|
224 |
* Constructs a ModelMBeanConstructorInfo object with a default descriptor. |
|
225 |
* |
|
226 |
* @param name The name of the constructor. |
|
227 |
* @param description A human readable description of the constructor. |
|
228 |
* @param signature MBeanParameterInfo object array describing the parameters(arguments) of the constructor. |
|
229 |
*/ |
|
230 |
||
231 |
public ModelMBeanConstructorInfo(String name, |
|
232 |
String description, |
|
233 |
MBeanParameterInfo[] signature) |
|
234 |
{ |
|
235 |
||
236 |
super(name, description, signature); |
|
237 |
// create default descriptor |
|
43235 | 238 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
239 |
MODELMBEAN_LOGGER.log(Level.TRACE, |
|
2 | 240 |
"ModelMBeanConstructorInfo(" + |
43235 | 241 |
"String,String,MBeanParameterInfo[]) Entry"); |
2 | 242 |
} |
243 |
consDescriptor = validDescriptor(null); |
|
244 |
} |
|
245 |
/** |
|
246 |
* Constructs a ModelMBeanConstructorInfo object. |
|
247 |
* |
|
248 |
* @param name The name of the constructor. |
|
249 |
* @param description A human readable description of the constructor. |
|
250 |
* @param signature MBeanParameterInfo objects describing the parameters(arguments) of the constructor. |
|
251 |
* @param descriptor An instance of Descriptor containing the appropriate metadata |
|
252 |
* for this instance of the MBeanConstructorInfo. If it is null then a default descriptor will be created. |
|
4156 | 253 |
* If the descriptor does not contain the field "displayName" this field |
254 |
* is added in the descriptor with its default value. |
|
2 | 255 |
* |
256 |
* @exception RuntimeOperationsException Wraps an |
|
257 |
* IllegalArgumentException. The descriptor is invalid, or |
|
4156 | 258 |
* descriptor field "name" is not equal to name |
259 |
* parameter, or descriptor field "descriptorType" is |
|
260 |
* not equal to "operation" or descriptor field "role" is |
|
2 | 261 |
* present but not equal to "constructor". |
262 |
*/ |
|
263 |
||
264 |
public ModelMBeanConstructorInfo(String name, |
|
265 |
String description, |
|
266 |
MBeanParameterInfo[] signature, |
|
267 |
Descriptor descriptor) |
|
268 |
{ |
|
269 |
super(name, description, signature); |
|
43235 | 270 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
271 |
MODELMBEAN_LOGGER.log(Level.TRACE, |
|
2 | 272 |
"ModelMBeanConstructorInfo(" + |
43235 | 273 |
"String,String,MBeanParameterInfo[],Descriptor) " + |
2 | 274 |
"Entry"); |
275 |
} |
|
276 |
consDescriptor = validDescriptor(descriptor); |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Constructs a new ModelMBeanConstructorInfo object from this ModelMBeanConstructor Object. |
|
281 |
* |
|
282 |
* @param old the ModelMBeanConstructorInfo to be duplicated |
|
283 |
* |
|
284 |
*/ |
|
285 |
ModelMBeanConstructorInfo(ModelMBeanConstructorInfo old) |
|
286 |
{ |
|
287 |
super(old.getName(), old.getDescription(), old.getSignature()); |
|
43235 | 288 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
289 |
MODELMBEAN_LOGGER.log(Level.TRACE, |
|
2 | 290 |
"ModelMBeanConstructorInfo(" + |
43235 | 291 |
"ModelMBeanConstructorInfo) Entry"); |
2 | 292 |
} |
293 |
consDescriptor = validDescriptor(consDescriptor); |
|
294 |
} |
|
295 |
||
296 |
/** |
|
297 |
* Creates and returns a new ModelMBeanConstructorInfo which is a duplicate of this ModelMBeanConstructorInfo. |
|
298 |
* |
|
299 |
*/ |
|
4156 | 300 |
@Override |
2 | 301 |
public Object clone () |
302 |
{ |
|
43235 | 303 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
304 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); |
|
2 | 305 |
} |
306 |
return(new ModelMBeanConstructorInfo(this)) ; |
|
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* Returns a copy of the associated Descriptor. |
|
311 |
* |
|
312 |
* @return Descriptor associated with the |
|
313 |
* ModelMBeanConstructorInfo object. |
|
314 |
* |
|
315 |
* @see #setDescriptor |
|
316 |
*/ |
|
317 |
||
318 |
||
4156 | 319 |
@Override |
2 | 320 |
public Descriptor getDescriptor() |
321 |
{ |
|
43235 | 322 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
323 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); |
|
2 | 324 |
} |
325 |
if (consDescriptor == null){ |
|
326 |
consDescriptor = validDescriptor(null); |
|
327 |
} |
|
328 |
return((Descriptor)consDescriptor.clone()); |
|
329 |
} |
|
330 |
/** |
|
331 |
* Sets associated Descriptor (full replace) of |
|
332 |
* ModelMBeanConstructorInfo. If the new Descriptor is null, |
|
333 |
* then the associated Descriptor reverts to a default |
|
334 |
* descriptor. The Descriptor is validated before it is |
|
335 |
* assigned. If the new Descriptor is invalid, then a |
|
336 |
* RuntimeOperationsException wrapping an |
|
337 |
* IllegalArgumentException is thrown. |
|
338 |
* |
|
339 |
* @param inDescriptor replaces the Descriptor associated with |
|
340 |
* the ModelMBeanConstructor. If the descriptor does not |
|
341 |
* contain all the following fields, the missing ones are added with |
|
342 |
* their default values: displayName, name, role, descriptorType. |
|
343 |
* |
|
344 |
* @exception RuntimeOperationsException Wraps an |
|
345 |
* IllegalArgumentException. The descriptor is invalid, or |
|
346 |
* descriptor field "name" is present but not equal to name |
|
347 |
* parameter, or descriptor field "descriptorType" is present |
|
348 |
* but not equal to "operation" or descriptor field "role" is |
|
349 |
* present but not equal to "constructor". |
|
350 |
* |
|
351 |
* @see #getDescriptor |
|
352 |
*/ |
|
353 |
public void setDescriptor(Descriptor inDescriptor) |
|
354 |
{ |
|
43235 | 355 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
356 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); |
|
2 | 357 |
} |
358 |
consDescriptor = validDescriptor(inDescriptor); |
|
359 |
} |
|
360 |
||
361 |
/** |
|
362 |
* Returns a string containing the entire contents of the ModelMBeanConstructorInfo in human readable form. |
|
363 |
*/ |
|
4156 | 364 |
@Override |
2 | 365 |
public String toString() |
366 |
{ |
|
43235 | 367 |
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { |
368 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); |
|
2 | 369 |
} |
370 |
String retStr = |
|
371 |
"ModelMBeanConstructorInfo: " + this.getName() + |
|
372 |
" ; Description: " + this.getDescription() + |
|
373 |
" ; Descriptor: " + this.getDescriptor() + |
|
374 |
" ; Signature: "; |
|
375 |
MBeanParameterInfo[] pTypes = this.getSignature(); |
|
376 |
for (int i=0; i < pTypes.length; i++) |
|
377 |
{ |
|
378 |
retStr = retStr.concat((pTypes[i]).getType() + ", "); |
|
379 |
} |
|
380 |
return retStr; |
|
381 |
} |
|
382 |
||
383 |
||
384 |
/** |
|
385 |
* Clones the passed in Descriptor, sets default values, and checks for validity. |
|
386 |
* If the Descriptor is invalid (for instance by having the wrong "name"), |
|
387 |
* this indicates programming error and a RuntimeOperationsException will be thrown. |
|
388 |
* |
|
389 |
* The following fields will be defaulted if they are not already set: |
|
390 |
* displayName=this.getName(), name=this.getName(), descriptorType="operation", |
|
391 |
* role="constructor" |
|
392 |
* |
|
393 |
* |
|
394 |
* @param in Descriptor to be checked, or null which is equivalent to |
|
395 |
* an empty Descriptor. |
|
396 |
* @exception RuntimeOperationsException if Descriptor is invalid |
|
397 |
*/ |
|
398 |
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException { |
|
4156 | 399 |
Descriptor clone; |
400 |
boolean defaulted = (in == null); |
|
401 |
if (defaulted) { |
|
2 | 402 |
clone = new DescriptorSupport(); |
43235 | 403 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Null Descriptor, creating new."); |
2 | 404 |
} else { |
405 |
clone = (Descriptor) in.clone(); |
|
406 |
} |
|
407 |
||
408 |
//Setting defaults. |
|
4156 | 409 |
if (defaulted && clone.getFieldValue("name")==null) { |
2 | 410 |
clone.setField("name", this.getName()); |
43235 | 411 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor name to " + this.getName()); |
2 | 412 |
} |
4156 | 413 |
if (defaulted && clone.getFieldValue("descriptorType")==null) { |
2 | 414 |
clone.setField("descriptorType", "operation"); |
43235 | 415 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting descriptorType to \"operation\""); |
2 | 416 |
} |
417 |
if (clone.getFieldValue("displayName") == null) { |
|
418 |
clone.setField("displayName",this.getName()); |
|
43235 | 419 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor displayName to " + this.getName()); |
2 | 420 |
} |
421 |
if (clone.getFieldValue("role") == null) { |
|
422 |
clone.setField("role","constructor"); |
|
43235 | 423 |
MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor role field to \"constructor\""); |
2 | 424 |
} |
425 |
||
426 |
//Checking validity |
|
427 |
if (!clone.isValid()) { |
|
428 |
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
|
429 |
"The isValid() method of the Descriptor object itself returned false,"+ |
|
430 |
"one or more required fields are invalid. Descriptor:" + clone.toString()); |
|
431 |
} |
|
4156 | 432 |
if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) { |
2 | 433 |
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
434 |
"The Descriptor \"name\" field does not match the object described. " + |
|
435 |
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name")); |
|
436 |
} |
|
4156 | 437 |
if (!"operation".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) { |
2 | 438 |
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
439 |
"The Descriptor \"descriptorType\" field does not match the object described. " + |
|
440 |
" Expected: \"operation\" ," + " was: " + clone.getFieldValue("descriptorType")); |
|
441 |
} |
|
442 |
if (! ((String)clone.getFieldValue("role")).equalsIgnoreCase("constructor")) { |
|
443 |
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
|
444 |
"The Descriptor \"role\" field does not match the object described. " + |
|
445 |
" Expected: \"constructor\" ," + " was: " + clone.getFieldValue("role")); |
|
446 |
} |
|
447 |
||
448 |
return clone; |
|
449 |
} |
|
450 |
||
451 |
/** |
|
452 |
* Deserializes a {@link ModelMBeanConstructorInfo} from an {@link ObjectInputStream}. |
|
453 |
*/ |
|
454 |
private void readObject(ObjectInputStream in) |
|
455 |
throws IOException, ClassNotFoundException { |
|
456 |
// New serial form ignores extra field "currClass" |
|
457 |
in.defaultReadObject(); |
|
458 |
} |
|
459 |
||
460 |
||
461 |
/** |
|
462 |
* Serializes a {@link ModelMBeanConstructorInfo} to an {@link ObjectOutputStream}. |
|
463 |
*/ |
|
464 |
private void writeObject(ObjectOutputStream out) |
|
465 |
throws IOException { |
|
466 |
if (compat) |
|
467 |
{ |
|
468 |
// Serializes this instance in the old serial form |
|
469 |
// |
|
470 |
ObjectOutputStream.PutField fields = out.putFields(); |
|
471 |
fields.put("consDescriptor", consDescriptor); |
|
472 |
fields.put("currClass", currClass); |
|
473 |
out.writeFields(); |
|
474 |
} |
|
475 |
else |
|
476 |
{ |
|
477 |
// Serializes this instance in the new serial form |
|
478 |
// |
|
479 |
out.defaultWriteObject(); |
|
480 |
} |
|
481 |
} |
|
482 |
||
483 |
} |