Qt 4.8
qxmlquery_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef QXMLQUERY_P_H
53 #define QXMLQUERY_P_H
54 
55 #include <QAbstractMessageHandler>
56 #include <QAbstractUriResolver>
57 #include <QPointer>
58 #include <QSourceLocation>
59 #include <QUrl>
60 #include <QVariant>
61 #include <QXmlName>
62 #include <QXmlNamePool>
63 #include <QXmlQuery>
64 
65 #include "qacceltreebuilder_p.h"
68 #include "qcommonsequencetypes_p.h"
69 #include "qexpressionfactory_p.h"
70 #include "qfocus_p.h"
74 #include "qnamepool_p.h"
77 #include "qresourcedelegator_p.h"
78 #include "qstaticfocuscontext_p.h"
79 #include "quriloader_p.h"
80 #include "qvariableloader_p.h"
81 
83 
85 {
86 public:
87 
88  inline QXmlQueryPrivate(const QXmlNamePool &np = QXmlNamePool()) : namePool(np)
89  , messageHandler(0)
90  , uriResolver(0)
91  , queryLanguage(QXmlQuery::XQuery10)
92  , m_networkAccessDelegator(new QPatternist::NetworkAccessDelegator(0, 0))
93  {
95  }
96 
97  void detach()
98  {
101 
102  delete m_networkAccessDelegator->m_variableURIManager;
104 
105  if(m_resourceLoader)
106  {
111  nev));
112  }
113  }
114 
115  bool isValid()
116  {
117  return expression();
118  }
119 
120  inline void recompileRequired()
121  {
122  m_expr.reset();
123  }
124 
126  {
127  if(!m_variableLoader)
129 
130  return m_variableLoader;
131  }
132 
134  {
135  if(m_staticContext && m_expr)
136  return m_staticContext;
137  /* Else, re-create the staticContext. */
138 
139  if(!messageHandler)
141 
142  if(!m_functionFactory)
143  {
146  else
148  }
149 
152  queryURI,
154  queryLanguage));
155  genericStaticContext->setResourceLoader(resourceLoader());
156 
157  genericStaticContext->setExternalVariableLoader(variableLoader());
158 
159  m_staticContext = genericStaticContext;
160 
161  if(!contextItem.isNull())
167 
168  for (int i = 0; i < m_additionalNamespaceBindings.count(); ++i) {
169  m_staticContext->namespaceBindings()->addBinding(m_additionalNamespaceBindings.at(i));
170  }
171 
172  return m_staticContext;
173  }
174 
176  {
177  const QPatternist::StaticContext::Ptr statContext(staticContext());
178  Q_ASSERT(statContext);
179 
180  QPatternist::GenericDynamicContext::Ptr dynContext(new QPatternist::GenericDynamicContext(namePool.d, statContext->messageHandler(),
181  statContext->sourceLocations()));
182 
184  dynContext.data()));
185  dynContext->setNodeBuilder(nodeBuilder);
186 
187  dynContext->setResourceLoader(statContext->resourceLoader());
188  dynContext->setExternalVariableLoader(statContext->externalVariableLoader());
189  dynContext->setUriResolver(uriResolver);
190 
191  if(callback)
192  dynContext->setOutputReceiver(callback);
193 
194  if(contextItem.isNull())
195  return dynContext;
196  else
197  {
200  it->next();
201  focus->setFocusIterator(it);
202  return focus;
203  }
204  }
205 
207  {
208  if(!m_resourceLoader)
210 
211  return m_resourceLoader;
212  }
213 
215  {
216  Q_ASSERT(seqType);
217  if(!m_requiredType || m_requiredType->is(seqType))
218  return;
219 
220  m_requiredType = seqType;
222  }
223 
225  {
226  if(m_requiredType)
227  return m_requiredType;
228  else
229  {
231  return m_requiredType;
232  }
233  }
234 
236  {
237  if(m_expr && !queryDevice)
238  return m_expr;
239 
240  /* If we need to update, but we don't have any source code, we can
241  * never create an Expression. */
242  if(!queryDevice)
244 
245  try
246  {
247  /* The static context has source locations, and they need to be
248  * updated to the new query. */
250 
253 
254  m_expr = m_expressionFactory->createExpression(queryDevice, staticContext(),
256  requiredType(),
257  queryURI,
259  }
260  catch(const QPatternist::Exception)
261  {
262  m_expr.reset();
263 
264  /* We don't call m_staticContext.reset() because it shouldn't be
265  * necessary, since m_staticContext is changed when the expression
266  * is changed. */
267  }
268 
269  return m_expr;
270  }
271 
272  inline void addAdditionalNamespaceBinding(const QXmlName &binding)
273  {
275  }
276 
286 
288  {
289  m_expressionFactory = expr;
290  }
291 
294 
296  {
297  if(!m_owner)
299 
300  return m_owner->value;
301  }
302 
312 
320 
322 };
323 
325 
327 
328 #endif
A DynamicContext supplying basic information that always is used.
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
QPatternist::FunctionFactory::Ptr m_functionFactory
Definition: qxmlquery_p.h:318
A DynamicContext that maintains the focus, a sequence of items.
Definition: qfocus_p.h:75
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
A StaticContext that carries a specified static type for the context item, but otherwise delegates to...
The central entry point for compiling expressions.
static const SequenceType::Ptr ZeroOrMoreItems
Handles requests for documents, and instantiates them as AccelTree instances.
#define it(className, varName)
QueryLanguage
Specifies whether you want QXmlQuery to interpret the input to setQuery() as an XQuery or as an XSLT ...
Definition: qxmlquery.h:82
A smart pointer very similar to std::auto_ptr.
Definition: qautoptr_p.h:73
The QXmlItem class contains either an XML node or an atomic value.
Builds an AccelTree from a stream of XML/Item events received through the NodeBuilder interface...
Definition: qacceltree_p.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QPatternist::SequenceType::Ptr m_requiredType
Definition: qxmlquery_p.h:317
void addAdditionalNamespaceBinding(const QXmlName &binding)
Definition: qxmlquery_p.h:272
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QPatternist::NetworkAccessDelegator::Ptr m_networkAccessDelegator
Definition: qxmlquery_p.h:319
static FunctionFactory::Ptr xslt20Factory(const NamePool::Ptr &np)
The QXmlNamePool class is a table of shared strings referenced by instances of QXmlName.
Definition: qxmlnamepool.h:69
QPatternist::SequenceType::Ptr requiredType()
Definition: qxmlquery_p.h:224
QPatternist::VariableLoader::Ptr variableLoader()
Definition: qxmlquery_p.h:125
void recompileRequired()
Definition: qxmlquery_p.h:120
QXmlName initialTemplateName
Definition: qxmlquery_p.h:285
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
The QAbstractUriResolver class is a callback interface for resolving Uniform Resource Identifiers...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Delegates to another ResourceLoader, but in case a URI is in an exception list, it delegates to a dif...
QList< QXmlName > m_additionalNamespaceBindings
Definition: qxmlquery_p.h:321
QXmlNamePool namePool
Definition: qxmlquery_p.h:277
QPatternist::ReferenceCountedValue< QObject >::Ptr m_owner
Definition: qxmlquery_p.h:311
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The namespace for the internal API of QtXmlPatterns.
QExplicitlySharedDataPointer< VariableLoader > Ptr
QExplicitlySharedDataPointer< QPatternist::NamePool > d
Definition: qxmlnamepool.h:88
QXmlItem contextItem
Definition: qxmlquery_p.h:284
QExplicitlySharedDataPointer< ExpressionFactory > Ptr
static const AnyNodeType::Ptr node
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
QPatternist::DeviceResourceLoader::Ptr m_resourceLoader
Definition: qxmlquery_p.h:306
static FunctionFactory::Ptr xpath20Factory(const NamePool::Ptr &np)
QXmlQuery::QueryLanguage queryLanguage
Definition: qxmlquery_p.h:292
QPatternist::ExpressionFactory::Ptr m_expressionFactory
Definition: qxmlquery_p.h:303
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
The QAbstractXmlReceiver class provides a callback interface for transforming the output of a QXmlQue...
void setRequiredType(const QPatternist::SequenceType::Ptr &seqType)
Definition: qxmlquery_p.h:214
QPatternist::StaticContext::Ptr m_staticContext
Definition: qxmlquery_p.h:304
QObject * ownerObject()
Definition: qxmlquery_p.h:295
QPatternist::AccelTreeResourceLoader::Ptr resourceLoader()
Definition: qxmlquery_p.h:206
static Item fromPublic(const QXmlItem &i)
Definition: qitem_p.h:408
QPointer< QNetworkAccessManager > userNetworkManager
Definition: qxmlquery_p.h:293
void setExpressionFactory(const QPatternist::ExpressionFactory::Ptr &expr)
Definition: qxmlquery_p.h:287
const QAbstractUriResolver * uriResolver
Definition: qxmlquery_p.h:283
QPatternist::Expression::Ptr expression(QIODevice *const queryDevice=0)
Definition: qxmlquery_p.h:235
void reset()
Resets this to be null.
Definition: qshareddata.h:150
QXmlQueryPrivate(const QXmlNamePool &np=QXmlNamePool())
Definition: qxmlquery_p.h:88
QPointer< QAbstractMessageHandler > messageHandler
Definition: qxmlquery_p.h:278
QExplicitlySharedDataPointer< StaticContext > Ptr
QExplicitlySharedDataPointer< ResourceLoader > Ptr
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
static ItemType::Ptr qtToXDMType(const QXmlItem &item)
#define QT_END_HEADER
Definition: qglobal.h:137
QPatternist::GenericStaticContext::Ptr staticContext()
Definition: qxmlquery_p.h:133
QPatternist::DynamicContext::Ptr dynamicContext(QAbstractXmlReceiver *const callback=0)
Definition: qxmlquery_p.h:175
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
Definition: qxmlquery.h:79
bool isNull() const
Returns true if this QXmlItem is neither a node nor an atomic value.
QPatternist::Expression::Ptr m_expr
Definition: qxmlquery_p.h:310
QPatternist::VariableLoader::Ptr m_variableLoader
Definition: qxmlquery_p.h:305
Provides setters and getters for the properties defined in StaticContext.