code: public String addLock(Session session, String path) throws LockException
     {
  
        String repoPath = session.getRepository().hashCode() + "/" + session.getWorkspace().getName() + "/" + path;
  
        if (!nullResourceLocks.containsKey(repoPath))
        {
           String newLockToken = IdGenerator.generate();
           session.addLockToken(newLockToken);
           nullResourceLocks.put(repoPath, newLockToken);
           return newLockToken;
        }
  
        // check if lock owned by this session
        String currentToken = nullResourceLocks.get(repoPath);
        for (String t : session.getLockTokens())
        {
           if (t.equals(currentToken))
              return t;
        }
        throw new LockException("Resource already locked " + repoPath);
     }
docs: Locks the node.
  
  @param session current session
  @param path node path
  @return thee lock token key
  @throws LockException {@link LockException}