try {
m_dependency.acquireWriteLockIfNotHeld();
if (m_matchingReferences.containsKey(reference)) {
// do we still accept the reference
TransformedServiceReference initial = m_matchingReferences.get(reference);
TransformedServiceReference accepted = new TransformedServiceReferenceImpl(reference);
accepted = accept(accepted);
if (accepted == null) {
// case 1
m_matchingReferences.remove(reference);
onDepartureOfAMatchingService(initial, service);
eventType = DEPARTURE;
eventRef = initial;
} else {
// Do we have a real change
if (!ServiceReferenceUtils.haveSameProperties(initial, accepted)) {
// case 3
m_matchingReferences.put(reference, accepted);
onModificationOfAMatchingService(accepted, service);
eventType = MODIFIED;
eventRef = accepted;
}
}
} else {
// Base does not contain the service, let's try to add it.
TransformedServiceReference transformed = new TransformedServiceReferenceImpl(reference);
transformed = accept(transformed);
if (transformed != null) {
// case 2
m_matchingReferences.put(reference, transformed);
onNewMatchingService(transformed);