Skip to content

Commit d426c2c

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[feature] Add class RenameExpr to support rename expression
1 parent 391afe9 commit d426c2c

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 RenameExpr extends ModifyingExpression {
38+
private final Expression newNameExpr;
39+
40+
public RenameExpr(final XQueryContext context, final Expression target, final Expression newName) {
41+
super(context, target);
42+
this.newNameExpr = newName;
43+
}
44+
45+
@Override
46+
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
47+
}
48+
49+
@Override
50+
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
51+
return Sequence.EMPTY_SEQUENCE;
52+
}
53+
54+
@Override
55+
public Cardinality getCardinality() {
56+
return Cardinality.ONE_OR_MORE;
57+
}
58+
59+
@Override
60+
public void dump(final ExpressionDumper dumper) {
61+
dumper.display("replace").nl();
62+
dumper.startIndent();
63+
targetExpr.dump(dumper);
64+
dumper.endIndent();
65+
dumper.startIndent();
66+
newNameExpr.dump(dumper);
67+
dumper.endIndent();
68+
}
69+
70+
@Override
71+
public String toString() {
72+
final StringBuilder result = new StringBuilder();
73+
result.append("replace ");
74+
result.append(targetExpr.toString());
75+
result.append(" ");
76+
result.append(newNameExpr.toString());
77+
return result.toString();
78+
}
79+
80+
public Expression getNewNameExpr() {
81+
return newNameExpr;
82+
}
83+
}

0 commit comments

Comments
 (0)