diff -ru dbxml-2.3.10-original/xqilla/include/xqilla/context/ContextHelpers.hpp dbxml-2.3.10/xqilla/include/xqilla/context/ContextHelpers.hpp --- dbxml-2.3.10-original/xqilla/include/xqilla/context/ContextHelpers.hpp 2006-11-01 16:37:11.000000000 +0000 +++ dbxml-2.3.10/xqilla/include/xqilla/context/ContextHelpers.hpp 2007-03-05 14:53:58.000000000 +0000 @@ -88,4 +88,24 @@ DynamicContext* context_; }; +class XQILLA_API AutoDocumentCacheReset +{ +public: + AutoDocumentCacheReset(DynamicContext* context) + : oldDC(const_cast(context->getDocumentCache())), + context_ (context) + { + } + + ~AutoDocumentCacheReset() + { + context_->setDocumentCache(oldDC); + } + + DocumentCache *oldDC; + +protected: + DynamicContext* context_; +}; + #endif diff -ru dbxml-2.3.10-original/xqilla/src/functions/XQUserFunction.cpp dbxml-2.3.10/xqilla/src/functions/XQUserFunction.cpp --- dbxml-2.3.10-original/xqilla/src/functions/XQUserFunction.cpp 2007-01-23 16:16:42.000000000 +0000 +++ dbxml-2.3.10/xqilla/src/functions/XQUserFunction.cpp 2007-03-05 14:58:18.000000000 +0000 @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -400,11 +401,11 @@ VariableStore* varStore=context->getVariableStore(); Scope *oldScope = varStore->getScopeState(); + AutoDocumentCacheReset reset(context); + DocumentCache* docCache=_di->getFunctionDefinition()->getModuleDocumentCache(); - DocumentCache* origDocCache=NULL; if(docCache!=NULL) { - origDocCache=const_cast(context->getDocumentCache()); context->setDocumentCache(docCache); } if(_toDo) { @@ -462,9 +463,9 @@ } // if we had to switch document cache, check that the returned types are known also in the original context; if not, upgrade them to the base type - if(origDocCache!=NULL) + if(docCache!=NULL) { - if(item!=NULLRCP && !origDocCache->isTypeDefined(item->getTypeURI(), item->getTypeName())) + if(item!=NULLRCP && !reset.oldDC->isTypeDefined(item->getTypeURI(), item->getTypeName())) { if(item->isNode()) { @@ -475,7 +476,7 @@ { AnyAtomicType::Ptr atom=item; const XMLCh* uri=atom->getTypeURI(), *name=atom->getTypeName(); - while(!origDocCache->isTypeDefined(uri, name)) + while(!reset.oldDC->isTypeDefined(uri, name)) { XERCES_CPP_NAMESPACE_QUALIFIER DatatypeValidator* pDV=docCache->getDatatypeValidator(uri, name); assert(pDV!=NULL); @@ -488,7 +489,6 @@ item=context->getItemFactory()->createDerivedFromAtomicType(uri, name, atom->asString(context), context); } } - context->setDocumentCache(origDocCache); } return item; }