@SuppressWarnings({ "unchecked", "rawtypes" })
protected void addRelations(RebindContext rebindContext, T memento) {
for (Map.Entry<String,Set<String>> rEntry : memento.getRelations().entrySet()) {
RelationshipType<? extends BrooklynObject, ? extends BrooklynObject> r = EntityRelations.lookup(instance.getManagementContext(), rEntry.getKey());
if (r==null) throw new IllegalStateException("Unsupported relationship -- "+rEntry.getKey() + " -- in "+memento);
for (String itemId: rEntry.getValue()) {
BrooklynObject item = rebindContext.lookup().lookup(null, itemId);
if (item != null) {
instance.relations().add((RelationshipType)r, item);
} else {
LOG.warn("Item not found; discarding item {} relation {} of entity {}({})",
new Object[] {itemId, r, memento.getType(), memento.getId()});
rebindContext.getExceptionHandler().onDanglingUntypedItemRef(itemId);
}
}
}
}