HashSet<String> toBeUnregistered = new HashSet<String>();
// get the current self-registrations
String[] regID = getFactory().getRegistrationIDs(this);
for (String i : regID) {
if (selfRegistered.contains(i)) {
RegistrationContext c = getFactory().getRegistrationContext(i);
if (c != null && !c.isPersistent()) {
toBeUnregistered.add(i);
}
}
}
// remove self-registrations that already exist and should continue
for (String i : toBeUnregistered) {
RegistrationContext r = getFactory().getRegistrationContext(i);
for (int j = 0; j < contexts.length; j++) {
if (contextsAreEqual(contexts[j], r)) {
toBeUnregistered.remove(i);
contexts[j] = null;
}
}
}
// unregister those that should not continue to exist
for (String i : toBeUnregistered) {
selfRegistered.remove(i);
getFactory().removeRegistration(i);
}
}
// add new self-segistrations
for (RegistrationContext r : contexts) {
if (r != null) {
String id = getFactory().registerConfigProvider(this,
r.getMessageLayer(), r.getAppContext(),
r.getDescription());
selfRegistered.add(id);
}
}
} finally {
wLock.unlock();