Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/AbstractLockInfo.java (working copy) @@ -59,13 +59,17 @@ /** * Create a new instance of this class. * - * @param lockToken lock token - * @param sessionScoped whether lock token is session scoped - * @param deep whether lock is deep - * @param lockOwner owner of lock + * @param lockToken + * lock token + * @param sessionScoped + * whether lock token is session scoped + * @param deep + * whether lock is deep + * @param lockOwner + * owner of lock */ - public AbstractLockInfo(LockToken lockToken, boolean sessionScoped, boolean deep, - String lockOwner) { + public AbstractLockInfo(LockToken lockToken, boolean sessionScoped, + boolean deep, String lockOwner) { this.lockToken = lockToken; this.sessionScoped = sessionScoped; this.deep = deep; @@ -74,7 +78,9 @@ /** * Set the live flag - * @param live live flag + * + * @param live + * live flag */ public void setLive(boolean live) { this.live = live; @@ -82,10 +88,11 @@ /** * Return the ID of the lock holding node + * * @return the id */ public NodeId getId() { - return lockToken.id; + return lockToken.getId(); } /** @@ -100,16 +107,17 @@ /** * Set the session currently holding the lock * - * @param lockHolder session currently holding the lock + * @param lockHolder + * session currently holding the lock */ public void setLockHolder(SessionImpl lockHolder) { this.lockHolder = lockHolder; } /** - * Return the lock token as seen by the session passed as parameter. If - * this session is currently holding the lock, it will get the lock token - * itself, otherwise a null string + * Return the lock token as seen by the session passed as parameter. If this + * session is currently holding the lock, it will get the lock token itself, + * otherwise a null string */ public String getLockToken(Session session) { if (session.equals(lockHolder)) { @@ -121,7 +129,8 @@ /** * Return a flag indicating whether the lock is live * - * @return true if the lock is live; otherwise false + * @return true if the lock is live; otherwise + * false */ public boolean isLive() { return live; @@ -137,8 +146,8 @@ /** * Return a flag indicating whether the lock is session-scoped * - * @return true if the lock is session-scoped; - * otherwise false + * @return true if the lock is session-scoped; otherwise + * false */ public boolean isSessionScoped() { return sessionScoped; Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockImpl.java (working copy) @@ -40,15 +40,18 @@ /** * Create a new instance of this class. * - * @param info lock information - * @param node node holding lock + * @param info + * lock information + * @param node + * node holding lock */ public LockImpl(AbstractLockInfo info, Node node) { this.info = info; this.node = node; } - //------------------------------------------------------------------< Lock > + // ------------------------------------------------------------------< Lock + // > /** * {@inheritDoc} @@ -98,8 +101,10 @@ /** * {@inheritDoc} - * @throws LockException if this Session is not the lock holder - * or if this Lock is not alive. + * + * @throws LockException + * if this Session is not the lock holder or if + * this Lock is not alive. */ public void refresh() throws LockException, RepositoryException { if (!isLive()) { Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java (working copy) @@ -31,14 +31,19 @@ public interface LockManager { /** - * Lock a node. Checks whether the node is not locked and then - * returns a lock object for this node. - * @param node node - * @param isDeep whether the lock applies to this node only - * @param isSessionScoped whether the lock is session scoped + * Lock a node. Checks whether the node is not locked and then returns a + * lock object for this node. + * + * @param node + * node + * @param isDeep + * whether the lock applies to this node only + * @param isSessionScoped + * whether the lock is session scoped * @return lock object - * @throws LockException if this node already is locked, or some descendant - * node is locked and isDeep is true + * @throws LockException + * if this node already is locked, or some descendant node is + * locked and isDeep is true * @see javax.jcr.Node#lock */ Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped) @@ -47,93 +52,120 @@ /** * Returns the Lock object that applies to a node. This may be either a lock * on this node itself or a deep lock on a node above this node. - * @param node node + * + * @param node + * node * @return lock object - * @throws LockException if this node is not locked + * @throws LockException + * if this node is not locked * @see javax.jcr.Node#getLock */ Lock getLock(NodeImpl node) throws LockException, RepositoryException; /** * Removes the lock on a node given by its path. - * @param node node - * @throws LockException if this node is not locked or the session - * does not have the correct lock token + * + * @param node + * node + * @throws LockException + * if this node is not locked or the session does not have the + * correct lock token * @see javax.jcr.Node#unlock */ void unlock(NodeImpl node) throws LockException, RepositoryException; /** - * Returns true if the node given holds a lock; - * otherwise returns false. - * @param node node - * @return true if the node given holds a lock; - * otherwise returns false + * Returns true if the node given holds a lock; otherwise + * returns false. + * + * @param node + * node + * @return true if the node given holds a lock; otherwise + * returns false * @see javax.jcr.Node#holdsLock */ boolean holdsLock(NodeImpl node) throws RepositoryException; /** * Returns true if the specified session holds a lock on the - * given node; otherwise returns false. - *

- * Note that isLockHolder(session, node)==true implies - * holdsLock(node)==true. - * @param session session - * @param node node + * given node; otherwise returns false.

Note that + * isLockHolder(session, node)==true implies + * holdsLock(node)==true. + * + * @param session + * session + * @param node + * node * @return if the specified session holds a lock on the given node; * otherwise returns false */ - boolean isLockHolder(Session session, NodeImpl node) throws RepositoryException; + boolean isLockHolder(Session session, NodeImpl node) + throws RepositoryException; /** - * Returns true if this node is locked either as a result - * of a lock held by this node or by a deep lock on a node above this - * node; otherwise returns false - * @param node node - * @return true if this node is locked either as a result - * of a lock held by this node or by a deep lock on a node above this - * node; otherwise returns false + * Returns true if this node is locked either as a result of + * a lock held by this node or by a deep lock on a node above this node; + * otherwise returns false + * + * @param node + * node + * @return true if this node is locked either as a result of + * a lock held by this node or by a deep lock on a node above this + * node; otherwise returns false * @see javax.jcr.Node#isLocked */ boolean isLocked(NodeImpl node) throws RepositoryException; /** - * Check whether the node given is locked by somebody else than the - * current session. Access is allowed if the node is not locked or - * if the session itself holds the lock to this node, i.e. the session - * contains the lock token for the lock. - * @param node node to check - * @throws LockException if write access to the specified node is not allowed - * @throws RepositoryException if some other error occurs + * Check whether the node given is locked by somebody else than the current + * session. Access is allowed if the node is not locked or if the session + * itself holds the lock to this node, i.e. the session contains the lock + * token for the lock. + * + * @param node + * node to check + * @throws LockException + * if write access to the specified node is not allowed + * @throws RepositoryException + * if some other error occurs */ - void checkLock(NodeImpl node) - throws LockException, RepositoryException; + void checkLock(NodeImpl node) throws LockException, RepositoryException; /** - * Check whether the path given is locked by somebody else than the - * session described. Access is allowed if the node is not locked or - * if the session itself holds the lock to this node, i.e. the session - * contains the lock token for the lock. - * @param path path to check - * @param session session - * @throws LockException if write access to the specified path is not allowed - * @throws RepositoryException if some other error occurs + * Check whether the path given is locked by somebody else than the session + * described. Access is allowed if the node is not locked or if the session + * itself holds the lock to this node, i.e. the session contains the lock + * token for the lock. + * + * @param path + * path to check + * @param session + * session + * @throws LockException + * if write access to the specified path is not allowed + * @throws RepositoryException + * if some other error occurs */ - void checkLock(Path path, Session session) - throws LockException, RepositoryException; + void checkLock(Path path, Session session) throws LockException, + RepositoryException; /** * Invoked by a session to inform that a lock token has been added. - * @param session session that has a added lock token - * @param lt added lock token + * + * @param session + * session that has a added lock token + * @param lt + * added lock token */ void lockTokenAdded(SessionImpl session, String lt); /** * Invoked by a session to inform that a lock token has been removed. - * @param session session that has a removed lock token - * @param lt removed lock token + * + * @param session + * session that has a removed lock token + * @param lt + * removed lock token */ void lockTokenRemoved(SessionImpl session, String lt); } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (working copy) @@ -19,8 +19,10 @@ import EDU.oswego.cs.dl.util.concurrent.ReentrantLock; import org.apache.commons.collections.map.LinkedMap; import org.apache.jackrabbit.core.ItemId; +import org.apache.jackrabbit.core.ItemManager; import org.apache.jackrabbit.core.NodeId; import org.apache.jackrabbit.core.NodeImpl; +import org.apache.jackrabbit.core.PropertyImpl; import org.apache.jackrabbit.util.PathMap; import org.apache.jackrabbit.core.SessionImpl; import org.apache.jackrabbit.core.SessionListener; @@ -59,12 +61,14 @@ /** * Provides the functionality needed for locking and unlocking nodes. */ -public class LockManagerImpl implements LockManager, SynchronousEventListener, LockEventListener { +public class LockManagerImpl implements LockManager, SynchronousEventListener, + LockEventListener { /** * Logger */ - private static final Logger log = LoggerFactory.getLogger(LockManagerImpl.class); + private static final Logger log = LoggerFactory + .getLogger(LockManagerImpl.class); /** * Name of the lock file @@ -109,28 +113,32 @@ /** * Create a new instance of this class. * - * @param session system session - * @param fs file system for persisting locks - * @throws RepositoryException if an error occurs + * @param session + * system session + * @param fs + * file system for persisting locks + * @throws RepositoryException + * if an error occurs */ public LockManagerImpl(SessionImpl session, FileSystem fs) throws RepositoryException { this.session = session; this.nsResolver = session.getNamespaceResolver(); - this.locksFile = new FileSystemResource(fs, FileSystem.SEPARATOR + LOCKS_FILE); + this.locksFile = new FileSystemResource(fs, FileSystem.SEPARATOR + + LOCKS_FILE); - session.getWorkspace().getObservationManager(). - addEventListener(this, Event.NODE_ADDED | Event.NODE_REMOVED, - "/", true, null, null, true); + session.getWorkspace().getObservationManager().addEventListener(this, + Event.NODE_ADDED | Event.NODE_REMOVED, "/", true, null, null, + true); try { if (locksFile.exists()) { load(); } } catch (FileSystemException e) { - throw new RepositoryException("I/O error while reading locks from '" - + locksFile.getPath() + "'", e); + throw new RepositoryException("I/O error while reading locks " + + "from '" + locksFile.getPath() + "'", e); } } @@ -148,8 +156,8 @@ BufferedReader reader = null; try { - reader = new BufferedReader( - new InputStreamReader(locksFile.getInputStream())); + reader = new BufferedReader(new InputStreamReader(locksFile + .getInputStream())); while (true) { String s = reader.readLine(); if (s == null || s.equals("")) { @@ -173,21 +181,25 @@ /** * Reapply a lock given a lock token that was read from the locks file * - * @param lockToken lock token to apply + * @param lockToken + * lock token to apply */ private void reapplyLock(LockToken lockToken) { try { - NodeImpl node = (NodeImpl) session.getItemManager().getItem(lockToken.id); - Path path = getPath(lockToken.id); + NodeImpl node = (NodeImpl) session.getItemManager().getItem( + lockToken.getId()); + Path path = getPath(lockToken.getId()); - LockInfo info = new LockInfo(lockToken, false, - node.getProperty(QName.JCR_LOCKISDEEP).getBoolean(), - node.getProperty(QName.JCR_LOCKOWNER).getString()); + PropertyImpl property = node.getProperty(QName.JCR_LOCKOWNER); + String lockOwner = property.getString(); + property = node.getProperty(QName.JCR_LOCKISDEEP); + boolean deep = property.getBoolean(); + LockInfo info = new LockInfo(lockToken, false, deep, lockOwner); info.setLive(true); lockMap.put(path, info); } catch (RepositoryException e) { - log.warn("Unable to recreate lock '" + lockToken - + "': " + e.getMessage()); + log.warn("Unable to recreate lock '" + lockToken + "': " + + e.getMessage()); log.debug("Root cause: ", e); } } @@ -202,33 +214,34 @@ final ArrayList list = new ArrayList(); - lockMap.traverse(new PathMap.ElementVisitor() { + PathMap.ElementVisitor elementVisitor = new PathMap.ElementVisitor() { public void elementVisited(PathMap.Element element) { LockInfo info = (LockInfo) element.get(); if (!info.sessionScoped) { list.add(info); } } - }, false); + }; + lockMap.traverse(elementVisitor, false); - BufferedWriter writer = null; try { - writer = new BufferedWriter( - new OutputStreamWriter(locksFile.getOutputStream())); + OutputStreamWriter osw; + osw = new OutputStreamWriter(locksFile.getOutputStream()); + writer = new BufferedWriter(osw); for (int i = 0; i < list.size(); i++) { AbstractLockInfo info = (AbstractLockInfo) list.get(i); writer.write(info.lockToken.toString()); writer.newLine(); } } catch (FileSystemException fse) { - log.warn("I/O error while saving locks to '" - + locksFile.getPath() + "': " + fse.getMessage()); + log.warn("I/O error while saving locks to '" + locksFile.getPath() + + "': " + fse.getMessage()); log.debug("Root cause: ", fse); } catch (IOException ioe) { - log.warn("I/O error while saving locks to '" - + locksFile.getPath() + "': " + ioe.getMessage()); + log.warn("I/O error while saving locks to '" + locksFile.getPath() + + "': " + ioe.getMessage()); log.debug("Root cause: ", ioe); } finally { if (writer != null) { @@ -242,17 +255,23 @@ } /** - * Internal lock implementation that takes the same parameters - * as the public method but will not modify content. - * @param node node to lock - * @param isDeep whether the lock applies to this node only - * @param isSessionScoped whether the lock is session scoped + * Internal lock implementation that takes the same + * parameters as the public method but will not modify content. + * + * @param node + * node to lock + * @param isDeep + * whether the lock applies to this node only + * @param isSessionScoped + * whether the lock is session scoped * @return lock - * @throws LockException if the node is already locked - * @throws RepositoryException if another error occurs + * @throws LockException + * if the node is already locked + * @throws RepositoryException + * if another error occurs */ - AbstractLockInfo internalLock(NodeImpl node, boolean isDeep, boolean isSessionScoped) - throws LockException, RepositoryException { + AbstractLockInfo internalLock(NodeImpl node, boolean isDeep, + boolean isSessionScoped) throws LockException, RepositoryException { SessionImpl session = (SessionImpl) node.getSession(); LockInfo info = new LockInfo(new LockToken(node.getNodeId()), @@ -268,7 +287,8 @@ LockInfo other = (LockInfo) element.get(); if (other != null) { if (element.hasPath(path)) { - throw new LockException("Node already locked: " + node.safeGetJCRPath()); + throw new LockException("Node already locked: " + + node.safeGetJCRPath()); } else if (other.deep) { throw new LockException("Parent node has deep lock."); } @@ -287,7 +307,8 @@ if (!info.sessionScoped) { if (eventChannel != null) { - eventChannel.locked(node.getNodeId(), isDeep, session.getUserID()); + String userID = session.getUserID(); + eventChannel.locked(node.getNodeId(), isDeep, userID); } save(); } @@ -300,12 +321,16 @@ /** * Unlock a node (internal implementation) - * @param node node to unlock - * @throws LockException if the node can not be unlocked - * @throws RepositoryException if another error occurs + * + * @param node + * node to unlock + * @throws LockException + * if the node can not be unlocked + * @throws RepositoryException + * if another error occurs */ - void internalUnlock(NodeImpl node) - throws LockException, RepositoryException { + void internalUnlock(NodeImpl node) throws LockException, + RepositoryException { acquire(); @@ -313,17 +338,19 @@ SessionImpl session = (SessionImpl) node.getSession(); // check whether node is locked by this session - PathMap.Element element = lockMap.map( - getPath(node.getId()), true); + PathMap.Element element = lockMap.map(getPath(node.getId()), true); if (element == null) { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } AbstractLockInfo info = (AbstractLockInfo) element.get(); if (info == null) { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } if (session != info.getLockHolder()) { - throw new LockException("Node not locked by session: " + node.safeGetJCRPath()); + throw new LockException("Node not locked by session: " + + node.safeGetJCRPath()); } session.removeLockToken(info.getLockToken(session), false); @@ -344,10 +371,12 @@ /** * Return the most appropriate lock information for a node. This is either - * the lock info for the node itself, if it is locked, or a lock info for one - * of its parents, if that is deep locked. + * the lock info for the node itself, if it is locked, or a lock info for + * one of its parents, if that is deep locked. + * * @return lock info or null if node is not locked - * @throws RepositoryException if an error occurs + * @throws RepositoryException + * if an error occurs */ public AbstractLockInfo getLockInfo(NodeId id) throws RepositoryException { acquire(); @@ -370,7 +399,7 @@ } } - //----------------------------------------------------------< LockManager > + // ----------------------------------------------------------< LockManager > /** * {@inheritDoc} @@ -385,8 +414,8 @@ /** * {@inheritDoc} */ - public Lock getLock(NodeImpl node) - throws LockException, RepositoryException { + public Lock getLock(NodeImpl node) throws LockException, + RepositoryException { acquire(); @@ -397,16 +426,21 @@ PathMap.Element element = lockMap.map(path, false); AbstractLockInfo info = (AbstractLockInfo) element.get(); if (info == null) { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } + if (element.hasPath(path) || info.deep) { - Node lockHolder = (Node) session.getItemManager().getItem(info.getId()); + ItemManager itemManager = session.getItemManager(); + Node lockHolder = (Node) itemManager.getItem(info.getId()); return new LockImpl(info, lockHolder); } else { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } } catch (ItemNotFoundException e) { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } finally { release(); } @@ -419,8 +453,8 @@ * events, content modifications should not be made from within code * sections that hold monitors. (see #JCR-194) */ - public void unlock(NodeImpl node) - throws LockException, RepositoryException { + public void unlock(NodeImpl node) throws LockException, + RepositoryException { internalUnlock(node); } @@ -447,7 +481,7 @@ /** * {@inheritDoc} */ - public boolean isLockHolder(Session session, NodeImpl node) + public boolean isLockHolder(Session session, NodeImpl node) throws RepositoryException { acquire(); @@ -494,8 +528,8 @@ /** * {@inheritDoc} */ - public void checkLock(NodeImpl node) - throws LockException, RepositoryException { + public void checkLock(NodeImpl node) throws LockException, + RepositoryException { SessionImpl session = (SessionImpl) node.getSession(); checkLock(getPath(node.getId()), session); @@ -504,8 +538,8 @@ /** * {@inheritDoc} */ - public void checkLock(Path path, Session session) - throws LockException, RepositoryException { + public void checkLock(Path path, Session session) throws LockException, + RepositoryException { PathMap.Element element = lockMap.map(path, false); AbstractLockInfo info = (AbstractLockInfo) element.get(); @@ -525,8 +559,8 @@ try { LockToken lockToken = LockToken.parse(lt); - NodeImpl node = (NodeImpl) this.session.getItemManager(). - getItem(lockToken.id); + ItemManager itemManager = this.session.getItemManager(); + NodeImpl node = (NodeImpl) itemManager.getItem(lockToken.getId()); PathMap.Element element = lockMap.map(node.getPrimaryPath(), true); if (element != null) { AbstractLockInfo info = (AbstractLockInfo) element.get(); @@ -557,8 +591,8 @@ try { LockToken lockToken = LockToken.parse(lt); - NodeImpl node = (NodeImpl) this.session.getItemManager(). - getItem(lockToken.id); + NodeImpl node = (NodeImpl) this.session.getItemManager().getItem( + lockToken.getId()); PathMap.Element element = lockMap.map(node.getPrimaryPath(), true); if (element != null) { AbstractLockInfo info = (AbstractLockInfo) element.get(); @@ -580,8 +614,8 @@ } /** - * Return the path of an item given its id. This method will lookup the - * item inside the systme session. + * Return the path of an item given its id. This method will lookup the item + * inside the systme session. */ private Path getPath(ItemId id) throws RepositoryException { return session.getHierarchyManager().getPath(id); @@ -591,7 +625,7 @@ * Acquire lock on the lock map. */ private void acquire() { - for (;;) { + while (true) { try { lockMapLock.acquire(); break; @@ -609,8 +643,8 @@ } /** - * Start an update operation. This will acquire the lock on the lock map - * and disable saving the lock map file. + * Start an update operation. This will acquire the lock on the lock map and + * disable saving the lock map file. */ public void beginUpdate() { acquire(); @@ -618,8 +652,8 @@ } /** - * End an update operation. This will save the lock map file and release - * the lock on the lock map. + * End an update operation. This will save the lock map file and release the + * lock on the lock map. */ public void endUpdate() { savingDisabled = false; @@ -635,9 +669,9 @@ release(); } + // ----------------------------------------------< SynchronousEventListener + // > - //----------------------------------------------< SynchronousEventListener > - /** * Internal event class that holds old and new paths for moved nodes */ @@ -672,9 +706,12 @@ /** * Create a new instance of this class. * - * @param id id - * @param path path - * @param type event type + * @param id + * id + * @param path + * path + * @param type + * event type */ public HierarchyEvent(NodeId id, Path path, int type) { this.id = id; @@ -686,7 +723,8 @@ * Merge this event with another event. The result will be stored in * this event * - * @param event other event to merge with + * @param event + * other event to merge with */ public void merge(HierarchyEvent event) { type |= event.type; @@ -736,23 +774,24 @@ while (iter.hasNext()) { HierarchyEvent event = (HierarchyEvent) iter.next(); switch (event.type) { - case Event.NODE_ADDED: - nodeAdded(event.path); - break; - case Event.NODE_REMOVED: - nodeRemoved(event.path); - break; - case Event.NODE_ADDED | Event.NODE_REMOVED: - nodeMoved(event.getOldPath(), event.getNewPath()); - break; + case Event.NODE_ADDED: + nodeAdded(event.path); + break; + case Event.NODE_REMOVED: + nodeRemoved(event.path); + break; + case Event.NODE_ADDED | Event.NODE_REMOVED: + nodeMoved(event.getOldPath(), event.getNewPath()); + break; + default: + // ignore } } } /** - * Consolidate an event iterator obtained from observation, merging - * add and remove operations on nodes with the same UUID into a move - * operation. + * Consolidate an event iterator obtained from observation, merging add and + * remove operations on nodes with the same UUID into a move operation. */ private Iterator consolidateEvents(EventIterator events) { LinkedMap eventMap = new LinkedMap(); @@ -762,9 +801,10 @@ HierarchyEvent he; try { - he = new HierarchyEvent(event.getChildId(), - PathFormat.parse(event.getPath(), nsResolver).getNormalizedPath(), - event.getType()); + NodeId childId = event.getChildId(); + Path pathFormat = PathFormat.parse(event.getPath(), nsResolver); + Path path = pathFormat.getNormalizedPath(); + he = new HierarchyEvent(childId, path, event.getType()); } catch (MalformedPathException e) { log.info("Unable to get event's path: " + e.getMessage()); continue; @@ -784,31 +824,32 @@ } /** - * Refresh a non-empty path element whose children might have changed - * its position. + * Refresh a non-empty path element whose children might have changed its + * position. */ private void refresh(PathMap.Element element) { final ArrayList infos = new ArrayList(); boolean needsSave = false; // save away non-empty children - element.traverse(new PathMap.ElementVisitor() { - public void elementVisited(PathMap.Element element) { - LockInfo info = (LockInfo) element.get(); - infos.add(info); - } - }, false); + PathMap.ElementVisitor elementVisitor = new PathMap.ElementVisitor() { + public void elementVisited(PathMap.Element element) { + LockInfo info = (LockInfo) element.get(); + infos.add(info); + } + }; + element.traverse(elementVisitor, false); // remove all children element.removeAll(); // now re-insert at appropriate location or throw away if node - // does no longer exist + // does not longer exist for (int i = 0; i < infos.size(); i++) { LockInfo info = (LockInfo) infos.get(i); try { - NodeImpl node = (NodeImpl) session.getItemManager(). - getItem(info.getId()); + ItemManager itemManager = session.getItemManager(); + NodeImpl node = (NodeImpl) itemManager.getItem(info.getId()); lockMap.put(node.getPrimaryPath(), info); } catch (RepositoryException e) { info.setLive(false); @@ -825,11 +866,11 @@ } /** - * Invoked when some node has been added. If the parent of that node - * exists, shift all name siblings of the new node having an index greater - * or equal. + * Invoked when some node has been added. If the parent of that node exists, + * shift all name siblings of the new node having an index greater or equal. * - * @param path path of added node + * @param path + * path of added node */ private void nodeAdded(Path path) { acquire(); @@ -847,11 +888,13 @@ } /** - * Invoked when some node has been moved. Relink the child inside our - * map to the new parent. + * Invoked when some node has been moved. Relink the child inside our map to + * the new parent. * - * @param oldPath old path - * @param newPath new path + * @param oldPath + * old path + * @param newPath + * new path */ private void nodeMoved(Path oldPath, Path newPath) { acquire(); @@ -869,10 +912,11 @@ } /** - * Invoked when some node has been removed. Remove the child from our - * path map. Disable all locks contained in that subtree. + * Invoked when some node has been removed. Remove the child from our path + * map. Disable all locks contained in that subtree. * - * @param path path of removed node + * @param path + * path of removed node */ private void nodeRemoved(Path path) { acquire(); @@ -898,13 +942,17 @@ /** * Create a new instance of this class. * - * @param lockToken lock token - * @param sessionScoped whether lock token is session scoped - * @param deep whether lock is deep - * @param lockOwner owner of lock + * @param lockToken + * lock token + * @param sessionScoped + * whether lock token is session scoped + * @param deep + * whether lock is deep + * @param lockOwner + * owner of lock */ public LockInfo(LockToken lockToken, boolean sessionScoped, - boolean deep, String lockOwner) { + boolean deep, String lockOwner) { super(lockToken, sessionScoped, deep, lockOwner); } @@ -912,10 +960,10 @@ * {@inheritDoc} *

* When the owning session is logging out, we have to perform some - * operations depending on the lock type. - * (1) If the lock was session-scoped, we unlock the node. - * (2) If the lock was open-scoped, we remove the lock token - * from the session and set the lockHolder field to null. + * operations depending on the lock type. (1) If the lock was + * session-scoped, we unlock the node. (2) If the lock was open-scoped, + * we remove the lock token from the session and set the lockHolder + * field to null. */ public void loggingOut(SessionImpl session) { if (live) { @@ -926,11 +974,14 @@ setLockHolder(session); } try { - NodeImpl node = (NodeImpl) session.getItemManager().getItem(getId()); + ItemManager itemManager = session.getItemManager(); + NodeImpl node = (NodeImpl) itemManager + .getItem(getId()); node.unlock(); } catch (RepositoryException e) { - log.warn("Unable to remove session-scoped lock on node '" - + lockToken + "': " + e.getMessage()); + log.warn("Unable to remove session-scoped lock on " + + "node '" + lockToken + "': " + + e.getMessage()); log.debug("Root cause: ", e); } } else { @@ -949,12 +1000,13 @@ } } - //----------------------------------------------------< LockEventListener > + // ----------------------------------------------------< LockEventListener > /** * Set a lock event channel * - * @param eventChannel lock event channel + * @param eventChannel + * lock event channel */ public void setEventChannel(LockEventChannel eventChannel) { this.eventChannel = eventChannel; @@ -964,14 +1016,16 @@ /** * {@inheritDoc} */ - public void externalLock(NodeId nodeId, boolean isDeep, String userId) throws RepositoryException { + public void externalLock(NodeId nodeId, boolean isDeep, String userId) + throws RepositoryException { acquire(); try { Path path = getPath(nodeId); // create lock token - LockInfo info = new LockInfo(new LockToken(nodeId), false, isDeep, userId); + LockToken lockToken = new LockToken(nodeId); + LockInfo info = new LockInfo(lockToken, false, isDeep, userId); info.setLive(true); lockMap.put(path, info); Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockToken.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockToken.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockToken.java (working copy) @@ -26,24 +26,29 @@ /** * ID of node holding lock */ - public final NodeId id; + private final NodeId id; /** - * Create a new instance of this class. Used when creating new locks upon - * a request. - * @param id the id. + * Create a new instance of this class. Used when creating new locks upon a + * request. + * + * @param id + * the id. */ public LockToken(NodeId id) { this.id = id; } /** - * Parse a lock token string representation and return a lock token instance. - * @param s string representation of lock token - * @throws IllegalArgumentException if some field is illegal + * Parse a lock token string representation and return a lock token + * instance. + * + * @param s + * string representation of lock token + * @throws IllegalArgumentException + * if some field is illegal */ - public static LockToken parse(String s) - throws IllegalArgumentException { + public static LockToken parse(String s) throws IllegalArgumentException { int sep = s.lastIndexOf('-'); if (sep == -1 || sep == s.length() - 1) { @@ -58,6 +63,7 @@ /** * Return the string representation of a lock token + * * @return string representation * @see #toString */ @@ -71,10 +77,16 @@ /** * Return the check digit for a lock token, given by its UUID - * @param uuid uuid + * + * @param uuid + * uuid * @return check digit */ private static char getCheckDigit(String uuid) { + /* + * TODO: this code contains is obfuscated and contains too many magic + * numbers + */ int result = 0; int multiplier = 36; @@ -107,4 +119,13 @@ return '+'; } } + + /** + * Returns ID of node holding lock. + * + * @return ID of node holding lock. + */ + public NodeId getId() { + return id; + } } Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java (working copy) @@ -39,7 +39,8 @@ /** * Logger instance for this class */ - private static final Logger log = LoggerFactory.getLogger(XAEnvironment.class); + private static final Logger log = LoggerFactory + .getLogger(XAEnvironment.class); /** * Global lock manager. @@ -73,7 +74,9 @@ /** * Create a new instance of this class. - * @param lockMgr global lock manager + * + * @param lockMgr + * global lock manager */ public XAEnvironment(LockManagerImpl lockMgr) { this.lockMgr = lockMgr; @@ -91,16 +94,22 @@ /** * Lock some node. - * @param node node to lock - * @param isDeep true to deep lock this node; - * false otherwise - * @param isSessionScoped true if lock should be session scoped; - * false otherwise - * @throws LockException if node is already locked - * @throws RepositoryException if an error occurs + * + * @param node + * node to lock + * @param isDeep + * true to deep lock this node; false + * otherwise + * @param isSessionScoped + * true if lock should be session scoped; + * false otherwise + * @throws LockException + * if node is already locked + * @throws RepositoryException + * if an error occurs */ - public AbstractLockInfo lock(NodeImpl node, boolean isDeep, boolean isSessionScoped) - throws LockException, RepositoryException { + public AbstractLockInfo lock(NodeImpl node, boolean isDeep, + boolean isSessionScoped) throws LockException, RepositoryException { NodeId id = node.getNodeId(); @@ -121,8 +130,9 @@ } // create a new lock info for this node - info = new LockInfo(node, new LockToken(id), - isSessionScoped, isDeep, node.getSession().getUserID()); + LockToken lockToken = new LockToken(id); + String userID = node.getSession().getUserID(); + info = new LockInfo(node, lockToken, isSessionScoped, isDeep, userID); SessionImpl session = (SessionImpl) node.getSession(); info.setLockHolder(session); info.setLive(true); @@ -135,11 +145,16 @@ /** * Unlock some node. - * @param node node to unlock - * @throws LockException if the node is not locked - * @throws RepositoryException if an error occurs + * + * @param node + * node to unlock + * @throws LockException + * if the node is not locked + * @throws RepositoryException + * if an error occurs */ - public void unlock(NodeImpl node) throws LockException, RepositoryException { + public void unlock(NodeImpl node) throws LockException, + RepositoryException { NodeId id = node.getNodeId(); // check positive set first @@ -164,9 +179,11 @@ /** * Return a flag indicating whether the specified node is locked. - * @return true if this node is locked; - * false otherwise - * @throws RepositoryException if an error occurs + * + * @return true if this node is locked; false + * otherwise + * @throws RepositoryException + * if an error occurs */ public boolean isLocked(NodeImpl node) throws RepositoryException { AbstractLockInfo info = getLockInfo(node); @@ -177,11 +194,15 @@ * Return the most appropriate lock information for a node. This is either * the lock info for the node itself, if it is locked, or a lock info for * one of its parents, if that one is deep locked. - * @param node node + * + * @param node + * node * @return LockInfo lock info or null if node is not locked - * @throws RepositoryException if an error occurs + * @throws RepositoryException + * if an error occurs */ - public AbstractLockInfo getLockInfo(NodeImpl node) throws RepositoryException { + public AbstractLockInfo getLockInfo(NodeImpl node) + throws RepositoryException { NodeId id = node.getNodeId(); // check negative set @@ -192,7 +213,7 @@ // check positive set, iteratively ascending in hierarchy if (!lockedNodesMap.isEmpty()) { NodeImpl current = node; - for (;;) { + while (true) { LockInfo info = (LockInfo) lockedNodesMap.get(current.getId()); if (info != null) { if (info.getId().equals(id) || info.deep) { @@ -212,21 +233,25 @@ /** * Add lock token to this environment. - * @param lt lock token + * + * @param lt + * lock token */ public void addLockToken(String lt) { } /** * Remove lock token from this environment. - * @param lt lock token + * + * @param lt + * lock token */ public void removeLockToken(String lt) { } /** - * Prepare update. Locks global lock manager and feeds all lock/ - * unlock operations. + * Prepare update. Locks global lock manager and feeds all lock/ unlock + * operations. */ public void prepare() throws TransactionException { status = Status.STATUS_PREPARING; @@ -247,7 +272,8 @@ if (opIndex < operations.size()) { while (opIndex > 0) { try { - LockInfo info = (LockInfo) operations.get(opIndex - 1); + LockInfo info = (LockInfo) operations + .get(opIndex - 1); info.undo(); } catch (RepositoryException e) { log.error("Unable to undo lock operation.", e); @@ -262,8 +288,8 @@ } /** - * Commit changes. This will finish the update and unlock the - * global lock manager. + * Commit changes. This will finish the update and unlock the global lock + * manager. */ public void commit() { int oldStatus = status; @@ -279,8 +305,8 @@ } /** - * Rollback changes. This will undo all updates and unlock the - * global lock manager. + * Rollback changes. This will undo all updates and unlock the global lock + * manager. */ public void rollback() { int oldStatus = status; @@ -305,8 +331,8 @@ } /** - * Return a flag indicating whether a lock info belongs to a different - * XA environment. + * Return a flag indicating whether a lock info belongs to a different XA + * environment. */ public boolean differentXAEnv(AbstractLockInfo info) { if (info instanceof LockInfo) { @@ -333,13 +359,18 @@ /** * Create a new instance of this class. - * @param lockToken lock token - * @param sessionScoped whether lock token is session scoped - * @param deep whether lock is deep - * @param lockOwner owner of lock + * + * @param lockToken + * lock token + * @param sessionScoped + * whether lock token is session scoped + * @param deep + * whether lock is deep + * @param lockOwner + * owner of lock */ public LockInfo(NodeImpl node, LockToken lockToken, - boolean sessionScoped, boolean deep, String lockOwner) { + boolean sessionScoped, boolean deep, String lockOwner) { super(lockToken, sessionScoped, deep, lockOwner); @@ -347,20 +378,23 @@ } /** - * Create a new instance of this class. Used to signal an - * unlock operation on some existing lock information. + * Create a new instance of this class. Used to signal an unlock + * operation on some existing lock information. */ public LockInfo(NodeImpl node, AbstractLockInfo info) { - super(info.lockToken, info.sessionScoped, info.deep, info.lockOwner); + super(info.lockToken, info.sessionScoped, info.deep, + info.lockOwner); this.node = node; this.isUnlock = true; } /** - * Return a flag indicating whether this info belongs to a unlock operation. - * @return true if this info belongs to an unlock operation; - * otherwise false + * Return a flag indicating whether this info belongs to a unlock + * operation. + * + * @return true if this info belongs to an unlock + * operation; otherwise false */ public boolean isUnlock() { return isUnlock; @@ -396,10 +430,8 @@ } /** - * {@inheritDoc} - *

- * As long as the XA environment is neither committed nor rolled back, - * associated lock information is subject to change. + * {@inheritDoc}

As long as the XA environment is neither committed + * nor rolled back, associated lock information is subject to change. */ public boolean mayChange() { if (status != Status.STATUS_COMMITTED Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALock.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALock.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALock.java (working copy) @@ -33,8 +33,11 @@ /** * Create a new instance of this class. - * @param info lock information - * @param node node holding lock + * + * @param info + * lock information + * @param node + * node holding lock */ public XALock(XALockManager lockMgr, AbstractLockInfo info, Node node) { super(info, node); @@ -43,9 +46,8 @@ } /** - * {@inheritDoc} - *

- * Refresh lock information if XA environment has changed. + * {@inheritDoc}

Refresh lock information if XA environment has + * changed. */ public boolean isLive() throws RepositoryException { if (info.mayChange()) { Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java =================================================================== --- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java (revision 484612) +++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java (working copy) @@ -17,6 +17,7 @@ package org.apache.jackrabbit.core.lock; import org.apache.jackrabbit.core.InternalXAResource; +import org.apache.jackrabbit.core.ItemManager; import org.apache.jackrabbit.core.NodeImpl; import org.apache.jackrabbit.core.SessionImpl; import org.apache.jackrabbit.core.TransactionContext; @@ -78,7 +79,8 @@ /** * {@inheritDoc} */ - public Lock getLock(NodeImpl node) throws LockException, RepositoryException { + public Lock getLock(NodeImpl node) throws LockException, + RepositoryException { AbstractLockInfo info; if (isInXA()) { info = xaEnv.getLockInfo(node); @@ -86,17 +88,20 @@ info = lockMgr.getLockInfo(node.getNodeId()); } if (info == null) { - throw new LockException("Node not locked: " + node.safeGetJCRPath()); + throw new LockException("Node not locked: " + + node.safeGetJCRPath()); } SessionImpl session = (SessionImpl) node.getSession(); - NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId()); + ItemManager itemManager = session.getItemManager(); + NodeImpl holder = (NodeImpl) itemManager.getItem(info.getId()); return new XALock(this, info, holder); } /** * {@inheritDoc} */ - public void unlock(NodeImpl node) throws LockException, RepositoryException { + public void unlock(NodeImpl node) throws LockException, + RepositoryException { if (isInXA()) { xaEnv.unlock(node); } else { @@ -148,7 +153,8 @@ /** * {@inheritDoc} */ - public void checkLock(NodeImpl node) throws LockException, RepositoryException { + public void checkLock(NodeImpl node) throws LockException, + RepositoryException { AbstractLockInfo info; if (isInXA()) { info = xaEnv.getLockInfo(node); @@ -219,7 +225,8 @@ * {@inheritDoc} */ public void prepare(TransactionContext tx) throws TransactionException { - XAEnvironment xaEnv = (XAEnvironment) tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + Object attribute = tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + XAEnvironment xaEnv = (XAEnvironment) attribute; if (xaEnv != null) { xaEnv.prepare(); } @@ -231,7 +238,8 @@ * This will finish the update and unlock the shared lock manager. */ public void commit(TransactionContext tx) { - XAEnvironment xaEnv = (XAEnvironment) tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + Object attribute = tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + XAEnvironment xaEnv = (XAEnvironment) attribute; if (xaEnv != null) { xaEnv.commit(); } @@ -243,7 +251,8 @@ * This will undo all updates and unlock the shared lock manager. */ public void rollback(TransactionContext tx) { - XAEnvironment xaEnv = (XAEnvironment) tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + Object attribute = tx.getAttribute(XA_ENV_ATTRIBUTE_NAME); + XAEnvironment xaEnv = (XAEnvironment) attribute; if (xaEnv != null) { xaEnv.rollback(); }