API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.management.modelmbean. ModelMBeanInfoSupport 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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078

/*
 * @(#)file      ModelMBeanInfoSupport.java
 * @(#)author    IBM Corp.
 * @(#)version   1.48
 * @(#)lastedit      06/01/27
 *
 * 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.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.RuntimeOperationsException;

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

/**
 * This class represents the meta data for ModelMBeans.  Descriptors have been 
 * added on the meta data objects.
 * <P>
 * Java resources wishing to be manageable instantiate the ModelMBean using the 
 * MBeanServer's createMBean method.  The resource then sets the ModelMBeanInfo 
 * and Descriptors for the ModelMBean instance. The attributes and operations 
 * exposed via the ModelMBeanInfo for the ModelMBean are accessible
 * from MBeans, connectors/adaptors like other MBeans. Through the Descriptors, 
 * values and methods in the managed application can be defined and mapped to 
 * attributes and operations of the ModelMBean.
 * This mapping can be defined during development in a file or dynamically and
 * programmatically at runtime.
 * <P>
 * Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
 * its attributes and operations
 * become remotely accessible through the connectors/adaptors connected to that 
 * MBeanServer.
 * A Java object cannot be registered in the MBeanServer unless it is a JMX 
 * compliant MBean.
 * By instantiating a ModelMBean, resources are guaranteed that the MBean is 
 * valid.
 *
 * MBeanException and RuntimeOperationsException must be thrown on every public 
 * method.  This allows for wrapping exceptions from distributed 
 * communications (RMI, EJB, etc.)
 *
 * <p>The <b>serialVersionUID</b> of this class is 
 * <code>-1935722590756516193L</code>.
 *
 * @since 1.5
 */
public class ModelMBeanInfoSupport extends MBeanInfo implements ModelMBeanInfo {
    
    // 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 = -3944083498453227709L;
    //
    // Serial version for new serial form
    private static final long newSerialVersionUID = -1935722590756516193L;
    //
    // Serializable fields in old serial form
    private static final ObjectStreamField[] oldSerialPersistentFields =
    {
        new ObjectStreamField("modelMBeanDescriptor", Descriptor.class),
                new ObjectStreamField("mmbAttributes", MBeanAttributeInfo[].class),
                new ObjectStreamField("mmbConstructors", MBeanConstructorInfo[].class),
                new ObjectStreamField("mmbNotifications", MBeanNotificationInfo[].class),
                new ObjectStreamField("mmbOperations", MBeanOperationInfo[].class),
                new ObjectStreamField("currClass", String.class)
    };
    //
    // Serializable fields in new serial form
    private static final ObjectStreamField[] newSerialPersistentFields =
    {
        new ObjectStreamField("modelMBeanDescriptor", Descriptor.class),
                new ObjectStreamField("modelMBeanAttributes", MBeanAttributeInfo[].class),
                new ObjectStreamField("modelMBeanConstructors", MBeanConstructorInfo[].class),
                new ObjectStreamField("modelMBeanNotifications", MBeanNotificationInfo[].class),
                new ObjectStreamField("modelMBeanOperations", MBeanOperationInfo[].class)
    };
    //
    // Actual serial version and serial form
    private static final long serialVersionUID;
    /**
     * @serialField modelMBeanDescriptor Descriptor The descriptor containing 
     *              MBean wide policy
     * @serialField modelMBeanAttributes ModelMBeanAttributeInfo[] The array of 
     *              {@link ModelMBeanAttributeInfo} objects which
     *              have descriptors
     * @serialField modelMBeanConstructors MBeanConstructorInfo[] The array of 
     *              {@link ModelMBeanConstructorInfo} objects which
     *              have descriptors
     * @serialField modelMBeanNotifications MBeanNotificationInfo[] The array of 
     *              {@link ModelMBeanNotificationInfo} objects which
     *              have descriptors
     * @serialField modelMBeanOperations MBeanOperationInfo[] The array of 
     *              {@link ModelMBeanOperationInfo} objects which
     *              have descriptors
     */
    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 MBean wide policy
     */
    private Descriptor modelMBeanDescriptor = null;
    
    /* The following fields always have the same values as the
       fields inherited from MBeanInfo and are retained only for
       compatibility.  By rewriting the serialization code we could
       get rid of them.
     
       These fields can't be final because they are assigned to by
       readObject().  */
    
    /**
     * @serial The array of {@link ModelMBeanAttributeInfo} objects which
     *         have descriptors
     */
    private MBeanAttributeInfo[] modelMBeanAttributes;
    
