FileDocCategorySizeDatePackage
BaseAdminEventHandler.javaAPI DocGlassfish v2 API6043Fri May 04 22:33:34 BST 2007com.sun.enterprise.admin.event

BaseAdminEventHandler

public class BaseAdminEventHandler extends Object
This class calls appropriates listener method for the event with a specific action code
author
Satish Viswanatham

Fields Summary
private AdminEvent
_event
private static String
ACTION_UPDATE_METHOD
private static String
ACTION_DELETE_METHOD
private static String
ACTION_CREATE_METHOD
private static String
GENERIC_PROCESS_EVENT_METHOD
Constructors Summary
public BaseAdminEventHandler(AdminEvent event)
Constructor

        _event = event;
     
Methods Summary
private voidinvokeAdminEventListener(AdminEventListener listener, AdminEvent e)

        
        AdminEventMulticaster aem = AdminEventMulticaster.getInstance();
        AdminEventResult result = AdminEventResult.getAdminEventResult(e);

        try {
           invokeNotification(listener, GENERIC_PROCESS_EVENT_METHOD, e);
           return;
        }catch (Throwable t) {
            if( !(t instanceof NoSuchMethodException))
                aem.handleListenerError(e, t, result);
        }
        
        try {
           invokeNotification(listener, GENERIC_PROCESS_EVENT_METHOD, e, AdminEvent.class);
           return;
        }catch (Throwable t) {
            if( !(t instanceof NoSuchMethodException))
                aem.handleListenerError(e, t, result);
        }
    
        try {
            ElementChangeEvent event = (ElementChangeEvent)e;
            int code = event.getActionType();
            if ( code == ElementChangeEvent.ACTION_ELEMENT_CREATE ) {
                invokeNotification(listener,ACTION_CREATE_METHOD, e);
            } else if ( code == ElementChangeEvent.ACTION_ELEMENT_UPDATE) {
                invokeNotification(listener,ACTION_UPDATE_METHOD, e);
            } else if (code == ElementChangeEvent.ACTION_ELEMENT_DELETE) {
                invokeNotification(listener,ACTION_DELETE_METHOD, e);
            } else {
                throw new RuntimeException("not valid error code");
            }
        } catch (Throwable t) {
            aem.handleListenerError(e, t, result);
        }
    
private voidinvokeNotification(AdminEventListener ae, java.lang.String methodName, AdminEvent e)

        invokeNotification(ae, methodName, e, ((Object)e).getClass());
    
private voidinvokeNotification(AdminEventListener ae, java.lang.String methodName, AdminEvent e, java.lang.Class eventParamClass)

        Method meth = null;
        meth = ae.getClass().getMethod( methodName, new Class[]{eventParamClass});
        try {
            meth.invoke(ae, new Object[]{e});
        } catch (Exception ex) {
            Throwable t = ex.getCause();
            if (t != null) {
                throw (Exception)t;
            }
            else {
                throw ex;
            }
        } 
    
public intprocessEvent()
This method processes the event.

        List list = AdminEventMulticaster.getInstance().getListeners(
                            _event.getType());
                if (list != null && !list.isEmpty()) {
            Iterator iter = list.iterator();
            while (iter.hasNext()) {
                AdminEventListener listener =
                        (AdminEventListener)iter.next();
                invokeAdminEventListener(listener, _event);
            }
        }
        return ((list != null) ? list.size() : 0);