下面列出了怎么用javax.management.RuntimeOperationsException的API类实例代码及写法,或者点击链接到github查看源代码。
private static int mbeanCreation(MBeanServer mbs, String name)
throws Exception {
int error = 0;
try {
System.out.println("Test: createMBean(" + name + ")");
mbs.createMBean(classname, ObjectName.getInstance(name));
error++;
System.out.println("Didn't get expected exception!");
System.out.println("Test failed!");
} catch (RuntimeOperationsException e) {
System.out.println("Got expected exception = " +
e.getCause().toString());
System.out.println("Test passed!");
}
return error;
}
/**
* Send an <code>AttributeChangeNotification</code> to all registered
* listeners.
*
* @param notification The <code>AttributeChangeNotification</code>
* that will be passed
*
* @exception MBeanException if an object initializer throws an
* exception
* @exception RuntimeOperationsException wraps IllegalArgumentException
* when the specified notification is <code>null</code> or invalid
*/
@Override
public void sendAttributeChangeNotification
(AttributeChangeNotification notification)
throws MBeanException, RuntimeOperationsException {
if (notification == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Notification is null"),
"Notification is null");
if (attributeBroadcaster == null)
return; // This means there are no registered listeners
if( log.isDebugEnabled() )
log.debug( "AttributeChangeNotification " + notification );
attributeBroadcaster.sendNotification(notification);
}
/**
* Send an <code>AttributeChangeNotification</code> to all registered
* listeners.
*
* @param oldValue The original value of the <code>Attribute</code>
* @param newValue The new value of the <code>Attribute</code>
*
* @exception MBeanException if an object initializer throws an
* exception
* @exception RuntimeOperationsException wraps IllegalArgumentException
* when the specified notification is <code>null</code> or invalid
*/
@Override
public void sendAttributeChangeNotification
(Attribute oldValue, Attribute newValue)
throws MBeanException, RuntimeOperationsException {
// Calculate the class name for the change notification
String type = null;
if (newValue.getValue() != null)
type = newValue.getValue().getClass().getName();
else if (oldValue.getValue() != null)
type = oldValue.getValue().getClass().getName();
else
return; // Old and new are both null == no change
AttributeChangeNotification notification =
new AttributeChangeNotification
(this, 1, System.currentTimeMillis(),
"Attribute value has changed",
oldValue.getName(), type,
oldValue.getValue(), newValue.getValue());
sendAttributeChangeNotification(notification);
}
protected void notifyJmx(String query, String type) {
try {
long sequence = notifySequence.incrementAndGet();
if (isNotifyPool()) {
if (this.pool!=null && this.pool.getJmxPool()!=null) {
this.pool.getJmxPool().notify(type, query);
}
} else {
if (notifier!=null) {
Notification notification =
new Notification(type,
this,
sequence,
System.currentTimeMillis(),
query);
notifier.sendNotification(notification);
}
}
} catch (RuntimeOperationsException e) {
if (log.isDebugEnabled()) {
log.debug("Unable to send failed query notification.",e);
}
}
}
/**
* Always fails since the MBeanServerDelegate MBean has no operation.
*
* @param actionName The name of the action to be invoked.
* @param params An array containing the parameters to be set when the
* action is invoked.
* @param signature An array containing the signature of the action.
*
* @return The object returned by the action, which represents
* the result of invoking the action on the MBean specified.
*
* @exception MBeanException Wraps a <CODE>java.lang.Exception</CODE>
* thrown by the MBean's invoked method.
* @exception ReflectionException Wraps a
* <CODE>java.lang.Exception</CODE> thrown while trying to invoke
* the method.
*/
public Object invoke(String actionName, Object params[],
String signature[])
throws MBeanException, ReflectionException {
// Check that operation name is not null.
//
if (actionName == null) {
final RuntimeException r =
new IllegalArgumentException("Operation name cannot be null");
throw new RuntimeOperationsException(r,
"Exception occurred trying to invoke the operation on the MBean");
}
throw new ReflectionException(
new NoSuchMethodException(actionName),
"The operation with name " + actionName +
" could not be found");
}
/**
* Load a class with the specified loader, or with this object
* class loader if the specified loader is null.
**/
static Class<?> loadClass(String className, ClassLoader loader)
throws ReflectionException {
Class<?> theClass;
if (className == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
ReflectUtil.checkPackageAccess(className);
try {
if (loader == null)
loader = MBeanInstantiator.class.getClassLoader();
if (loader != null) {
theClass = Class.forName(className, false, loader);
} else {
theClass = Class.forName(className);
}
} catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The MBean class could not be loaded");
}
return theClass;
}
/**
* Gets the class for the specified class name using the specified
* class loader
*/
public Class<?> findClass(String className, ObjectName aLoader)
throws ReflectionException, InstanceNotFoundException {
if (aLoader == null)
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null loader passed in parameter");
// Retrieve the class loader from the repository
ClassLoader loader = null;
synchronized (this) {
loader = getClassLoader(aLoader);
}
if (loader == null) {
throw new InstanceNotFoundException("The loader named " +
aLoader + " is not registered in the MBeanServer");
}
return findClass(className,loader);
}
/**
* Loads the class with the specified name using this object's
* Default Loader Repository.
**/
public Class<?> findClassWithDefaultLoaderRepository(String className)
throws ReflectionException {
Class<?> theClass;
if (className == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
ReflectUtil.checkPackageAccess(className);
try {
if (clr == null) throw new ClassNotFoundException(className);
theClass = clr.loadClass(className);
}
catch (ClassNotFoundException ee) {
throw new ReflectionException(ee,
"The MBean class could not be loaded by the default loader repository");
}
return theClass;
}
/**
* Gets the class for the specified class name using the specified
* class loader
*/
public Class<?> findClass(String className, ObjectName aLoader)
throws ReflectionException, InstanceNotFoundException {
if (aLoader == null)
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null loader passed in parameter");
// Retrieve the class loader from the repository
ClassLoader loader = null;
synchronized (this) {
loader = getClassLoader(aLoader);
}
if (loader == null) {
throw new InstanceNotFoundException("The loader named " +
aLoader + " is not registered in the MBeanServer");
}
return findClass(className,loader);
}
/**
* Load a class with the specified loader, or with this object
* class loader if the specified loader is null.
**/
static Class<?> loadClass(String className, ClassLoader loader)
throws ReflectionException {
Class<?> theClass;
if (className == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
ReflectUtil.checkPackageAccess(className);
try {
if (loader == null)
loader = MBeanInstantiator.class.getClassLoader();
if (loader != null) {
theClass = Class.forName(className, false, loader);
} else {
theClass = Class.forName(className);
}
} catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The MBean class could not be loaded");
}
return theClass;
}
private static int mbeanCreation(MBeanServer mbs, String name)
throws Exception {
int error = 0;
try {
System.out.println("Test: createMBean(" + name + ")");
mbs.createMBean(classname, ObjectName.getInstance(name));
error++;
System.out.println("Didn't get expected exception!");
System.out.println("Test failed!");
} catch (RuntimeOperationsException e) {
System.out.println("Got expected exception = " +
e.getCause().toString());
System.out.println("Test passed!");
}
return error;
}
/**
* Descriptor constructor. Takes as parameter the initial
* capacity of the Map that stores the descriptor fields.
* Capacity will grow as needed.<br> Note that the created empty
* descriptor is not a valid descriptor (the method {@link
* #isValid isValid} returns <CODE>false</CODE>).
*
* @param initNumFields The initial capacity of the Map that
* stores the descriptor fields.
*
* @exception RuntimeOperationsException for illegal value for
* initNumFields (<= 0)
* @exception MBeanException Wraps a distributed communication Exception.
*/
public DescriptorSupport(int initNumFields)
throws MBeanException, RuntimeOperationsException {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(initNumFields = " + initNumFields + ")",
"Constructor");
}
if (initNumFields <= 0) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(initNumFields)",
"Illegal arguments: initNumFields <= 0");
}
final String msg =
"Descriptor field limit invalid: " + initNumFields;
final RuntimeException iae = new IllegalArgumentException(msg);
throw new RuntimeOperationsException(iae, msg);
}
init(null);
}
public synchronized Object getFieldValue(String fieldName)
throws RuntimeOperationsException {
if ((fieldName == null) || (fieldName.equals(""))) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"getFieldValue(String fieldName)",
"Illegal arguments: null field name");
}
final String msg = "Fieldname requested is null";
final RuntimeException iae = new IllegalArgumentException(msg);
throw new RuntimeOperationsException(iae, msg);
}
Object retValue = descriptorMap.get(fieldName);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"getFieldValue(String fieldName = " + fieldName + ")",
"Returns '" + retValue + "'");
}
return(retValue);
}
/**
* Loads the class with the specified name using this object's
* Default Loader Repository.
**/
public Class<?> findClassWithDefaultLoaderRepository(String className)
throws ReflectionException {
Class<?> theClass;
if (className == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
ReflectUtil.checkPackageAccess(className);
try {
if (clr == null) throw new ClassNotFoundException(className);
theClass = clr.loadClass(className);
}
catch (ClassNotFoundException ee) {
throw new ReflectionException(ee,
"The MBean class could not be loaded by the default loader repository");
}
return theClass;
}
/**
* Always fails since the MBeanServerDelegate MBean has no operation.
*
* @param actionName The name of the action to be invoked.
* @param params An array containing the parameters to be set when the
* action is invoked.
* @param signature An array containing the signature of the action.
*
* @return The object returned by the action, which represents
* the result of invoking the action on the MBean specified.
*
* @exception MBeanException Wraps a <CODE>java.lang.Exception</CODE>
* thrown by the MBean's invoked method.
* @exception ReflectionException Wraps a
* <CODE>java.lang.Exception</CODE> thrown while trying to invoke
* the method.
*/
public Object invoke(String actionName, Object params[],
String signature[])
throws MBeanException, ReflectionException {
// Check that operation name is not null.
//
if (actionName == null) {
final RuntimeException r =
new IllegalArgumentException("Operation name cannot be null");
throw new RuntimeOperationsException(r,
"Exception occurred trying to invoke the operation on the MBean");
}
throw new ReflectionException(
new NoSuchMethodException(actionName),
"The operation with name " + actionName +
" could not be found");
}
public Object getAttribute(String attributeName) throws AttributeNotFoundException,
MBeanException,
ReflectionException {
if ( attributeName == null ) {
throw new RuntimeOperationsException( new IllegalArgumentException( "attributeName cannot be null" ),
"Cannot invoke a getter of " + getClass().getName() );
} else if ( attributeName.equals( ATTR_ID ) ) {
return getId();
} else if ( attributeName.equals( ATTR_SESSION_COUNT ) ) {
return Long.valueOf( getSessionCount() );
} else if ( attributeName.equals( ATTR_GLOBALS ) ) {
try {
return getGlobals();
} catch ( OpenDataException e ) {
throw new RuntimeOperationsException( new RuntimeException( "Error retrieving globals list",
e ),
"Error retrieving globals list " + e.getMessage() );
}
} else if ( attributeName.equals( ATTR_PACKAGES ) ) {
return getPackages();
}
throw new AttributeNotFoundException( "Cannot find " + attributeName + " attribute " );
}
/**
* Descriptor constructor. Takes as parameter the initial
* capacity of the Map that stores the descriptor fields.
* Capacity will grow as needed.<br> Note that the created empty
* descriptor is not a valid descriptor (the method {@link
* #isValid isValid} returns <CODE>false</CODE>).
*
* @param initNumFields The initial capacity of the Map that
* stores the descriptor fields.
*
* @exception RuntimeOperationsException for illegal value for
* initNumFields (<= 0)
* @exception MBeanException Wraps a distributed communication Exception.
*/
public DescriptorSupport(int initNumFields)
throws MBeanException, RuntimeOperationsException {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(initNumFields = " + initNumFields + ")",
"Constructor");
}
if (initNumFields <= 0) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(initNumFields)",
"Illegal arguments: initNumFields <= 0");
}
final String msg =
"Descriptor field limit invalid: " + initNumFields;
final RuntimeException iae = new IllegalArgumentException(msg);
throw new RuntimeOperationsException(iae, msg);
}
init(null);
}
/**
* Load a class with the specified loader, or with this object
* class loader if the specified loader is null.
**/
static Class<?> loadClass(String className, ClassLoader loader)
throws ReflectionException {
Class<?> theClass;
if (className == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
ReflectUtil.checkPackageAccess(className);
try {
if (loader == null)
loader = MBeanInstantiator.class.getClassLoader();
if (loader != null) {
theClass = Class.forName(className, false, loader);
} else {
theClass = Class.forName(className);
}
} catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The MBean class could not be loaded");
}
return theClass;
}
/**
* Obtain and return the value of a specific attribute of this MBean.
*
* @param name Name of the requested attribute
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
}
ContextResourceLink cl = doGetManagedResource();
String value = null;
if ("global".equals(name)) {
return cl.getGlobal();
} else if ("description".equals(name)) {
return cl.getDescription();
} else if ("name".equals(name)) {
return cl.getName();
} else if ("type".equals(name)) {
return cl.getType();
} else {
value = (String) cl.getProperty(name);
if (value == null) {
throw new AttributeNotFoundException("Cannot find attribute [" + name + "]");
}
}
return value;
}
/**
* Set the value of a specific attribute of this MBean.
*
* @param attribute The identification of the attribute to be set
* and the new value
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute is null"),
"Attribute is null");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
}
ContextResourceLink crl = doGetManagedResource();
if ("global".equals(name)) {
crl.setGlobal((String) value);
} else if ("description".equals(name)) {
crl.setDescription((String) value);
} else if ("name".equals(name)) {
crl.setName((String) value);
} else if ("type".equals(name)) {
crl.setType((String) value);
} else {
crl.setProperty(name, "" + value);
}
// cannot use side-effects. It's removed and added back each time
// there is a modification in a resource.
NamingResources nr = crl.getNamingResources();
nr.removeResourceLink(crl.getName());
nr.addResourceLink(crl);
}
protected T doGetManagedResource() throws MBeanException {
try {
@SuppressWarnings("unchecked")
T resource = (T) getManagedResource();
return resource;
} catch (InstanceNotFoundException | RuntimeOperationsException |
InvalidTargetObjectTypeException e) {
throw new MBeanException(e);
}
}
/**
* Obtain and return the value of a specific attribute of this MBean.
*
* @param name Name of the requested attribute
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
}
ContextResource cr = doGetManagedResource();
String value = null;
if ("auth".equals(name)) {
return cr.getAuth();
} else if ("description".equals(name)) {
return cr.getDescription();
} else if ("name".equals(name)) {
return cr.getName();
} else if ("scope".equals(name)) {
return cr.getScope();
} else if ("type".equals(name)) {
return cr.getType();
} else {
value = (String) cr.getProperty(name);
if (value == null) {
throw new AttributeNotFoundException
("Cannot find attribute [" + name + "]");
}
}
return value;
}
/**
* Set the instance handle of the object against which we will execute
* all methods in this ModelMBean management interface.
*
* The caller can provide the mbean instance or the object name to
* the resource, if needed.
*
* @param resource The resource object to be managed
* @param type The type of reference for the managed resource
* ("ObjectReference", "Handle", "IOR", "EJBHandle", or
* "RMIReference")
*
* @exception InstanceNotFoundException if the managed resource object
* cannot be found
* @exception MBeanException if the initializer of the object throws
* an exception
* @exception RuntimeOperationsException if the managed resource or the
* resource type is <code>null</code> or invalid
*/
public void setManagedResource(Object resource, String type)
throws InstanceNotFoundException,
MBeanException, RuntimeOperationsException
{
if (resource == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Managed resource is null"),
"Managed resource is null");
// if (!"objectreference".equalsIgnoreCase(type))
// throw new InvalidTargetObjectTypeException(type);
this.resource = resource;
this.resourceType = resource.getClass().getName();
// // Make the resource aware of the model mbean.
// try {
// Method m=resource.getClass().getMethod("setModelMBean",
// new Class[] {ModelMBean.class});
// if( m!= null ) {
// m.invoke(resource, new Object[] {this});
// }
// } catch( NoSuchMethodException t ) {
// // ignore
// } catch( Throwable t ) {
// log.error( "Can't set model mbean ", t );
// }
}
public void setMBeanDescriptor(Descriptor inMBeanDescriptor)
throws MBeanException, RuntimeOperationsException {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"setMBeanDescriptor(Descriptor)", "Entry");
}
modelMBeanDescriptor = validDescriptor(inMBeanDescriptor);
}
public ModelMBeanOperationInfo getOperation(String inName)
throws MBeanException, RuntimeOperationsException {
ModelMBeanOperationInfo retInfo = null;
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getOperation(String)", "Entry");
}
if (inName == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("inName is null"),
"Exception occurred trying to get the " +
"ModelMBeanOperationInfo of the MBean");
}
MBeanOperationInfo[] operList = modelMBeanOperations; //this.getOperations();
int numOpers = 0;
if (operList != null) numOpers = operList.length;
for (int i=0; (i < numOpers) && (retInfo == null); i++) {
if (inName.equals(operList[i].getName())) {
retInfo = ((ModelMBeanOperationInfo) operList[i].clone());
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getOperation(String)", "Exit");
}
return retInfo;
}
/**
* Sets the values of an array of attributes of this ModelMBean.
* Executes the setAttribute() method for each attribute in the list.
*
* @param attributes A list of attributes: The identification of the
* attributes to be set and the values they are to be set to.
*
* @return The array of attributes that were set, with their new
* values in Attribute instances.
*
* @exception RuntimeOperationsException Wraps an
* {@link IllegalArgumentException}: The object name in parameter
* is null or attributes in parameter is null.
*
* @see #getAttributes
**/
public AttributeList setAttributes(AttributeList attributes) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"setAttribute(Attribute)", "Entry");
}
if (attributes == null)
throw new RuntimeOperationsException(new
IllegalArgumentException("attributes must not be null"),
"Exception occurred trying to set attributes of a "+
"RequiredModelMBean");
final AttributeList responseList = new AttributeList();
// Go through the list of attributes
for (Attribute attr : attributes.asList()) {
try {
setAttribute(attr);
responseList.add(attr);
} catch (Exception excep) {
responseList.remove(attr);
}
}
return responseList;
}
public boolean isRegistered(ObjectName name) {
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Object name cannot be null"),
"Object name cannot be null");
}
name = nonDefaultDomain(name);
/* No Permission check */
// isRegistered is always unchecked as per JMX spec.
return (repository.contains(name));
}
public ModelMBeanNotificationInfo getNotification(String inName)
throws MBeanException, RuntimeOperationsException {
ModelMBeanNotificationInfo retInfo = null;
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getNotification(String)", "Entry");
}
if (inName == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Notification name is null"),
"Exception occurred trying to get the " +
"ModelMBeanNotificationInfo of the MBean");
}
MBeanNotificationInfo[] notifList = modelMBeanNotifications; //this.getNotifications();
int numNotifs = 0;
if (notifList != null) numNotifs = notifList.length;
for (int i=0; (i < numNotifs) && (retInfo == null); i++) {
if (inName.equals(notifList[i].getName())) {
retInfo = ((ModelMBeanNotificationInfo) notifList[i].clone());
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getNotification(String)", "Exit");
}
return retInfo;
}
public void addNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException {
// ------------------------------
// ------------------------------
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"addNotificationListener", "ObjectName = " + name);
}
DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "addNotificationListener");
NotificationBroadcaster broadcaster =
getNotificationBroadcaster(name, instance,
NotificationBroadcaster.class);
// ------------------
// Check listener
// ------------------
if (listener == null) {
throw new RuntimeOperationsException(new
IllegalArgumentException("Null listener"),"Null listener");
}
NotificationListener listenerWrapper =
getListenerWrapper(listener, name, instance, true);
broadcaster.addNotificationListener(listenerWrapper, filter, handback);
}
/**
* Constructor taking field names and field values. Neither array
* can be null.
*
* @param fieldNames String array of field names. No elements of
* this array can be null.
* @param fieldValues Object array of the corresponding field
* values. Elements of the array can be null. The
* <code>fieldValue</code> must be valid for the
* <code>fieldName</code> (as defined in method {@link #isValid
* isValid})
*
* <p>Note: array sizes of parameters should match. If both arrays
* are empty, then an empty descriptor is created.</p>
*
* @exception RuntimeOperationsException for illegal value for
* field Names or field Values. The array lengths must be equal.
* If the descriptor construction fails for any reason, this
* exception will be thrown.
*
*/
public DescriptorSupport(String[] fieldNames, Object[] fieldValues)
throws RuntimeOperationsException {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(fieldNames,fieldObjects)", "Constructor");
}
if ((fieldNames == null) || (fieldValues == null) ||
(fieldNames.length != fieldValues.length)) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(fieldNames,fieldObjects)",
"Illegal arguments");
}
final String msg =
"Null or invalid fieldNames or fieldValues";
final RuntimeException iae = new IllegalArgumentException(msg);
throw new RuntimeOperationsException(iae, msg);
}
/* populate internal structure with fields */
init(null);
for (int i=0; i < fieldNames.length; i++) {
// setField will throw an exception if a fieldName is be null.
// the fieldName and fieldValue will be validated in setField.
setField(fieldNames[i], fieldValues[i]);
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) {
MODELMBEAN_LOGGER.logp(Level.FINEST,
DescriptorSupport.class.getName(),
"Descriptor(fieldNames,fieldObjects)", "Exit");
}
}