if (args.length != 1)
{
throw new CommandException("Missing object name");
}
ObjectName target = super.createObjectName(args[0]);
MBeanInfo mbeanInfo = getMBeanServer().getMBeanInfo(target);
MBeanConstructorInfo[] ctors = mbeanInfo.getConstructors();
MBeanAttributeInfo[] attrs = mbeanInfo.getAttributes();
MBeanOperationInfo[] ops = mbeanInfo.getOperations();
MBeanNotificationInfo[] notifs = mbeanInfo.getNotifications();
PrintWriter out = context.getWriter();
// header
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<!DOCTYPE mbean PUBLIC");
out.println(" \"-//JBoss//DTD JBOSS XMBEAN 1.2//EN\"");
out.println(" \"http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd\">");
out.println("<!--");
out.println(" xmbean descriptor generated by 'twiddle'");
out.println(" on " + new Date());
out.println(" for '" + target + "'");
out.println("-->");
out.println("<mbean>");
// mbean
out.println(" <description>" + mbeanInfo.getDescription() + "</description>");
out.println(" <class>" + mbeanInfo.getClassName() + "</class>");
out.println();
// constructors
if (ctors.length > 0)
{
for (int i = 0; i < ctors.length; i++)
{
MBeanConstructorInfo ctorInfo = ctors[i];
out.println(" <constructor>");
out.println(" <description>" + ctorInfo.getDescription() + "</description>");
out.println(" <name>" + ctorInfo.getName() + "</name>");
outputParameters(out, ctorInfo.getSignature());
out.println(" </constructor>");
}
out.println();
}
// attributes
if (attrs.length > 0)
{
for (int i = 0; i < attrs.length; i++)
{
MBeanAttributeInfo attrInfo = attrs[i];
// determine access, rw by default
String access = "read-write";
access = attrInfo.isReadable() ? access : "write-only";
access = attrInfo.isWritable() ? access : "read-only";
String accessString = " access='" + access + "'";
// determine get method, if any
String getMethodString = "";
if (attrInfo.isReadable())
{
getMethodString = " getMethod='" +
(attrInfo.isIs() ? "is" : "get") + attrInfo.getName() + "'";
}
// determine set method, if any
String setMethodString = "";
if (attrInfo.isWritable())
{
setMethodString = " setMethod='set" + attrInfo.getName() + "'";
}
out.println(" <attribute" + accessString + getMethodString + setMethodString + ">");
out.println(" <description>" + attrInfo.getDescription() + "</description>");
out.println(" <name>" + attrInfo.getName() + "</name>");
out.println(" <type>" + attrInfo.getType() + "</type>");
out.println(" </attribute>");
}
out.println();
}
// operations
if (ops.length > 0)
{
for (int i = 0; i < ops.length; i++)
{
MBeanOperationInfo opInfo = ops[i];
// nobody uses opInfo.getImpact()
out.println(" <operation>");
out.println(" <description>" + opInfo.getDescription() + "</description>");
out.println(" <name>" + opInfo.getName() + "</name>");
outputParameters(out, opInfo.getSignature());
out.println(" <return-type>" + opInfo.getReturnType() + "</return-type>");
out.println(" </operation>");
}
out.println();
}
// notifications
if (notifs.length > 0)
{
for (int i = 0; i < notifs.length; i++)
{
MBeanNotificationInfo notifInfo = notifs[i];
String[] types = notifInfo.getNotifTypes();
out.println(" <notification>");
out.println(" <description>" + notifInfo.getDescription() + "</description>");
out.println(" <name>" + notifInfo.getName() + "</name>");
for (int j = 0; j < types.length; j++)
{
out.println(" <notification-type>" + types[j] + "</notification-type>");
}
out.println(" </notification>");
}
out.println();
}
out.println("</mbean>");
out.flush();