synchronized (cache) { cached = (CachedExpression) cache.get(uri);
cached = (CachedExpression) ((Map)cache.get()).get(uri);
	public void generate() throws IOException, SAXException,			ProcessingException {		if (inputSource == null)			throw new ProcessingException("No input source");		Request request = ObjectModelHelper.getRequest(objectModel);		Response response = ObjectModelHelper.getResponse(objectModel);		Context context = ObjectModelHelper.getContext(objectModel);		Session session = request.getSession(createSession);		String baseURI = request.getRequestURI();		int p = baseURI.lastIndexOf('/');		if (p > -1)			baseURI = baseURI.substring(0, p);		baseURI = context.getRealPath(baseURI.substring(request				.getContextPath().length()));		String user = null;		String password = null;		// check if user and password can be read from the session		if (session != null && request.isRequestedSessionIdValid()) {			user = (String) session.getAttribute("user");			password = (String) session.getAttribute("password");		}		if (user == null)			user = defaultUser;		if (password == null)			password = defaultPassword;		try {			Collection collection = DatabaseManager.getCollection(					collectionURI, user, password);			if (collection == null) {				if (getLogger().isErrorEnabled())					getLogger().error(							"Collection " + collectionURI + " not found");				throw new ProcessingException("Collection " + collectionURI						+ " not found");			}			XQueryService service = (XQueryService) collection.getService(					"XQueryService", "1.0");			service.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");			service.setProperty(EXistOutputKeys.EXPAND_XINCLUDES,					expandXIncludes ? "yes" : "no");			service.setProperty("base-uri", baseURI);			String prefix = RequestModule.PREFIX;			service.setNamespace(prefix, RequestModule.NAMESPACE_URI);			service.setModuleLoadPath(baseURI);			HttpServletRequest httpRequest = (HttpServletRequest) objectModel					.get(HttpEnvironment.HTTP_REQUEST_OBJECT);			service.declareVariable(prefix + ":request",					new CocoonRequestWrapper(request, httpRequest));			service.declareVariable(prefix + ":response",					new CocoonResponseWrapper(response));			service.declareVariable(prefix + ":session",					new CocoonSessionWrapper(session));			declareParameters(service);						String uri = inputSource.getURI();			CompiledExpression expr;			CachedExpression cached;			synchronized (cache) {				cached = (CachedExpression) cache.get(uri);				if (cached != null) {					// check if source is valid or should be reloaded					int valid = cached.validity.isValid();					if (valid == SourceValidity.UNKNOWN)						valid = cached.validity.isValid(inputSource								.getValidity());					if (valid != SourceValidity.VALID) {						cache.remove(uri);						cached = null;					}				}				if (cached == null) {					String xquery = readQuery();					expr = service.compile(xquery);					cached = new CachedExpression(inputSource.getValidity(),							expr);					cache.put(uri, cached);				} else					expr = cached.expr;			}			ResourceSet result = service.execute(expr);			XMLResource resource;			this.contentHandler.startDocument();			for (long i = 0; i < result.getSize(); i++) {				resource = (XMLResource) result.getResource(i);				resource.getContentAsSAX(this.contentHandler);			}			this.contentHandler.endDocument();		} catch (XMLDBException e) {			throw new ProcessingException("XMLDBException occurred: "					+ e.getMessage(), e);		}	}