SourceForge.net Logo

ContextHelpers.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2006
00003  *     DecisionSoft Limited. All rights reserved.
00004  * Copyright (c) 2004-2006
00005  *     Progress Software Corporation. All rights reserved.
00006  * Copyright (c) 2004-2006
00007  *     Oracle. All rights reserved.
00008  *
00009  * See the file LICENSE for redistribution information.
00010  *
00011  * $Id: ContextHelpers.hpp,v 1.4 2007/07/10 16:28:57 jpcs Exp $
00012  */
00013 
00014 #ifndef CONTEXTHELPERS_HPP
00015 #define CONTEXTHELPERS_HPP
00016 
00017 #include <xqilla/framework/XQillaExport.hpp>
00018 #include <xqilla/context/DynamicContext.hpp>
00019 
00020 class XQILLA_API AutoNodeSetOrderingReset
00021 {
00022 public:
00023   AutoNodeSetOrderingReset(StaticContext* context, StaticContext::NodeSetOrdering ordering = StaticContext::ORDERING_UNORDERED)
00024   {
00025     context_ = context;
00026     ordering_ = context->getNodeSetOrdering();
00027     context->setNodeSetOrdering(ordering);
00028   }
00029 
00030   ~AutoNodeSetOrderingReset()
00031   {
00032     context_->setNodeSetOrdering(ordering_);
00033   }
00034 
00035 protected:
00036   StaticContext* context_;
00037   StaticContext::NodeSetOrdering ordering_;  
00038 };
00039 
00040 class XQILLA_API AutoContextItemTypeReset
00041 {
00042 public:
00043   AutoContextItemTypeReset(StaticContext* context, const StaticType &sType)
00044   {
00045     context_ = context;
00046     sType_ = context->getContextItemType();
00047     context->setContextItemType(sType);
00048   }
00049 
00050   ~AutoContextItemTypeReset()
00051   {
00052     context_->setContextItemType(sType_);
00053   }
00054 
00055 protected:
00056   StaticContext* context_;
00057   StaticType sType_;
00058 };
00059 
00060 class XQILLA_API AutoNsScopeReset
00061 {
00062 public:
00063   AutoNsScopeReset(StaticContext* context, XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* newResolver)
00064   {
00065     _context=context;
00066     _oldNSResolver=_context->getNSResolver();
00067     _defaultElementAndTypeNS=context->getDefaultElementAndTypeNS();
00068     _context->setNSResolver(newResolver);
00069   }
00070 
00071   ~AutoNsScopeReset()
00072   {
00073     _context->setNSResolver(_oldNSResolver);
00074     _context->setDefaultElementAndTypeNS(_defaultElementAndTypeNS);
00075   }
00076 
00077 protected:
00078   StaticContext* _context;
00079   const XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* _oldNSResolver;
00080   const XMLCh *_defaultElementAndTypeNS;
00081   
00082 };
00083 
00084 class XQILLA_API AutoContextInfoReset
00085 {
00086 public:
00087   AutoContextInfoReset(DynamicContext* context)
00088     : oldContextItem(context->getContextItem()),
00089       oldContextPosition(context->getContextPosition()),
00090       oldContextSize(context->getContextSize()),
00091       context_(context)
00092   {
00093   }
00094 
00095   ~AutoContextInfoReset()
00096   {
00097     resetContextInfo();
00098   }
00099 
00100   void resetContextInfo()
00101   {
00102     context_->setContextItem(oldContextItem);
00103     context_->setContextPosition(oldContextPosition);
00104     context_->setContextSize(oldContextSize);
00105   }
00106 
00107   Item::Ptr oldContextItem;
00108   unsigned int oldContextPosition;
00109   unsigned int oldContextSize;
00110 
00111 private:
00112   DynamicContext* context_;
00113 };
00114 
00115 class XQILLA_API AutoDocumentCacheReset
00116 {
00117 public:
00118   AutoDocumentCacheReset(DynamicContext* context)
00119     : oldDC(const_cast<DocumentCache*>(context->getDocumentCache())),
00120       context_ (context)
00121   {
00122   }
00123 
00124   ~AutoDocumentCacheReset()
00125   {
00126     context_->setDocumentCache(oldDC);
00127   }
00128 
00129   DocumentCache *oldDC;
00130 
00131 protected:
00132   DynamicContext* context_;
00133 };
00134 
00135 class XQILLA_API AutoVariableStoreReset
00136 {
00137 public:
00138   AutoVariableStoreReset(DynamicContext *context, const VariableStore *store = 0)
00139   {
00140     _context = context;
00141     _oldVarStore = _context->getVariableStore();
00142     if(store)
00143       _context->setVariableStore(store);
00144   }
00145 
00146   ~AutoVariableStoreReset()
00147   {
00148     _context->setVariableStore(_oldVarStore);
00149   }
00150 
00151   void reset()
00152   {
00153     _context->setVariableStore(_oldVarStore);
00154   }
00155 
00156 protected:
00157   DynamicContext *_context;
00158   const VariableStore *_oldVarStore;
00159   
00160 };
00161 
00162 #endif

Generated on Fri Aug 31 14:37:35 2007 for XQilla Simple API by  doxygen 1.5.1