SourceForge.net Logo

ContextHelpers.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2008
00003  *     DecisionSoft Limited. All rights reserved.
00004  * Copyright (c) 2004-2008
00005  *     Oracle. All rights reserved.
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  *
00019  * $Id: ContextHelpers.hpp 475 2008-01-08 18:47:44Z jpcs $
00020  */
00021 
00022 #ifndef CONTEXTHELPERS_HPP
00023 #define CONTEXTHELPERS_HPP
00024 
00025 #include <xqilla/framework/XQillaExport.hpp>
00026 #include <xqilla/context/DynamicContext.hpp>
00027 
00028 class XQILLA_API AutoNodeSetOrderingReset
00029 {
00030 public:
00031   AutoNodeSetOrderingReset(StaticContext* context, StaticContext::NodeSetOrdering ordering = StaticContext::ORDERING_UNORDERED)
00032   {
00033     context_ = context;
00034     ordering_ = context->getNodeSetOrdering();
00035     context->setNodeSetOrdering(ordering);
00036   }
00037 
00038   ~AutoNodeSetOrderingReset()
00039   {
00040     context_->setNodeSetOrdering(ordering_);
00041   }
00042 
00043 protected:
00044   StaticContext* context_;
00045   StaticContext::NodeSetOrdering ordering_;  
00046 };
00047 
00048 class XQILLA_API AutoContextItemTypeReset
00049 {
00050 public:
00051   AutoContextItemTypeReset(StaticContext* context, const StaticType &sType)
00052   {
00053     context_ = context;
00054     sType_ = context->getContextItemType();
00055     context->setContextItemType(sType);
00056   }
00057 
00058   ~AutoContextItemTypeReset()
00059   {
00060     context_->setContextItemType(sType_);
00061   }
00062 
00063 protected:
00064   StaticContext* context_;
00065   StaticType sType_;
00066 };
00067 
00068 class XQILLA_API AutoNsScopeReset
00069 {
00070 public:
00071   AutoNsScopeReset(StaticContext* context, XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* newResolver)
00072   {
00073     _context=context;
00074     _oldNSResolver=_context->getNSResolver();
00075     _defaultElementAndTypeNS=context->getDefaultElementAndTypeNS();
00076     _context->setNSResolver(newResolver);
00077   }
00078 
00079   ~AutoNsScopeReset()
00080   {
00081     _context->setNSResolver(_oldNSResolver);
00082     _context->setDefaultElementAndTypeNS(_defaultElementAndTypeNS);
00083   }
00084 
00085 protected:
00086   StaticContext* _context;
00087   const XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* _oldNSResolver;
00088   const XMLCh *_defaultElementAndTypeNS;
00089   
00090 };
00091 
00092 class XQILLA_API AutoContextInfoReset
00093 {
00094 public:
00095   AutoContextInfoReset(DynamicContext* context)
00096     : oldContextItem(context->getContextItem()),
00097       oldContextPosition(context->getContextPosition()),
00098       oldContextSize(context->getContextSize()),
00099       context_(context)
00100   {
00101   }
00102 
00103   ~AutoContextInfoReset()
00104   {
00105     resetContextInfo();
00106   }
00107 
00108   void resetContextInfo()
00109   {
00110     context_->setContextItem(oldContextItem);
00111     context_->setContextPosition(oldContextPosition);
00112     context_->setContextSize(oldContextSize);
00113   }
00114 
00115   Item::Ptr oldContextItem;
00116   size_t oldContextPosition;
00117   size_t oldContextSize;
00118 
00119 private:
00120   DynamicContext* context_;
00121 };
00122 
00123 class XQILLA_API AutoDocumentCacheReset
00124 {
00125 public:
00126   AutoDocumentCacheReset(DynamicContext* context)
00127     : oldDC(const_cast<DocumentCache*>(context->getDocumentCache())),
00128       context_ (context)
00129   {
00130   }
00131 
00132   ~AutoDocumentCacheReset()
00133   {
00134     context_->setDocumentCache(oldDC);
00135   }
00136 
00137   DocumentCache *oldDC;
00138 
00139 protected:
00140   DynamicContext* context_;
00141 };
00142 
00143 class XQILLA_API AutoVariableStoreReset
00144 {
00145 public:
00146   AutoVariableStoreReset(DynamicContext *context, const VariableStore *store = 0)
00147   {
00148     _context = context;
00149     _oldVarStore = _context->getVariableStore();
00150     if(store)
00151       _context->setVariableStore(store);
00152   }
00153 
00154   ~AutoVariableStoreReset()
00155   {
00156     _context->setVariableStore(_oldVarStore);
00157   }
00158 
00159   void reset()
00160   {
00161     _context->setVariableStore(_oldVarStore);
00162   }
00163 
00164 protected:
00165   DynamicContext *_context;
00166   const VariableStore *_oldVarStore;
00167   
00168 };
00169 
00170 #endif

Generated on Mon Apr 28 16:40:48 2008 for XQilla Simple API by  doxygen 1.5.1