use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class ContextResourceLinkMBean method setAttribute.
/**
* 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);
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class ContextResourceMBean method setAttribute.
/**
* 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");
}
ContextResource cr = doGetManagedResource();
if ("auth".equals(name)) {
cr.setAuth((String) value);
} else if ("description".equals(name)) {
cr.setDescription((String) value);
} else if ("name".equals(name)) {
cr.setName((String) value);
} else if ("scope".equals(name)) {
cr.setScope((String) value);
} else if ("type".equals(name)) {
cr.setType((String) value);
} else {
cr.setProperty(name, "" + value);
}
// cannot use side-effects. It's removed and added back each time
// there is a modification in a resource.
NamingResources nr = cr.getNamingResources();
nr.removeResource(cr.getName());
nr.addResource(cr);
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class ContextResourceMBean method getAttribute.
/**
* 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;
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class BaseModelMBean method setAttribute.
/**
* 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 {
if (log.isDebugEnabled())
log.debug("Setting attribute " + this + " " + attribute);
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
try {
((DynamicMBean) resource).setAttribute(attribute);
} catch (InvalidAttributeValueException e) {
throw new MBeanException(e);
}
return;
}
// 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");
Object oldValue = null;
//if( getAttMap.get(name) != null )
// oldValue=getAttribute( name );
Method m = managedBean.getSetter(name, this, resource);
try {
if (m.getDeclaringClass().isAssignableFrom(this.getClass())) {
m.invoke(this, new Object[] { value });
} else {
m.invoke(resource, new Object[] { value });
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException(e, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
try {
sendAttributeChangeNotification(new Attribute(name, oldValue), attribute);
} catch (Exception ex) {
log.error("Error sending notification " + name, ex);
}
//attributes.put( name, value );
// if( source != null ) {
// // this mbean is associated with a source - maybe we want to persist
// source.updateField(oname, name, value);
// }
}
use of javax.management.RuntimeOperationsException in project tomcat by apache.
the class BaseModelMBean method sendNotification.
/**
* Send a <code>Notification</code> which contains the specified string
* as a <code>jmx.modelmbean.generic</code> notification.
*
* @param message The message string to 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 sendNotification(String message) throws MBeanException, RuntimeOperationsException {
if (message == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Message is null"), "Message is null");
Notification notification = new Notification("jmx.modelmbean.generic", this, 1, message);
sendNotification(notification);
}
Aggregations