if(res.getResourceType().equals("XMLResource")) doc = ((LocalXMLResource) res).getDocument(broker, true); else doc = ((LocalBinaryResource) res).getDocument(broker, true);
doc = ((AbstractEXistResource) res).openDocument(broker, Lock.WRITE_LOCK);
	public void unlockResource(Resource res) 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();			User lockOwner = doc.getUserLock();			if(lockOwner != null && !(lockOwner.equals(user) || manager.hasAdminPrivileges(user))) {				throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,						"Resource is already locked by user " + lockOwner.getName());			}			doc.setUserLock(null);			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);		}	}