@Override
public void notifyChanged(Notification msg) {
//
// Get ID factory
//
EFeatureIDFactory eIDFactory = eIDFactory();
//
// Does this context generate IDs?
//
if( !(eIDFactory instanceof EFeatureVoidIDFactory) ) {
//
// Is added or removed?
//
if( msg.getEventType() == Notification.ADD ) {
Object value = msg.getNewValue();
if(value instanceof EObject) {
//
// Implements EFeature?
//
if(value instanceof EFeature) {
//
// Cast to EFeature
//
EFeature eFeature = (EFeature)value;
//
// ----------------------------------------------------------
// Adapt given EFeature (does nothing if already in context)
// ----------------------------------------------------------
// This is a very important step: It's part of the context
// startup problem solution (see EFeatureContextHelper),
// and ensures that context-unaware objects become
// aware of the context they are added to. Without this
// step, EFeature stays context-unaware, preventing
// EFeatureReaders from reading them using a context ID
// known by client code.
// ----------------------------------------------------------
//
eAdapt(eFeature, true);
//
// Get current ID
//
String eID = eFeature.getID();
//
// Resolve unique ID
//
if( !( eID==null || eID.length()==0 ) ) {
eIDFactory.useID(eFeature, eID);
} else {
eIDFactory.createID(eFeature);
}
} else if(eIDFactory.creates((EObject)value)) {
//
// Adapt object directly to context
//
eStructure().eAdapt((EObject)value);
}
}
else if(value instanceof Resource) {
((Resource)value).eAdapters().add(this);
}
} else if( msg.getEventType() == Notification.REMOVE ) {
Object value = msg.getOldValue();
if(value instanceof EObject) {
//
// Cast to EObject
//
EObject eObject = (EObject)value;
//
// ID created for this object?
//
if(eIDFactory.contains(eObject)) {
try {
//
// This should never fail...
//
eIDFactory.disposeID(eObject);
} catch (IllegalArgumentException e) {
//
// ... but if it does, log a warning ...
//