Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Locked.java
===================================================================
--- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Locked.java	(revision 1065585)
+++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Locked.java	(working copy)
@@ -23,6 +23,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.LockManager;
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
@@ -99,19 +100,40 @@
      */
     public Object with(Node lockable, boolean isDeep)
             throws RepositoryException, InterruptedException {
-        return with(lockable, isDeep, Long.MAX_VALUE);
+        return with(lockable, isDeep, true);
     }
-
+    
     /**
+     * Executes {@link #run} while the lock on <code>lockable</code> is held.
+     * This method will block until {@link #run} is executed while holding the
+     * lock on node <code>lockable</code>.
+     *
+     * @param lockable a lockable node.
+     * @param isDeep   <code>true</code> if <code>lockable</code> will be locked
+     *                 deep.
+     * @param isSessionScoped <code>true</code> if the lock is session scoped.
+     * @return the object returned by {@link #run}.
+     * @throws IllegalArgumentException if <code>lockable</code> is not
+     *      <i>mix:lockable</i>.
+     * @throws RepositoryException  if {@link #run} throws an exception.
+     * @throws InterruptedException if this thread is interrupted while waiting
+     *                              for the lock on node <code>lockable</code>.
+     */
+    public Object with(Node lockable, boolean isDeep, boolean isSessionScoped)
+            throws RepositoryException, InterruptedException {
+        return with(lockable, isDeep, Long.MAX_VALUE, isSessionScoped);
+    }
+    
+    /**
      * Executes the method {@link #run} within the scope of a lock held on
      * <code>lockable</code>.
      *
      * @param lockable the node where the lock is obtained from.
      * @param isDeep   <code>true</code> if <code>lockable</code> will be locked
      *                 deep.
-     * @param timeout  time in milliseconds to wait at most to aquire the lock.
+     * @param timeout  time in milliseconds to wait at most to acquire the lock.
      * @return the object returned by {@link #run} or {@link #TIMED_OUT} if the
-     *         lock on <code>lockable</code> could not be aquired within the
+     *         lock on <code>lockable</code> could not be acquired within the
      *         specified timeout.
      * @throws IllegalArgumentException if <code>timeout</code> is negative or
      *                                  <code>lockable</code> is not
@@ -126,6 +148,34 @@
      */
     public Object with(Node lockable, boolean isDeep, long timeout)
             throws UnsupportedRepositoryOperationException, RepositoryException, InterruptedException {
+	return with(lockable, isDeep, timeout, true);		
+    }
+
+    /**
+     * Executes the method {@link #run} within the scope of a lock held on
+     * <code>lockable</code>.
+     *
+     * @param lockable the node where the lock is obtained from.
+     * @param isDeep   <code>true</code> if <code>lockable</code> will be locked
+     *                 deep.
+     * @param timeout  time in milliseconds to wait at most to acquire the lock.
+     * @param isSessionScoped <code>true</code> if the lock is session scoped.
+     * @return the object returned by {@link #run} or {@link #TIMED_OUT} if the
+     *         lock on <code>lockable</code> could not be acquired within the
+     *         specified timeout.
+     * @throws IllegalArgumentException if <code>timeout</code> is negative or
+     *                                  <code>lockable</code> is not
+     *                                  <i>mix:lockable</i>.
+     * @throws RepositoryException      if {@link #run} throws an exception.
+     * @throws UnsupportedRepositoryOperationException
+     *                                  if this repository does not support
+     *                                  locking.
+     * @throws InterruptedException     if this thread is interrupted while
+     *                                  waiting for the lock on node
+     *                                  <code>lockable</code>.
+     */
+    public Object with(Node lockable, boolean isDeep, long timeout, boolean isSessionScoped)
+            throws UnsupportedRepositoryOperationException, RepositoryException, InterruptedException {
         if (timeout < 0) {
             throw new IllegalArgumentException("timeout must be >= 0");
         }
@@ -140,7 +190,7 @@
                 throw new IllegalArgumentException("Node is not lockable");
             }
 
-            Lock lock = tryLock(lockable, isDeep);
+            Lock lock = tryLock(lockable, isDeep, timeout, isSessionScoped);
             if (lock != null) {
                 return runAndUnlock(lock);
             }
@@ -175,7 +225,7 @@
             // the current thread when the lockable node is possibly unlocked
             for (; ;) {
                 synchronized (this) {
-                    lock = tryLock(lockable, isDeep);
+                    lock = tryLock(lockable, isDeep, timeout, isSessionScoped);
                     if (lock != null) {
                         return runAndUnlock(lock);
                     } else {
@@ -223,10 +273,11 @@
      * @throws RepositoryException if an error occurs.
      */
     private Object runAndUnlock(Lock lock) throws RepositoryException {
+	final Node node = lock.getNode();
         try {
-            return run(lock.getNode());
+            return run(node);
         } finally {
-            lock.getNode().unlock();
+            node.getSession().getWorkspace().getLockManager().unlock(node.getPath());
         }
     }
 
@@ -235,16 +286,21 @@
      *
      * @param lockable the lockable node
      * @param isDeep   <code>true</code> if the lock should be deep
+     * @param timeout  time in milliseconds to wait at most to acquire the lock.
+     * @param isSessionScoped <code>true</code> if the lock is session scoped.
      * @return The <code>Lock</code> or <code>null</code> if the
      *         <code>lockable</code> cannot be locked.
      * @throws UnsupportedRepositoryOperationException
      *                             if this repository does not support locking.
      * @throws RepositoryException if an error occurs
      */
-    private static Lock tryLock(Node lockable, boolean isDeep)
+    private static Lock tryLock(Node lockable, boolean isDeep, long timeout, boolean isSessionScoped)
             throws UnsupportedRepositoryOperationException, RepositoryException {
         try {
-            return lockable.lock(isDeep, true);
+            
+            final LockManager lm = lockable.getSession().getWorkspace().getLockManager();
+            return lm.lock(lockable.getPath(), isDeep, isSessionScoped, timeout, null);
+
         } catch (LockException e) {
             // locked by some other session
         }
Index: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/lock/Locked.java
===================================================================
--- jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/lock/Locked.java	(revision 1065585)
+++ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/lock/Locked.java	(working copy)
@@ -75,7 +75,10 @@
  *     long nextValue = ((Long) ret).longValue();
  * }
  * </pre>
- */
+ * 
+ *
+ * @deprecated Use org.apache.jackrabbit.util.Locked instead.
+ */ 
 public abstract class Locked {
 
     /**
