code: public static javax.jcr.Node nodeForValue(final Session session, final Value v) throws RepositoryException {
          if (v.getType() == PATH) {
              return session.getNode(v.getString());
          } else if (v.getType() == REFERENCE || v.getType() == WEAKREFERENCE) {
              return session.getNodeByIdentifier(v.getString());
          } else {
              throw new RepositoryRuntimeException("Cannot convert value of type "
                      + PropertyType.nameFromValue(v.getType()) + " to a node reference");
          }
      }
docs: Get the node that a property value refers to.
  @param session Session to use to load the node.
  @param v Value that refers to a node.
  @return the JCR node
  @throws RepositoryException When there is an error accessing the node.
  @throws RepositoryRuntimeException When the value type is not PATH, REFERENCE or WEAKREFERENCE.