001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management.compliance.serialization.support;
010:
011: import java.lang.reflect.Constructor;
012: import java.util.ArrayList;
013: import javax.management.Attribute;
014: import javax.management.AttributeChangeNotification;
015: import javax.management.AttributeChangeNotificationFilter;
016: import javax.management.AttributeList;
017: import javax.management.AttributeNotFoundException;
018: import javax.management.AttributeValueExp;
019: import javax.management.BadAttributeValueExpException;
020: import javax.management.BadBinaryOpValueExpException;
021: import javax.management.BadStringOperationException;
022: import javax.management.Descriptor;
023: import javax.management.InstanceAlreadyExistsException;
024: import javax.management.InstanceNotFoundException;
025: import javax.management.IntrospectionException;
026: import javax.management.InvalidApplicationException;
027: import javax.management.InvalidAttributeValueException;
028: import javax.management.JMException;
029: import javax.management.JMRuntimeException;
030: import javax.management.ListenerNotFoundException;
031: import javax.management.MBeanAttributeInfo;
032: import javax.management.MBeanConstructorInfo;
033: import javax.management.MBeanException;
034: import javax.management.MBeanFeatureInfo;
035: import javax.management.MBeanInfo;
036: import javax.management.MBeanNotificationInfo;
037: import javax.management.MBeanOperationInfo;
038: import javax.management.MBeanParameterInfo;
039: import javax.management.MBeanPermission;
040: import javax.management.MBeanRegistrationException;
041: import javax.management.MBeanServerDelegate;
042: import javax.management.MBeanServerNotification;
043: import javax.management.MBeanServerPermission;
044: import javax.management.MBeanTrustPermission;
045: import javax.management.MalformedObjectNameException;
046: import javax.management.NotCompliantMBeanException;
047: import javax.management.Notification;
048: import javax.management.NotificationBroadcasterSupport;
049: import javax.management.NotificationFilterSupport;
050: import javax.management.ObjectInstance;
051: import javax.management.ObjectName;
052: import javax.management.OperationsException;
053: import javax.management.Query;
054: import javax.management.QueryExp;
055: import javax.management.ReflectionException;
056: import javax.management.RuntimeErrorException;
057: import javax.management.RuntimeMBeanException;
058: import javax.management.RuntimeOperationsException;
059: import javax.management.ServiceNotFoundException;
060: import javax.management.StringValueExp;
061: import javax.management.ValueExp;
062: import javax.management.modelmbean.DescriptorSupport;
063: import javax.management.modelmbean.InvalidTargetObjectTypeException;
064: import javax.management.modelmbean.ModelMBean;
065: import javax.management.modelmbean.ModelMBeanAttributeInfo;
066: import javax.management.modelmbean.ModelMBeanConstructorInfo;
067: import javax.management.modelmbean.ModelMBeanInfo;
068: import javax.management.modelmbean.ModelMBeanInfoSupport;
069: import javax.management.modelmbean.ModelMBeanNotificationBroadcaster;
070: import javax.management.modelmbean.ModelMBeanNotificationInfo;
071: import javax.management.modelmbean.ModelMBeanOperationInfo;
072: import javax.management.modelmbean.XMLParseException;
073: import javax.management.monitor.MonitorNotification;
074: import javax.management.monitor.MonitorSettingException;
075: import javax.management.openmbean.ArrayType;
076: import javax.management.openmbean.CompositeDataSupport;
077: import javax.management.openmbean.CompositeType;
078: import javax.management.openmbean.InvalidKeyException;
079: import javax.management.openmbean.InvalidOpenTypeException;
080: import javax.management.openmbean.KeyAlreadyExistsException;
081: import javax.management.openmbean.OpenDataException;
082: import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
083: import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
084: import javax.management.openmbean.OpenMBeanInfoSupport;
085: import javax.management.openmbean.OpenMBeanOperationInfo;
086: import javax.management.openmbean.OpenMBeanOperationInfoSupport;
087: import javax.management.openmbean.OpenMBeanParameterInfo;
088: import javax.management.openmbean.OpenMBeanParameterInfoSupport;
089: import javax.management.openmbean.OpenType;
090: import javax.management.openmbean.SimpleType;
091: import javax.management.openmbean.TabularDataSupport;
092: import javax.management.openmbean.TabularType;
093: import javax.management.relation.InvalidRelationIdException;
094: import javax.management.relation.InvalidRelationServiceException;
095: import javax.management.relation.InvalidRelationTypeException;
096: import javax.management.relation.InvalidRoleInfoException;
097: import javax.management.relation.InvalidRoleValueException;
098: import javax.management.relation.MBeanServerNotificationFilter;
099: import javax.management.relation.Relation;
100: import javax.management.relation.RelationException;
101: import javax.management.relation.RelationNotFoundException;
102: import javax.management.relation.RelationNotification;
103: import javax.management.relation.RelationService;
104: import javax.management.relation.RelationServiceNotRegisteredException;
105: import javax.management.relation.RelationType;
106: import javax.management.relation.RelationTypeNotFoundException;
107: import javax.management.relation.RelationTypeSupport;
108: import javax.management.relation.Role;
109: import javax.management.relation.RoleInfo;
110: import javax.management.relation.RoleInfoNotFoundException;
111: import javax.management.relation.RoleList;
112: import javax.management.relation.RoleNotFoundException;
113: import javax.management.relation.RoleResult;
114: import javax.management.relation.RoleStatus;
115: import javax.management.relation.RoleUnresolved;
116: import javax.management.relation.RoleUnresolvedList;
117: import javax.management.timer.TimerNotification;
118:
119: /**
120: * @version $Revision: 1.12 $
121: */
122: public class Instantiator {
123: //
124: // JAVAX.MANAGEMENT
125: //
126:
127: public QueryExp createAndQueryExp() {
128: return Query.and(createBetweenQueryExp(),
129: createBinaryRelQueryExp());
130: }
131:
132: public Attribute createAttribute() {
133: return new Attribute("attr-name", "attr-value");
134: }
135:
136: public AttributeChangeNotification createAttributeChangeNotification() {
137: AttributeChangeNotification notification = new AttributeChangeNotification(
138: "notif-source", 13L, System.currentTimeMillis(),
139: "notif-message", "attr-name", "attr-type", "old", "new");
140: notification.setUserData("notif-user");
141: return notification;
142: }
143:
144: public AttributeChangeNotificationFilter createAttributeChangeNotificationFilter() {
145: AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
146: filter.enableAttribute("attribute-name");
147: return filter;
148: }
149:
150: public AttributeList createAttributeList() {
151: AttributeList list = new AttributeList();
152: list.add(createAttribute());
153: return list;
154: }
155:
156: public AttributeNotFoundException createAttributeNotFoundException() {
157: return new AttributeNotFoundException(
158: "AttributeNotFoundException");
159: }
160:
161: public AttributeValueExp createAttributeValueExp() {
162: return new AttributeValueExp("attribute");
163: }
164:
165: public BadAttributeValueExpException createBadAttributeValueExpException() {
166: return new BadAttributeValueExpException(
167: "BadAttributeValueExpException");
168: }
169:
170: public BadBinaryOpValueExpException createBadBinaryOpValueExpException() {
171: return new BadBinaryOpValueExpException(createStringValueExp());
172: }
173:
174: public BadStringOperationException createBadStringOperationException() {
175: return new BadStringOperationException(
176: "BadStringOperationException");
177: }
178:
179: public QueryExp createBetweenQueryExp() {
180: return Query.between(Query.value(5), Query.value(3), Query
181: .value(7));
182: }
183:
184: public ValueExp createBinaryOpValueExp() {
185: return Query.plus(Query.value(2), Query.value(5));
186: }
187:
188: public QueryExp createBinaryRelQueryExp() {
189: return Query.eq(Query.value("simon"), Query.value("simon"));
190: }
191:
192: public ValueExp createBooleanValueExp() {
193: return Query.value(true);
194: }
195:
196: public ValueExp createClassAttributeValueExp() {
197: return Query.classattr();
198: }
199:
200: public Descriptor createDescriptor() {
201: throw new Error();
202: }
203:
204: public QueryExp createInQueryExp() {
205: return Query.in(Query.value(4), new ValueExp[] {
206: Query.value(3), Query.value(4), Query.value(5) });
207: }
208:
209: public InstanceAlreadyExistsException createInstanceAlreadyExistsException() {
210: return new InstanceAlreadyExistsException(
211: "InstanceAlreadyExistsException");
212: }
213:
214: public InstanceNotFoundException createInstanceNotFoundException() {
215: return new InstanceNotFoundException(
216: "InstanceNotFoundException");
217: }
218:
219: public IntrospectionException createIntrospectionException() {
220: return new IntrospectionException("IntrospectionException");
221: }
222:
223: public InvalidApplicationException createInvalidApplicationException() {
224: return new InvalidApplicationException(
225: "InvalidApplicationException");
226: }
227:
228: public InvalidAttributeValueException createInvalidAttributeValueException() {
229: return new InvalidAttributeValueException(
230: "InvalidAttributeValueException");
231: }
232:
233: public JMException createJMException() {
234: return new JMException("JMException");
235: }
236:
237: public JMRuntimeException createJMRuntimeException() {
238: return new JMRuntimeException("JMRuntimeException");
239: }
240:
241: public ListenerNotFoundException createListenerNotFoundException() {
242: return new ListenerNotFoundException(
243: "ListenerNotFoundException");
244: }
245:
246: public MalformedObjectNameException createMalformedObjectNameException() {
247: return new MalformedObjectNameException(
248: "MalformedObjectNameException");
249: }
250:
251: public QueryExp createMatchQueryExp() {
252: return Query.match(createAttributeValueExp(),
253: createStringValueExp());
254: }
255:
256: public MBeanAttributeInfo createMBeanAttributeInfo() {
257: return new MBeanAttributeInfo("name", "boolean", "description",
258: true, true, true);
259: }
260:
261: public MBeanConstructorInfo createMBeanConstructorInfo() {
262: return new MBeanConstructorInfo("name", "description",
263: new MBeanParameterInfo[] { createMBeanParameterInfo() });
264: }
265:
266: public MBeanException createMBeanException() {
267: return new MBeanException(new NullPointerException(
268: "NullPointerException"), "MBeanException");
269: }
270:
271: public MBeanFeatureInfo createMBeanFeatureInfo() {
272: return new MBeanFeatureInfo("name", "description");
273: }
274:
275: public MBeanInfo createMBeanInfo() {
276: return new MBeanInfo(
277: "my.class.name",
278: "description",
279: new MBeanAttributeInfo[] { createMBeanAttributeInfo() },
280: new MBeanConstructorInfo[] { createMBeanConstructorInfo() },
281: new MBeanOperationInfo[] { createMBeanOperationInfo() },
282: new MBeanNotificationInfo[] { createMBeanNotificationInfo() });
283: }
284:
285: public MBeanNotificationInfo createMBeanNotificationInfo() {
286: return new MBeanNotificationInfo(new String[] { "type1",
287: "type2" }, "name", "description");
288: }
289:
290: public MBeanOperationInfo createMBeanOperationInfo() {
291: return new MBeanOperationInfo(
292: "name",
293: "description",
294: new MBeanParameterInfo[] { createMBeanParameterInfo() },
295: "java.lang.Exception", MBeanOperationInfo.UNKNOWN);
296: }
297:
298: public MBeanParameterInfo createMBeanParameterInfo() {
299: return new MBeanParameterInfo("name", "java.lang.Object",
300: "description");
301: }
302:
303: public MBeanPermission createMBeanPermission()
304: throws MalformedObjectNameException {
305: return new MBeanPermission("className", "methodName",
306: createObjectName(), "instantiate,registerMBean");
307: }
308:
309: public MBeanRegistrationException createMBeanRegistrationException() {
310: return new MBeanRegistrationException(new NullPointerException(
311: "NullPointerException"), "MBeanRegistrationException");
312: }
313:
314: public MBeanServerDelegate createMBeanServerDelegate() {
315: return new MBeanServerDelegate();
316: }
317:
318: public MBeanServerNotification createMBeanServerNotification()
319: throws MalformedObjectNameException {
320: MBeanServerNotification n = new MBeanServerNotification(
321: MBeanServerNotification.REGISTRATION_NOTIFICATION,
322: "notif-source", 13L, new ObjectName(":key=value"));
323: n.setUserData("user-data");
324: return n;
325: }
326:
327: public MBeanServerPermission createMBeanServerPermission() {
328: return new MBeanServerPermission("newMBeanServer");
329: }
330:
331: public MBeanTrustPermission createMBeanTrustPermission() {
332: return new MBeanTrustPermission("register");
333: }
334:
335: public NotCompliantMBeanException createNotCompliantMBeanException() {
336: return new NotCompliantMBeanException(
337: "NotCompliantMBeanException");
338: }
339:
340: public Notification createNotification() {
341: Notification notification = new Notification("notif-type",
342: "notif-source", 13L, System.currentTimeMillis(),
343: "notif-message");
344: notification.setUserData("notif-user");
345: return notification;
346: }
347:
348: public NotificationBroadcasterSupport createNotificationBroadcasterSupport() {
349: return new NotificationBroadcasterSupport();
350: }
351:
352: public NotificationFilterSupport createNotificationFilterSupport() {
353: NotificationFilterSupport filter = new NotificationFilterSupport();
354: filter.enableType("notif-type");
355: return filter;
356: }
357:
358: public QueryExp createNotQueryExp() {
359: return Query.not(Query.eq(Query.value("simon"), Query
360: .value("bordet")));
361: }
362:
363: public ValueExp createNumericValueExp() {
364: return Query.value(1);
365: }
366:
367: public ObjectInstance createObjectInstance()
368: throws MalformedObjectNameException {
369: return new ObjectInstance(new ObjectName("domain:p1=v1"),
370: "java.lang.Object");
371: }
372:
373: public ObjectName createObjectName()
374: throws MalformedObjectNameException {
375: return new ObjectName("domain?:p2=v2,*,p1=v1");
376: }
377:
378: public OperationsException createOperationsException() {
379: return new OperationsException("OperationsException");
380: }
381:
382: public QueryExp createOrQueryExp() {
383: return Query.or(createBetweenQueryExp(),
384: createBinaryRelQueryExp());
385: }
386:
387: public AttributeValueExp createQualifiedAttributeValueExp() {
388: return Query.attr("mx4j.Foo", "attribute");
389: }
390:
391: public ReflectionException createReflectionException() {
392: return new ReflectionException(new NullPointerException(
393: "NullPointerException"), "ReflectionException");
394: }
395:
396: public RuntimeErrorException createRuntimeErrorException() {
397: return new RuntimeErrorException(new Error("Error"),
398: "RuntimeErrorException");
399: }
400:
401: public RuntimeMBeanException createRuntimeMBeanException() {
402: return new RuntimeMBeanException(new NullPointerException(
403: "NullPointerException"), "RuntimeMBeanException");
404: }
405:
406: public RuntimeOperationsException createRuntimeOperationsException() {
407: return new RuntimeOperationsException(new NullPointerException(
408: "NullPointerException"), "RuntimeOperationsException");
409: }
410:
411: public ServiceNotFoundException createServiceNotFoundException() {
412: return new ServiceNotFoundException("ServiceNotFoundException");
413: }
414:
415: public StringValueExp createStringValueExp() {
416: return new StringValueExp("StringValueExp");
417: }
418:
419: //
420: // JAVAX.MANAGEMENT.MODELMBEAN
421: //
422:
423: public DescriptorSupport createDescriptorSupport() {
424: return new DescriptorSupport(new String[] { "name" },
425: new Object[] { "value" });
426: }
427:
428: public InvalidTargetObjectTypeException createInvalidTargetObjectTypeException() {
429: return new InvalidTargetObjectTypeException(
430: new NullPointerException("NullPointerException"),
431: "InvalidTargetObjectTypeException");
432: }
433:
434: public ModelMBean createModelMBean() {
435: throw new Error();
436: }
437:
438: public ModelMBeanAttributeInfo createModelMBeanAttributeInfo() {
439: String[] names = new String[] { "name", "descriptortype",
440: "value", "iterable", "displayname" };
441: Object[] values = new Object[] { "name", "attribute", null,
442: "false", "name" };
443: DescriptorSupport descriptor = new DescriptorSupport(names,
444: values);
445: return new ModelMBeanAttributeInfo("name", "boolean",
446: "description", true, true, true, descriptor);
447: }
448:
449: public ModelMBeanConstructorInfo createModelMBeanConstructorInfo() {
450: String[] names = new String[] { "name", "descriptortype",
451: "role", "displayname"/*, "lastReturnedTimeStamp"*/};
452: Object[] values = new Object[] { "name", "operation",
453: "constructor", "name"/*, "0"*/};
454: DescriptorSupport descriptor = new DescriptorSupport(names,
455: values);
456: return new ModelMBeanConstructorInfo(
457: "name",
458: "description",
459: new MBeanParameterInfo[] { createMBeanParameterInfo() },
460: descriptor);
461: }
462:
463: public ModelMBeanInfo createModelMBeanInfo() {
464: throw new Error();
465: }
466:
467: public ModelMBeanInfoSupport createModelMBeanInfoSupport() {
468: String[] names = new String[] { "name", "descriptortype",
469: "displayname", "persistpolicy", "log", "export",
470: "visibility" };
471: Object[] values = new Object[] { "name", "MBean", "name",
472: "Never", "false", "F", "1" };
473: DescriptorSupport descriptor = new DescriptorSupport(names,
474: values);
475: return new ModelMBeanInfoSupport(
476: "my.class.name",
477: "description",
478: new ModelMBeanAttributeInfo[] { createModelMBeanAttributeInfo() },
479: new ModelMBeanConstructorInfo[] { createModelMBeanConstructorInfo() },
480: new ModelMBeanOperationInfo[] { createModelMBeanOperationInfo() },
481: new ModelMBeanNotificationInfo[] { createModelMBeanNotificationInfo() },
482: descriptor);
483: }
484:
485: public ModelMBeanNotificationBroadcaster createModelMBeanNotificationBroadcaster() {
486: throw new Error();
487: }
488:
489: public ModelMBeanNotificationInfo createModelMBeanNotificationInfo() {
490: String[] names = new String[] { "name", "descriptortype",
491: "severity", "displayname"/*, "messageId", "log", "logfile"*/};
492: Object[] values = new Object[] { "name", "notification", "5",
493: "name"/*, "0", "???", "???"*/};
494: DescriptorSupport descriptor = new DescriptorSupport(names,
495: values);
496: return new ModelMBeanNotificationInfo(new String[] { "type1",
497: "type2" }, "name", "description", descriptor);
498: }
499:
500: public ModelMBeanOperationInfo createModelMBeanOperationInfo() {
501: String[] names = new String[] { "name", "descriptortype",
502: "role", "displayname"/*, "lastReturnedTimeStamp"*/};
503: Object[] values = new Object[] { "name", "operation",
504: "operation", "name"/*, "0"*/};
505: DescriptorSupport descriptor = new DescriptorSupport(names,
506: values);
507: return new ModelMBeanOperationInfo(
508: "name",
509: "description",
510: new MBeanParameterInfo[] { createMBeanParameterInfo() },
511: "java.lang.Object", MBeanOperationInfo.UNKNOWN,
512: descriptor);
513: }
514:
515: public XMLParseException createXMLParseException() {
516: return new XMLParseException("XMLParseException");
517: }
518:
519: //
520: // JAVAX.MANAGEMENT.MONITOR
521: //
522:
523: public MonitorNotification createMonitorNotification()
524: throws Exception {
525: Constructor ctor = MonitorNotification.class
526: .getDeclaredConstructor(new Class[] { String.class,
527: Object.class, long.class, long.class,
528: String.class, ObjectName.class, String.class,
529: Object.class, Object.class });
530: ctor.setAccessible(true);
531: MonitorNotification notification = (MonitorNotification) ctor
532: .newInstance(new Object[] { "type", "source",
533: new Long(13),
534: new Long(System.currentTimeMillis()),
535: "message", new ObjectName("domain:p1=v1"),
536: "attribute", "gauge", "trigger" });
537: notification.setUserData("user");
538: return notification;
539: }
540:
541: public MonitorSettingException createMonitorSettingException() {
542: return new MonitorSettingException("MonitorSettingException");
543: }
544:
545: //
546: // JAVAX.MANAGEMENT.OPENMBEAN
547: //
548:
549: public ArrayType createArrayType() throws OpenDataException {
550: return new ArrayType(5, SimpleType.BIGDECIMAL);
551: }
552:
553: public CompositeDataSupport createCompositeDataSupport()
554: throws OpenDataException {
555: CompositeType ct = createCompositeType();
556: return new CompositeDataSupport(ct, new String[] { "key1",
557: "key2" }, new Object[] { "value1", "value2" });
558: }
559:
560: public CompositeType createCompositeType() throws OpenDataException {
561: return new CompositeType("composite1", "description1",
562: new String[] { "key1", "key2" }, new String[] { "d1",
563: "d2" }, new OpenType[] { SimpleType.STRING,
564: SimpleType.STRING });
565: }
566:
567: public InvalidKeyException createInvalidKeyException() {
568: return new InvalidKeyException("InvalidKeyException");
569: }
570:
571: public InvalidOpenTypeException createInvalidOpenTypeException() {
572: return new InvalidOpenTypeException("InvalidOpenTypeException");
573: }
574:
575: public KeyAlreadyExistsException createKeyAlreadyExistsException() {
576: return new KeyAlreadyExistsException(
577: "KeyAlreadyExistsException");
578: }
579:
580: public OpenDataException createOpenDataException() {
581: return new OpenDataException("OpenDataException");
582: }
583:
584: public OpenMBeanAttributeInfoSupport createOpenMBeanAttributeInfoSupport() {
585: return new OpenMBeanAttributeInfoSupport("attrib",
586: "An Attribute", SimpleType.STRING, true, true, false);
587: }
588:
589: public OpenMBeanConstructorInfoSupport createOpenMBeanConstructorInfoSupport() {
590: return new OpenMBeanConstructorInfoSupport(
591: "const",
592: "a constructor",
593: new OpenMBeanParameterInfoSupport[] { createOpenMBeanParameterInfoSupport() });
594: }
595:
596: public OpenMBeanInfoSupport createOpenMBeanInfoSupport()
597: throws OpenDataException {
598: OpenMBeanAttributeInfoSupport[] attrInfo = new OpenMBeanAttributeInfoSupport[] { createOpenMBeanAttributeInfoSupport() };
599: OpenMBeanConstructorInfoSupport[] ctorInfo = new OpenMBeanConstructorInfoSupport[] { createOpenMBeanConstructorInfoSupport() };
600: OpenMBeanOperationInfo[] operInfo = new OpenMBeanOperationInfoSupport[] { createOpenMBeanOperationInfoSupport() };
601: MBeanNotificationInfo[] notifInfo = new MBeanNotificationInfo[] { new MBeanNotificationInfo(
602: new String[] { "notif1", "notif2" }, "name",
603: "description") };
604: return new OpenMBeanInfoSupport("test.class.Name",
605: "description1", attrInfo, ctorInfo, operInfo, notifInfo);
606: }
607:
608: public OpenMBeanOperationInfoSupport createOpenMBeanOperationInfoSupport() {
609: return new OpenMBeanOperationInfoSupport(
610: "operation",
611: "A operation",
612: new OpenMBeanParameterInfo[] { createOpenMBeanParameterInfoSupport() },
613: SimpleType.STRING, MBeanOperationInfo.ACTION);
614: }
615:
616: public OpenMBeanParameterInfoSupport createOpenMBeanParameterInfoSupport() {
617: return new OpenMBeanParameterInfoSupport("param1", "A param",
618: SimpleType.STRING);
619: }
620:
621: public SimpleType createSimpleType() {
622: return SimpleType.STRING;
623: }
624:
625: public TabularDataSupport createTabularDataSupport()
626: throws OpenDataException {
627: return new TabularDataSupport(createTabularType());
628: }
629:
630: public TabularType createTabularType() throws OpenDataException {
631: return new TabularType("typename", "descr1",
632: createCompositeType(), new String[] { "key1", "key2" });
633: }
634:
635: //
636: // JAVAX.MANAGEMENT.RELATION
637: //
638:
639: public InvalidRelationIdException createInvalidRelationIdException() {
640: return new InvalidRelationIdException(
641: "InvalidRelationIdException");
642: }
643:
644: public InvalidRelationServiceException createInvalidRelationServiceException() {
645: return new InvalidRelationServiceException(
646: "InvalidRelationServiceException");
647: }
648:
649: public InvalidRelationTypeException createInvalidRelationTypeException() {
650: return new InvalidRelationTypeException(
651: "InvalidRelationTypeException");
652: }
653:
654: public InvalidRoleInfoException createInvalidRoleInfoException() {
655: return new InvalidRoleInfoException("InvalidRoleInfoException");
656: }
657:
658: public InvalidRoleValueException createInvalidRoleValueException() {
659: return new InvalidRoleValueException(
660: "InvalidRoleValueException");
661: }
662:
663: public MBeanServerNotificationFilter createMBeanServerNotificationFilter()
664: throws MalformedObjectNameException {
665: MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
666: filter.enableType("notif-type");
667: filter.disableAllObjectNames();
668: filter.enableObjectName(new ObjectName("domain:key=val"));
669: return filter;
670: }
671:
672: public Relation createRelation() {
673: throw new Error();
674: }
675:
676: public RelationException createRelationException() {
677: return new RelationException("RelationException");
678: }
679:
680: public RelationNotFoundException createRelationNotFoundException() {
681: return new RelationNotFoundException(
682: "RelationNotFoundException");
683: }
684:
685: public RelationNotification createRelationNotification()
686: throws MalformedObjectNameException {
687: try {
688: // MX4J version
689: RelationNotification n = new RelationNotification(
690: RelationNotification.RELATION_BASIC_UPDATE,
691: "source", 13L, System.currentTimeMillis(),
692: "message", "relation-id", "relation-type",
693: new ObjectName(":key=value"), "role-name",
694: createRoleList(), createRoleUnresolvedList());
695: n.setUserData("user-data");
696: return n;
697: } catch (IllegalArgumentException x) {
698: // JMXRI version
699: RelationNotification n = new RelationNotification(
700: RelationNotification.RELATION_BASIC_UPDATE,
701: new RelationService(true), 13L, System
702: .currentTimeMillis(), "message",
703: "relation-id", "relation-type", new ObjectName(
704: ":key=value"), "role-name",
705: createRoleList(), createRoleUnresolvedList());
706: n.setUserData("user-data");
707: n.setSource("source");
708: return n;
709: }
710: }
711:
712: public RelationServiceNotRegisteredException createRelationServiceNotRegisteredException() {
713: return new RelationServiceNotRegisteredException(
714: "RelationServiceNotRegisteredException");
715: }
716:
717: public RelationTypeNotFoundException createRelationTypeNotFoundException() {
718: return new RelationTypeNotFoundException(
719: "RelationTypeNotFoundException");
720: }
721:
722: public RelationType createRelationType() {
723: throw new Error();
724: }
725:
726: public RelationTypeSupport createRelationTypeSupport()
727: throws InvalidRelationTypeException,
728: InvalidRoleInfoException, ClassNotFoundException,
729: NotCompliantMBeanException {
730: return new RelationTypeSupport("relation-type",
731: new RoleInfo[] { createRoleInfo() });
732: }
733:
734: public Role createRole() throws MalformedObjectNameException {
735: ArrayList list = new ArrayList();
736: list.add(new ObjectName("domain:key=value"));
737: return new Role("Role", list);
738: }
739:
740: public RoleInfo createRoleInfo() throws InvalidRoleInfoException,
741: ClassNotFoundException, NotCompliantMBeanException {
742: return new RoleInfo("RoleInfo",
743: "javax.management.MBeanServerDelegate", true, true, 13,
744: 17, "Description");
745: }
746:
747: public RoleInfoNotFoundException createRoleInfoNotFoundException() {
748: return new RoleInfoNotFoundException(
749: "RoleInfoNotFoundException");
750: }
751:
752: public RoleList createRoleList()
753: throws MalformedObjectNameException {
754: RoleList list = new RoleList();
755: list.add(createRole());
756: return list;
757: }
758:
759: public RoleNotFoundException createRoleNotFoundException() {
760: return new RoleNotFoundException("RoleNotFoundException");
761: }
762:
763: public RoleResult createRoleResult()
764: throws MalformedObjectNameException {
765: return new RoleResult(createRoleList(),
766: createRoleUnresolvedList());
767: }
768:
769: public RoleUnresolved createRoleUnresolved()
770: throws MalformedObjectNameException {
771: ArrayList list = new ArrayList();
772: list.add(new ObjectName("domain:key=value"));
773: return new RoleUnresolved("RoleName", list,
774: RoleStatus.NO_ROLE_WITH_NAME);
775: }
776:
777: public RoleUnresolvedList createRoleUnresolvedList()
778: throws MalformedObjectNameException {
779: RoleUnresolvedList list = new RoleUnresolvedList();
780: list.add(createRoleUnresolved());
781: return list;
782: }
783:
784: //
785: // JAVAX.MANAGEMENT.TIMER
786: //
787:
788: public TimerNotification createTimerNotification() throws Exception {
789: // First try MX4J version
790: try {
791: Constructor ctor = TimerNotification.class
792: .getDeclaredConstructor(new Class[] { String.class,
793: Object.class, String.class, Integer.class });
794: ctor.setAccessible(true);
795: TimerNotification notification = (TimerNotification) ctor
796: .newInstance(new Object[] { "type", "source",
797: "message", new Integer(13) });
798: notification.setUserData("user");
799: return notification;
800: } catch (NoSuchMethodException x) {
801: // Then try JMX RI version
802: Constructor ctor = TimerNotification.class
803: .getDeclaredConstructor(new Class[] { String.class,
804: Object.class, long.class, long.class,
805: String.class, Integer.class });
806: ctor.setAccessible(true);
807: TimerNotification notification = (TimerNotification) ctor
808: .newInstance(new Object[] { "type", "source",
809: new Long(0), new Long(0), "message",
810: new Integer(13) });
811: notification.setUserData("user");
812: return notification;
813: }
814: }
815: }
|