code: public Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
        RepositoryException
     {
  
        String lockToken = IdGenerator.generate();
  
        NodeData data = (NodeData)node.getData();
  
        LockData lData = lockManager.getExactNodeOrCloseParentLock(data);
        if (lData != null)
        {
           if (lData.getNodeIdentifier().equals(node.getIdentifier()))
           {
              throw new LockException("Node already locked: " + data.getQPath());
           }
           else if (lData.isDeep())
           {
              throw new LockException("Parent node has deep lock.");
           }
        }
  
        if (isDeep && lockManager.getClosedChild(data) != null)
        {
           throw new LockException("Some child node is locked.");
        }
  
        String lockTokenHash = lockManager.getLockTokenHash(lockToken);
  
        lData =
           new LockData(node.getIdentifier(), lockTokenHash, isDeep, isSessionScoped, node.getSession().getUserID(),
              timeOut > 0 ? timeOut : lockManager.getDefaultLockTimeOut());
  
        lockedNodes.put(node.getInternalIdentifier(), lData);
        pendingLocks.add(node.getInternalIdentifier());
        tokens.put(lockToken, lData.getTokenHash());
  
        LockImpl lock = new CacheLockImpl(node.getSession(), lData, this);
  
        return lock;
     }
docs: {@inheritDoc}