| Method from org.apache.commons.modeler.ManagedBean Detail: |
public void addAttribute(AttributeInfo attribute) {
synchronized (attributes) {
AttributeInfo results[] =
new AttributeInfo[attributes.length + 1];
System.arraycopy(attributes, 0, results, 0, attributes.length);
results[attributes.length] = attribute;
attributes = results;
this.info = null;
}
}
Add a new attribute to the set of attributes for this MBean. |
public void addConstructor(ConstructorInfo constructor) {
synchronized (constructors) {
ConstructorInfo results[] =
new ConstructorInfo[constructors.length + 1];
System.arraycopy(constructors, 0, results, 0, constructors.length);
results[constructors.length] = constructor;
constructors = results;
this.info = null;
}
}
Add a new constructor to the set of constructors for this MBean. |
public void addField(FieldInfo field) {
fields.add(field);
}
Add a new field to the fields associated with the
Descriptor that will be created from this metadata.
|
public void addNotification(NotificationInfo notification) {
synchronized (notifications) {
NotificationInfo results[] =
new NotificationInfo[notifications.length + 1];
System.arraycopy(notifications, 0, results, 0,
notifications.length);
results[notifications.length] = notification;
notifications = results;
this.info = null;
}
}
Add a new notification to the set of notifications for this MBean. |
public void addOperation(OperationInfo operation) {
synchronized (operations) {
OperationInfo results[] =
new OperationInfo[operations.length + 1];
System.arraycopy(operations, 0, results, 0, operations.length);
results[operations.length] = operation;
operations = results;
this.info = null;
}
}
Add a new operation to the set of operations for this MBean. |
public ModelMBean createMBean() throws InstanceNotFoundException, InvalidTargetObjectTypeException, RuntimeOperationsException, MBeanException {
return (createMBean(null));
}
Create and return a ModelMBean that has been
preconfigured with the ModelMBeanInfo information
for this managed bean, but is not associated with any particular
managed resource. The returned ModelMBean will
NOT have been registered with our
MBeanServer. |
public ModelMBean createMBean(Object instance) throws InstanceNotFoundException, InvalidTargetObjectTypeException, RuntimeOperationsException, MBeanException {
// Load the ModelMBean implementation class
Class clazz = null;
Exception ex = null;
try {
clazz = Class.forName(getClassName());
} catch (Exception e) {
}
if( clazz==null ) {
try {
ClassLoader cl= Thread.currentThread().getContextClassLoader();
if ( cl != null)
clazz= cl.loadClass(getClassName());
} catch (Exception e) {
ex=e;
}
}
if( clazz==null) {
throw new MBeanException
(ex, "Cannot load ModelMBean class " + getClassName());
}
// Create a new ModelMBean instance
ModelMBean mbean = null;
try {
mbean = (ModelMBean) clazz.newInstance();
mbean.setModelMBeanInfo(createMBeanInfo());
} catch (MBeanException e) {
throw e;
} catch (RuntimeOperationsException e) {
throw e;
} catch (Exception e) {
throw new MBeanException
(e, "Cannot instantiate ModelMBean of class " +
getClassName());
}
// Set the managed resource (if any)
try {
if (instance != null)
mbean.setManagedResource(instance, "ObjectReference");
} catch (InstanceNotFoundException e) {
throw e;
} catch (InvalidTargetObjectTypeException e) {
throw e;
}
return (mbean);
}
Create and return a ModelMBean that has been
preconfigured with the ModelMBeanInfo information
for this managed bean, and is associated with the specified
managed object instance. The returned ModelMBean
will NOT have been registered with our
MBeanServer. |
public ModelMBeanInfo createMBeanInfo() {
// Return our cached information (if any)
if (info != null)
return (info);
// Create subordinate information descriptors as required
AttributeInfo attrs[] = getAttributes();
ModelMBeanAttributeInfo attributes[] =
new ModelMBeanAttributeInfo[attrs.length];
for (int i = 0; i < attrs.length; i++)
attributes[i] = attrs[i].createAttributeInfo();
ConstructorInfo consts[] = getConstructors();
ModelMBeanConstructorInfo constructors[] =
new ModelMBeanConstructorInfo[consts.length];
for (int i = 0; i < consts.length; i++)
constructors[i] = consts[i].createConstructorInfo();
NotificationInfo notifs[] = getNotifications();
ModelMBeanNotificationInfo notifications[] =
new ModelMBeanNotificationInfo[notifs.length];
for (int i = 0; i < notifs.length; i++)
notifications[i] = notifs[i].createNotificationInfo();
OperationInfo opers[] = getOperations();
ModelMBeanOperationInfo operations[] =
new ModelMBeanOperationInfo[opers.length];
for (int i = 0; i < opers.length; i++)
operations[i] = opers[i].createOperationInfo();
/*
// Add operations for attribute getters and setters as needed
ArrayList list = new ArrayList();
for (int i = 0; i < operations.length; i++)
list.add(operations[i]);
for (int i = 0; i < attributes.length; i++) {
Descriptor descriptor = attributes[i].getDescriptor();
String getMethod = (String) descriptor.getFieldValue("getMethod");
if (getMethod != null) {
OperationInfo oper =
new OperationInfo(getMethod, true,
attributes[i].getType());
list.add(oper.createOperationInfo());
}
String setMethod = (String) descriptor.getFieldValue("setMethod");
if (setMethod != null) {
OperationInfo oper =
new OperationInfo(setMethod, false,
attributes[i].getType());
list.add(oper.createOperationInfo());
}
}
if (list.size() > operations.length)
operations =
(ModelMBeanOperationInfo[]) list.toArray(operations);
*/
// Construct and return a new ModelMBeanInfo object
info = new ModelMBeanInfoSupport
(getClassName(), getDescription(),
attributes, constructors, operations, notifications);
try {
Descriptor descriptor = info.getMBeanDescriptor();
Iterator fields = getFields().iterator();
while (fields.hasNext()) {
FieldInfo field = (FieldInfo) fields.next();
descriptor.setField(field.getName(), field.getValue());
}
info.setMBeanDescriptor(descriptor);
} catch (MBeanException e) {
;
}
return (info);
}
Create and return a ModelMBeanInfo object that
describes this entire managed bean. |
public AttributeInfo[] getAttributes() {
return (this.attributes);
}
The collection of attributes for this MBean. |
public String getClassName() {
return (this.className);
}
The fully qualified name of the Java class of the MBean
described by this descriptor. If not specified, the standard JMX
class (javax.management.modelmbean.RequiredModeLMBean)
will be utilized. |
public ConstructorInfo[] getConstructors() {
return (this.constructors);
}
The collection of constructors for this MBean. |
public String getDescription() {
return (this.description);
}
The human-readable description of this MBean. |
public String getDomain() {
return (this.domain);
}
The (optional) ObjectName domain in which this MBean
should be registered in the MBeanServer. |
public List getFields() {
return (this.fields);
}
Return a List of the FieldInfo objects for
the name/value pairs that should be
added to the Descriptor created from this metadata.
|
public String getGroup() {
return (this.group);
}
The (optional) group to which this MBean belongs. |
public String getName() {
return (this.name);
}
The name of this managed bean, which must be unique among all
MBeans managed by a particular MBeans server. |
public NotificationInfo[] getNotifications() {
return (this.notifications);
}
The collection of notifications for this MBean. |
public OperationInfo[] getOperations() {
return (this.operations);
}
The collection of operations for this MBean. |
public String getType() {
return (this.type);
}
The fully qualified name of the Java class of the resource
implementation class described by the managed bean described
by this descriptor. |
public void setClassName(String className) {
this.className = className;
this.info = null;
}
|
public void setDescription(String description) {
this.description = description;
this.info = null;
}
|
public void setDomain(String domain) {
this.domain = domain;
}
|
public void setGroup(String group) {
this.group = group;
}
|
public void setName(String name) {
this.name = name;
this.info = null;
}
|
public void setType(String type) {
this.type = type;
this.info = null;
}
|
public String toString() {
StringBuffer sb = new StringBuffer("ManagedBean[");
sb.append("name=");
sb.append(name);
sb.append(", className=");
sb.append(className);
sb.append(", description=");
sb.append(description);
if (group != null) {
sb.append(", group=");
sb.append(group);
}
sb.append(", type=");
sb.append(type);
sb.append("]");
return (sb.toString());
}
Return a string representation of this managed bean. |