SourceForge.net Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Examples

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 734 2009-01-30 18:08:37Z gmfeinberg $
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     if(context_) {
00035       ordering_ = context->getNodeSetOrdering();
00036       context->setNodeSetOrdering(ordering);
00037     }
00038   }
00039 
00040   ~AutoNodeSetOrderingReset()
00041   {
00042     if(context_) {
00043       context_->setNodeSetOrdering(ordering_);
00044     }
00045   }
00046 
00047 protected:
00048   StaticContext* context_;
00049   StaticContext::NodeSetOrdering ordering_;  
00050 };
00051 
00052 class XQILLA_API AutoContextItemTypeReset
00053 {
00054 public:
00055   AutoContextItemTypeReset(StaticContext* context)
00056   {
00057     context_ = context;
00058     if(context_) {
00059       sType_ = context->getContextItemType();
00060     }
00061   }
00062 
00063   AutoContextItemTypeReset(StaticContext* context, const StaticType &sType)
00064   {
00065     context_ = context;
00066     if(context_) {
00067       sType_ = context->getContextItemType();
00068       context->setContextItemType(sType);
00069     }
00070   }
00071 
00072   ~AutoContextItemTypeReset()
00073   {
00074     if(context_) {
00075       context_->setContextItemType(sType_);
00076     }
00077   }
00078 
00079 protected:
00080   StaticContext* context_;
00081   StaticType sType_;
00082 };
00083 
00084 class XQILLA_API AutoNsScopeReset
00085 {
00086 public:
00087   AutoNsScopeReset(StaticContext* context, XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* newResolver)
00088   {
00089     context_=context;
00090     if(context_) {
00091       _oldNSResolver=context_->getNSResolver();
00092       _defaultElementAndTypeNS=context->getDefaultElementAndTypeNS();
00093       context_->setNSResolver(newResolver);
00094     }
00095   }
00096 
00097   ~AutoNsScopeReset()
00098   {
00099     if(context_) {
00100       context_->setNSResolver(_oldNSResolver);
00101       context_->setDefaultElementAndTypeNS(_defaultElementAndTypeNS);
00102     }
00103   }
00104 
00105 protected:
00106   StaticContext* context_;
00107   const XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* _oldNSResolver;
00108   const XMLCh *_defaultElementAndTypeNS;
00109   
00110 };
00111 
00112 class XQILLA_API AutoContextInfoReset
00113 {
00114 public:
00115   AutoContextInfoReset(DynamicContext *context)
00116     : oldContextItem(context->getContextItem()),
00117       oldContextPosition(context->getContextPosition()),
00118       oldContextSize(context->getContextSize()),
00119       context_(context)
00120   {
00121   }
00122 
00123   AutoContextInfoReset(DynamicContext *context, const Item::Ptr &contextItem, size_t contextPosition = 0, size_t contextSize = 0)
00124     : oldContextItem(context->getContextItem()),
00125       oldContextPosition(context->getContextPosition()),
00126       oldContextSize(context->getContextSize()),
00127       context_(context)
00128   {
00129     context->setContextItem(contextItem);
00130     context->setContextPosition(contextPosition);
00131     context->setContextSize(contextSize);
00132   }
00133 
00134   ~AutoContextInfoReset()
00135   {
00136     resetContextInfo();
00137   }
00138 
00139   void resetContextInfo()
00140   {
00141     context_->setContextItem(oldContextItem);
00142     context_->setContextPosition(oldContextPosition);
00143     context_->setContextSize(oldContextSize);
00144   }
00145 
00146   Item::Ptr oldContextItem;
00147   size_t oldContextPosition;
00148   size_t oldContextSize;
00149 
00150 private:
00151   DynamicContext* context_;
00152 };
00153 
00154 class XQILLA_API AutoDocumentCacheReset
00155 {
00156 public:
00157   AutoDocumentCacheReset(DynamicContext* context)
00158     : oldDC(const_cast<DocumentCache*>(context->getDocumentCache())),
00159       context_ (context)
00160   {
00161   }
00162 
00163   ~AutoDocumentCacheReset()
00164   {
00165     context_->setDocumentCache(oldDC);
00166   }
00167 
00168   DocumentCache *oldDC;
00169 
00170 protected:
00171   DynamicContext* context_;
00172 };
00173 
00174 class XQILLA_API AutoVariableStoreReset
00175 {
00176 public:
00177   AutoVariableStoreReset(DynamicContext *context, const VariableStore *store = 0)
00178   {
00179     context_ = context;
00180     _oldVarStore = context_->getVariableStore();
00181     if(store)
00182       context_->setVariableStore(store);
00183   }
00184 
00185   ~AutoVariableStoreReset()
00186   {
00187     context_->setVariableStore(_oldVarStore);
00188   }
00189 
00190   void reset()
00191   {
00192     context_->setVariableStore(_oldVarStore);
00193   }
00194 
00195 protected:
00196   DynamicContext *context_;
00197   const VariableStore *_oldVarStore;
00198 };
00199 
00200 class XQILLA_API AutoRegexGroupStoreReset
00201 {
00202 public:
00203   AutoRegexGroupStoreReset(DynamicContext *context, const RegexGroupStore *store = 0)
00204   {
00205     context_ = context;
00206     _oldRegexStore = context_->getRegexGroupStore();
00207     if(store)
00208       context_->setRegexGroupStore(store);
00209   }
00210 
00211   ~AutoRegexGroupStoreReset()
00212   {
00213     context_->setRegexGroupStore(_oldRegexStore);
00214   }
00215 
00216   void reset()
00217   {
00218     context_->setRegexGroupStore(_oldRegexStore);
00219   }
00220 
00221 protected:
00222   DynamicContext *context_;
00223   const RegexGroupStore *_oldRegexStore;
00224 };
00225 
00226 class XQILLA_API AutoMessageListenerReset
00227 {
00228 public:
00229   AutoMessageListenerReset(StaticContext* context, MessageListener *listener = 0)
00230   {
00231     context_ = context;
00232     if(context_) {
00233       listener_ = context->getMessageListener();
00234       context->setMessageListener(listener);
00235     }
00236   }
00237 
00238   ~AutoMessageListenerReset()
00239   {
00240     if(context_) {
00241       context_->setMessageListener(listener_);
00242     }
00243   }
00244 
00245 protected:
00246   StaticContext* context_;
00247   MessageListener *listener_;  
00248 };
00249 
00250 class XQILLA_API AutoStackFrameReset
00251 {
00252 public:
00253   AutoStackFrameReset(DynamicContext *context, const StackFrame *frame)
00254   {
00255     context_ = context;
00256     _oldFrame = context_->getStackFrame();
00257     context_->setStackFrame(frame);
00258   }
00259 
00260   ~AutoStackFrameReset()
00261   {
00262     context_->setStackFrame(_oldFrame);
00263   }
00264 
00265   void reset()
00266   {
00267     context_->setStackFrame(_oldFrame);
00268   }
00269 
00270 protected:
00271   DynamicContext *context_;
00272   const StackFrame *_oldFrame;
00273 };
00274 
00275 template<typename T> class XQILLA_API AutoReset
00276 {
00277 public:
00278   AutoReset(T &orig)
00279     : orig_(orig)
00280   {
00281     old_ = orig;
00282   }
00283 
00284   ~AutoReset()
00285   {
00286     reset();
00287   }
00288 
00289   void reset()
00290   {
00291     orig_ = old_;
00292   }
00293 
00294 protected:
00295   T &orig_;
00296   T old_;
00297 };
00298 
00299 #endif

Generated on Fri Sep 25 06:55:26 2009 for XQilla Simple API by  doxygen 1.3.9.1