In this example code, the method simply processes the EventNotification object for the conditions where it contains a collection of nested EventNotification objects, and prints some detail about each EventNotification object.
public void onEvent(EventNotification eventNotification)
throws EventException
{
// output a message that an event was received
String vargs[] = { eventNotification.toStringShort() };
System.out.println(getMessage("event.received",vargs));
// output some details about the event
switch (eventNotification.getSubject() )
{
// generic transaction subject events can contain a
// collection of event notifications related
// to a single transaction
case EventRegistration.SUBJECT_GENERIC_TRANSACTION:
if (
eventNotification.getNestedEventNotifications()
== null)
showEventNotificationDetail(eventNotification);
else
{
Iterator eventIter =
eventNotification.
getNestedEventNotifications().iterator();
while ( eventIter.hasNext() )
{
EventNotification nestedEvent =
(EventNotification) eventIter.next();
showEventNotificationDetail(nestedEvent);
}
}
break;
case EventRegistration.SUBJECT_SERVER: showEventNotificationDetail(eventNotification);
break;
}
}
private void showEventNotificationDetail(
EventNotification eventNotification)
{
BaseValueObject valueObject =
eventNotification.getValueObject();
String vargs[] = {EventRegistration.getAspectName (
eventNotification.getAspect()),
valueObject.getName(),
valueObject.toStringDebug() };
System.out.println(getMessage("event.detail",vargs));
}
)