broker.saveCollection(doc.getCollection()); } catch (PermissionDeniedException e) { throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, e.getMessage(), e);
collection.saveCollection();
	public void lockResource(Resource res, User u) throws XMLDBException {		DocumentImpl doc = null;		DBBroker broker = null;		try {			broker = pool.get(user);			if(res.getResourceType().equals("XMLResource"))				doc = ((LocalXMLResource) res).getDocument(broker, true);			else			    doc = ((LocalBinaryResource) res).getDocument(broker, true);			if (!doc.getPermissions().validate(user, Permission.UPDATE))				throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, 						"User is not allowed to lock resource " + res.getId());			org.exist.security.SecurityManager manager = pool.getSecurityManager();			if(!(user.equals(u) || manager.hasAdminPrivileges(user))) {				throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,						"User " + user.getName() + " is not allowed to lock resource for " +						"user " + u.getName());			}			User lockOwner = doc.getUserLock();			if(lockOwner != null) {				if(lockOwner.equals(u))					return;				else if(!manager.hasAdminPrivileges(user))					throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,							"Resource is already locked by user " + lockOwner.getName());			}			doc.setUserLock(u);			broker.saveCollection(doc.getCollection());		} catch (PermissionDeniedException e) {			throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,					e.getMessage(), e);		} catch (EXistException e) {			throw new XMLDBException(ErrorCodes.VENDOR_ERROR,					e.getMessage(), e);		} finally {		    collection.getCollection().releaseDocument(doc);			pool.release(broker);		}	}