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

ElementChangeEvent

public class ElementChangeEvent extends com.sun.enterprise.admin.event.AdminEvent
Config Element Change Event - emitted by DAS after comletion of create/delete/update operation on domain.xml element (node) only for those elements which have nonempty "ChangeListener" field in correspondent descriptor entry. Contains element(mbean) type, id (primary key value), and action type.

Fields Summary
public static final int
ACTION_ELEMENT_UNDEFINED
Constant denoting action code
public static final int
ACTION_ELEMENT_CREATE
public static final int
ACTION_ELEMENT_DELETE
public static final int
ACTION_ELEMENT_UPDATE
static final String
eventType
Event type
private int
change_action
Attributes
private String
element_id
private String
element_type
private String
element_path
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public ElementChangeEvent(String instance, String evtType, int actionCode, String elementId)

        super(evtType, instance);

        //set element's id(primary key value) [can be null]
        element_id = elementId;
        //validate and set action code
        setAction(actionCode);
    
Methods Summary
public voidaddConfigChange(java.util.ArrayList changeList)

        // only initial changes add allowed
        if(getConfigChangeList()!=null)
        { 
            String msg = localStrings.getString( "admin.event.wrong_configchange" );
            throw new IllegalArgumentException( msg );
        }
        /* commented for now to avoid double check
         if(ElementChangeHelpe.checkChangeListForElement(changeList);
        {
            String msg = localStrings.getString( "admin.event.wrong_configchange" );
            throw new IllegalArgumentException( msg );
        }*/
        super.addConfigChange(changeList);
    
public intgetActionType()
Get action type for this event.

        return change_action;
    
public java.lang.StringgetElementId()
Get element's id(primary key value)

        return this.element_id;
    
public java.lang.StringgetElementXPath()
get element's xpath

        return ElementChangeHelper.getElementXPath(this.getConfigChangeList());
    
public static java.util.ArrayListgetEventInstances(java.lang.String event_type, java.lang.String instanceName, java.lang.String elementType, java.util.ArrayList changeList, com.sun.enterprise.config.ConfigContext ctx)


    /* *****************************************************
     *  default ElementChange events factory
     * @param event_type - event type from mbean decriptor xml file
     * @param instanceName
     * @param changeList
     * @param ctx
     */
       
                     
                     
    
        int      action          = ElementChangeHelper.getActionCodeForChanges(changeList);
        if(action==ElementChangeEvent.ACTION_ELEMENT_UNDEFINED)
            return null; //ignore wrong type
        String   element_xpath   = ElementChangeHelper.getElementXPath(changeList);
        String   element_id      = ElementChangeHelper.getConfigElementPrimaryKey(element_xpath); 

        AdminEvent event = null;
        if(event_type.equals(eventType))
        {
            //ElementChangeEvent ?
            event = new ElementChangeEvent(instanceName, event_type, action, element_id);
        }
        else
        {
            //let's try construct  
            try {
                Class cl = Class.forName(event_type);
                Constructor contr;
                try {
                    // unnamed element event ?
                    contr = cl.getConstructor(
                      new Class[]{String.class, Integer.TYPE});
                    event = (AdminEvent)contr.newInstance(
                      new Object[]{instanceName, new Integer(action)});
                } catch (Exception e) { 
                }
                
                if(event==null)
                {
                    //maybe named
                    contr = cl.getConstructor(
                        new Class[]{String.class, Integer.TYPE, String.class});
                    event = (AdminEvent)contr.newInstance(
                        new Object[]{instanceName, new Integer(action), element_id});
                }
                if(event!=null)
                    event.addConfigChange(changeList);
            } catch (Exception e) { 
                //throw e;
                return null; //?
            }
        }
        if(event!=null)
        {
            String targetName = ElementChangeHelper.getConfigElementTargetName(element_xpath, ctx);
            event.setTargetDestination(targetName);
            ArrayList events = new ArrayList();
            events.add(event);
            return events;
        }
        return null;
    
private voidsetAction(int action)
Set action to specified value. If action is not one of allowed, then IllegalArgumentException is thrown.

throws
IllegalArgumentException if action is invalid

        boolean valid = false;
        if (action==ACTION_ELEMENT_CREATE ||
            action==ACTION_ELEMENT_DELETE ||
            action==ACTION_ELEMENT_UPDATE )
            valid = true;
        if (!valid) {
			String msg = localStrings.getString( "admin.event.invalid_action", ""+action );
            throw new IllegalArgumentException( msg );
        }
        this.change_action = action;