protected void setParent(RebindContext rebindContext, EntityMemento memento) {
   Entity parent =
       (memento.getParent() != null) ? rebindContext.getEntity(memento.getParent()) : null;
   if (parent != null) {
     entity.setParent(parent);
   } else if (memento.getParent() != null) {
     LOG.warn(
         "Entity not found; discarding parent {} of entity {}({}), so entity will be orphaned and unmanaged",
         new Object[] {memento.getParent(), memento.getType(), memento.getId()});
   }
 }
 protected void addEnrichers(RebindContext rebindContext, EntityMemento memento) {
   for (String enricherId : memento.getEnrichers()) {
     AbstractEnricher enricher = (AbstractEnricher) rebindContext.getEnricher(enricherId);
     if (enricher != null) {
       entity.addEnricher(enricher);
     } else {
       LOG.warn(
           "Enricher not found; discarding enricher {} of entity {}({})",
           new Object[] {enricherId, memento.getType(), memento.getId()});
     }
   }
 }
 protected void addPolicies(RebindContext rebindContext, EntityMemento memento) {
   for (String policyId : memento.getPolicies()) {
     AbstractPolicy policy = (AbstractPolicy) rebindContext.getPolicy(policyId);
     if (policy != null) {
       entity.addPolicy(policy);
     } else {
       LOG.warn(
           "Policy not found; discarding policy {} of entity {}({})",
           new Object[] {policyId, memento.getType(), memento.getId()});
     }
   }
 }
 protected void addLocations(RebindContext rebindContext, EntityMemento memento) {
   for (String id : memento.getLocations()) {
     Location loc = rebindContext.getLocation(id);
     if (loc != null) {
       ((EntityInternal) entity).addLocations(ImmutableList.of(loc));
     } else {
       LOG.warn(
           "Location not found; discarding location {} of entity {}({})",
           new Object[] {id, memento.getType(), memento.getId()});
     }
   }
 }
 protected void addChildren(RebindContext rebindContext, EntityMemento memento) {
   for (String childId : memento.getChildren()) {
     Entity child = rebindContext.getEntity(childId);
     if (child != null) {
       entity.addChild(child);
     } else {
       LOG.warn(
           "Entity not found; discarding child {} of entity {}({})",
           new Object[] {childId, memento.getType(), memento.getId()});
     }
   }
 }
 protected void addMembers(RebindContext rebindContext, EntityMemento memento) {
   if (memento.getMembers().size() > 0) {
     if (entity instanceof Group) {
       for (String memberId : memento.getMembers()) {
         Entity member = rebindContext.getEntity(memberId);
         if (member != null) {
           ((Group) entity).addMember(member);
         } else {
           LOG.warn(
               "Entity not found; discarding member {} of group {}({})",
               new Object[] {memberId, memento.getType(), memento.getId()});
         }
       }
     } else {
       throw new UnsupportedOperationException(
           "Entity with members should be a group: entity="
               + entity
               + "; type="
               + entity.getClass()
               + "; members="
               + memento.getMembers());
     }
   }
 }