final boolean READABLE = true;
final boolean WRITABLE = true;
final boolean BOOLEAN = true;
// Default Domain attribute
DescriptorSupport descDefaultDomain = new DescriptorSupport();
descDefaultDomain.setField("name", "DefaultDomain");
descDefaultDomain.setField("descriptorType", "attribute");
descDefaultDomain.setField("displayName", "Default Domain");
descDefaultDomain.setField("default", getDefaultDomain());
descDefaultDomain.setField("currencyTimeLimit", "-1");
ModelMBeanAttributeInfo defaultDomainInfo =
new ModelMBeanAttributeInfo
(
"DefaultDomain", String.class.getName(),
"The domain to use when an object name has no domain",
READABLE, !WRITABLE, !BOOLEAN,
descDefaultDomain
);
// Size attribute
DescriptorSupport descSize = new DescriptorSupport();
descSize.setField("name", "Size");
descSize.setField("descriptorType", "attribute");
descSize.setField("displayName", "Size");
descSize.setField("getMethod", "getSize");
ModelMBeanAttributeInfo sizeInfo =
new ModelMBeanAttributeInfo
(
"Size", Integer.TYPE.getName(),
"The number of MBeans registered in the MBean Server",
READABLE, !WRITABLE, !BOOLEAN,
descSize
);
// registerMBean operation
DescriptorSupport descRegisterMBean = new DescriptorSupport();
descRegisterMBean.setField("name", "registerMBean");
descRegisterMBean.setField("descriptorType", "operation");
descRegisterMBean.setField("role", "operation");
MBeanParameterInfo[] registerMBeanParms =
new MBeanParameterInfo[]
{
new MBeanParameterInfo
(
"Resource",
Object.class.getName(),
"A compliant MBean to be registered in the MBean Server"
),
new MBeanParameterInfo
(
"ObjectName",
ObjectName.class.getName(),
"The object name of the MBean"
),
new MBeanParameterInfo
(
"ValueMap",
Map.class.getName(),
"Values associated with the registration"
),
};
ModelMBeanOperationInfo registerMBeanInfo =
new ModelMBeanOperationInfo
(
"registerMBean",
"Adds an MBean in the MBeanServer",
registerMBeanParms,
ObjectInstance.class.getName(),
ModelMBeanOperationInfo.ACTION_INFO,
descRegisterMBean
);
// unregisterMBean operation
DescriptorSupport descUnregisterMBean = new DescriptorSupport();
descUnregisterMBean.setField("name", "unregisterMBean");
descUnregisterMBean.setField("descriptorType", "operation");
descUnregisterMBean.setField("role", "operation");
MBeanParameterInfo[] unregisterMBeanParms =
new MBeanParameterInfo[]
{
new MBeanParameterInfo
(
"ObjectName",
ObjectName.class.getName(),
"The object name of the MBean to remove"
)
};
ModelMBeanOperationInfo unregisterMBeanInfo =
new ModelMBeanOperationInfo
(
"unregisterMBean",
"Removes an MBean from the MBeanServer",
unregisterMBeanParms,
Void.TYPE.getName(),
ModelMBeanOperationInfo.ACTION,
descUnregisterMBean
);
// getSize operation
DescriptorSupport descGetSize = new DescriptorSupport();
descGetSize.setField("name", "getSize");
descGetSize.setField("descriptorType", "operation");
descGetSize.setField("role", "operation");
MBeanParameterInfo[] getSizeParms = new MBeanParameterInfo[0];
ModelMBeanOperationInfo getSizeInfo =
new ModelMBeanOperationInfo
(
"getSize",
"Gets the number of MBeans registered",
getSizeParms,
Integer.TYPE.getName(),
ModelMBeanOperationInfo.INFO,
descGetSize
);
// get operation
DescriptorSupport descGet = new DescriptorSupport();
descGet.setField("name", "get");
descGet.setField("descriptorType", "operation");
descGet.setField("role", "operation");
MBeanParameterInfo[] getParam = new MBeanParameterInfo[1];
getParam[0]=new MBeanParameterInfo("ObjectName",ObjectName.class.getName(),"object name to find");
ModelMBeanOperationInfo getInfo =
new ModelMBeanOperationInfo
(
"get",
"Gets the MBeanEntry for a given ObjectName",
getParam,
MBeanEntry.class.getName(),
ModelMBeanOperationInfo.INFO,
descGet
);
// getValue operation
DescriptorSupport descGetValue = new DescriptorSupport();
descGetValue.setField("name", "getValue");
descGetValue.setField("descriptorType", "operation");
descGetValue.setField("role", "operation");
MBeanParameterInfo[] getValueParms = new MBeanParameterInfo[]
{
new MBeanParameterInfo
(
"ObjectName",
ObjectName.class.getName(),
"The object name of the registered MBean"
),
new MBeanParameterInfo
(
"Key",
String.class.getName(),
"The key to the value stored"
)
};
ModelMBeanOperationInfo getValueInfo =
new ModelMBeanOperationInfo
(
"getValue",
"Get a value stored in the MBean's registration",
getValueParms,
Object.class.getName(),
ModelMBeanOperationInfo.INFO,
descGetValue
);
// Construct the modelmbean
DescriptorSupport descMBean = new DescriptorSupport();
descMBean.setField("name", "MBeanRegistry");
descMBean.setField("descriptorType", "MBean");
ModelMBeanInfoSupport info = new ModelMBeanInfoSupport
(
RequiredModelMBean.class.getName(),
"Managed Bean Registry",
new ModelMBeanAttributeInfo[]