List extensionList = null;
if(notification.getEventType() == Notification.REMOVE_MANY)
extensionList = (List) notification.getOldValue();
else{
extensionList = new BasicEList();
extensionList.add(notification.getOldValue());
}
for (Iterator iter = extensionList.iterator(); iter.hasNext();) {
Extension extension = (Extension) iter.next();
EObject extendedObject = extension.getExtendedObject();
// if the exended EObject had an adapter, remove it.
if(extendedObject != null){
EList adapters = extendedObject.eAdapters();
EList removeAdapterList = new BasicEList();
for (Iterator iter2 = adapters.iterator();iter2.hasNext();) {
Adapter adapter = (Adapter) iter2.next();
if((adapter instanceof ExtendedObjectUserAdapter && ((ExtendedObjectUserAdapter)adapter).getNamespace().equals(((ExtensionMap)getTarget()).getNamespace()))||
adapter instanceof ExtendedObjectAdapter && ((ExtendedObjectAdapter)adapter).getNamespace().equals(((ExtensionMap)getTarget()).getNamespace())){
removeAdapterList.add(adapter);
}
}
for (Iterator iter2 = removeAdapterList.iterator(); iter2.hasNext();) {
Adapter adapter = (Adapter) iter2.next();
try{
((ExtendedObjectAdapter)adapter).setExtension(null);
}catch(ClassCastException e){}
extendedObject.eAdapters().remove(adapter);
}
}
// Set the Extension attributes to null.
if (!(notification.getNotifier() instanceof Extension)){
if(extension.getExtendedObject() != null)
extension.setExtendedObject(null);
if(extension.getExtensionObject() != null)
extension.setExtensionObject(null);
}
}
break;
case Notification.REMOVING_ADAPTER :
ExtensionMap map = (ExtensionMap) notification.getNotifier();
Set extendedObjects = map.keySet();
for (Iterator iter = extendedObjects.iterator(); iter.hasNext();) {
EObject element = (EObject) iter.next();
List remove = new BasicEList();
for (Iterator iterator = element.eAdapters().iterator(); iterator.hasNext();) {
Adapter adapter = (Adapter) iterator.next();
if(adapter instanceof ExtendedObjectUserAdapter ||
adapter instanceof ExtendedObjectAdapter)
remove.add(adapter);
}
element.eAdapters().removeAll(remove);
}
break;