📄 mbeandescriptor.java
字号:
/*
======================================================================
MBeanDescriptor.java
Created by Claude Duguay
Copyright (c) 2005
======================================================================
*/
package com.claudeduguay.mbeans.model;
import java.util.*;
import javax.management.modelmbean.*;
import org.jdom.*;
import com.claudeduguay.util.jdom.*;
public class MBeanDescriptor implements IStorableElement, IStorableDocument
{
protected String type;
protected String description;
protected List<MBeanConstructorDescriptor> constructors = new ArrayList<MBeanConstructorDescriptor>();
protected List<MBeanAttributeDescriptor> attributes = new ArrayList<MBeanAttributeDescriptor>();
protected List<MBeanOperationDescriptor> operations = new ArrayList<MBeanOperationDescriptor>();
protected List<MBeanNotificationDescriptor> notifications = new ArrayList<MBeanNotificationDescriptor>();
public MBeanDescriptor() {}
public MBeanDescriptor(Element element)
{
parseElement(element);
}
public MBeanDescriptor(Document doc)
{
parseDocument(doc);
}
public ModelMBeanInfo createMBeanInfo()
{
return new ModelMBeanInfoSupport(type, description,
createMBeanAttributeInfoArray(),
createMBeanConstructorInfoArray(),
createMBeanOperationInfoArray(),
createMBeanNotificationInfoArray());
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public List<MBeanConstructorDescriptor> getConstructors()
{
return constructors;
}
public void setConstructors(List<MBeanConstructorDescriptor> constructors)
{
this.constructors = constructors;
}
public void addConstructor(MBeanConstructorDescriptor constructor)
{
constructors.add(constructor);
}
protected ModelMBeanConstructorInfo[] createMBeanConstructorInfoArray()
{
int count = constructors.size();
ModelMBeanConstructorInfo[] array = new ModelMBeanConstructorInfo[count];
for (int i = 0; i < count; i++)
{
array[i] = constructors.get(i).createMBeanConstructorInfo();
}
return array;
}
public List<MBeanAttributeDescriptor> getAttributes()
{
return attributes;
}
public void setAttributes(List<MBeanAttributeDescriptor> attributes)
{
this.attributes = attributes;
}
public void addAttribute(MBeanAttributeDescriptor attribute)
{
attributes.add(attribute);
}
protected ModelMBeanAttributeInfo[] createMBeanAttributeInfoArray()
{
int count = attributes.size();
ModelMBeanAttributeInfo[] array = new ModelMBeanAttributeInfo[count];
for (int i = 0; i < count; i++)
{
array[i] = attributes.get(i).createMBeanAttributeInfo();
}
return array;
}
public List<MBeanOperationDescriptor> getOperations()
{
return operations;
}
public void setOperations(List<MBeanOperationDescriptor> operations)
{
this.operations = operations;
}
public void addOperation(MBeanOperationDescriptor operation)
{
operations.add(operation);
}
protected ModelMBeanOperationInfo[] createMBeanOperationInfoArray()
{
int count = operations.size();
ModelMBeanOperationInfo[] array = new ModelMBeanOperationInfo[count];
for (int i = 0; i < count; i++)
{
array[i] = operations.get(i).createMBeanOperationInfo();
}
return array;
}
public List<MBeanNotificationDescriptor> getNotifications()
{
return notifications;
}
public void setNotifications(List<MBeanNotificationDescriptor> notifications)
{
this.notifications = notifications;
}
public void addNotification(MBeanNotificationDescriptor notification)
{
notifications.add(notification);
}
protected ModelMBeanNotificationInfo[] createMBeanNotificationInfoArray()
{
int count = notifications.size();
ModelMBeanNotificationInfo[] array = new ModelMBeanNotificationInfo[count];
for (int i = 0; i < count; i++)
{
array[i] = notifications.get(i).createMBeanNotificationInfo();
}
return array;
}
public Element buildElement()
{
Element element = new Element("mbean");
element.setAttribute("type", getType());
element.setAttribute("description", getDescription());
for (MBeanAttributeDescriptor info : attributes)
{
element.addContent(info.buildElement());
}
for (MBeanConstructorDescriptor info : constructors)
{
element.addContent(info.buildElement());
}
for (MBeanOperationDescriptor info : operations)
{
element.addContent(info.buildElement());
}
for (MBeanNotificationDescriptor info : notifications)
{
element.addContent(info.buildElement());
}
return element;
}
public void parseElement(Element element)
{
setType(element.getAttributeValue("type"));
setDescription(element.getAttributeValue("description"));
List children = element.getChildren();
for (int i = 0; i < children.size(); i++)
{
Element child = (Element) children.get(i);
String childName = child.getName();
if (childName.equals("attribute"))
{
addAttribute(new MBeanAttributeDescriptor(child));
}
if (childName.equals("constructor"))
{
addConstructor(new MBeanConstructorDescriptor(child));
}
if (childName.equals("operation"))
{
addOperation(new MBeanOperationDescriptor(child));
}
if (childName.equals("notification"))
{
addNotification(new MBeanNotificationDescriptor(child));
}
}
}
public Document buildDocument()
{
Document doc = new Document();
Element root = buildElement();
doc.setRootElement(root);
return doc;
}
public void parseDocument(Document doc)
{
parseElement(doc.getRootElement());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -