use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class MBeanInstantiator method instantiate.
/**
* Instantiates an object given its class, the parameters and
* signature of its constructor The call returns a reference to
* the newly created object.
*/
public Object instantiate(Class<?> theClass, Object[] params, String[] signature, ClassLoader loader) throws ReflectionException, MBeanException {
checkMBeanPermission(theClass, null, null, "instantiate");
// Instantiate the new object
// ------------------------------
// ------------------------------
final Class<?>[] tab;
Object moi;
try {
// Build the signature of the method
//
ClassLoader aLoader = theClass.getClassLoader();
// Build the signature of the method
//
tab = ((signature == null) ? null : findSignatureClasses(signature, aLoader));
}// Exception IllegalArgumentException raised in Jdk1.1.8
catch (IllegalArgumentException e) {
throw new ReflectionException(e, "The constructor parameter classes could not be loaded");
}
// Query the metadata service to get the right constructor
Constructor<?> cons = findConstructor(theClass, tab);
if (cons == null) {
throw new ReflectionException(new NoSuchMethodException("No such constructor"));
}
try {
ReflectUtil.checkPackageAccess(theClass);
ensureClassAccess(theClass);
moi = cons.newInstance(params);
} catch (NoSuchMethodError error) {
throw new ReflectionException(new NoSuchMethodException("No such constructor found"), "No such constructor");
} catch (InstantiationException e) {
throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's constructor");
} catch (IllegalAccessException e) {
throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's constructor");
} catch (InvocationTargetException e) {
// Wrap the exception.
Throwable th = e.getTargetException();
if (th instanceof RuntimeException) {
throw new RuntimeMBeanException((RuntimeException) th, "RuntimeException thrown in the MBean's constructor");
} else if (th instanceof Error) {
throw new RuntimeErrorException((Error) th, "Error thrown in the MBean's constructor");
} else {
throw new MBeanException((Exception) th, "Exception thrown in the MBean's constructor");
}
}
return moi;
}
use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class MBeanInstantiator method instantiate.
/**
* Instantiates an object given its class, using its empty constructor.
* The call returns a reference to the newly created object.
*/
public Object instantiate(Class<?> theClass) throws ReflectionException, MBeanException {
checkMBeanPermission(theClass, null, null, "instantiate");
Object moi;
// ------------------------------
// ------------------------------
Constructor<?> cons = findConstructor(theClass, null);
if (cons == null) {
throw new ReflectionException(new NoSuchMethodException("No such constructor"));
}
// Instantiate the new object
try {
ReflectUtil.checkPackageAccess(theClass);
ensureClassAccess(theClass);
moi = cons.newInstance();
} catch (InvocationTargetException e) {
// Wrap the exception.
Throwable t = e.getTargetException();
if (t instanceof RuntimeException) {
throw new RuntimeMBeanException((RuntimeException) t, "RuntimeException thrown in the MBean's empty constructor");
} else if (t instanceof Error) {
throw new RuntimeErrorException((Error) t, "Error thrown in the MBean's empty constructor");
} else {
throw new MBeanException((Exception) t, "Exception thrown in the MBean's empty constructor");
}
} catch (NoSuchMethodError error) {
throw new ReflectionException(new NoSuchMethodException("No constructor"), "No such constructor");
} catch (InstantiationException e) {
throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalAccessException e) {
throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalArgumentException e) {
throw new ReflectionException(e, "Exception thrown trying to invoke the MBean's empty constructor");
}
return moi;
}
use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method set.
/**
* Set the value of an SNMP variable.
*
* <p><b><i>
* You should never need to use this method directly.
* </i></b></p>
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* @return The new value of the variable after the operation.
*
* @exception SnmpStatusException whenever an SNMP exception must be
* raised. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Attribute att = new Attribute(attname, attvalue);
Object result = null;
try {
server.setAttribute(name, att);
result = server.getAttribute(name, attname);
} catch (InvalidAttributeValueException iv) {
throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
} catch (InstanceNotFoundException f) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
return meta.buildSnmpValue(id, result);
}
use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method check.
/**
* Checks whether a SET operation can be performed on a given SNMP
* variable.
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* <p>
* This method calls checkSetAccess() on the meta object, and then
* tries to invoke the check<i>AttributeName</i>() method on the MBean.
* If this method is not defined then it is assumed that the SET
* won't fail.
* </p>
*
* <p><b><i>
* This method is called internally by <code>mibgen</code> generated
* objects and you should never need to call it directly.
* </i></b></p>
*
* @exception SnmpStatusException if the requested SET operation must
* be rejected. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
*
**/
// XXX xxx ZZZ zzz Maybe we should go through the MBeanInfo here?
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
meta.checkSetAccess(x, id, data);
try {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Object[] params = new Object[1];
final String[] signature = new String[1];
params[0] = attvalue;
signature[0] = attvalue.getClass().getName();
server.invoke(name, "check" + attname, params, signature);
} catch (SnmpStatusException e) {
throw e;
} catch (InstanceNotFoundException i) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
// checkXXXX() not defined => do nothing
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
}
use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class SnmpMibAgent method setSnmpAdaptorName.
/**
* Sets the reference to the SNMP protocol adaptor through which the MIB
* will be SNMP accessible and add this new MIB in the SNMP MIB handler
* associated to the specified <CODE>name</CODE>.
*
* @param name The name of the SNMP protocol adaptor.
*
* @exception InstanceNotFoundException The SNMP protocol adaptor does
* not exist in the MBean server.
*
* @exception ServiceNotFoundException This SNMP MIB is not registered
* in the MBean server or the requested service is not supported.
*/
@Override
public void setSnmpAdaptorName(ObjectName name) throws InstanceNotFoundException, ServiceNotFoundException {
if (server == null) {
throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
}
//
if (adaptor != null) {
adaptor.removeMib(this);
}
// Then update the reference to the new adaptor server.
//
Object[] params = { this };
String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent" };
try {
adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
} catch (InstanceNotFoundException e) {
throw new InstanceNotFoundException(name.toString());
} catch (ReflectionException e) {
throw new ServiceNotFoundException(name.toString());
} catch (MBeanException e) {
// Should never occur...
}
adaptorName = name;
}
Aggregations