FileDocCategorySizeDatePackage
MBeanServerConnectionExceptionThrower.javaAPI DocGlassfish v2 API17245Fri May 04 22:36:24 BST 2007com.sun.enterprise.admin.jmx.remote.internal

MBeanServerConnectionExceptionThrower

public class MBeanServerConnectionExceptionThrower extends Object
A purely convenience class. MBeanServerConnection interface methods throw a lot of exceptions and an implementation of this interface generally ends up writing large try-catch blocks.

This class has methods whose names are chosen from the class MBeanServerRequestMessage {@link javax.management.remote.message.MBeanServerRequestMessage} and all they do is return specific exceptions cast from the passed exception. If the passed exception is none of the exceptions that a method throws, (which should not be the case most of the times) then a ClassCastException results.

The principal advantage of this class is that it does the repetitive work at one place and moves the exception conversion task away from actual MBeanServerConnection implementation. This way some reuse of the methods throwing the same exceptions is achieved.

author
Kedar Mhaswade.
since
S1AS8.0
version
1.0

Fields Summary
Constructors Summary
private MBeanServerConnectionExceptionThrower()
Creates a new instance of MBeanServerConnectionExceptionThrower

    
Methods Summary
public static voidaddNotificationListenerObjectName(java.lang.Exception e)

		if (e instanceof InstanceNotFoundException)
			throw (InstanceNotFoundException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
		else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
	
public static voidaddNotificationListeners(java.lang.Exception e)

		addNotificationListenerObjectName(e);
	
public static voidcreateMBean(java.lang.Exception e)

        if (e instanceof ReflectionException)
            throw (ReflectionException)e;
        else if (e instanceof InstanceAlreadyExistsException)
            throw (InstanceAlreadyExistsException)e;
        else if (e instanceof MBeanRegistrationException)
            throw (MBeanRegistrationException)e;
        else if (e instanceof MBeanException)
            throw (MBeanException)e;
        else if (e instanceof NotCompliantMBeanException)
            throw (NotCompliantMBeanException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidcreateMBeanLoader(java.lang.Exception e)

        if (e instanceof ReflectionException)
            throw (ReflectionException)e;
        else if (e instanceof InstanceAlreadyExistsException)
            throw (InstanceAlreadyExistsException)e;
        else if (e instanceof MBeanRegistrationException)
            throw (MBeanRegistrationException)e;
        else if (e instanceof MBeanException)
            throw (MBeanException)e;
        else if (e instanceof NotCompliantMBeanException)
            throw (NotCompliantMBeanException)e;
        else if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidcreateMBeanLoaderParams(java.lang.Exception e)

        createMBeanLoader(e); //throws exact same set of exceptions.
    
public static voidcreateMBeanParams(java.lang.Exception e)

        createMBean(e); //throws exact same set of exceptions.
    
public static voidgetAttribute(java.lang.Exception e)

        if (e instanceof MBeanException)
            throw (MBeanException)e;
        else if (e instanceof AttributeNotFoundException)
            throw (AttributeNotFoundException)e;
        else if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof ReflectionException)
            throw (ReflectionException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else //has to be this, otherwise a ClassCastException results.
            throw wrappingIoException(e);
    
public static voidgetAttributes(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof ReflectionException)
            throw (ReflectionException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidgetDefaultDomain(java.lang.Exception e)

        getIOException(e); //throws exact same set of exceptions
    
public static voidgetDomains(java.lang.Exception e)

        getIOException(e); // throws exact same set of exceptions
    
private static voidgetIOException(java.lang.Exception e)

        throw wrappingIoException(e); // has to be this, otherwise ClassCastException results
    
public static voidgetMBeanCount(java.lang.Exception e)

        getIOException(e); // throws exact same set of exceptions
    
public static voidgetMBeanInfo(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof IntrospectionException)
            throw (IntrospectionException)e;
        else if (e instanceof ReflectionException)
            throw (ReflectionException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidgetObjectInstance(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidinvoke(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof MBeanException)
            throw (MBeanException)e;
        else if (e instanceof ReflectionException)
            throw (ReflectionException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else //CCE Results?
			throw wrappingIoException(e);
    
public static voidisInstanceOf(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidisRegistered(java.lang.Exception e)

        getIOException(e); // throws exact same set of exceptions
    
public static voidqueryMBeans(java.lang.Exception e)

        if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        getIOException(e); // throws exact same set of exceptions
    
public static voidqueryNames(java.lang.Exception e)

        if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        getIOException(e); // throws exact same set of exceptions
    
public static voidremoveNotificationListener(java.lang.Exception e)

		if (e instanceof InstanceNotFoundException)
			throw (InstanceNotFoundException)e;
		else if (e instanceof ListenerNotFoundException)
			throw (ListenerNotFoundException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
		else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
	
public static voidremoveNotificationListenerFilterHandback(java.lang.Exception e)

		removeNotificationListener(e);
	
public static voidremoveNotificationListenerObjectName(java.lang.Exception e)

		removeNotificationListener(e);
	
public static voidremoveNotificationListenerObjectNameFilterHandback(java.lang.Exception e)

		removeNotificationListener(e);
	
public static voidsetAttribute(java.lang.Exception e)

        if (e instanceof AttributeNotFoundException)
            throw (AttributeNotFoundException)e;
        else if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof InvalidAttributeValueException)
            throw (InvalidAttributeValueException)e;
        else if (e instanceof MBeanException)
            throw (MBeanException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidsetAttributes(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof ReflectionException)
            throw (ReflectionException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
public static voidunregisterMBean(java.lang.Exception e)

        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException)e;
        else if (e instanceof MBeanRegistrationException)
            throw (MBeanRegistrationException)e;
		else if (e instanceof RuntimeException)
			throw (RuntimeException)e;
        else if (e instanceof NotSerializableException)
            throw wrappedSerializationException(e);
        else
			throw wrappingIoException(e);
    
private static java.lang.RuntimeExceptionwrappedSerializationException(java.lang.Exception e)
A method to create a {@link java.io.NotSerializableException} if that is what gets thrown by the server. It may happen that the server while invoking a specific MBeanServerConnection method throws a NotSerializableException especially if an MBean attribute is not serialiable, invocation result of invoke method is not serializable etc. There is an argument around what to do in this case because {@link java.io.IOException} is kind of reserved for any communication problems and {@link java.io.NotSerializableException} extends {@link java.io.IOException} :). This means that I can't throw only IOException. Hence this method.

return
an instance of {@link java.io.NotSerializableException} that is wrapped inside a {@link RuntimeException}
param
id indicating the integer in @link javax.management.remote.message.MBeanServerRequestMessage} that gives information about the method to invoke

		final String dm = e.getMessage();
		final Throwable cause = e.getCause();
		final StackTraceElement[] st = e.getStackTrace();
		final RuntimeException re = new RuntimeException(dm);
		if (cause != null) {
			re.initCause(cause);
		}
		if (st != null) {
			re.setStackTrace(st);
		}
		return ( re );
    
private static java.io.IOExceptionwrappingIoException(java.lang.Throwable t)
The method which acts as a "catch-all". In the distributed environment, it is obvious that a large set of exceptions is thrown under various circumstances. The ultimate exception on which this implementation falls back is {@link java.io.IOException}. This method receives such an exception, that is not any of those thrown by MBeanServerConnection's methods, and carefully arranges its stack and initial cause. The returned instance of IOException has these properties:
  • Its stack is intact. (if not null)
  • The actual exception becomes the init cause. (if not null, which is the case)
  •             if (t instanceof RedirectException) return (RedirectException) t;
    		final String dm = t.getMessage();
    		final Throwable cause = t.getCause();
    		final StackTraceElement[] st = t.getStackTrace();
    		final IOException ioe = new IOException (dm);
    		if (cause != null) {
    			ioe.initCause(cause);
    		}
    		if (st != null) {
    			ioe.setStackTrace(st);
    		}
    		return ( ioe );