Source Code Cross Referenced for ModelMBeanInfoSupport.java in  » JMX » jfoxmx » javax » management » modelmbean » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jfoxmx » javax.management.modelmbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management.modelmbean;
009:
010:        import java.io.Serializable;
011:        import java.util.Arrays;
012:        import java.util.List;
013:        import java.util.ArrayList;
014:
015:        import javax.management.MBeanOperationInfo;
016:        import javax.management.MBeanNotificationInfo;
017:        import javax.management.MBeanConstructorInfo;
018:        import javax.management.MBeanAttributeInfo;
019:        import javax.management.Descriptor;
020:        import javax.management.MBeanException;
021:        import javax.management.RuntimeOperationsException;
022:        import javax.management.MBeanInfo;
023:
024:        /**
025:         * This class represents the meta data for ModelMBeans.  Descriptors have been added on the meta data objects.
026:         * <P>
027:         * Java resources wishing to be manageable instatiate the ModelMBean using the MBeanServer's
028:         * createMBean method.  The resource then sets the ModelMBeanInfo and Descriptors for the ModelMBean
029:         * instance. The attributes and operations exposed via the ModelMBeanInfo for the ModelMBean are accessible
030:         * from Mbeans, connectors/adapters like other MBeans. Through the Descriptors, values and methods in
031:         * the managed application can be defined and mapped to attributes and operations of the ModelMBean.
032:         * This mapping can be defined during development in a file or dynamically and
033:         * programmatically at runtime.
034:         * <P>
035:         * Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
036:         * its attributes and operations
037:         * become remotely accessible through the connectors/adaptors connected to that MBeanServer.
038:         * A Java object cannot be registered in the MBeanServer unless it is a JMX compliant MBean.
039:         * By instantiating a ModelMBean, resources are guaranteed that the MBean is valid.
040:         *
041:         * MBeanException and RuntimeOperationsException must be thrown on every public method.  This allows
042:         *  for wrappering exceptions from distributed communications (RMI, EJB, etc.)
043:         *
044:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
045:         */
046:
047:        public class ModelMBeanInfoSupport extends MBeanInfo implements 
048:                ModelMBeanInfo, Serializable {
049:            private Descriptor modelMBeanDescriptor = null;
050:            private MBeanAttributeInfo modelMBeanAttributes[] = null;
051:            private MBeanConstructorInfo modelMBeanConstructors[] = null;
052:            private MBeanNotificationInfo modelMBeanNotifications[] = null;
053:            private MBeanOperationInfo modelMBeanOperations[] = null;
054:
055:            /**
056:             * constructs a ModelMBeanInfoSupport which is a duplicate of the one passed in.
057:             *
058:             * @param mbeanInfo - the ModelMBeanInfo instance from which the ModelMBeanInfo
059:             * being created is initialized.
060:             */
061:            public ModelMBeanInfoSupport(ModelMBeanInfo mbeanInfo) {
062:                super (mbeanInfo.getClassName(), mbeanInfo.getDescription(),
063:                        mbeanInfo.getAttributes(), mbeanInfo.getConstructors(),
064:                        mbeanInfo.getOperations(), mbeanInfo.getNotifications());
065:                modelMBeanAttributes = mbeanInfo.getAttributes();
066:                modelMBeanConstructors = mbeanInfo.getConstructors();
067:                modelMBeanOperations = mbeanInfo.getOperations();
068:                modelMBeanNotifications = mbeanInfo.getNotifications();
069:                try {
070:                    Descriptor descriptor = mbeanInfo.getMBeanDescriptor();
071:                    setMBeanDescriptor(descriptor);
072:                } catch (MBeanException mbeanexception) {
073:                    modelMBeanDescriptor = createDefaultDescriptor();
074:                }
075:            }
076:
077:            /**
078:             * Creates a ModelMBeanInfoSupport with the provided information, but the descriptor is a default.
079:             * The default descriptor is: name=mbeanName,descriptorType=mbean,
080:             * displayName=this.getClassName(), persistPolicy=never,log=F,export=F,visiblity=1
081:             *
082:             * @param className - classname of ModelMBeanInfo
083:             * @param description - human readable description of the ModelMBean
084:             * @param attributes - array of ModelMBeanAttributeInfo objects which have descriptors
085:             * @param constructors - array of ModelMBeanConstructorInfo objects which have descriptor
086:             * @param operations - array of ModelMBeanOperationInfo objects which have descriptor
087:             * @param notifications - array of ModelMBeanNotificationInfo objects which have descriptor
088:             */
089:            public ModelMBeanInfoSupport(String className, String description,
090:                    ModelMBeanAttributeInfo[] attributes,
091:                    ModelMBeanConstructorInfo[] constructors,
092:                    ModelMBeanOperationInfo[] operations,
093:                    ModelMBeanNotificationInfo[] notifications) {
094:                super (className, description, attributes, constructors,
095:                        operations, notifications);
096:                modelMBeanAttributes = attributes;
097:                modelMBeanConstructors = constructors;
098:                modelMBeanOperations = operations;
099:                modelMBeanNotifications = notifications;
100:                modelMBeanDescriptor = createDefaultDescriptor();
101:            }
102:
103:            /**
104:             * Creates a ModelMBeanInfoSupport with the provided information, but the descriptor is a default.
105:             *
106:             * @param className - classname of ModelMBeanInfo
107:             * @param description - human readable description of the ModelMBean
108:             * @param attributes - array of ModelMBeanAttributeInfo objects which have descriptors
109:             * @param constructors - array of ModelMBeanConstructorInfo objects which have descriptor
110:             * @param operations - array of ModelMBeanOperationInfo objects which have descriptor
111:             * @param notifications - array of ModelMBeanNotificationInfo objects which have descriptor
112:             * @param descriptor - descriptor to be used as the MBeanDescriptor containing mbean wide policy. if the
113:             *		descriptor is invalid or null, a default descriptor will be constructed.
114:             * The default descriptor is: name=mbeanName,descriptorType=mbean,
115:             * displayName=this.getClassName(), persistPolicy=never,log=F,export=F,visiblity=1.
116:             * If the descriptor does not contain all these fields, they will be added with these default values.
117:             */
118:            public ModelMBeanInfoSupport(String className, String description,
119:                    ModelMBeanAttributeInfo[] attributes,
120:                    ModelMBeanConstructorInfo[] constructors,
121:                    ModelMBeanOperationInfo[] operations,
122:                    ModelMBeanNotificationInfo[] notifications,
123:                    Descriptor descriptor) {
124:                super (className, description, attributes, constructors,
125:                        operations, notifications);
126:                modelMBeanAttributes = attributes;
127:                modelMBeanConstructors = constructors;
128:                modelMBeanOperations = operations;
129:                modelMBeanNotifications = notifications;
130:                try {
131:                    setMBeanDescriptor(descriptor);
132:                } catch (MBeanException mbeanexception) {
133:                    modelMBeanDescriptor = createDefaultDescriptor();
134:                }
135:            }
136:
137:            /**
138:             * returns a new ModelMBeanInfoSupport object that is a copy of this ModelMBeanInfoSupport.
139:             */
140:            public Object clone() {
141:                return new ModelMBeanInfoSupport(this );
142:            }
143:
144:            /**
145:             * Returns a DescriptorList.
146:             * It contains all Descriptors for the ModelMBean including the attributeDescriptors,
147:             * operationDescriptors, and notificationDescriptors.
148:             *
149:             * @return Descriptor array containing all descriptors for the ModelMBean
150:             *
151:             * @exception MBeanException Wraps another exception
152:             * @exception RuntimeOperationsException Wraps another exception
153:             *
154:             */
155:            public Descriptor[] getDescriptors(String descriptionType)
156:                    throws MBeanException, RuntimeOperationsException {
157:                if (descriptionType == null || descriptionType == "")
158:                    descriptionType = "all";
159:                if (descriptionType.equals(DescriptorConstants.MBEAN_TYPE)) {
160:                    return new Descriptor[] { modelMBeanDescriptor };
161:                }
162:                Descriptor[] descriptors;
163:                if (descriptionType.equals(DescriptorConstants.ATTRIBUTE_TYPE)) {
164:                    descriptors = getAttributeDescriptors();
165:                } else if (descriptionType
166:                        .equals(DescriptorConstants.OPERATION_TYPE)) {
167:                    descriptors = getOperationDescriptors();
168:                } else if (descriptionType
169:                        .equals(DescriptorConstants.CONSTRUCTOR_TYPE)) {
170:                    descriptors = getConstructorDescriptors();
171:                } else if (descriptionType
172:                        .equals(DescriptorConstants.NOTIFICATION_TYPE)) {
173:                    descriptors = getNotificationDescriptors();
174:                } else if (descriptionType.equals("all")) {
175:                    Descriptor[] attrDescriptors = getAttributeDescriptors();
176:                    Descriptor[] operDescriptors = getOperationDescriptors();
177:                    Descriptor[] consDescriptors = getConstructorDescriptors();
178:                    Descriptor[] notiDescriptors = getNotificationDescriptors();
179:                    descriptors = new Descriptor[attrDescriptors.length
180:                            + operDescriptors.length + consDescriptors.length
181:                            + notiDescriptors.length];
182:                    List descriptorList = new ArrayList(Arrays
183:                            .asList(attrDescriptors));
184:                    descriptorList.addAll(Arrays.asList(operDescriptors));
185:                    descriptorList.addAll(Arrays.asList(consDescriptors));
186:                    descriptorList.addAll(Arrays.asList(notiDescriptors));
187:                    descriptors = (Descriptor[]) descriptorList
188:                            .toArray(new Descriptor[0]);
189:                } else {
190:                    throw new RuntimeOperationsException(
191:                            new IllegalArgumentException(
192:                                    "Descriptor Type is invalid"),
193:                            "Exception occured trying find the descriptors of the MBean");
194:                }
195:                return descriptors;
196:            }
197:
198:            private Descriptor[] getAttributeDescriptors() {
199:                if (modelMBeanAttributes == null)
200:                    return new Descriptor[0];
201:                int length = modelMBeanAttributes.length;
202:                Descriptor[] descriptors = new Descriptor[length];
203:                for (int i = 0; i < length; i++)
204:                    descriptors[i] = (Descriptor) ((ModelMBeanAttributeInfo) modelMBeanAttributes[i])
205:                            .getDescriptor().clone();
206:                return descriptors;
207:            }
208:
209:            private Descriptor[] getOperationDescriptors() {
210:                if (modelMBeanOperations == null)
211:                    return new Descriptor[0];
212:                int length = modelMBeanOperations.length;
213:                Descriptor[] descriptors = new Descriptor[length];
214:                for (int i = 0; i < length; i++)
215:                    descriptors[i] = (Descriptor) ((ModelMBeanOperationInfo) modelMBeanOperations[i])
216:                            .getDescriptor().clone();
217:                return descriptors;
218:            }
219:
220:            private Descriptor[] getConstructorDescriptors() {
221:                if (modelMBeanConstructors == null)
222:                    return new Descriptor[0];
223:                int length = modelMBeanConstructors.length;
224:                Descriptor[] descriptors = new Descriptor[length];
225:                for (int i = 0; i < length; i++)
226:                    descriptors[i] = (Descriptor) ((ModelMBeanConstructorInfo) modelMBeanConstructors[i])
227:                            .getDescriptor().clone();
228:                return descriptors;
229:            }
230:
231:            private Descriptor[] getNotificationDescriptors() {
232:                if (modelMBeanNotifications == null)
233:                    return new Descriptor[0];
234:                int length = modelMBeanNotifications.length;
235:                Descriptor[] descriptors = new Descriptor[length];
236:                for (int i = 0; i < length; i++)
237:                    descriptors[i] = (Descriptor) ((ModelMBeanNotificationInfo) modelMBeanNotifications[i])
238:                            .getDescriptor().clone();
239:                return descriptors;
240:            }
241:
242:            /**
243:             * Adds or replaces descriptors in all the ModelMBeanInfoSupport for the ModelMBean.
244:             *
245:             * @param descriptors The descriptors to be set in the ModelMBean.
246:             *      All descriptors must have name and descriptorType fields and be valid.
247:             *      If the descriptor list is empty, no sets will occur.  If it is null, an exception
248:             *      will be thrown. Null elements of the list will be ignored.
249:             *
250:             *
251:             * @exception RuntimeOperationsException Wraps exceptions for illegal or null arguments
252:             *
253:             */
254:            public void setDescriptors(Descriptor[] descriptors)
255:                    throws MBeanException, RuntimeOperationsException {
256:                if (descriptors == null)
257:                    throw new RuntimeOperationsException(
258:                            new IllegalArgumentException(
259:                                    "Descriptor list is invalid"),
260:                            "Exception occured trying set the descriptors of the MBeanInfo");
261:                if (descriptors.length == 0)
262:                    return;
263:                for (int i = 0; i < descriptors.length; i++)
264:                    setDescriptor(descriptors[i], null);
265:            }
266:
267:            /**
268:             * Returns a Descriptor requested by name
269:             *
270:             * @param descriptorName The name of the descriptor.
271:             * @return Descriptor containing the descriptor for the ModelMBean with the same name and descriptorType.
272:             *
273:             * @exception MBeanException Wraps another exception
274:             * @exception RuntimeOperationsException Wraps another exception
275:             *
276:             */
277:            public Descriptor getDescriptor(String descriptorName)
278:                    throws MBeanException, RuntimeOperationsException {
279:                return getDescriptor(descriptorName, null);
280:            }
281:
282:            /**
283:             * Returns a Descriptor requested by name and descriptorType.
284:             *
285:             * @param descriptorName The name of the descriptor.
286:             * @param descriptorType The type of the descriptor being requested.  If this is null
287:             * a RuntimeOperationsException will be thrown.
288:             * Type must match that in the 'descriptorType' field on the Descriptor.  It must be "mbean",
289:             * "attribute", "operation", or "notification".
290:             *
291:             * @return Descriptor containing the descriptor for the ModelMBean with the same name and descriptorType.
292:             *
293:             * @exception MBeanException Wraps another exception
294:             * @exception RuntimeOperationsException Wraps another exception
295:             *
296:             */
297:            public Descriptor getDescriptor(String descriptorName,
298:                    String descriptorType) throws MBeanException,
299:                    RuntimeOperationsException {
300:                Descriptor descriptor = null;
301:                if (descriptorName == null)
302:                    throw new RuntimeOperationsException(
303:                            new IllegalArgumentException(
304:                                    "Descriptor is invalid"),
305:                            "Exception occured trying set the descriptors of the MBeanInfo");
306:                if (descriptorType == null)
307:                    throw new RuntimeOperationsException(
308:                            new IllegalArgumentException(
309:                                    "Descriptor Type is invalid"),
310:                            "Exception occured trying set the descriptors of the MBean");
311:                if (descriptorType.equals(DescriptorConstants.MBEAN_TYPE))
312:                    descriptor = (Descriptor) modelMBeanDescriptor.clone();
313:                else if (descriptorType
314:                        .equals(DescriptorConstants.ATTRIBUTE_TYPE)
315:                        || descriptorType == null || descriptor != null) {
316:                    ModelMBeanAttributeInfo attributeInfo = getAttribute(descriptorName);
317:                    if (attributeInfo != null)
318:                        descriptor = attributeInfo.getDescriptor();
319:                } else if (descriptorType
320:                        .equals(DescriptorConstants.OPERATION_TYPE)
321:                        || descriptorType == null || descriptor != null) {
322:                    ModelMBeanOperationInfo operationInfo = getOperation(descriptorName);
323:                    if (operationInfo != null)
324:                        descriptor = operationInfo.getDescriptor();
325:                } else if (descriptorType
326:                        .equals(DescriptorConstants.CONSTRUCTOR_TYPE)
327:                        || descriptorType == null || descriptor != null) {
328:                    ModelMBeanConstructorInfo constructorInfo = getConstructor(descriptorName);
329:                    if (constructorInfo != null)
330:                        descriptor = constructorInfo.getDescriptor();
331:                } else if (descriptorType
332:                        .equals(DescriptorConstants.NOTIFICATION_TYPE)
333:                        || descriptorType == null || descriptor != null) {
334:                    ModelMBeanNotificationInfo notificationInfo = getNotification(descriptorName);
335:                    if (notificationInfo != null)
336:                        descriptor = notificationInfo.getDescriptor();
337:                } else {
338:                    throw new RuntimeOperationsException(
339:                            new IllegalArgumentException(
340:                                    "Descriptor Type is invalid"),
341:                            "Exception occured trying find the descriptors of the MBean");
342:                }
343:                return descriptor;
344:            }
345:
346:            /**
347:             * Adds or replaces a descriptor in the ModelMBeanInfoSupport.
348:             *
349:             * @param descriptor The descriptor to be set in the ModelMBean.
350:             *      If the descriptor to be set is null, no sets will be done.
351:             * All descriptors must have name and descriptorType fields.
352:             * @param descriptorType The type of the descriptor being requested.  If this is null then
353:             * the value of the 'descriptorType' field in the inDescriptor will be used.
354:             * Type must match that in the 'descriptorType' field on the Descriptor.  It must be "mbean",
355:             * "attribute", "operation", or "notification".
356:             *
357:             *
358:             * @exception RuntimeOperationsException Wraps exceptions for illegal or null arguments
359:             *
360:             */
361:            public void setDescriptor(Descriptor descriptor,
362:                    String descriptorType) throws MBeanException,
363:                    RuntimeOperationsException {
364:                if (descriptor == null)
365:                    return;
366:
367:                if (descriptorType == null || descriptorType == "") {
368:                    descriptorType = (String) descriptor
369:                            .getFieldValue(DescriptorConstants.DESCRIPTORTYPE);
370:                    if (descriptorType == null)
371:                        throw new RuntimeOperationsException(
372:                                new IllegalArgumentException(
373:                                        "Descriptor Type is invalid"),
374:                                "Exception occured trying set the descriptors of the MBean");
375:                }
376:                String descriptorName = (String) descriptor
377:                        .getFieldValue(DescriptorConstants.NAME);
378:                if (descriptorName == null)
379:                    throw new RuntimeOperationsException(
380:                            new IllegalArgumentException(
381:                                    "Descriptor Name is invalid"),
382:                            "Exception occured trying set the descriptors of the MBean");
383:                boolean found = false;
384:                if (descriptorType.equals(DescriptorConstants.MBEAN_TYPE)) {
385:                    setMBeanDescriptor(descriptor);
386:                    found = true;
387:                } else if (descriptorType
388:                        .equalsIgnoreCase(DescriptorConstants.ATTRIBUTE_TYPE)) {
389:                    if (modelMBeanAttributes != null) {
390:                        for (int i = 0; i < modelMBeanAttributes.length; i++)
391:                            if (descriptorName.equals(modelMBeanAttributes[i]
392:                                    .getName())) {
393:                                found = true;
394:                                ((ModelMBeanAttributeInfo) modelMBeanAttributes[i])
395:                                        .setDescriptor(descriptor);
396:                                break;
397:                            }
398:                    }
399:                } else if (descriptorType
400:                        .equalsIgnoreCase(DescriptorConstants.OPERATION_TYPE)) {
401:                    if (modelMBeanOperations != null) {
402:                        for (int i = 0; i < modelMBeanOperations.length; i++)
403:                            if (descriptorName.equals(modelMBeanOperations[i]
404:                                    .getName())) {
405:                                found = true;
406:                                ((ModelMBeanOperationInfo) modelMBeanOperations[i])
407:                                        .setDescriptor(descriptor);
408:                                break;
409:                            }
410:                    }
411:                } else if (descriptorType
412:                        .equalsIgnoreCase(DescriptorConstants.CONSTRUCTOR_TYPE)) {
413:                    if (modelMBeanConstructors != null) {
414:                        for (int i = 0; i < modelMBeanConstructors.length; i++)
415:                            if (descriptorName.equals(modelMBeanConstructors[i]
416:                                    .getName())) {
417:                                found = true;
418:                                ((ModelMBeanConstructorInfo) modelMBeanConstructors[i])
419:                                        .setDescriptor(descriptor);
420:                                break;
421:                            }
422:                    }
423:                } else if (descriptorType
424:                        .equalsIgnoreCase(DescriptorConstants.NOTIFICATION_TYPE)) {
425:                    if (modelMBeanNotifications != null) {
426:                        for (int i = 0; i < modelMBeanNotifications.length; i++)
427:                            if (descriptorName
428:                                    .equals(modelMBeanNotifications[i]
429:                                            .getName())) {
430:                                found = true;
431:                                ((ModelMBeanNotificationInfo) modelMBeanNotifications[i])
432:                                        .setDescriptor(descriptor);
433:                                break;
434:                            }
435:                    }
436:                } else {
437:                    throw new RuntimeOperationsException(
438:                            new IllegalArgumentException(
439:                                    "Descriptor Type is invalid"),
440:                            "Exception occured trying set the descriptors of the MBean");
441:                }
442:                if (!found)
443:                    throw new RuntimeOperationsException(
444:                            new IllegalArgumentException(
445:                                    "Descriptor Name is invalid"),
446:                            "Exception occured trying set the descriptors of the MBean");
447:            }
448:
449:            /**
450:             * Returns a ModelMBeanAttributeInfo requested by name.
451:             *
452:             * @param name The name of the ModelMBeanAttributeInfo to get.
453:             *
454:             * @exception MBeanException Wraps another exception
455:             * @exception RuntimeOperationsException Wraps another exception for invalid attribute
456:             * name or ModelMBeanAttributeInfo to be returned.
457:             *
458:             */
459:            public ModelMBeanAttributeInfo getAttribute(String name)
460:                    throws MBeanException, RuntimeOperationsException {
461:                if (modelMBeanAttributes == null)
462:                    return null;
463:                if (name == null)
464:                    throw new RuntimeOperationsException(
465:                            new IllegalArgumentException(
466:                                    "Attribute Name is null"),
467:                            "Exception occured trying get the ModelMBeanAttributeInfo of the MBean");
468:
469:                ModelMBeanAttributeInfo attributeInfo = null;
470:                for (int i = 0; i < modelMBeanAttributes.length; i++) {
471:                    if (name.equals(modelMBeanAttributes[i].getName())) {
472:                        attributeInfo = (ModelMBeanAttributeInfo) modelMBeanAttributes[i]
473:                                .clone();
474:                        break;
475:                    }
476:                }
477:                return attributeInfo;
478:            }
479:
480:            /**
481:             * Returns a ModelMBeanOperationInfo requested by name.
482:             *
483:             * @param name The name of the ModelMBeanOperationInfo to get.
484:             *
485:             * @exception MBeanException Wraps another exception
486:             * @exception RuntimeOperationsException Wraps another exception for invalid attribute
487:             * name or ModelMBeanAttributeInfo to be returned.
488:             *
489:             */
490:            public ModelMBeanOperationInfo getOperation(String name)
491:                    throws MBeanException, RuntimeOperationsException {
492:                if (modelMBeanOperations == null)
493:                    return null;
494:                if (name == null)
495:                    throw new RuntimeOperationsException(
496:                            new IllegalArgumentException(
497:                                    "Operation Name is null"),
498:                            "Exception occured trying get the ModelMBeanOperationInfo of the MBean");
499:
500:                ModelMBeanOperationInfo operationInfo = null;
501:                for (int i = 0; i < modelMBeanOperations.length; i++) {
502:                    if (name.equals(modelMBeanOperations[i].getName())) {
503:                        operationInfo = (ModelMBeanOperationInfo) modelMBeanOperations[i]
504:                                .clone();
505:                        break;
506:                    }
507:                }
508:                return operationInfo;
509:            }
510:
511:            /**
512:             * Returns a ModelMBeanConstructorInfo requested by name.
513:             *
514:             */
515:            public ModelMBeanConstructorInfo getConstructor(String name)
516:                    throws MBeanException, RuntimeOperationsException {
517:                if (modelMBeanConstructors == null)
518:                    return null;
519:                if (name == null)
520:                    throw new RuntimeOperationsException(
521:                            new IllegalArgumentException(
522:                                    "Constructor name is null"),
523:                            "Exception occured trying get the ModelMBeanConstructorInfo of the MBean");
524:
525:                ModelMBeanConstructorInfo constructorInfo = null;
526:                for (int i = 0; i < modelMBeanConstructors.length; i++) {
527:                    if (name.equals(modelMBeanConstructors[i].getName())) {
528:                        constructorInfo = (ModelMBeanConstructorInfo) modelMBeanConstructors[i]
529:                                .clone();
530:                        break;
531:                    }
532:                }
533:                return constructorInfo;
534:            }
535:
536:            /**
537:             * Returns a ModelMBeanNotificationInfo requested by name.
538:             *
539:             * @param name The name of the ModelMBeanNotificationInfo to get.
540:             *
541:             * @exception MBeanException Wraps another exception
542:             * @exception RuntimeOperationsException Wraps another exception
543:             *
544:             */
545:            public ModelMBeanNotificationInfo getNotification(String name)
546:                    throws MBeanException, RuntimeOperationsException {
547:                if (modelMBeanNotifications == null)
548:                    return null;
549:                if (name == null)
550:                    throw new RuntimeOperationsException(
551:                            new IllegalArgumentException(
552:                                    "Notification name is null"),
553:                            "Exception occured trying get the ModelMBeanNotificationInfo of the MBean");
554:
555:                ModelMBeanNotificationInfo notificationInfo = null;
556:                for (int i = 0; i < modelMBeanNotifications.length; i++) {
557:                    if (name.equals(modelMBeanNotifications[i].getName())) {
558:                        notificationInfo = (ModelMBeanNotificationInfo) modelMBeanNotifications[i]
559:                                .clone();
560:                        break;
561:                    }
562:                }
563:                return notificationInfo;
564:            }
565:
566:            /**
567:             * Returns the list of  attributes exposed for management as ModelMBeanAttributeInfo objects.
568:             * This method signature must specify MBeanAttributeInfo to be compliant with the
569:             * the DynamicMBean interface.
570:             * @return MBeanAttributeInfo object array.
571:             */
572:            public MBeanAttributeInfo[] getAttributes() {
573:                if (modelMBeanAttributes == null)
574:                    return new MBeanAttributeInfo[0];
575:                MBeanAttributeInfo[] attributeInfos = new MBeanAttributeInfo[modelMBeanAttributes.length];
576:                for (int i = 0; i < modelMBeanAttributes.length; i++)
577:                    attributeInfos[i] = (MBeanAttributeInfo) modelMBeanAttributes[i]
578:                            .clone();
579:
580:                return attributeInfos;
581:            }
582:
583:            /**
584:             * Returns the list of operations exposed for management as ModelMBeanOperationInfo objects.
585:             * This method signature must specify MBeanOperationInfo to be compliant with the
586:             * the DynamicMBean interface.
587:             * @return  MBeanOperationInfo object array.
588:             */
589:            public MBeanOperationInfo[] getOperations() {
590:                if (modelMBeanOperations == null)
591:                    return new MBeanOperationInfo[0];
592:                MBeanOperationInfo[] operationInfos = new MBeanOperationInfo[modelMBeanOperations.length];
593:                for (int i = 0; i < modelMBeanOperations.length; i++)
594:                    operationInfos[i] = (MBeanOperationInfo) modelMBeanOperations[i]
595:                            .clone();
596:
597:                return operationInfos;
598:            }
599:
600:            /**
601:             * Returns the list of constructors exposed for management as ModelMBeanConstructorInfo objects.
602:             * This method signature must specify MBeanConstructorInfo to be compliant with the
603:             * the DynamicMBean interface.
604:             * @return  MBeanConstructorInfo object array.
605:             */
606:            public MBeanConstructorInfo[] getConstructors() {
607:                if (modelMBeanConstructors == null)
608:                    return new MBeanConstructorInfo[0];
609:                MBeanConstructorInfo[] constructorInfos = new MBeanConstructorInfo[modelMBeanConstructors.length];
610:                for (int i = 0; i < modelMBeanConstructors.length; i++)
611:                    constructorInfos[i] = (MBeanConstructorInfo) modelMBeanConstructors[i]
612:                            .clone();
613:
614:                return constructorInfos;
615:            }
616:
617:            /**
618:             * Returns the list of notifications exposed for management as ModelMBeanNotificationInfo objects.
619:             * This method signature must specify MBeanNotificationInfo to be compliant with the
620:             * the DynamicMBean interface.
621:             * @return  MBeanNotificationInfo object array.
622:             */
623:            public MBeanNotificationInfo[] getNotifications() {
624:                if (modelMBeanNotifications == null)
625:                    return new MBeanNotificationInfo[0];
626:                MBeanNotificationInfo[] notificationInfos = new MBeanNotificationInfo[modelMBeanNotifications.length];
627:                for (int i = 0; i < modelMBeanNotifications.length; i++)
628:                    notificationInfos[i] = (MBeanNotificationInfo) modelMBeanNotifications[i]
629:                            .clone();
630:
631:                return notificationInfos;
632:            }
633:
634:            /**
635:             * Returns the ModelMBean's descriptor which contains mbean wide policies.  This descriptor contains
636:             * metadata about the MBean and default policies for persistence and caching.
637:             * <P> <PRE>
638:             * The fields in the descriptor are defined, but not limited to, the following:
639:             * name           : mbean name
640:             * descriptorType : must be "mbean"
641:             * displayName    : name of attribute to be used in displays
642:             * persistPolicy  : OnUpdate|OnTimer|NoMoreOftenThan|Always|Never
643:             * persistLocation : The fully qualified directory name where the MBean should be persisted (if appropriate)
644:             * persistFile    : File name into which the MBean should be persisted
645:             * persistPeriod  : seconds - frequency of persist cycle for OnTime and NoMoreOftenThan PersistPolicy
646:             * persistLocation : directory name in which to store mbeans that support the PersistentMBean interface
647:             * currencyTimeLimit : how long value is valid, <0 never, =0 always, >0 seconds
648:             * log            : where t: log all notifications f: log no notifications
649:             * logfile        : fully qualified filename to log events to
650:             * visibility     : 1-4 where 1: always visible 4: rarely visible
651:             * export         : name to be used to export/expose this MBean so that it is findable by
652:             *                  other JMX Agents.
653:             * presentationString : xml formatted string to allow presentation of data to be associated with the MBean.
654:             * </PRE>
655:             * <P>
656:             * The default descriptor is: name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
657:             *	persistPolicy=never,log=F,export=F,visiblity=1
658:             * If the descriptor does not contain all these fields, they will be added with these default values.
659:             *
660:             * @exception MBeanException Wraps another exception
661:             * @exception RuntimeOperationsException Wraps another exception
662:             *
663:             */
664:            public Descriptor getMBeanDescriptor() throws MBeanException,
665:                    RuntimeOperationsException {
666:                if (modelMBeanDescriptor == null)
667:                    return null;
668:                return (Descriptor) modelMBeanDescriptor.clone();
669:            }
670:
671:            /**
672:             * Sets the ModelMBean's descriptor.  This descriptor contains default, mbean wide
673:             * metadata about the MBean and default policies for persistence and caching. This operation
674:             * does a complete replacement of the descriptor, no merging is done. If the descriptor to
675:             * set to is invalid then the existing or default descriptor will be preserved.
676:             * The default descriptor is: name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
677:             *	persistPolicy=never,log=F,export=F,visiblity=1
678:             * If the descriptor does not contain all these fields, they will be added with these default values.
679:             *
680:             * See getMBeanDescriptor method javadoc for description of valid field names.
681:             *
682:             * @exception MBeanException Wraps another exception
683:             * @exception RuntimeOperationsException Wraps another exception for bad descriptor.
684:             *
685:             */
686:            public void setMBeanDescriptor(Descriptor descriptor)
687:                    throws MBeanException, RuntimeOperationsException {
688:                if (descriptor == null) {
689:                    modelMBeanDescriptor = createDefaultDescriptor();
690:                } else if (isValidDescriptor(descriptor))
691:                    modelMBeanDescriptor = (Descriptor) descriptor.clone();
692:                else
693:                    throw new RuntimeOperationsException(
694:                            new IllegalArgumentException(
695:                                    "Invalid descriptor passed in parameter"));
696:            }
697:
698:            /* The default descriptor is:
699:             * name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
700:             *	persistPolicy=never,log=F,export=F,visiblity=1
701:             */
702:            private Descriptor createDefaultDescriptor() {
703:                DescriptorSupport descriptorsupport = null;
704:                descriptorsupport = new DescriptorSupport(new String[] {
705:                        DescriptorConstants.NAME + "=" + getClassName(),
706:                        DescriptorConstants.DESCRIPTORTYPE + "="
707:                                + DescriptorConstants.MBEAN_TYPE,
708:                        DescriptorConstants.DISPLAYNAME + "=" + getClassName(),
709:                        DescriptorConstants.PERSISTPOLICY + "="
710:                                + DescriptorConstants.PERSISTPOLICY_NEVER,
711:                        DescriptorConstants.LOG + "="
712:                                + DescriptorConstants.FALSE,
713:                        DescriptorConstants.EXPORT + "="
714:                                + DescriptorConstants.FALSE,
715:                        DescriptorConstants.VISIBILITY + "="
716:                                + DescriptorConstants.VISIBILITY_LARGEST });
717:                return descriptorsupport;
718:            }
719:
720:            /*
721:             * Validates the ModelMBeanDescriptor
722:             * If the descriptor does not contain all these fields, they will be added with these default values.
723:             * name=mbeanName,descriptorType=mbean, displayName=this.getClassName(),
724:             *	persistPolicy=never,log=F,export=F,visiblity=1
725:             *
726:             * Will return false if the MBeanDescriptor has a null name or descriptorType.
727:             */
728:            private boolean isValidDescriptor(Descriptor descriptor) {
729:                boolean isValid = true;
730:                if (descriptor == null) {
731:                    isValid = false;
732:                } else if (!descriptor.isValid()) {
733:                    isValid = false;
734:                }
735:                if ((String) descriptor.getFieldValue(DescriptorConstants.NAME) == null) {
736:                    isValid = false;
737:                } else if (!((String) descriptor
738:                        .getFieldValue(DescriptorConstants.DESCRIPTORTYPE))
739:                        .equalsIgnoreCase(DescriptorConstants.MBEAN_TYPE)) {
740:                    isValid = false;
741:                } else if (descriptor
742:                        .getFieldValue(DescriptorConstants.DISPLAYNAME) == null)
743:                    descriptor.setField(DescriptorConstants.DISPLAYNAME,
744:                            getClassName());
745:                else if (descriptor
746:                        .getFieldValue(DescriptorConstants.PERSISTPOLICY) == null)
747:                    descriptor.setField(DescriptorConstants.PERSISTPOLICY,
748:                            DescriptorConstants.PERSISTPOLICY_NEVER);
749:                else if (descriptor.getFieldValue(DescriptorConstants.LOG) == null)
750:                    descriptor.setField(DescriptorConstants.LOG,
751:                            DescriptorConstants.FALSE);
752:                else if (descriptor.getFieldValue(DescriptorConstants.EXPORT) == null)
753:                    descriptor.setField(DescriptorConstants.EXPORT,
754:                            DescriptorConstants.FALSE);
755:                else if (descriptor
756:                        .getFieldValue(DescriptorConstants.VISIBILITY) == null)
757:                    descriptor.setField(DescriptorConstants.VISIBILITY,
758:                            DescriptorConstants.VISIBILITY_LARGEST + "");
759:                return isValid;
760:            }
761:
762:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.