📄 managedbean.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.tomcat.util.modeler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import javax.management.ServiceNotFoundException;
//import javax.management.modelmbean.InvalidTargetObjectTypeException;
/**
* <p>Internal configuration information for a managed bean (MBean)
* descriptor.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
*/
public class ManagedBean implements java.io.Serializable
{
private static final String BASE_MBEAN = "org.apache.tomcat.util.modeler.BaseModelMBean";
// ----------------------------------------------------- Instance Variables
static final Object[] NO_ARGS_PARAM=new Object[0];
static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
/**
* The <code>ModelMBeanInfo</code> object that corresponds
* to this <code>ManagedBean</code> instance.
*/
transient MBeanInfo info = null;
// Map<AttributeInfo>
private Map attributes = new HashMap();
//Map<OperationInfo>
private Map operations = new HashMap();
protected String className = BASE_MBEAN;
//protected ConstructorInfo constructors[] = new ConstructorInfo[0];
protected String description = null;
protected String domain = null;
protected String group = null;
protected String name = null;
//protected List fields = new ArrayList();
protected NotificationInfo notifications[] = new NotificationInfo[0];
protected String type = null;
/** Constructor. Will add default attributes.
*
*/
public ManagedBean() {
AttributeInfo ai=new AttributeInfo();
ai.setName("modelerType");
ai.setDescription("Type of the modeled resource. Can be set only once");
ai.setType("java.lang.String");
ai.setWriteable(false);
addAttribute(ai);
}
// ------------------------------------------------------------- Properties
/**
* The collection of attributes for this MBean.
*/
public AttributeInfo[] getAttributes() {
AttributeInfo result[] = new AttributeInfo[attributes.size()];
attributes.values().toArray(result);
return result;
}
/**
* The fully qualified name of the Java class of the MBean
* described by this descriptor. If not specified, the standard JMX
* class (<code>javax.management.modelmbean.RequiredModeLMBean</code>)
* will be utilized.
*/
public String getClassName() {
return (this.className);
}
public void setClassName(String className) {
this.className = className;
this.info = null;
}
// /**
// * The collection of constructors for this MBean.
// */
// public ConstructorInfo[] getConstructors() {
// return (this.constructors);
// }
/**
* The human-readable description of this MBean.
*/
public String getDescription() {
return (this.description);
}
public void setDescription(String description) {
this.description = description;
this.info = null;
}
/**
* The (optional) <code>ObjectName</code> domain in which this MBean
* should be registered in the MBeanServer.
*/
public String getDomain() {
return (this.domain);
}
public void setDomain(String domain) {
this.domain = domain;
}
/**
* <p>Return a <code>List</code> of the {@link FieldInfo} objects for
* the name/value pairs that should be
* added to the Descriptor created from this metadata.</p>
*/
// public List getFields() {
// return (this.fields);
// }
//
/**
* The (optional) group to which this MBean belongs.
*/
public String getGroup() {
return (this.group);
}
public void setGroup(String group) {
this.group = group;
}
/**
* The name of this managed bean, which must be unique among all
* MBeans managed by a particular MBeans server.
*/
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
this.info = null;
}
/**
* The collection of notifications for this MBean.
*/
public NotificationInfo[] getNotifications() {
return (this.notifications);
}
/**
* The collection of operations for this MBean.
*/
public OperationInfo[] getOperations() {
OperationInfo[] result = new OperationInfo[operations.size()];
operations.values().toArray(result);
return result;
}
/**
* The fully qualified name of the Java class of the resource
* implementation class described by the managed bean described
* by this descriptor.
*/
public String getType() {
return (this.type);
}
public void setType(String type) {
this.type = type;
this.info = null;
}
// --------------------------------------------------------- Public Methods
/**
* Add a new attribute to the set of attributes for this MBean.
*
* @param attribute The new attribute descriptor
*/
public void addAttribute(AttributeInfo attribute) {
attributes.put(attribute.getName(), attribute);
}
/**
* Add a new constructor to the set of constructors for this MBean.
*
* @param constructor The new constructor descriptor
*/
// 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;
// }
//
// }
/**
* <p>Add a new field to the fields associated with the
* Descriptor that will be created from this metadata.</p>
*
* @param field The field to be added
*/
// public void addField(FieldInfo field) {
// fields.add(field);
// }
/**
* Add a new notification to the set of notifications for this MBean.
*
* @param notification The new notification descriptor
*/
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 operation to the set of operations for this MBean.
*
* @param operation The new operation descriptor
*/
public void addOperation(OperationInfo operation) {
operations.put(operation.getName(), operation);
}
/**
* Create and return a <code>ModelMBean</code> that has been
* preconfigured with the <code>ModelMBeanInfo</code> information
* for this managed bean, but is not associated with any particular
* managed resource. The returned <code>ModelMBean</code> will
* <strong>NOT</strong> have been registered with our
* <code>MBeanServer</code>.
*
* @exception InstanceNotFoundException if the managed resource
* object cannot be found
* @exception InvalidTargetObjectTypeException if our MBean cannot
* handle object references (should never happen)
* @exception MBeanException if a problem occurs instantiating the
* <code>ModelMBean</code> instance
* @exception RuntimeOperationsException if a JMX runtime error occurs
*/
public DynamicMBean createMBean()
throws InstanceNotFoundException,
MBeanException, RuntimeOperationsException {
return (createMBean(null));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -