Retrieving Event Objects
EventContext and EventROContext let you access the current event object. You can do so in either of the following ways, as illustrated in the following code for an event listener:
cim1265
EventContext and EventROContext let you access the current event object. You can do so in either of the following ways, as illustrated in the following code for an event listener:
- Call getEventName() to return the name of the current event. You can test for the events that the event listener is mapped to, and that you expect to apply to this listener, and then retrieve the event object accordingly:int before(EventContext eCtx) { if(eCtx.getEventName().equals(ImEventName.CREATEUSEREVENT)) CreateUserEvent evt = (CreateUserEvent); . . . // Event listener processing continues. }
- Call getEvent() to return an IMEvent base interface for the event. For example, if the event listener is mapped to a specific event, such as CreateUserEvent, you can cast the IMEvent object as a CreateUserEvent object, as follows:int before(EventContext eCtx) { CreateUserEvent evt = (CreateUserEvent)eCtx.getEvent(); User user = evt.getUser(); user.setAttribute("CreateTime",new Date().toString()); }