// it does not exist as far as we are concerned
if (ctx == null)
throw new AttributeNotFoundException("not found: " + attribute.getName());
// create the invocation object
Invocation invocation = new Invocation();
// copy the server context to the invocation
invocation.addContext(ctx);
// indicate the access point as setAttribute()
invocation.setType(InvocationContext.OP_SETATTRIBUTE);
// set the attribute value as the argument
invocation.setArgs(new Object[] { attribute.getValue() });
try
{
// the default invocation implementation will invoke each interceptor
// declared in the invocation context before invoking the target method
invocation.invoke();
}
// Both interceptors and the invocation object propagate only one exception
// type, InvocationException, which wraps the underlying JMX exception
// (which in turn may wrap application exception, as per the JMX spec).
// Unwrap the outermost InvocationException layer here.
catch (InvocationException e)
{
if (e.getTargetException() instanceof InvalidAttributeValueException)
throw (InvalidAttributeValueException)e.getTargetException();
if (e.getTargetException() instanceof AttributeNotFoundException)
throw (AttributeNotFoundException)e.getTargetException();
if (e.getTargetException() instanceof MBeanException)
throw (MBeanException)e.getTargetException();
else if (e.getTargetException() instanceof ReflectionException)
throw (ReflectionException)e.getTargetException();
else if (e.getTargetException() instanceof RuntimeMBeanException)
throw (RuntimeMBeanException)e.getTargetException();
else if (e.getTargetException() instanceof RuntimeErrorException)
throw (RuntimeErrorException)e.getTargetException();
else
throw new RuntimeException(e.getTargetException().toString());
}
// any other throwable object that gets propagated back to the invoker
// indicates an error in the server or in the interceptor implementation.
catch (Throwable t)
{
throw new RuntimeOperationsException(new RuntimeException(
"Unhandled throwable propagated to the invoker by " +
invocation + ":" +t.toString())
);
}
// TODO: should be fixed by adding invocation return value object
finally
{
ctx.setDescriptor(invocation.getDescriptor());
}
}