broker.storeDocument(transaction, doc);
broker.storeXMLResource(transaction, doc);
    public void setPermissions(java.lang.String sessionId, java.lang.String resource, java.lang.String owner, java.lang.String ownerGroup, int permissions) throws java.rmi.RemoteException {        DBBroker broker = null;		Session session = getSession(sessionId);        Collection collection = null;        DocumentImpl doc = null;        TransactionManager transact = pool.getTransactionManager();        Txn transaction = transact.beginTransaction();        try {            broker = pool.get(session.getUser());            org.exist.security.SecurityManager manager = pool                    .getSecurityManager();            collection = broker.openCollection(resource, Lock.WRITE_LOCK);            if (collection == null) {                doc = (DocumentImpl) broker.openDocument(resource, Lock.WRITE_LOCK);                if (doc == null)                    throw new RemoteException("document or collection "                            + resource + " not found");                LOG.debug("changing permissions on document " + resource);                Permission perm = doc.getPermissions();                if (perm.getOwner().equals(session.getUser().getName())                || manager.hasAdminPrivileges(session.getUser())) {                    if (owner != null) {                        perm.setOwner(owner);                        perm.setGroup(ownerGroup);                    }                    perm.setPermissions(permissions);                    broker.storeDocument(transaction, doc);                    transact.commit(transaction);                    broker.flush();                    return;//                    return true;                }                transact.abort(transaction);                throw new PermissionDeniedException("not allowed to change permissions");            }            LOG.debug("changing permissions on collection " + resource);            Permission perm = collection.getPermissions();            if (perm.getOwner().equals(session.getUser().getName())            || manager.hasAdminPrivileges(session.getUser())) {                perm.setPermissions(permissions);                if (owner != null) {                    perm.setOwner(owner);                    perm.setGroup(ownerGroup);                }                transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);                broker.saveCollection(transaction, collection);                transact.commit(transaction);                broker.flush();                return;            }            transact.abort(transaction);            throw new PermissionDeniedException("not allowed to change permissions");        } catch (PermissionDeniedException e) {            transact.abort(transaction);            throw new RemoteException(e.getMessage());        } catch (TransactionException e) {            throw new RemoteException(e.getMessage());        } catch (EXistException e) {            throw new RemoteException(e.getMessage());        } finally {            if(doc != null)                doc.getUpdateLock().release(Lock.WRITE_LOCK);            pool.release(broker);        }    }