SourceForge.net Logo
ContextHelpers.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2008
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004-2008
5  * Oracle. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * $Id$
20  */
21 
22 #ifndef CONTEXTHELPERS_HPP
23 #define CONTEXTHELPERS_HPP
24 
25 #include <xqilla/framework/XQillaExport.hpp>
27 
28 class XQILLA_API AutoNodeSetOrderingReset
29 {
30 public:
32  {
33  context_ = context;
34  if(context_) {
35  ordering_ = context->getNodeSetOrdering();
36  context->setNodeSetOrdering(ordering);
37  }
38  }
39 
41  {
42  if(context_) {
43  context_->setNodeSetOrdering(ordering_);
44  }
45  }
46 
47 protected:
50 };
51 
52 class XQILLA_API AutoContextItemTypeReset
53 {
54 public:
56  {
57  context_ = context;
58  if(context_) {
59  sType_ = context->getContextItemType();
60  }
61  }
62 
64  {
65  context_ = context;
66  if(context_) {
67  sType_ = context->getContextItemType();
68  context->setContextItemType(sType);
69  }
70  }
71 
73  {
74  if(context_) {
75  context_->setContextItemType(sType_);
76  }
77  }
78 
79 protected:
82 };
83 
84 class XQILLA_API AutoNsScopeReset
85 {
86 public:
87  AutoNsScopeReset(StaticContext* context, XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* newResolver)
88  {
89  context_=context;
90  if(context_) {
91  _oldNSResolver=context_->getNSResolver();
92  _defaultElementAndTypeNS=context->getDefaultElementAndTypeNS();
93  context_->setNSResolver(newResolver);
94  }
95  }
96 
98  {
99  if(context_) {
100  context_->setNSResolver(_oldNSResolver);
101  context_->setDefaultElementAndTypeNS(_defaultElementAndTypeNS);
102  }
103  }
104 
105 protected:
107  const XERCES_CPP_NAMESPACE_QUALIFIER DOMXPathNSResolver* _oldNSResolver;
109 
110 };
111 
112 class XQILLA_API AutoContextInfoReset
113 {
114 public:
116  : oldContextItem(context->getContextItem()),
117  oldContextPosition(context->getContextPosition()),
118  oldContextSize(context->getContextSize()),
119  context_(context)
120  {
121  }
122 
123  AutoContextInfoReset(DynamicContext *context, const Item::Ptr &contextItem, size_t contextPosition = 0, size_t contextSize = 0)
124  : oldContextItem(context->getContextItem()),
125  oldContextPosition(context->getContextPosition()),
126  oldContextSize(context->getContextSize()),
127  context_(context)
128  {
129  context->setContextItem(contextItem);
130  context->setContextPosition(contextPosition);
131  context->setContextSize(contextSize);
132  }
133 
135  {
136  resetContextInfo();
137  }
138 
140  {
141  context_->setContextItem(oldContextItem);
142  context_->setContextPosition(oldContextPosition);
143  context_->setContextSize(oldContextSize);
144  }
145 
149 
150 private:
151  DynamicContext* context_;
152 };
153 
154 class XQILLA_API AutoDocumentCacheReset
155 {
156 public:
158  : oldDC(const_cast<DocumentCache*>(context->getDocumentCache())),
159  context_ (context)
160  {
161  }
162 
164  {
165  context_->setDocumentCache(oldDC);
166  }
167 
169 
170 protected:
172 };
173 
174 class XQILLA_API AutoVariableStoreReset
175 {
176 public:
178  {
179  context_ = context;
180  _oldVarStore = context_->getVariableStore();
181  if(store)
182  context_->setVariableStore(store);
183  }
184 
186  {
187  context_->setVariableStore(_oldVarStore);
188  }
189 
190  void reset()
191  {
192  context_->setVariableStore(_oldVarStore);
193  }
194 
195 protected:
198 };
199 
200 class XQILLA_API AutoRegexGroupStoreReset
201 {
202 public:
204  {
205  context_ = context;
206  _oldRegexStore = context_->getRegexGroupStore();
207  if(store)
208  context_->setRegexGroupStore(store);
209  }
210 
212  {
213  context_->setRegexGroupStore(_oldRegexStore);
214  }
215 
216  void reset()
217  {
218  context_->setRegexGroupStore(_oldRegexStore);
219  }
220 
221 protected:
224 };
225 
226 class XQILLA_API AutoMessageListenerReset
227 {
228 public:
230  {
231  context_ = context;
232  if(context_) {
233  listener_ = context->getMessageListener();
234  context->setMessageListener(listener);
235  }
236  }
237 
239  {
240  if(context_) {
241  context_->setMessageListener(listener_);
242  }
243  }
244 
245 protected:
248 };
249 
250 class XQILLA_API AutoStackFrameReset
251 {
252 public:
254  {
255  context_ = context;
256  _oldFrame = context_->getStackFrame();
257  context_->setStackFrame(frame);
258  }
259 
261  {
262  context_->setStackFrame(_oldFrame);
263  }
264 
265  void reset()
266  {
267  context_->setStackFrame(_oldFrame);
268  }
269 
270 protected:
273 };
274 
275 template<typename T> class XQILLA_API AutoReset
276 {
277 public:
278  AutoReset(T &orig)
279  : orig_(orig)
280  {
281  old_ = orig;
282  }
283 
285  {
286  reset();
287  }
288 
289  void reset()
290  {
291  orig_ = old_;
292  }
293 
294 protected:
295  T &orig_;
296  T old_;
297 };
298 
299 #endif
~AutoContextInfoReset()
Definition: ContextHelpers.hpp:134
void resetContextInfo()
Definition: ContextHelpers.hpp:139
NodeSetOrdering
Definition: StaticContext.hpp:62
MessageListener * listener_
Definition: ContextHelpers.hpp:247
size_t oldContextPosition
Definition: ContextHelpers.hpp:147
void reset()
Definition: ContextHelpers.hpp:265
StaticContext * context_
Definition: ContextHelpers.hpp:48
Expression Context is a storage for contexts.
Definition: DocumentCache.hpp:54
AutoDocumentCacheReset(DynamicContext *context)
Definition: ContextHelpers.hpp:157
~AutoDocumentCacheReset()
Definition: ContextHelpers.hpp:163
T & orig_
Definition: ContextHelpers.hpp:295
virtual const xercesc::DOMXPathNSResolver * getNSResolver() const =0
Get the NS resolver.
AutoVariableStoreReset(DynamicContext *context, const VariableStore *store=0)
Definition: ContextHelpers.hpp:177
~AutoNodeSetOrderingReset()
Definition: ContextHelpers.hpp:40
~AutoMessageListenerReset()
Definition: ContextHelpers.hpp:238
DynamicContext * context_
Definition: ContextHelpers.hpp:271
virtual void setContextItemType(const StaticType &st)=0
Set the static type of the context item.
~AutoNsScopeReset()
Definition: ContextHelpers.hpp:97
A class that represents an item in a query call stack.
Definition: StackFrame.hpp:47
AutoNsScopeReset(StaticContext *context, xercesc::DOMXPathNSResolver *newResolver)
Definition: ContextHelpers.hpp:87
const StackFrame * _oldFrame
Definition: ContextHelpers.hpp:272
AutoContextItemTypeReset(StaticContext *context, const StaticType &sType)
Definition: ContextHelpers.hpp:63
virtual void setContextSize(size_t size)=0
Set the context size.
AutoReset(T &orig)
Definition: ContextHelpers.hpp:278
AutoRegexGroupStoreReset(DynamicContext *context, const RegexGroupStore *store=0)
Definition: ContextHelpers.hpp:203
virtual const RegexGroupStore * getRegexGroupStore() const =0
get the regex group store
Definition: ContextHelpers.hpp:174
The parse time static context interface.
Definition: StaticContext.hpp:59
Item::Ptr oldContextItem
Definition: ContextHelpers.hpp:146
~AutoContextItemTypeReset()
Definition: ContextHelpers.hpp:72
virtual void setMessageListener(MessageListener *listener)=0
Set the listener for warning and trace messages.
StaticContext * context_
Definition: ContextHelpers.hpp:106
virtual void setNodeSetOrdering(NodeSetOrdering newOrder)=0
Set the ordering method for node sets.
virtual const StackFrame * getStackFrame() const =0
Gets the listener for debug messages.
size_t oldContextSize
Definition: ContextHelpers.hpp:148
~AutoReset()
Definition: ContextHelpers.hpp:284
Definition: ContextHelpers.hpp:154
Definition: ContextHelpers.hpp:112
virtual const XMLCh * getDefaultElementAndTypeNS() const =0
get the value of the default namespace for elements and types
Definition: ContextHelpers.hpp:84
Definition: ContextHelpers.hpp:28
void reset()
Definition: ContextHelpers.hpp:190
Definition: StaticContext.hpp:64
Definition: ContextHelpers.hpp:200
AutoContextInfoReset(DynamicContext *context)
Definition: ContextHelpers.hpp:115
virtual MessageListener * getMessageListener() const =0
Gets the listener for warning and trace messages.
virtual void setContextItem(const Item::Ptr &item)=0
Set the context item to item.
Definition: ContextHelpers.hpp:275
DynamicContext * context_
Definition: ContextHelpers.hpp:222
Definition: ContextHelpers.hpp:250
AutoContextItemTypeReset(StaticContext *context)
Definition: ContextHelpers.hpp:55
A class used to listen for warnings or trace information.
Definition: MessageListener.hpp:35
StaticType sType_
Definition: ContextHelpers.hpp:81
const VariableStore * _oldVarStore
Definition: ContextHelpers.hpp:197
Definition: ContextHelpers.hpp:226
AutoStackFrameReset(DynamicContext *context, const StackFrame *frame)
Definition: ContextHelpers.hpp:253
AutoMessageListenerReset(StaticContext *context, MessageListener *listener=0)
Definition: ContextHelpers.hpp:229
The execution time dynamic context interface.
Definition: DynamicContext.hpp:39
The pure virtual base class for accessing regular expression group values at runtime.
Definition: RegexGroupStore.hpp:32
The pure virtual base class for accessing variables at runtime.
Definition: VariableStore.hpp:33
const xercesc::DOMXPathNSResolver * _oldNSResolver
Definition: ContextHelpers.hpp:107
DynamicContext * context_
Definition: ContextHelpers.hpp:171
~AutoVariableStoreReset()
Definition: ContextHelpers.hpp:185
const RegexGroupStore * _oldRegexStore
Definition: ContextHelpers.hpp:223
AutoNodeSetOrderingReset(StaticContext *context, StaticContext::NodeSetOrdering ordering=StaticContext::ORDERING_UNORDERED)
Definition: ContextHelpers.hpp:31
StaticContext::NodeSetOrdering ordering_
Definition: ContextHelpers.hpp:49
AutoContextInfoReset(DynamicContext *context, const Item::Ptr &contextItem, size_t contextPosition=0, size_t contextSize=0)
Definition: ContextHelpers.hpp:123
void reset()
Definition: ContextHelpers.hpp:289
StaticContext * context_
Definition: ContextHelpers.hpp:80
virtual void setContextPosition(size_t pos)=0
Set the context position.
DocumentCache * oldDC
Definition: ContextHelpers.hpp:168
virtual const StaticType & getContextItemType() const =0
Get the static type of the context item.
Class that represents the static type of an expression.
Definition: StaticType.hpp:35
~AutoRegexGroupStoreReset()
Definition: ContextHelpers.hpp:211
DynamicContext * context_
Definition: ContextHelpers.hpp:196
~AutoStackFrameReset()
Definition: ContextHelpers.hpp:260
void reset()
Definition: ContextHelpers.hpp:216
virtual const VariableStore * getVariableStore() const =0
get the variable store
StaticContext * context_
Definition: ContextHelpers.hpp:246
T old_
Definition: ContextHelpers.hpp:296
Definition: ContextHelpers.hpp:52
const XMLCh * _defaultElementAndTypeNS
Definition: ContextHelpers.hpp:108
virtual NodeSetOrdering getNodeSetOrdering() const =0
Return the ordering method for node sets.