MBeanAttributeInfo[] mbais = mbi.getAttributes();
for (int i = 0; i < mbais.length; i++) {
MBeanAttributeInfo mbai = mbais[i];
String name = mbai.getName();
Field typeField = c.getField(name + "Type");
OpenType typeValue = (OpenType) typeField.get(null);
OpenType openType =
(OpenType) mbai.getDescriptor().getFieldValue("openType");
if (typeValue.equals(openType))
success("attribute " + name);
else {
final String msg =
"Wrong type attribute " + name + ": " +
openType + " should be " + typeValue;
failure(msg);
}
}
MBeanOperationInfo[] mbois = mbi.getOperations();
for (int i = 0; i < mbois.length; i++) {
MBeanOperationInfo mboi = mbois[i];
String oname = mboi.getName();
if (!oname.startsWith("op"))
throw new Error();
OpenType retType =
(OpenType) mboi.getDescriptor().getFieldValue("openType");
MBeanParameterInfo[] params = mboi.getSignature();
MBeanParameterInfo p1i = params[0];
MBeanParameterInfo p2i = params[1];
OpenType p1Type =
(OpenType) p1i.getDescriptor().getFieldValue("openType");
OpenType p2Type =
(OpenType) p2i.getDescriptor().getFieldValue("openType");
if (!retType.equals(p1Type) || !p1Type.equals(p2Type)) {
final String msg =
"Parameter and return open types should all be same " +
"but are not: " + retType + " " + oname + "(" + p1Type +
", " + p2Type + ")";
failure(msg);
continue;
}
String name = oname.substring(2);
Field typeField = c.getField(name + "Type");
OpenType typeValue = (OpenType) typeField.get(null);
if (typeValue.equals(retType))
success("operation " + oname);
else {
final String msg =
"Wrong type operation " + oname + ": " +
retType + " should be " + typeValue;
failure(msg);
}
}
System.out.println("Mapping check...");
Object proxy =
JMX.newMXBeanProxy(mbsc, on, c);
Method[] methods = c.getMethods();
for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
if (method.getDeclaringClass() != c)
continue; // skip hashCode() etc inherited from Object
final String mname = method.getName();
final int what = getType(method);
final String name = getName(method);
final Field refField = c.getField(name);
if (nullTest && refField.getType().isPrimitive())
continue;
final Field openTypeField = c.getField(name + "Type");
final OpenType openType = (OpenType) openTypeField.get(null);
final Object refValue = nullTest ? null : refField.get(null);
Object setValue = refValue;
try {
Field onField = c.getField(name + "ObjectName");
String refName = (String) onField.get(null);
ObjectName refObjName = ObjectName.getInstance(refName);
Class<?> mxbeanInterface = refField.getType();
setValue = nullTest ? null :
JMX.newMXBeanProxy(mbsc, refObjName, mxbeanInterface);
} catch (Exception e) {
// no xObjectName field, setValue == refValue
}
boolean ok = true;
try {
switch (what) {
case GET:
final Object gotOpen = mbsc.getAttribute(on, name);
if (nullTest) {
if (gotOpen != null) {
failure(mname + " got non-null value " +
gotOpen);
ok = false;
}
} else if (!openType.isValue(gotOpen)) {
if (gotOpen instanceof TabularData) {
// detail the mismatch
TabularData gotTabular = (TabularData) gotOpen;
compareTabularType((TabularType) openType,
gotTabular.getTabularType());