// Restore the back references ...
if (!referrersByNodeKey.isEmpty()) {
for (Map.Entry<NodeKey, ReferrerCounts> entry : referrersByNodeKey.entrySet()) {
PropertyFactory propFactory = context.getPropertyFactory();
MutableCachedNode referred = cache.mutable(entry.getKey());
ReferrerCounts counts = entry.getValue();
if (referred != null && counts != null) {
// Add in the strong and weak referrers (that are outside the import scope) that used to be in the node
// before it was replaced ...
for (NodeKey key : counts.getStrongReferrers()) {
int count = counts.countStrongReferencesFrom(key);
for (int i = 0; i != count; ++i) {
Property prop = propFactory.create(nameFor(key.toString() + i));
referred.addReferrer(cache, prop, key, ReferenceType.STRONG);
}
}
for (NodeKey key : counts.getWeakReferrers()) {
int count = counts.countWeakReferencesFrom(key);
for (int i = 0; i != count; ++i) {
Property prop = propFactory.create(nameFor(key.toString() + i));
referred.addReferrer(cache, prop, key, ReferenceType.WEAK);
}
}