Search code examples
javajcr

NodeUtil unwrap method


What does the NodeUtil unwrap method do in this snipet and what is the effect on the Node:

Node node;
if (subMap.get(JcrConstants.JCR_UUID) != null && NodeUtil.unwrap(root) instanceof NodeImpl) {
         final Node unwrapped = NodeUtil.unwrap(root);
         node = ((NodeImpl) unwrapped).addNodeWithUuid(key, nodeType, 
         String.valueOf(subMap.get(JcrConstants.JCR_UUID)));
} else {
         node = root.addNode(key, nodeType);
}

Solution

  • The two lines

    final Node unwrapped = NodeUtil.unwrap(root);
    node = ((NodeImpl) unwrapped).addNodeWithUuid(key, nodeType, 
             String.valueOf(subMap.get(JcrConstants.JCR_UUID)));
    

    basically allow you to add a note with a specific UUID as opposed to the system generated one.