    /**
     * @serial The array of {@link ModelMBeanConstructorInfo} objects which
     *         have descriptors
     */
    private MBeanConstructorInfo[] modelMBeanConstructors;
    
    /**
     * @serial The array of {@link ModelMBeanNotificationInfo} objects which
     *         have descriptors
     */
    private MBeanNotificationInfo[] modelMBeanNotifications;
    
    /**
     * @serial The array of {@link ModelMBeanOperationInfo} objects which
     *         have descriptors
     */
    private MBeanOperationInfo[] modelMBeanOperations;
    
    private static final String ATTR = "attribute";
    private static final String OPER = "operation";
    private static final String NOTF = "notification";
    private static final String CONS = "constructor";
    private static final String MMB = "mbean";
    private static final String ALL = "all";
    private static final String currClass = "ModelMBeanInfoSupport";
    
    /**
     * Constructs a ModelMBeanInfoSupport which is a duplicate of the given
     * ModelMBeanInfo.  The returned object is a shallow copy of the given
     * object.  Neither the Descriptor nor the contained arrays
     * ({@code ModelMBeanAttributeInfo[]} etc) are cloned.  This method is
     * chiefly of interest to modify the Descriptor of the returned instance
     * via {@link #setDescriptor setDescriptor} without affecting the
     * Descriptor of the original object.
     *
     * @param mbi the ModelMBeanInfo instance from which the ModelMBeanInfo
     * being created is initialized.
     */
    public ModelMBeanInfoSupport(ModelMBeanInfo  mbi) {
        super(mbi.getClassName(),
                mbi.getDescription(),
                mbi.getAttributes(),
                mbi.getConstructors(),
                mbi.getOperations(),
                mbi.getNotifications());
        
        modelMBeanAttributes = mbi.getAttributes();
        modelMBeanConstructors = mbi.getConstructors();
        modelMBeanOperations = mbi.getOperations();
        modelMBeanNotifications = mbi.getNotifications();
        
        try {
            Descriptor mbeandescriptor = mbi.getMBeanDescriptor();
            
            if ((mbeandescriptor != null) && isValidDescriptor(mbeandescriptor)) {
                if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)",
                        "ModelMBeanDescriptor is valid, cloning Descriptor *" + 
                        mbeandescriptor.toString() + "*");
                modelMBeanDescriptor = (Descriptor) mbeandescriptor.clone();
                addDefaultFields();
            } else {
                if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)",
                        "ModelMBeanDescriptor in ModelMBeanInfo " +
                        "is null or invalid, setting to default value");
                modelMBeanDescriptor = createDefaultDescriptor();
            }
        } catch (MBeanException mbe) {
            modelMBeanDescriptor = createDefaultDescriptor();
            if (tracing()) trace("ModelMBeanInfo(ModelMBeanInfo)",
                    "Could not get modelMBeanDescriptor, " +
                    "setting to default value");
        }
        
        if (tracing()) {
            trace("ModelMBeanInfo(ModelMBeanInfo)","Executed");
        }
    }
    
    /**
     * Creates a ModelMBeanInfoSupport with the provided information,
     * but the descriptor is a default.
     * The default descriptor is: name=mbeanName, descriptorType=mbean,
     * displayName=ClassName, persistPolicy=never, log=F, visibility=1
     *
     * @param className classname of the MBean
     * @param description human readable description of the
     * ModelMBean
     * @param attributes array of ModelMBeanAttributeInfo objects
     * which have descriptors
     * @param constructors array of ModelMBeanConstructorInfo
     * objects which have descriptors
     * @param operations array of ModelMBeanOperationInfo objects
     * which have descriptors
     * @param notifications array of ModelMBeanNotificationInfo
     * objects which have descriptors
     */
    public ModelMBeanInfoSupport(String className,
            String description,
            ModelMBeanAttributeInfo[] attributes,
            ModelMBeanConstructorInfo[] constructors,
            ModelMBeanOperationInfo[] operations,
            ModelMBeanNotificationInfo[] notifications) {
        this(className, description, attributes, constructors,
                operations, notifications, null);
    }
    
    /**
     * Creates a ModelMBeanInfoSupport with the provided information
     * and the descriptor given in parameter.
     *
     * @param className classname of the MBean
     * @param description human readable description of the
     * ModelMBean
     * @param attributes array of ModelMBeanAttributeInfo objects
     * which have descriptors
     * @param constructors array of ModelMBeanConstructorInfo
     * objects which have descriptor
     * @param operations array of ModelMBeanOperationInfo objects
     * which have descriptor
     * @param notifications array of ModelMBeanNotificationInfo
     * objects which have descriptor
     * @param mbeandescriptor descriptor to be used as the
     * MBeanDescriptor containing MBean wide policy. If the
     * descriptor is null, a default descriptor will be constructed.
     * The default descriptor is:
     * name=className, descriptorType=mbean, displayName=className,
     * persistPolicy=never, log=F, visibility=1.  If the
     * descriptor does not contain all these fields, they will be
     * added with these default values.
     *
     * @exception RuntimeOperationsException Wraps an
     * IllegalArgumentException for invalid descriptor passed in
     * parameter.  (see {@link #getMBeanDescriptor
     * getMBeanDescriptor} for the definition of a valid MBean
     * descriptor.)
     */
    
    public ModelMBeanInfoSupport(String    className,
            String description,
            ModelMBeanAttributeInfo[] attributes,
            ModelMBeanConstructorInfo[] constructors,
            ModelMBeanOperationInfo[] operations,
            ModelMBeanNotificationInfo[] notifications,
            Descriptor mbeandescriptor) {
        super(className,
                description,
                (attributes != null) ? attributes : NO_ATTRIBUTES,
                (constructors != null) ? constructors : NO_CONSTRUCTORS,
                (operations != null) ? operations : NO_OPERATIONS,
                (notifications != null) ? notifications : NO_NOTIFICATIONS);
        /* The values saved here are possibly null, but we
           check this everywhere they are referenced.  If at
           some stage we replace null with an empty array
           here, as we do in the superclass constructor
           parameters, then we must also do this in
           readObject().  */
        modelMBeanAttributes = attributes;
        modelMBeanConstructors = constructors;
        modelMBeanOperations = operations;
        modelMBeanNotifications = notifications;
        if (mbeandescriptor ==null) {
            if (tracing())
                trace("ModelMBeanInfo(String,String,ModelMBeanAttributeInfo[]," +
                        "ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
                        "ModelMBeanNotificationInfo[],Descriptor)",
                        "MBeanDescriptor is null, setting default descriptor");
            
            modelMBeanDescriptor = createDefaultDescriptor();
        } else {
            if (isValidDescriptor(mbeandescriptor)) {
                modelMBeanDescriptor = (Descriptor) mbeandescriptor.clone();
                addDefaultFields();
            } else {
                throw new RuntimeOperationsException(
                        new IllegalArgumentException(
                        "Invalid descriptor passed in parameter"));
            }
        }
        if (tracing()) {
            trace("ModelMBeanInfo(String,String,ModelMBeanAttributeInfo[]," +
                    "ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
                    "ModelMBeanNotificationInfo[],Descriptor)",
                    "Executed");
        }
    }
    
    private static final ModelMBeanAttributeInfo[] NO_ATTRIBUTES =
            new ModelMBeanAttributeInfo[0];
    private static final ModelMBeanConstructorInfo[] NO_CONSTRUCTORS =
            new ModelMBeanConstructorInfo[0];
    private static final ModelMBeanNotificationInfo[] NO_NOTIFICATIONS =
            new ModelMBeanNotificationInfo[0];
    private static final ModelMBeanOperationInfo[] NO_OPERATIONS =
            new ModelMBeanOperationInfo[0];
    
    // Java doc inherited from MOdelMBeanInfo interface
    
    /**
     * Returns a shallow clone of this instance.  Neither the Descriptor nor
     * the contained arrays ({@code ModelMBeanAttributeInfo[]} etc) are
     * cloned.  This method is chiefly of interest to modify the Descriptor
     * of the clone via {@link #setDescriptor setDescriptor} without affecting
     * the Descriptor of the original object.
     *
     * @return a shallow clone of this instance.
     */
    public Object clone() {
        return(new ModelMBeanInfoSupport(this));
    }
    
    
    public Descriptor[] getDescriptors(String inDescriptorType)
    throws MBeanException, RuntimeOperationsException {
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getDescriptors()","Entry");
        }
        
        if ((inDescriptorType == null) || (inDescriptorType == "")) {
            inDescriptorType = "all";
        }
        
        // if no descriptors of that type, will return empty array
        //
        final Descriptor[] retList;
        
        if (inDescriptorType.equalsIgnoreCase(MMB)) {
            retList = new Descriptor[] {modelMBeanDescriptor};
        } else if (inDescriptorType.equalsIgnoreCase(ATTR)) {
            final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
            int numAttrs = 0;
            if (attrList != null) numAttrs = attrList.length;
            
            retList = new Descriptor[numAttrs];
            for (int i=0; i < numAttrs; i++) {
                retList[i] = (((ModelMBeanAttributeInfo) 
                    attrList[i]).getDescriptor());
            }
        } else if (inDescriptorType.equalsIgnoreCase(OPER)) {
            final MBeanOperationInfo[] operList = modelMBeanOperations;
            int numOpers = 0;
            if (operList != null) numOpers = operList.length;
            
            retList = new Descriptor[numOpers];
            for (int i=0; i < numOpers; i++) {
                retList[i] = (((ModelMBeanOperationInfo) 
                    operList[i]).getDescriptor());
            }
        } else if (inDescriptorType.equalsIgnoreCase(CONS)) {
            final MBeanConstructorInfo[] consList =  modelMBeanConstructors;
            int numCons = 0;
            if (consList != null) numCons = consList.length;
            
            retList = new Descriptor[numCons];
            for (int i=0; i < numCons; i++) {
                retList[i] = (((ModelMBeanConstructorInfo) 
                    consList[i]).getDescriptor());
            }
        } else if (inDescriptorType.equalsIgnoreCase(NOTF)) {
            final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
            int numNotifs = 0;
            if (notifList != null) numNotifs = notifList.length;
            
            retList = new Descriptor[numNotifs];
            for (int i=0; i < numNotifs; i++) {
                retList[i] = (((ModelMBeanNotificationInfo) 
                    notifList[i]).getDescriptor());
            }
        } else if (inDescriptorType.equalsIgnoreCase(ALL)) {
            
            final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
            int numAttrs = 0;
            if (attrList != null) numAttrs = attrList.length;
            
            final MBeanOperationInfo[] operList = modelMBeanOperations;
            int numOpers = 0;
            if (operList != null) numOpers = operList.length;
            
            final MBeanConstructorInfo[] consList = modelMBeanConstructors;
            int numCons = 0;
            if (consList != null) numCons = consList.length;
            
            final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
            int numNotifs = 0;
            if (notifList != null) numNotifs = notifList.length;
            
            int count = numAttrs + numCons + numOpers + numNotifs + 1;
            retList = new Descriptor[count];
            
            retList[count-1] = modelMBeanDescriptor;

            int j=0;
            for (int i=0; i < numAttrs; i++) {
                retList[j] = (((ModelMBeanAttributeInfo) 
                    attrList[i]).getDescriptor());
                j++;
            }
            for (int i=0; i < numCons; i++) {
                retList[j] = (((ModelMBeanConstructorInfo)
                    consList[i]).getDescriptor());
                j++;
            }
            for (int i=0; i < numOpers; i++) {
                retList[j] = (((ModelMBeanOperationInfo)operList[i]).
                        getDescriptor());
                j++;
            }
            for (int i=0; i < numNotifs; i++) {
                retList[j] = (((ModelMBeanNotificationInfo)notifList[i]).
                        getDescriptor());
                j++;
            }
        } else {
            final IllegalArgumentException iae =
                    new IllegalArgumentException("Descriptor Type is invalid");
            final String msg = "Exception occurred trying to find"+
                    " the descriptors of the MBean";
            throw new RuntimeOperationsException(iae,msg);
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getDescriptors()","Exit");
        }
        
        return retList;
    }
    
    
    public void setDescriptors(Descriptor[] inDescriptors)
    throws MBeanException, RuntimeOperationsException {
        if (tracing()) {
            trace("ModelMBeanInfoSupport.setDescriptors(Descriptor[])","Entry");
        }
        if (inDescriptors==null) {
            // throw RuntimeOperationsException - invalid descriptor
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("Descriptor list is invalid"),
                    "Exception occurred trying to set the descriptors " +
                    "of the MBeanInfo");
        }
        if (inDescriptors.length == 0) { // empty list, no-op
            return;
        }
        for (int j=0; j < inDescriptors.length; j++) {
            setDescriptor(inDescriptors[j],null);
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.setDescriptors(Descriptor[])","Exit");
        }
        
    }
    
    
    /**
     * Returns a Descriptor requested by name.
     *
     * @param inDescriptorName The name of the descriptor.
     *
     * @return Descriptor containing a descriptor for the ModelMBean with the 
     *         same name. If no descriptor is found, null is returned.
     *
     * @exception MBeanException Wraps a distributed communication Exception.
     * @exception RuntimeOperationsException Wraps an IllegalArgumentException 
     *            for null name.
     *
     * @see #setDescriptor
     */
    
    public Descriptor getDescriptor(String inDescriptorName)
    throws MBeanException, RuntimeOperationsException {
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getDescriptor(String)","Entry");
        }
        return(getDescriptor(inDescriptorName, null));
    }
    
    
    public Descriptor getDescriptor(String inDescriptorName,
            String inDescriptorType)
            throws MBeanException, RuntimeOperationsException {
        if (inDescriptorName==null) {
            // throw RuntimeOperationsException - invalid descriptor
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("Descriptor is invalid"),
                    "Exception occurred trying to set the descriptors of " +
                    "the MBeanInfo");
        }
        
        if (MMB.equalsIgnoreCase(inDescriptorType)) {
            return (Descriptor) modelMBeanDescriptor.clone();
        }
        
            /* The logic here is a bit convoluted, because we are
               dealing with two possible cases, depending on whether
               inDescriptorType is null.  If it's not null, then only
               one of the following ifs will run, and it will either
               return a descriptor or null.  If inDescriptorType is
               null, then all of the following ifs will run until one
               of them finds a descriptor.  */
        if (ATTR.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
            ModelMBeanAttributeInfo attr = getAttribute(inDescriptorName);
            if (attr != null)
                return attr.getDescriptor();
            if (inDescriptorType != null)
                return null;
        }
        if (OPER.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
            ModelMBeanOperationInfo oper = getOperation(inDescriptorName);
            if (oper != null)
                return oper.getDescriptor();
            if (inDescriptorType != null)
                return null;
        }
        if (CONS.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
            ModelMBeanConstructorInfo oper =
                    getConstructor(inDescriptorName);
            if (oper != null)
                return oper.getDescriptor();
            if (inDescriptorType != null)
                return null;
        }
        if (NOTF.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
            ModelMBeanNotificationInfo notif =
                    getNotification(inDescriptorName);
            if (notif != null)
                return notif.getDescriptor();
            if (inDescriptorType != null)
                return null;
        }
        if (inDescriptorType == null)
            return null;
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Descriptor Type is invalid"),
                "Exception occurred trying to find the descriptors of the MBean");
        
    }
    
    
    
    public void setDescriptor(Descriptor inDescriptor,
            String inDescriptorType)
            throws MBeanException, RuntimeOperationsException {
        final String excMsg =
                "Exception occurred trying to set the descriptors of the MBean";
        
        if (tracing()) {
            trace("ModelMBeanInfoSupport.setDescriptor(Descriptor,String)",
                    "Entry");
        }
        
        if (inDescriptor==null) {
            RuntimeException iae =
                    new IllegalArgumentException("Null Descriptor");
            throw new RuntimeOperationsException(iae, excMsg);
        }
        
        if ((inDescriptorType == null) || (inDescriptorType == "")) {
            inDescriptorType =
                    (String) inDescriptor.getFieldValue("descriptorType");
            
            if (inDescriptorType == null) {
                RuntimeException iae =
                        new IllegalArgumentException("Descriptor type is invalid");
                throw new RuntimeOperationsException(iae, excMsg);
            }
        }
        
        String inDescriptorName =
                (String) inDescriptor.getFieldValue("name");
        if (inDescriptorName == null) {
            RuntimeException iae =
                    new IllegalArgumentException("Descriptor name is invalid");
            throw new RuntimeOperationsException(iae, excMsg);
        }
        boolean found = false;
        if (inDescriptorType.equalsIgnoreCase(MMB)) {
            setMBeanDescriptor(inDescriptor);
            found = true;
        } else if (inDescriptorType.equalsIgnoreCase(ATTR)) {
            MBeanAttributeInfo[] attrList =  modelMBeanAttributes;
            int numAttrs = 0;
            if (attrList != null) numAttrs = attrList.length;
            
            for (int i=0; i < numAttrs; i++) {
                if (inDescriptorName.equals(attrList[i].getName())) {
                    found = true;
                    ModelMBeanAttributeInfo mmbai =
                            (ModelMBeanAttributeInfo) attrList[i];
                    mmbai.setDescriptor(inDescriptor);
                    if (tracing()) {
                        trace("ModelMBeanInfoSupport.setDescriptor",
                                "setting descriptor to " + inDescriptor);
                        trace("ModelMBeanInfoSupport.setDescriptor",
                                "local: AttributeInfo descriptor is " +
                                mmbai.getDescriptor());
                        trace("ModelMBeanInfoSupport.setDescriptor",
                                "modelMBeanInfo: AttributeInfo descriptor is " +
                                this.getDescriptor(inDescriptorName,
                                "attribute"));
                    }
                }
            }
        } else if (inDescriptorType.equalsIgnoreCase(OPER)) {
            MBeanOperationInfo[] operList =  modelMBeanOperations;
            int numOpers = 0;
            if (operList != null) numOpers = operList.length;
            
            for (int i=0; i < numOpers; i++) {
                if (inDescriptorName.equals(operList[i].getName())) {
                    found = true;
                    ModelMBeanOperationInfo mmboi =
                            (ModelMBeanOperationInfo) operList[i];
                    mmboi.setDescriptor(inDescriptor);
                }
            }
        } else if (inDescriptorType.equalsIgnoreCase(CONS)) {
            MBeanConstructorInfo[] consList =  modelMBeanConstructors;
            int numCons = 0;
            if (consList != null) numCons = consList.length;
            
            for (int i=0; i < numCons; i++) {
                if (inDescriptorName.equals(consList[i].getName())) {
                    found = true;
                    ModelMBeanConstructorInfo mmbci =
                            (ModelMBeanConstructorInfo) consList[i];
                    mmbci.setDescriptor(inDescriptor);
                }
            }
        } else if (inDescriptorType.equalsIgnoreCase(NOTF)) {
            MBeanNotificationInfo[] notifList =  modelMBeanNotifications;
            int numNotifs = 0;
            if (notifList != null) numNotifs = notifList.length;
            
            for (int i=0; i < numNotifs; i++) {
                if (inDescriptorName.equals(notifList[i].getName())) {
                    found = true;
                    ModelMBeanNotificationInfo mmbni =
                            (ModelMBeanNotificationInfo) notifList[i];
                    mmbni.setDescriptor(inDescriptor);
                }
            }
        } else {
            RuntimeException iae =
                    new IllegalArgumentException("Invalid descriptor type: " +
                    inDescriptorType);
            throw new RuntimeOperationsException(iae, excMsg);
        }
        
        if (!found) {
            RuntimeException iae =
                    new IllegalArgumentException("Descriptor name is invalid: " +
                    "type=" + inDescriptorType +
                    "; name=" + inDescriptorName);
            throw new RuntimeOperationsException(iae, excMsg);
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.setDescriptor(Descriptor,String)",
                    "Exit");
        }
        
    }
    
    
    public ModelMBeanAttributeInfo getAttribute(String inName)
    throws MBeanException, RuntimeOperationsException {
        ModelMBeanAttributeInfo retInfo = null;
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getAttributeInfo(String)","Entry");
        }
        if (inName == null) {
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("Attribute Name is null"),
                    "Exception occurred trying to get the " +
                    "ModelMBeanAttributeInfo of the MBean");
        }
        MBeanAttributeInfo[] attrList = modelMBeanAttributes;
        int numAttrs = 0;
        if (attrList != null) numAttrs = attrList.length;
        
        for (int i=0; (i < numAttrs) && (retInfo == null); i++) {
            if (tracing()) {
                trace("ModelMBeanInfoSupport.getAttribute",
                        "this.getAttributes() MBeanAttributeInfo Array " + i + 
                        ":" + ((ModelMBeanAttributeInfo)attrList[i]).
                        getDescriptor().toString());
                trace("ModelMBeanInfoSupport.getAttribute",
                        "this.modelMBeanAttributes MBeanAttributeInfo Array " +
                        i + ":" + 
                        ((ModelMBeanAttributeInfo)modelMBeanAttributes[i]).
                        getDescriptor().toString());
            }
            if (inName.equals(attrList[i].getName())) {
                retInfo = ((ModelMBeanAttributeInfo)attrList[i].clone());
            }
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getAttribute()","Exit");
        }
        
        return retInfo;
    }
    
    
    
    public ModelMBeanOperationInfo getOperation(String inName)
    throws MBeanException, RuntimeOperationsException {
        ModelMBeanOperationInfo retInfo = null;
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getOperation(String)","Entry");
        }
        if (inName == null) {
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("inName is null"),
                    "Exception occurred trying to get the " +
                    "ModelMBeanOperationInfo of the MBean");
        }
        MBeanOperationInfo[] operList = modelMBeanOperations; //this.getOperations();
        int numOpers = 0;
        if (operList != null) numOpers = operList.length;
        
        for (int i=0; (i < numOpers) && (retInfo == null); i++) {
            if (inName.equals(operList[i].getName())) {
                retInfo = ((ModelMBeanOperationInfo) operList[i].clone());
            }
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getOperation(String)","Exit");
        }
        
        return retInfo;
    }
    
    /**
     * Returns the ModelMBeanConstructorInfo requested by name.
     * If no ModelMBeanConstructorInfo exists for this name null is returned.
     *
     * @param inName the name of the constructor.
     *
     * @return the constructor info for the named constructor, or null
     * if there is none.
     *
     * @exception MBeanException Wraps a distributed communication Exception.
     * @exception RuntimeOperationsException Wraps an IllegalArgumentException 
     *            for a null constructor name.
     */
    
    public ModelMBeanConstructorInfo getConstructor(String inName)
    throws MBeanException, RuntimeOperationsException {
        ModelMBeanConstructorInfo retInfo = null;
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getConstructor(String)","Entry");
        }
        if (inName == null) {
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("Constructor name is null"),
                    "Exception occurred trying to get the " +
                    "ModelMBeanConstructorInfo of the MBean");
        }
        MBeanConstructorInfo[] consList = modelMBeanConstructors; //this.getConstructors();
        int numCons = 0;
        if (consList != null) numCons = consList.length;
        
        for (int i=0; (i < numCons) && (retInfo == null); i++) {
            if (inName.equals(consList[i].getName())) {
                retInfo = ((ModelMBeanConstructorInfo) consList[i].clone());
            }
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getConstructor(String)","Exit");
        }
        
        return retInfo;
    }
    
    
    public ModelMBeanNotificationInfo getNotification(String inName)
    throws MBeanException, RuntimeOperationsException {
        ModelMBeanNotificationInfo retInfo = null;
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getNotification(String)","Entry");
        }
        if (inName == null) {
            throw new RuntimeOperationsException(
                    new IllegalArgumentException("Notification name is null"),
                    "Exception occurred trying to get the " +
                    "ModelMBeanNotificationInfo of the MBean");
        }
        MBeanNotificationInfo[] notifList = modelMBeanNotifications; //this.getNotifications();
        int numNotifs = 0;
        if (notifList != null) numNotifs = notifList.length;
        
        for (int i=0; (i < numNotifs) && (retInfo == null); i++) {
            if (inName.equals(notifList[i].getName())) {
                retInfo = ((ModelMBeanNotificationInfo) notifList[i].clone());
            }
        }
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getNotification(String)","Exit");
        }
        
        return retInfo;
    }
    
    
    /* We override MBeanInfo.getDescriptor() to return our descriptor. */
    /**
     * @since 1.6
     */
