OpenAnnotatedStandardMBean.java
6.67 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.jmx.annotation;
import com.adobe.granite.jmx.annotation.AnnotatedStandardMBean;
import com.adobe.granite.jmx.annotation.OpenTypeInfo;
import com.adobe.granite.jmx.annotation.OpenTypeUtils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.NotCompliantMBeanException;
import javax.management.openmbean.OpenMBeanAttributeInfo;
import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
import javax.management.openmbean.OpenMBeanConstructorInfo;
import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
import javax.management.openmbean.OpenMBeanInfoSupport;
import javax.management.openmbean.OpenMBeanOperationInfo;
import javax.management.openmbean.OpenMBeanOperationInfoSupport;
import javax.management.openmbean.OpenMBeanParameterInfo;
import javax.management.openmbean.OpenMBeanParameterInfoSupport;
import javax.management.openmbean.OpenType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class OpenAnnotatedStandardMBean
extends AnnotatedStandardMBean {
private static final Logger log = LoggerFactory.getLogger(OpenAnnotatedStandardMBean.class);
public <T> OpenAnnotatedStandardMBean(T implementation, Class<T> mbeanInterface) throws NotCompliantMBeanException {
super(implementation, mbeanInterface);
}
protected OpenAnnotatedStandardMBean(Class<?> mbeanInterface) throws NotCompliantMBeanException {
super(mbeanInterface);
}
@Override
public MBeanInfo getMBeanInfo() {
MBeanInfo info = super.getMBeanInfo();
try {
if (info instanceof OpenMBeanInfoSupport) {
return info;
}
MBeanAttributeInfo[] attrs = info.getAttributes();
OpenMBeanAttributeInfo[] openAttrs = new OpenMBeanAttributeInfo[attrs.length];
for (int i = 0; i < attrs.length; ++i) {
openAttrs[i] = this.convert(attrs[i]);
}
MBeanConstructorInfo[] consts = info.getConstructors();
OpenMBeanConstructorInfo[] openConsts = new OpenMBeanConstructorInfo[consts.length];
for (int i2 = 0; i2 < consts.length; ++i2) {
openConsts[i2] = this.convert(consts[i2]);
}
MBeanOperationInfo[] ops = info.getOperations();
OpenMBeanOperationInfo[] openOps = new OpenMBeanOperationInfo[ops.length];
for (int i3 = 0; i3 < ops.length; ++i3) {
openOps[i3] = this.convert(ops[i3]);
}
OpenMBeanInfoSupport open = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(), openAttrs, openConsts, openOps, info.getNotifications());
this.cacheMBeanInfo(open);
return open;
}
catch (Exception e) {
log.warn("Error occur coverting to OpenMBeanInfo", (Throwable)e);
return info;
}
}
private OpenMBeanAttributeInfo convert(MBeanAttributeInfo info) throws Exception {
Class ret = info.isReadable() ? this.getReadMethod(info).getReturnType() : this.getWriteMethod(info).getParameterTypes()[0];
OpenTypeInfo typeInfo = this.getAnnotation(info, OpenTypeInfo.class);
OpenType type = OpenTypeUtils.createOpenType(ret, typeInfo);
return new OpenMBeanAttributeInfoSupport(info.getName(), info.getDescription(), type, info.isReadable(), info.isWritable(), info.isIs());
}
private OpenMBeanConstructorInfo convert(MBeanConstructorInfo info) throws Exception {
MBeanParameterInfo[] sig = info.getSignature();
OpenMBeanParameterInfo[] openSig = new OpenMBeanParameterInfo[sig.length];
for (int i = 0; i < sig.length; ++i) {
openSig[i] = this.convert(info, sig[i], i);
}
return new OpenMBeanConstructorInfoSupport(info.getName(), info.getDescription(), openSig);
}
private OpenMBeanOperationInfo convert(MBeanOperationInfo info) throws Exception {
Class returnType = this.getClass(info.getReturnType());
OpenTypeInfo typeInfo = this.getMethod(info).getAnnotation(OpenTypeInfo.class);
OpenType openType = OpenTypeUtils.createOpenType(returnType, typeInfo);
MBeanParameterInfo[] sig = info.getSignature();
OpenMBeanParameterInfo[] openSig = new OpenMBeanParameterInfo[sig.length];
for (int i = 0; i < sig.length; ++i) {
openSig[i] = this.convert(info, sig[i], i);
}
return new OpenMBeanOperationInfoSupport(info.getName(), info.getDescription(), openSig, openType, info.getImpact());
}
private OpenMBeanParameterInfo convert(MBeanConstructorInfo ctor, MBeanParameterInfo info, int seq) throws Exception {
Class clazz = this.getClass(info.getType());
OpenTypeInfo typeInfo = this.getParamAnnotation(ctor, seq, OpenTypeInfo.class);
OpenType openType = OpenTypeUtils.createOpenType(clazz, typeInfo);
return new OpenMBeanParameterInfoSupport(info.getName(), info.getDescription(), openType);
}
private OpenMBeanParameterInfo convert(MBeanOperationInfo op, MBeanParameterInfo info, int seq) throws Exception {
Class clazz = this.getClass(info.getType());
OpenTypeInfo typeInfo = this.getParamAnnotation(op, seq, OpenTypeInfo.class);
OpenType openType = OpenTypeUtils.createOpenType(clazz, typeInfo);
return new OpenMBeanParameterInfoSupport(info.getName(), info.getDescription(), openType);
}
private Class<?> getClass(String type) throws ClassNotFoundException {
if ("void".equals(type)) {
return Void.class;
}
if ("boolean".equals(type)) {
return Boolean.TYPE;
}
if ("byte".equals(type)) {
return Byte.TYPE;
}
if ("char".equals(type)) {
return Character.TYPE;
}
if ("double".equals(type)) {
return Double.TYPE;
}
if ("float".equals(type)) {
return Float.TYPE;
}
if ("int".equals(type)) {
return Integer.TYPE;
}
if ("long".equals(type)) {
return Long.TYPE;
}
if ("short".equals(type)) {
return Short.TYPE;
}
return this.getMBeanInterface().getClassLoader().loadClass(type);
}
}