API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.management.modelmbean. ModelMBeanOperationInfo View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

/*
 * @(#)file      ModelMBeanOperationInfo.java
 * @(#)author    IBM Corp.
 * @(#)version   1.41
 * @(#)lastedit      06/01/17
 */
/*
 * Copyright IBM Corp. 1999-2000.  All rights reserved.
 * 
 * The program is provided "as is" without any warranty express or implied,
 * including the warranty of non-infringement and the implied warranties of
 * merchantibility and fitness for a particular purpose. IBM will not be
 * liable for any damages suffered by you or any third party claim against 
 * you regarding the Program.
 *
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * This software is the proprietary information of Sun Microsystems, Inc.
 * Use is subject to license terms.
 * 
 * Copyright 2006 Sun Microsystems, Inc.  Tous droits reserves.
 * Ce logiciel est propriete de Sun Microsystems, Inc.
 * Distribue par des licences qui en restreignent l'utilisation. 
 *
 */



package javax.management.modelmbean;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.management.Descriptor;       
import javax.management.DescriptorAccess; 
import javax.management.*;
import java.lang.reflect.*;

import com.sun.jmx.mbeanserver.GetPropertyAction;
import com.sun.jmx.trace.Trace;         


/**
 * The ModelMBeanOperationInfo object describes a management operation of the ModelMBean.
 * It is a subclass of MBeanOperationInfo with the addition of an associated Descriptor
 * and an implementation of the DescriptorAccess interface.
 * <P>
 * <PRE>
 * The fields in the descriptor are defined, but not limited to, the following: 
 * name           : operation name 
 * descriptorType : must be "operation"    
 * class          : class where method is defined (fully qualified) 
 * role           : must be "operation", "getter", or "setter
 * targetObject   : object on which to execute this method          
 * targetType     : type of object reference for targetObject. Can be: ObjectReference | Handle | EJBHandle | IOR | RMIReference.
 * value          : cached value for operation                   
 * currencyTimeLimit : how long cached value is valid               
 * lastUpdatedTimeStamp : when cached value was set                
 * visibility            : 1-4 where 1: always visible 4: rarely visible 
 * presentationString :  xml formatted string to describe how to present operation 
 * </PRE>
 * The default descriptor will have name, descriptorType, displayName and role fields set.
 *
 * <p><b>Note:</b> because of inconsistencies in previous versions of
 * this specification, it is recommended not to use negative or zero
 * values for <code>currencyTimeLimit</code>.  To indicate that a
 * cached value is never valid, omit the
 * <code>currencyTimeLimit</code> field.  To indicate that it is
 * always valid, use a very large number for this field.</p>
 *
 * <p>The <b>serialVersionUID</b> of this class is <code>6532732096650090465L</code>.
 * 
 * @since 1.5
 */