@Override
    public Descriptor getDescriptor() {
        return getMBeanDescriptorNoException();
    }
    
    public Descriptor getMBeanDescriptor() throws MBeanException {
        return getMBeanDescriptorNoException();
    }
    
    private Descriptor getMBeanDescriptorNoException() {
        if (tracing())
            trace("ModelMBeanInfoSupport.getMBeanDescriptor()", "Executed");
        if (modelMBeanDescriptor == null)
            modelMBeanDescriptor = createDefaultDescriptor();
        if (tracing()) {
            trace("ModelMBeanInfoSupport.getMbeanDescriptor()",
                    "Returning " + modelMBeanDescriptor);
        }
        return (Descriptor) modelMBeanDescriptor.clone();
    }
    
    public void setMBeanDescriptor(Descriptor inMBeanDescriptor)
    throws MBeanException, RuntimeOperationsException {
        if (tracing()) {
            trace("ModelMBeanInfoSupport.setMBeanDescriptor(Descriptor)",
                    "Executed");
        }
        
        if (inMBeanDescriptor == null) {
            if (tracing()) 
                trace("ModelMBeanInfoSupport.setMBeanDescriptor(Descriptor)",
                        "MBean Descriptor is not valid");
            modelMBeanDescriptor = createDefaultDescriptor();
        } else {
            if (isValidDescriptor(inMBeanDescriptor)) {
                modelMBeanDescriptor = (Descriptor) inMBeanDescriptor.clone();
                addDefaultFields();
            } else {
                throw new RuntimeOperationsException(
                        new IllegalArgumentException("Invalid descriptor " +
                        "passed in parameter"));
            }
            
        }
    }
    
        /* The default descriptor is:
         * name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
         *	persistPolicy=never,log=F,visibility=1
         */
    private Descriptor createDefaultDescriptor() {
        
        Descriptor dftDesc = null;
        dftDesc = new DescriptorSupport(new String[] {
                ("name=" + this.getClassName()),
                "descriptorType=mbean",
                ("displayName=" + this.getClassName()),
                "persistPolicy=never",
                "log=F",
                "visibility=1"});
                return dftDesc;
    }
    
    /*
     * Validates the ModelMBeanDescriptor
     * If the descriptor does not contain all these fields,
     * they will be added with these default values.
     * name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
     *	persistPolicy=never,log=F,visibility=1
     *
     * Will return false if the MBeanDescriptor has a null name or descriptorType.
     */
    private boolean isValidDescriptor(Descriptor inDesc) {
        String badField = null;
        // if name != mbi.getClassName
        // if (descriptorType != mbean)
        // look for displayName, persistPolicy, logging, visibility and add in
        if (tracing())
            trace("isValidDescriptor",
                    "Validating descriptor: " + inDesc.toString());
        if (inDesc == null)
            badField = "nullDescriptor";
        else if (!inDesc.isValid())
            // checks for empty descriptors, null,
            // checks for empty name and descriptorType and
            // valid values for fields.
            badField="InvalidDescriptor";
        else if ((((String)inDesc.getFieldValue("name")) == null))
            badField="name";
        else if (! ((String)inDesc.getFieldValue("descriptorType"))
        .equalsIgnoreCase(MMB))
            badField="descriptorType";
        else { // no bad fields
            if (tracing())
                trace("isValidDescriptor", "returning true");
            return true;
        }
        
        if (tracing())
            trace("isValidDescriptor",
                    "returning false: invalid field is " + badField);
        
        return false;
    }
    
    private void addDefaultFields() {
        final Descriptor d = modelMBeanDescriptor;
        
        if ((d.getFieldValue("displayName")) == null)
            d.setField("displayName",this.getClassName());
        if ((d.getFieldValue("persistPolicy")) == null)
            d.setField("persistPolicy","never");
        if ((d.getFieldValue("log")) == null)
            d.setField("log","F");
        if ((d.getFieldValue("visibility")) == null)
            d.setField("visibility","1");
    }
    
    // SUN Trace and debug functions
    private boolean tracing() {
        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN);
    }
    
    private void trace(String inClass, String inMethod, String inText) {
        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MODELMBEAN, inClass,
                inMethod, inText);
    }
    
    private void trace(String inMethod, String inText) {
        trace(currClass, inMethod, inText);
    }
    
    /**
     * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
     */
    private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException {
        if (compat) {
            // Read an object serialized in the old serial form
            //
            ObjectInputStream.GetField fields = in.readFields();
            modelMBeanDescriptor = 
                    (Descriptor) fields.get("modelMBeanDescriptor", null);
            if (fields.defaulted("modelMBeanDescriptor")) {
                throw new NullPointerException("modelMBeanDescriptor");
            }
            modelMBeanAttributes = 
                    (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
            if (fields.defaulted("mmbAttributes")) {
                throw new NullPointerException("mmbAttributes");
            }
            modelMBeanConstructors = 
                    (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
            if (fields.defaulted("mmbConstructors")) {
                throw new NullPointerException("mmbConstructors");
            }
            modelMBeanNotifications = 
                    (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
            if (fields.defaulted("mmbNotifications")) {
                throw new NullPointerException("mmbNotifications");
            }
            modelMBeanOperations = 
                    (MBeanOperationInfo[]) fields.get("mmbOperations", null);
            if (fields.defaulted("mmbOperations")) {
                throw new NullPointerException("mmbOperations");
            }
        } else {
            // Read an object serialized in the new serial form
            //
            in.defaultReadObject();
        }
    }
    
    
    /**
     * Serializes a {@link ModelMBeanInfoSupport} 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("modelMBeanDescriptor", modelMBeanDescriptor);
            fields.put("mmbAttributes", modelMBeanAttributes);
            fields.put("mmbConstructors", modelMBeanConstructors);
            fields.put("mmbNotifications", modelMBeanNotifications);
            fields.put("mmbOperations", modelMBeanOperations);
            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