Qt 4.8
qelementconstructor.cpp
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 #include "qcommonsequencetypes_p.h"
45 #include "qnodebuilder_p.h"
46 #include "qoutputvalidator_p.h"
47 #include "qqnamevalue_p.h"
49 
50 #include "qelementconstructor_p.h"
51 
53 
54 using namespace QPatternist;
55 
57  const Expression::Ptr &op2,
58  const bool isXSLT) : PairContainer(op1, op2)
59  , m_isXSLT(isXSLT)
60 {
61 }
62 
64 {
65  const Item name(m_operand1->evaluateSingleton(context));
66 
67  const NodeBuilder::Ptr nodeBuilder(context->nodeBuilder(m_staticBaseURI));
68  OutputValidator validator(nodeBuilder.data(), context, this, m_isXSLT);
69 
70  const DynamicContext::Ptr receiverContext(context->createReceiverContext(&validator));
71 
72  nodeBuilder->startElement(name.as<QNameValue>()->qName());
73  m_operand2->evaluateToSequenceReceiver(receiverContext);
74  nodeBuilder->endElement();
75 
76  const QAbstractXmlNodeModel::Ptr nm(nodeBuilder->builtDocument());
77  context->addNodeModel(nm);
78 
79  return nm->root(QXmlNodeModelIndex());
80 }
81 
83 {
84  /* We create an OutputValidator here too. If we're serializing(a common
85  * case, unfortunately) the receiver is already validating in order to
86  * catch cases where a computed attribute constructor is followed by an
87  * element constructor, but in the cases where we're not serializing it's
88  * necessary that we validate in this step. */
89  const Item name(m_operand1->evaluateSingleton(context));
90  QAbstractXmlReceiver *const receiver = context->outputReceiver();
91 
92  OutputValidator validator(receiver, context, this, m_isXSLT);
93  const DynamicContext::Ptr receiverContext(context->createReceiverContext(&validator));
94 
95  receiver->startElement(name.as<QNameValue>()->qName());
96  m_operand2->evaluateToSequenceReceiver(receiverContext);
97  receiver->endElement();
98 }
99 
101  const SequenceType::Ptr &reqType)
102 {
103  /* What does this code do? When type checking our children, our namespace
104  * bindings, which are also children of the form of NamespaceConstructor
105  * instances, must be statically in-scope for them, so find them and
106  * shuffle their bindings into the StaticContext. */
107 
108  m_staticBaseURI = context->baseURI();
109 
110  /* Namespace declarations changes the in-scope bindings, so let's
111  * first lookup our child NamespaceConstructors. */
112  const ID operandID = m_operand2->id();
113 
114  NamespaceResolver::Bindings overrides;
115  if(operandID == IDExpressionSequence)
116  {
118  const int len = operands.count();
119 
120  for(int i = 0; i < len; ++i)
121  {
123  {
124  const QXmlName &nb = operands.at(i)->as<NamespaceConstructor>()->namespaceBinding();
125  overrides.insert(nb.prefix(), nb.namespaceURI());
126  }
127  }
128  }
129 
130  const NamespaceResolver::Ptr newResolver(new DelegatingNamespaceResolver(context->namespaceBindings(), overrides));
131  const StaticContext::Ptr augmented(new StaticNamespaceContext(newResolver, context));
132 
133  return PairContainer::typeCheck(augmented, reqType);
134 }
135 
137 {
139 }
140 
142 {
143  SequenceType::List result;
146  return result;
147 }
148 
150 {
152 }
153 
156 {
157  return visitor->visit(this);
158 }
159 
virtual Expression::List operands() const
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm)=0
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const SequenceType::Ptr ZeroOrMoreItems
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
static const SequenceType::Ptr ExactlyOneQName
Constructs a namespace on an element, and naturally only appears as a child of ElementConstructor.
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Contains a set of bindings, plus a pointer to another resolver which is delegates requests to...
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
virtual ID id() const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QXmlName qName() const
Definition: qqnamevalue_p.h:96
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const TCastTarget * as() const
const char * name
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.
virtual NamespaceResolver::Ptr namespaceBindings() const =0
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Expression::List operands() const =0
Receives QAbstractXmlReceiver events and validates that they are correct, before sending them on to a...
virtual SequenceType::Ptr staticType() const
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
virtual Properties properties() const
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Implements the value instance of the xs:QName type.
Definition: qqnamevalue_p.h:73
A StaticContext that carries a specified namespace resolver for the context item, but otherwise deleg...
DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver)
virtual NodeBuilder::Ptr nodeBuilder(const QUrl &baseURI) const =0
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
virtual QAbstractXmlReceiver * outputReceiver() const =0
virtual SequenceType::List expectedOperandTypes() const
bool is(const ID id) const
static const SequenceType::Ptr ExactlyOneElement
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
virtual QUrl baseURI() const =0
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
ElementConstructor(const Expression::Ptr &operand1, const Expression::Ptr &operand2, const bool isXSLT)
Base class for expressions that has exactly two operands.