|
1 |
| package org.jconfig.jmx; |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| import java.util.Iterator; |
|
6 |
| |
|
7 |
| import javax.management.Attribute; |
|
8 |
| import javax.management.AttributeList; |
|
9 |
| import javax.management.DynamicMBean; |
|
10 |
| import javax.management.MBeanRegistration; |
|
11 |
| import javax.management.MBeanServer; |
|
12 |
| import javax.management.ObjectName; |
|
13 |
| import javax.management.RuntimeOperationsException; |
|
14 |
| |
|
15 |
| public abstract class AbstractDynamicMBean implements DynamicMBean, MBeanRegistration { |
|
16 |
| |
|
17 |
| String dClassName; |
|
18 |
| MBeanServer server; |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
0
| public AttributeList getAttributes(String[] attributeNames) {
|
|
24 |
| |
|
25 |
| |
|
26 |
0
| if (attributeNames == null) {
|
|
27 |
0
| throw new RuntimeOperationsException(
|
|
28 |
| new IllegalArgumentException("attributeNames[] cannot be null"), |
|
29 |
| "Cannot invoke a getter of " + dClassName); |
|
30 |
| } |
|
31 |
| |
|
32 |
0
| AttributeList resultList = new AttributeList();
|
|
33 |
| |
|
34 |
| |
|
35 |
0
| if (attributeNames.length == 0)
|
|
36 |
0
| return resultList;
|
|
37 |
| |
|
38 |
| |
|
39 |
0
| for (int i = 0; i < attributeNames.length; i++) {
|
|
40 |
0
| try {
|
|
41 |
0
| Object value = getAttribute((String) attributeNames[i]);
|
|
42 |
0
| resultList.add(new Attribute(attributeNames[i], value));
|
|
43 |
| } catch (Exception e) { |
|
44 |
0
| e.printStackTrace();
|
|
45 |
| } |
|
46 |
| } |
|
47 |
0
| return (resultList);
|
|
48 |
| } |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
0
| public AttributeList setAttributes(AttributeList attributes) {
|
|
55 |
| |
|
56 |
| |
|
57 |
0
| if (attributes == null) {
|
|
58 |
0
| throw new RuntimeOperationsException(
|
|
59 |
| new IllegalArgumentException("AttributeList attributes cannot be null"), |
|
60 |
| "Cannot invoke a setter of " + dClassName); |
|
61 |
| } |
|
62 |
0
| AttributeList resultList = new AttributeList();
|
|
63 |
| |
|
64 |
| |
|
65 |
0
| if (attributes.isEmpty())
|
|
66 |
0
| return resultList;
|
|
67 |
| |
|
68 |
| |
|
69 |
0
| for (Iterator i = attributes.iterator(); i.hasNext();) {
|
|
70 |
0
| Attribute attr = (Attribute) i.next();
|
|
71 |
0
| try {
|
|
72 |
0
| setAttribute(attr);
|
|
73 |
0
| String name = attr.getName();
|
|
74 |
0
| Object value = getAttribute(name);
|
|
75 |
0
| resultList.add(new Attribute(name, value));
|
|
76 |
| } catch (Exception e) { |
|
77 |
0
| e.printStackTrace();
|
|
78 |
| } |
|
79 |
| } |
|
80 |
0
| return (resultList);
|
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
0
| public void postDeregister() {
|
|
86 |
| |
|
87 |
| } |
|
88 |
| |
|
89 |
0
| public void postRegister(java.lang.Boolean registrationDone) {
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| public void preDeregister() {
|
|
93 |
| |
|
94 |
| } |
|
95 |
| |
|
96 |
0
| public ObjectName preRegister(MBeanServer server, ObjectName name) {
|
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
0
| this.server = server;
|
|
102 |
0
| return name;
|
|
103 |
| } |
|
104 |
| } |