Collection parent = collection.getParent();
	public boolean removeCollection(User user, String name) throws PermissionDeniedException {		if (readOnly)			throw new PermissionDeniedException("database is read-only");		try {			if (!name.startsWith("/db"))				name = "/db" + name;			Collection collection = getCollection(name);			if (collection == null) {				LOG.debug("collection " + name + " not found!");				return false;			}			Collection parent = collection.getParent();			if (!collection.getPermissions().validate(user, Permission.WRITE))				throw new PermissionDeniedException("not allowed to remove collection");			((NativeTextEngine) textEngine).removeCollection(collection);			LOG.debug("removing elements ...");			short collectionId = collection.getId();			Value ref = new ElementValue(collectionId);			IndexQuery query = new IndexQuery(null, IndexQuery.TRUNC_RIGHT, ref);			Lock lock = elementsDb.getLock();			try {				lock.acquire(this, Lock.WRITE_LOCK);				lock.enter(this);				ArrayList elements = elementsDb.findKeys(query);				LOG.debug("found " + elements.size() + " elements.");				Value val;				for (Iterator i = elements.iterator(); i.hasNext();) {					val = (Value) i.next();					elementsDb.remove(val.getAddress());					elementsDb.removeValue(val);				}			} catch (LockException e) {				LOG.error("could not acquire lock on elements index", e);			} finally {				lock.release(this);			}			elementPool.clear();			if (parent != null) {				parent.removeCollection(name.substring(name.lastIndexOf("/") + 1));				saveCollection(parent);			}			String childCollection;			LOG.debug("removing sub-collections");			for (Iterator i = collection.collectionIterator(); i.hasNext();) {				childCollection = (String) i.next();				removeCollection(					(name.equals("/") ? "/" + childCollection : name + "/" + childCollection));			}			// if this is not the root collection remove it completely			if (name.equals("/db"))				saveCollection(collection);			else {				Value key;				try {					key = new Value(name.getBytes("UTF-8"));				} catch (UnsupportedEncodingException uee) {					key = new Value(name.getBytes());				}				synchronized (collectionsDb) {					collectionsDb.remove(key);				}			}			LOG.debug("removed collection ...");			LOG.debug("removing dom ...");			DocumentImpl doc;			for (Iterator i = collection.iterator(); i.hasNext();) {				doc = (DocumentImpl) i.next();				synchronized (domDb) {					NodeList children = doc.getChildNodes();					NodeImpl node;					for (int j = 0; j < children.getLength(); j++) {						node = (NodeImpl) children.item(j);						Iterator k = getDOMIterator(doc, node.getGID());						removeNodes(k);					}				}				ref = new NodeRef(doc.getDocId());				query = new IndexQuery(null, IndexQuery.TRUNC_RIGHT, ref);				lock = domDb.getLock();				// try to acquire a lock on the file				try {					lock.acquire(this, Lock.WRITE_LOCK);					lock.enter(this);					domDb.setOwnerObject(this);					ArrayList nodes = domDb.findKeys(query);					for (Iterator j = nodes.iterator(); j.hasNext();) {						ref = (Value) j.next();						domDb.removeValue(ref);					}					domDb.flush();				} catch (LockException e) {					// timed out					e.printStackTrace();					return false;				} finally {					lock.release(this);				}			}			return true;		} catch (IOException ioe) {			LOG.warn(ioe);		} catch (BTreeException bte) {			LOG.warn(bte);		} catch (DBException dbe) {			LOG.warn(dbe);		} catch (ReadOnlyException e) {			LOG.warn("database is read-only");		}		return false;	}