/** Create naming event from a change control */ private DSEvent createDSEvent(LDAPEntry entry, LDAPEntryChangeControl changeCtrl, Request req) throws Exception { DSEvent dsEvent = new DSEvent(); if (debugger.messageEnabled()) { debugger.message( "EventService.createDSEvent() - Notifying event " + "to: " + req.getListener()); } // Get the dn from the entry String dn = entry.getDN(); dsEvent.setID(dn); // Get information on the type of change made int changeType = changeCtrl.getChangeType(); dsEvent.setEventType(changeType); // Pass the search ID as the event's change info dsEvent.setSearchID(req.getRequestID()); // set the object class name String className = entry.getAttribute("objectclass").toString(); dsEvent.setClassName(className); return dsEvent; }
/** Process change notification attached as the change control to the message */ protected void processSearchResultMessage(LDAPSearchResult res, Request req) { LDAPEntry modEntry = res.getEntry(); if (debugger.messageEnabled()) { debugger.message( "EventService.processSearchResultMessage() - " + "Changed " + modEntry.getDN()); } /* Get any entry change controls. */ LDAPControl[] ctrls = res.getControls(); // Can not create event without change control if (ctrls == null) { Exception ex = new Exception("EventService - Cannot create " + "NamingEvent, no change control info"); dispatchException(ex, req); } else { // Multiple controls might be in the message for (int i = 0; i < ctrls.length; i++) { LDAPEntryChangeControl changeCtrl = null; if (ctrls[i].getType() == LDAPControl.LDAP_ENTRY_CHANGE_CONTROL) { changeCtrl = (LDAPEntryChangeControl) ctrls[i]; if (debugger.messageEnabled()) { debugger.message( "EventService." + "processSearchResultMessage() changeCtrl = " + changeCtrl.toString()); } // Can not create event without change control if (changeCtrl.getChangeType() == -1) { Exception ex = new Exception( "EventService - Cannot " + "create NamingEvent, no change control info"); dispatchException(ex, req); } // Convert control into a DSEvent and dispatch to listeners try { DSEvent event = createDSEvent(modEntry, changeCtrl, req); dispatchEvent(event, req); } catch (Exception ex) { dispatchException(ex, req); } } } } }