Skip to content

Commit 2ec4bd8

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[feature] Add ReplaceExpr class to implement replace expression
1 parent 7e6fffc commit 2ec4bd8

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.xquery.update;
23+
24+
import org.exist.xquery.AnalyzeContextInfo;
25+
import org.exist.xquery.Cardinality;
26+
import org.exist.xquery.Expression;
27+
import org.exist.xquery.XPathException;
28+
import org.exist.xquery.XQueryContext;
29+
import org.exist.xquery.util.ExpressionDumper;
30+
import org.exist.xquery.value.Item;
31+
import org.exist.xquery.value.Sequence;
32+
33+
/**
34+
* @author <a href="[email protected]">Adam Retter</a>
35+
* @author <a href="[email protected]">Gabriele Tomassetti</a>
36+
*/
37+
public class ReplaceExpr extends ModifyingExpression {
38+
public enum ReplacementType {
39+
NODE,
40+
VALUE
41+
}
42+
43+
private final Expression withExpr;
44+
private final ReplaceExpr.ReplacementType replacementType;
45+
46+
public ReplaceExpr(final XQueryContext context, final Expression target, final Expression with, final ReplaceExpr.ReplacementType replacementType) {
47+
super(context, target);
48+
this.withExpr = with;
49+
this.replacementType = replacementType;
50+
}
51+
52+
@Override
53+
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
54+
}
55+
56+
@Override
57+
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
58+
return Sequence.EMPTY_SEQUENCE;
59+
}
60+
61+
@Override
62+
public Cardinality getCardinality() {
63+
return Cardinality.ONE_OR_MORE;
64+
}
65+
66+
@Override
67+
public void dump(final ExpressionDumper dumper) {
68+
dumper.display("replace").nl();
69+
dumper.startIndent();
70+
targetExpr.dump(dumper);
71+
dumper.endIndent();
72+
dumper.display(replacementType).nl();
73+
dumper.startIndent();
74+
withExpr.dump(dumper);
75+
dumper.endIndent();
76+
}
77+
78+
@Override
79+
public String toString() {
80+
final StringBuilder result = new StringBuilder();
81+
result.append("replace ");
82+
result.append(targetExpr.toString());
83+
result.append(" ");
84+
result.append(replacementType.toString());
85+
result.append(" ");
86+
result.append(withExpr.toString());
87+
return result.toString();
88+
}
89+
90+
public ReplaceExpr.ReplacementType getReplacementType() {
91+
return replacementType;
92+
}
93+
94+
public Expression getWithExpr() {
95+
return withExpr;
96+
}
97+
}

0 commit comments

Comments
 (0)