destCollection.addDocument(this, child);
destCollection.addDocument(this, newDoc);
	public void copyCollection(Collection collection, Collection destination, String newName)	throws PermissionDeniedException, LockException {		if (readOnly)			throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);		if(!collection.getPermissions().validate(user, Permission.READ))			throw new PermissionDeniedException("Read permission denied on collection " +					collection.getName());		if(collection.getId() == destination.getId())	    	throw new PermissionDeniedException("Cannot move collection to itself");		if(!destination.getPermissions().validate(user, Permission.WRITE))	        throw new PermissionDeniedException("Insufficient privileges on target collection " +	                destination.getName());		if(newName == null) {            int p = collection.getName().lastIndexOf('/');            newName = collection.getName().substring(p + 1);        }	    if(newName.indexOf('/') > -1)	        throw new PermissionDeniedException("New collection name is illegal (may not contain a '/')");	    //	check if another collection with the same name exists at the destination	    Collection old = openCollection(newName, Lock.WRITE_LOCK);	    if(old != null) {	    	try {	    		removeCollection(old);	    	} finally {	    		old.release();	    	}	    }	    Lock lock = null;	    try {	        lock = collectionsDb.getLock();	        lock.acquire(Lock.WRITE_LOCK);	        newName = destination.getName() + '/' + newName;	        		    Collection destCollection = getOrCreateCollection(newName);		    for(Iterator i = collection.iterator(this); i.hasNext(); ) {		    	DocumentImpl child = (DocumentImpl) i.next();		    			    	DocumentImpl newDoc = new DocumentImpl(this, child.getFileName(), destCollection);		        newDoc.copyOf(child);		        copyResource(child, newDoc);		        flush();		        destCollection.addDocument(this, child);		    }		    saveCollection(destCollection);		    saveCollection(destination);        } finally {	        lock.release();	    }	}