2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is TransforMiiX XSLT processor.
14
* The Initial Developer of the Original Code is The MITRE Corporation.
15
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
17
* Portions created by Keith Visco as a Non MITRE employee,
18
* (C) 1999 Keith Visco. All Rights Reserved.
21
* Keith Visco, kvisco@ziplink.net
27
#include "txIXPathContext.h"
28
#include "txNodeSet.h"
36
* Creates a new UnionExpr
38
UnionExpr::UnionExpr() {
43
* Destructor, will delete all Path Expressions
45
UnionExpr::~UnionExpr() {
46
txListIterator iter(&expressions);
47
while (iter.hasNext()) {
48
delete (Expr*)iter.next();
53
* Adds the Expr to this UnionExpr
54
* @param expr the Expr to add to this UnionExpr
57
UnionExpr::addExpr(Expr* aExpr)
59
nsresult rv = expressions.add(aExpr);
66
//-----------------------------/
67
//- Virtual methods from Expr -/
68
//-----------------------------/
71
* Evaluates this Expr based on the given context node and processor state
72
* @param context the context node for evaluation of this Expr
73
* @param ps the ContextState containing the stack information needed
75
* @return the result of the evaluation
78
UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
81
nsRefPtr<txNodeSet> nodes;
82
nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
83
NS_ENSURE_SUCCESS(rv, rv);
85
txListIterator iter(&expressions);
86
while (iter.hasNext()) {
87
Expr* expr = (Expr*)iter.next();
88
nsRefPtr<txAExprResult> exprResult;
89
rv = expr->evaluate(aContext, getter_AddRefs(exprResult));
90
NS_ENSURE_SUCCESS(rv, rv);
92
if (exprResult->getResultType() != txAExprResult::NODESET) {
93
//XXX ErrorReport: report nonnodeset error
94
return NS_ERROR_XSLT_NODESET_EXPECTED;
97
nsRefPtr<txNodeSet> resultSet, ownedSet;
98
resultSet = NS_STATIC_CAST(txNodeSet*,
99
NS_STATIC_CAST(txAExprResult*, exprResult));
101
rv = aContext->recycler()->
102
getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet));
103
NS_ENSURE_SUCCESS(rv, rv);
105
rv = nodes->addAndTransfer(ownedSet);
106
NS_ENSURE_SUCCESS(rv, rv);
116
* Returns the String representation of this Expr.
117
* @param dest the String to use when creating the String
118
* representation. The String representation will be appended to
119
* any data in the destination String, to allow cascading calls to
120
* other #toString() methods for Expressions.
121
* @return the String representation of this Expr.
123
void UnionExpr::toString(nsAString& dest) {
124
txListIterator iter(&expressions);
127
while (iter.hasNext()) {
130
dest.Append(NS_LITERAL_STRING(" | "));
131
((Expr*)iter.next())->toString(dest);