{
if (info instanceof ModelMBeanInfoSupport)
return (ModelMBeanInfoSupport)info;
if (info instanceof ModelMBeanInfo)
return new ModelMBeanInfoSupport((ModelMBeanInfo)info);
// create attributes
MBeanAttributeInfo[] attributes = info.getAttributes();
ModelMBeanAttributeInfo[] mmbAttributes = new ModelMBeanAttributeInfo[attributes.length];
List accessorOperations = new ArrayList();
for (int i = 0; i < attributes.length; ++i)
{
// add basic info
ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo(
attributes[i].getName(),
attributes[i].getType(),
attributes[i].getDescription(),
attributes[i].isReadable(),
attributes[i].isWritable(),
attributes[i].isIs()
);
// by default, conversion metadata should not try to cache attributes
Descriptor d = attrInfo.getDescriptor();
d.setField(CURRENCY_TIME_LIMIT, CACHE_NEVER);
attrInfo.setDescriptor(d);
mmbAttributes[i] = attrInfo;
// if we're doing attribute operation mapping, find the accessor methods
// from the Standard MBean interface, and create the 'setter' and 'getter'
// management operations for them. Map the Model MBean attributes to
// these operations.
if (createAttributeOperationMapping)
{
String getterOperationName = null;
String setterOperationName = null;
Descriptor getterDescriptor = null;
Descriptor setterDescriptor = null;
// figure out the getter type
if (attributes[i].isReadable())
{
if (attributes[i].isIs())
getterOperationName = "is" + attributes[i].getName();
else
getterOperationName = "get" + attributes[i].getName();
// create a descriptor for 'getter' mgmt operation
getterDescriptor = new DescriptorSupport();
getterDescriptor.setField(NAME, getterOperationName);
getterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
getterDescriptor.setField(ROLE, ROLE_GETTER);
// create the new management operation
ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
getterOperationName,
"Read accessor operation for '" + attributes[i].getName() + "' attribute.",
new MBeanParameterInfo[0], // void signature
attributes[i].getType(), // return type
MBeanOperationInfo.INFO, // impact
getterDescriptor
);
// modify the attributes descriptor to map the read operation
// to the above created management operation
Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
attrDescriptor.setField(GET_METHOD, getterOperationName);
mmbAttributes[i].setDescriptor(attrDescriptor);
accessorOperations.add(opInfo);
}
// figure out the setter
if (attributes[i].isWritable())
{
setterOperationName = "set" + attributes[i].getName();
// create a descriptor for 'setter' mgmt operation
setterDescriptor = new DescriptorSupport();
setterDescriptor.setField(NAME, setterOperationName);
setterDescriptor.setField(DESCRIPTOR_TYPE, OPERATION_DESCRIPTOR);
setterDescriptor.setField(ROLE, ROLE_SETTER);
// create the new management operation
ModelMBeanOperationInfo opInfo = new ModelMBeanOperationInfo(
setterOperationName,
"Write accessor operation for '" + attributes[i].getName() + "' attribute.",
new MBeanParameterInfo[] {
new MBeanParameterInfo("value", attributes[i].getType(), "Attribute's value.")
},
Void.TYPE.getName(),
MBeanOperationInfo.ACTION,
setterDescriptor
);
// modify the attributes descriptor to map the read operation
// to the above created management operation
Descriptor attrDescriptor = mmbAttributes[i].getDescriptor();
attrDescriptor.setField(SET_METHOD, setterOperationName);
mmbAttributes[i].setDescriptor(attrDescriptor);
accessorOperations.add(opInfo);
}
}
}
// deal with the basic manaement operations (non-getter and setter types)
MBeanOperationInfo[] operations = info.getOperations();
ModelMBeanOperationInfo[] mmbOperations = new ModelMBeanOperationInfo[operations.length + accessorOperations.size()];
for (int i = 0; i < operations.length; ++i)
{
mmbOperations[i] = new ModelMBeanOperationInfo(
operations[i].getName(),
operations[i].getDescription(),
operations[i].getSignature(),
operations[i].getReturnType(),
operations[i].getImpact()
);
}
for (int i = operations.length; i < mmbOperations.length; ++i)
mmbOperations[i] = (ModelMBeanOperationInfo)accessorOperations.get(i - operations.length);
// the constructors...
MBeanConstructorInfo[] constructors = info.getConstructors();
ModelMBeanConstructorInfo[] mmbConstructors = new ModelMBeanConstructorInfo[constructors.length];
for (int i = 0; i < constructors.length; ++i)
{
mmbConstructors[i] = new ModelMBeanConstructorInfo(
constructors[i].getName(),
constructors[i].getDescription(),
constructors[i].getSignature()
);
}
// and finally the notifications
// FIXME: we are assuming here that the Model MBean implementation adds the
// default generic and attribute change notifications to the metadata.
// I think we could explicitly add them here as well, can't see it
// do any harm. [JPL]
MBeanNotificationInfo[] notifications = info.getNotifications();
ModelMBeanNotificationInfo[] mmbNotifications = new ModelMBeanNotificationInfo[notifications.length];
for (int i = 0; i < notifications.length; ++i)
{
mmbNotifications[i] = new ModelMBeanNotificationInfo(
notifications[i].getNotifTypes(),
notifications[i].getName(),
notifications[i].getDescription()
);
}
return new ModelMBeanInfoSupport(info.getClassName(), info.getDescription(),
mmbAttributes, mmbConstructors, mmbOperations, mmbNotifications);
}