Ejemplo n.º 1
0
  private void handleOrphanedComponents(
      final NCSComponent parent,
      final ComponentIdentifier child,
      final ComponentEventQueue ceq,
      final boolean deleteOrphans) {
    final ComponentIdentifier parentId = getIdentifier(parent);
    final NCSComponent childComponent = getComponent(child);

    final Set<ComponentIdentifier> childChildren =
        getIdentifiers(childComponent.getSubcomponents());
    final Set<ComponentIdentifier> childParents =
        getIdentifiers(childComponent.getParentComponents());

    LogUtils.tracef(this, "handleOrphanedComponents: parent: %s", parentId);
    LogUtils.tracef(this, "handleOrphanedComponents: child: %s", child);
    LogUtils.tracef(this, "handleOrphanedComponents: child's children: %s", childChildren);
    LogUtils.tracef(this, "handleOrphanedComponents: child's parents: %s", childParents);

    if (childParents.size() == 1) {
      final ComponentIdentifier childParent = childParents.iterator().next();
      if (childParent.equals(parentId)) {
        LogUtils.tracef(
            this,
            "handleOrphanedComponents: child (%s) has only one parent (%s) and it's being deleted.",
            child,
            childParent);
        deleteComponent(child, ceq, deleteOrphans);
      } else {
        LogUtils.tracef(
            this,
            "handleOrphanedComponents: child (%s) has only one parent (%s) but it's not the one we expected. This is weird.",
            child,
            childParent);
        ceq.componentUpdated(childParent);
      }
    } else {
      LogUtils.tracef(
          this,
          "handleOrphanedComponents: child (%s) has more than one parent, sending updates for remaining parents.",
          child);
      for (final ComponentIdentifier childParent : childParents) {
        ceq.componentUpdated(childParent);
      }
    }
  }