code: public static Optional<Node> getContainingNode(final Node node) {
          try {
              if (node.getDepth() == 0) {
                  return empty();
              }
  
              // check ancestors recursively only either of the following two cases applies:
              // 1. the PARENT is a FEDORA_PAIRTREE
              // 2. the PARENT is FEDORA_NON_RDF_SOURCE_DESCRIPTION
              final Node parent = node.getParent();
              if (parent.isNodeType(FEDORA_PAIRTREE) || parent.isNodeType(FEDORA_NON_RDF_SOURCE_DESCRIPTION)) {
                  return getContainingNode(parent);
              }
              return Optional.of(parent);
          } catch (final RepositoryException ex) {
              throw new RepositoryRuntimeException(ex);
          }
      }
docs: Get the JCR Node that corresponds to the containing node in the repository.
  This may be the direct parent node, but it may also be a more distant ancestor.
  
  @param node the JCR node
  @return the containing node, if one is present