public class ModelMBeanOperationInfo extends MBeanOperationInfo 
	 implements DescriptorAccess
{

    // Serialization compatibility stuff:
    // Two serial forms are supported in this class. The selected form depends
    // on system property "jmx.serial.form":
    //  - "1.0" for JMX 1.0
    //  - any other value for JMX 1.1 and higher
    //
    // Serial version for old serial form 
    private static final long oldSerialVersionUID = 9087646304346171239L;
    //
    // Serial version for new serial form 
    private static final long newSerialVersionUID = 6532732096650090465L;
    //
    // Serializable fields in old serial form
    private static final ObjectStreamField[] oldSerialPersistentFields = 
    {
      new ObjectStreamField("operationDescriptor", Descriptor.class),
      new ObjectStreamField("currClass", String.class)
    };
    //
    // Serializable fields in new serial form
    private static final ObjectStreamField[] newSerialPersistentFields = 
    {
      new ObjectStreamField("operationDescriptor", Descriptor.class)
    };
    //
    // Actual serial version and serial form
    private static final long serialVersionUID;
    /**
     * @serialField operationDescriptor Descriptor The descriptor containing the appropriate metadata for this instance
     */
    private static final ObjectStreamField[] serialPersistentFields;
    private static boolean compat = false;  
    static {
	try {
	    GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
	    String form = AccessController.doPrivileged(act);
	    compat = (form != null && form.equals("1.0"));
	} catch (Exception e) {
	    // OK: No compat with 1.0
	}
	if (compat) {
	    serialPersistentFields = oldSerialPersistentFields;
	    serialVersionUID = oldSerialVersionUID;
	} else {
	    serialPersistentFields = newSerialPersistentFields;
	    serialVersionUID = newSerialVersionUID;
	}
    }
    //
    // END Serialization compatibility stuff

        /**
         * @serial The descriptor containing the appropriate metadata for this instance
         */
	private Descriptor operationDescriptor = createDefaultDescriptor();

	private static final String currClass = "ModelMBeanOperationInfo";

	/**
	 * Constructs a ModelMBeanOperationInfo object with a default
	 * descriptor. The {@link Descriptor} of the constructed
	 * object will include fields contributed by any annotations
	 * on the {@code Method} object that contain the {@link
	 * DescriptorKey} meta-annotation.
	 *
	 * @param operationMethod The java.lang.reflect.Method object
	 * describing the MBean operation.
	 * @param description A human readable description of the operation.
	 */

	public ModelMBeanOperationInfo(String description,
				       Method operationMethod)
	{
		super(description, operationMethod);
		// create default descriptor
		if (tracing())
		{
			trace("ModelMBeanOperationInfo(String,Method)","Executed");
		}
		operationDescriptor = createDefaultDescriptor();


	}

	/**
	 * Constructs a ModelMBeanOperationInfo object. The {@link
	 * Descriptor} of the constructed object will include fields
	 * contributed by any annotations on the {@code Method} object
	 * that contain the {@link DescriptorKey} meta-annotation.
         *
	 * @param operationMethod The java.lang.reflect.Method object
	 * describing the MBean operation.
	 * @param description A human readable description of the
	 * operation.
	 * @param descriptor An instance of Descriptor containing the
	 * appropriate metadata for this instance of the
	 * ModelMBeanOperationInfo.  If it is null a default
	 * descriptor will be created. If the descriptor does not
	 * contain the fields "displayName" or "role" these fields are
	 * added in the descriptor with their default values.
	 *
	 * @exception RuntimeOperationsException Wraps an
	 * IllegalArgumentException. The descriptor is invalid; or
	 * descriptor field "name" is not equal to operation name; or
	 * descriptor field "DescriptorType" is not equal to
	 * "operation"; or descriptor optional field "role" is not equal to
	 * "operation", "getter", or "setter".
	 *
	 */

	public ModelMBeanOperationInfo(String description,
				       Method operationMethod,
				       Descriptor descriptor)
	{

		super(description, operationMethod);
		if (tracing())
		{
			trace("ModelMBeanOperationInfo(String,Method,Descriptor)","Executed");
		}
		if (descriptor == null)
		{
			if (tracing())
			{
				trace("ModelMBeanOperationInfo()","Received null for new descriptor value, setting descriptor to default values");
			}
			operationDescriptor = createDefaultDescriptor();
		} else
		{
			if (isValid(descriptor))
			{
				operationDescriptor = (Descriptor) descriptor.clone();
			} else
			{
				operationDescriptor = createDefaultDescriptor();
				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor passed in parameter"), ("Exception occurred in ModelMBeanOperationInfo constructor"));
			}
		}
	}

	/**
	* Constructs a ModelMBeanOperationInfo object with a default descriptor.
	*
	* @param name The name of the method.
	* @param description A human readable description of the operation.
	* @param signature MBeanParameterInfo objects describing the parameters(arguments) of the method.
	* @param type The type of the method's return value.
	* @param impact The impact of the method, one of INFO, ACTION, ACTION_INFO, UNKNOWN.
	*/

	public ModelMBeanOperationInfo(String name,
				       String description,
				       MBeanParameterInfo[] signature, 
				       String type,
				       int impact)
	{

		super(name, description, signature, type, impact);
		// create default descriptor
		if (tracing())
		{
			trace("ModelMBeanOperationInfo(String,String,MBeanParameterInfo[],String,int)","Executed");
		}
		operationDescriptor = createDefaultDescriptor();

	}

	/**
	* Constructs a ModelMBeanOperationInfo object.
	*
	* @param name The name of the method.
	* @param description A human readable description of the operation.
	* @param signature MBeanParameterInfo objects describing the parameters(arguments) of the method.
	* @param type The type of the method's return value.
	* @param impact The impact of the method, one of INFO, ACTION, ACTION_INFO, UNKNOWN.
	* @param descriptor An instance of Descriptor containing the appropriate metadata.
	* for this instance of the MBeanOperationInfo.If it is null then a default descriptor will be created.
	* If the descriptor does not contain the fields 
	* "displayName" or "role" these fields are added in the descriptor with their default values.
	*
	* @exception RuntimeOperationsException Wraps an
	* IllegalArgumentException. The descriptor is invalid; or
	* descriptor field "name" is not equal to operation name; or
	* descriptor field "DescriptorType" is not equal to
	* "operation"; or descriptor optional field "role" is not equal to
	* "operation", "getter", or "setter".
	*/

	public ModelMBeanOperationInfo(String name,
				       String description,
				       MBeanParameterInfo[] signature, 
				       String type,
				       int impact,
				       Descriptor descriptor)
	{
		super(name, description, signature, type, impact);
		if (tracing())
		{
			trace("ModelMBeanOperationInfo(String,String,MBeanParameterInfo[],String,int,Descriptor)","Executed");
		}
		if (descriptor == null)
		{
			if (tracing())
			{
				trace("ModelMBeanOperationInfo()","Received null for new descriptor value, setting descriptor to default values");
			}
			operationDescriptor = createDefaultDescriptor();
		} else
		{
			if (isValid(descriptor))
			{
				operationDescriptor = (Descriptor) descriptor.clone();
			} else
			{
				operationDescriptor = createDefaultDescriptor();
				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor passed in parameter"), ("Exception occurred in ModelMBeanOperationInfo constructor"));
			}

		}
	}

	/**
	 * Constructs a new ModelMBeanOperationInfo object from this ModelMBeanOperation Object.
	 *
	 * @param inInfo the ModelMBeanOperationInfo to be duplicated
	 *
	 */

	public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo)
	{
		super(inInfo.getName(), 
			  inInfo.getDescription(), 
			  inInfo.getSignature(),
			  inInfo.getReturnType(), 
			  inInfo.getImpact());
		if (tracing())
		{
			trace("ModelMBeanOperationInfo(ModelMBeanOperationInfo)","Executed");
		}
		Descriptor newDesc = inInfo.getDescriptor();
		if (newDesc == null)
		{
			operationDescriptor = createDefaultDescriptor();
		} else
		{
			if (isValid(newDesc))
			{
				operationDescriptor = (Descriptor) newDesc.clone();
			} else
			{
				operationDescriptor = createDefaultDescriptor();
				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor passed in parameter"), ("Exception occurred in ModelMBeanOperationInfo constructor"));
			}

		}
	}

	/**
	* Creates and returns a new ModelMBeanOperationInfo which is a duplicate of this ModelMBeanOperationInfo.
	*
	*/

	public Object clone ()
	{
		if (tracing())
		{
			trace("ModelMBeanOperationInfo.clone()","Executed");
		}
		return(new ModelMBeanOperationInfo(this)) ;
	}

	/** 
	 * Returns a copy of the associated Descriptor of the
	 * ModelMBeanOperationInfo.
	 *
	 * @return Descriptor associated with the
	 * ModelMBeanOperationInfo object.
	 *
	 * @see #setDescriptor
	 */

	public Descriptor getDescriptor()
	{
		if (tracing())
		{
			trace("ModelMBeanOperationInfo.getDescriptor()","Executed");
		}
		if (operationDescriptor == null)
		{
			operationDescriptor = createDefaultDescriptor();
		}

		return((Descriptor) operationDescriptor.clone());
	}

	/**
	 * Sets associated Descriptor (full replace) for the
	 * ModelMBeanOperationInfo If the new Descriptor is null, then
	 * the associated Descriptor reverts to a default descriptor.
	 * The Descriptor is validated before it is assigned.  If the
	 * new Descriptor is invalid, then a
	 * RuntimeOperationsException wrapping an
	 * IllegalArgumentException is thrown.
	 *
	 * @param inDescriptor replaces the Descriptor associated with the 
	 * ModelMBeanOperation.	 	 
	 *
	 * @exception RuntimeOperationsException Wraps an
	 * IllegalArgumentException for invalid Descriptor.
	 *
	 * @see #getDescriptor
	 */
	public void setDescriptor(Descriptor inDescriptor)
	{
		if (tracing())
		{
			trace("ModelMBeanOperationInfo.setDescriptor(Descriptor)","Executed");
		}
		if (inDescriptor == null)
		{
			if (tracing())
			{
				trace("ModelMBeanOperationInfo.setDescriptor()","Received null for new descriptor value, setting descriptor to default values");
			}
			operationDescriptor = createDefaultDescriptor();
		} else
		{
			if (isValid(inDescriptor))
			{
				operationDescriptor = (Descriptor) inDescriptor.clone();
			} else
			{
				throw new RuntimeOperationsException(new IllegalArgumentException("Invalid descriptor passed in parameter"), ("Exception occurred in ModelMBeanOperationInfo setDescriptor"));
			}
		}
	}

	/**
	* Returns a string containing the entire contents of the ModelMBeanOperationInfo in human readable form.
	*/
	public String toString()
	{
		if (tracing())
		{
			trace("ModelMBeanConstructorInfo.toString()","Executed");
		}
		String retStr =
		    "ModelMBeanOperationInfo: " + this.getName() +
		    " ; Description: " + this.getDescription() +
		    " ; Descriptor: " + this.getDescriptor() +
		    " ; ReturnType: " + this.getReturnType() +
		    " ; Signature: ";
		MBeanParameterInfo[] pTypes = this.getSignature();
		for (int i=0; i < pTypes.length; i++)
		{
			retStr = retStr.concat((pTypes[i]).getType() + ", ");
		}
		return retStr;
	}
	/**
	* Creates default descriptor for operation as follows:
	* descriptorType=operation,role=operation, name=this.getName(),displayname=this.getName().
	*/
	private Descriptor createDefaultDescriptor()
	{
		if (tracing())
		{
			trace("ModelMBeanOperationInfo.createDefaultDescriptor()","Executed");
		}
		return new DescriptorSupport(new String[] {"descriptorType=operation",
							       ("name=" + this.getName()),
							       "role=operation",
							       ("displayname=" + this.getName())});
	}


	/**
	* Tests that the descriptor is valid and adds appropriate
	* default fields not already specified.  Field values must be
	* correct for field names.  descriptorType field must be
	* "operation".  We do not check the targetType because a
	* custom implementation of ModelMBean could recognize
	* additional types beyond the "standard" ones.  The following
	* fields will be defaulted if they are not already set:
	* role=operation,displayName=this.getName()
	*/
	private boolean isValid(Descriptor inDesc)
	{
		boolean results = true;
		String badField = "none";
		// if name != this.getName
		// if (descriptorType != operation)
		// look for displayName, persistPolicy, visibility and add in
		if (inDesc == null)
		{
			results = false;
		}

		else if (!inDesc.isValid())
		{	 // checks for empty descriptors, null,
			// checks for empty name and descriptorType
			// and valid values for fields.
			results = false;
		} else
		{
			if (! ((String)inDesc.getFieldValue("name")).equalsIgnoreCase(this.getName()))
			{
				results = false;
			}
			if (! ((String)inDesc.getFieldValue("descriptorType")).equalsIgnoreCase("operation"))
			{
				results = false;
			}
			Object roleValue = inDesc.getFieldValue("role");
			if (roleValue == null)
			{
				inDesc.setField("role","operation");
			} else {
			    final String role = (String)roleValue;
			    if (!(role.equalsIgnoreCase("operation")
				  || role.equalsIgnoreCase("setter")
				  || role.equalsIgnoreCase("getter"))) {
				results = false;
				badField="role";
			    }
			}

			Object targetValue = inDesc.getFieldValue("targetType");
			if (targetValue != null) {
			    if (!(targetValue instanceof java.lang.String)) {
				results = false;
				badField="targetType";
				
			    }
			}
			if ((inDesc.getFieldValue("displayName")) == null)
			    {
				inDesc.setField("displayName",this.getName());
			    }
		}
		if (tracing()) trace("isValid()",("Returning " + results + ": Invalid field is " + badField));
		return results;
	}

	// SUN Trace and debug functions
	private boolean tracing()
	{
		//      return false;
		return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN);
	}

	private void trace(String inClass, String inMethod, String inText)
	{
		//      System.out.println("TRACE: " + inClass + ":" + inMethod + ": " + inText);
		Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN, inClass,
				   inMethod,  Integer.toHexString(this.hashCode()) + " " + inText); 
	}

	private void trace(String inMethod, String inText)
	{
		trace(currClass, inMethod, inText);
	}

    /**
     * Deserializes a {@link ModelMBeanOperationInfo} from an {@link ObjectInputStream}.
     */
    private void readObject(ObjectInputStream in)
	    throws IOException, ClassNotFoundException {
      // New serial form ignores extra field "currClass"
      in.defaultReadObject();
    }


    /**
     * Serializes a {@link ModelMBeanOperationInfo} to an {@link ObjectOutputStream}.
     */
    private void writeObject(ObjectOutputStream out)
	    throws IOException {
      if (compat)
      {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
	fields.put("operationDescriptor", operationDescriptor);
	fields.put("currClass", currClass);
	out.writeFields();
      }
      else
      {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
      }
    }

}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar