public void setManagementContext(ManagementContextInternal managementContext) {
    this.managementContext = managementContext;
    if (displayNameAutoGenerated && id != null)
      name.set(getClass().getSimpleName() + ":" + id.substring(0, Math.min(id.length(), 4)));

    Location oldParent = parent.get();
    Set<Location> oldChildren = children;
    Map<String, Object> oldConfig = configBag.getAllConfig();
    Long oldCreationTimeUtc = creationTimeUtc.get();
    String oldDisplayName = name.get();
    HostGeoInfo oldHostGeoInfo = hostGeoInfo.get();

    parent = managementContext.getStorage().getReference(id + "-parent");
    children =
        SetFromLiveMap.create(
            managementContext.getStorage().<Location, Boolean>getMap(id + "-children"));
    creationTimeUtc = managementContext.getStorage().getReference(id + "-creationTime");
    hostGeoInfo = managementContext.getStorage().getReference(id + "-hostGeoInfo");
    name = managementContext.getStorage().getReference(id + "-displayName");

    // Only override stored defaults if we have actual values. We might be in setManagementContext
    // because we are reconstituting an existing entity in a new brooklyn management-node (in which
    // case believe what is already in the storage), or we might be in the middle of creating a new
    // entity. Normally for a new entity (using EntitySpec creation approach), this will get called
    // before setting the parent etc. However, for backwards compatibility we still support some
    // things calling the entity's constructor directly.
    if (oldParent != null) parent.set(oldParent);
    if (oldChildren.size() > 0) children.addAll(oldChildren);
    if (creationTimeUtc.isNull()) creationTimeUtc.set(oldCreationTimeUtc);
    if (hostGeoInfo.isNull()) hostGeoInfo.set(oldHostGeoInfo);
    if (name.isNull()) {
      name.set(oldDisplayName);
    } else {
      displayNameAutoGenerated = false;
    }

    configBag =
        ConfigBag.newLiveInstance(
            managementContext.getStorage().<String, Object>getMap(id + "-config"));
    if (oldConfig.size() > 0) {
      configBag.putAll(oldConfig);
    }
  }
  @Override
  public void setParent(Location newParent) {
    if (newParent == this) {
      throw new IllegalArgumentException("Location cannot be its own parent: " + this);
    }
    if (newParent == parent.get()) {
      return; // no-op; already have desired parent
    }

    // TODO Should we support a location changing parent? The resulting unmanage/manage might cause
    // problems.
    if (parent.get() != null) {
      Location oldParent = parent.get();
      parent.set(null);
      ((AbstractLocation) oldParent).removeChild(this); // FIXME Nasty cast
    }
    if (newParent != null) {
      parent.set(newParent);
      ((AbstractLocation) parent.get()).addChild(this); // FIXME Nasty cast
    }
  }
 @Override
 public HostGeoInfo getHostGeoInfo() {
   return hostGeoInfo.get();
 }
 @Override
 public Location getParent() {
   return parent.get();
 }
 @Override
 public String getDisplayName() {
   return name.get();
 }