Debian Codegraph @

net/sf/saxon/functions/GenerateId_1.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.functions;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.StaticProperty;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.om.Item;
14 import net.sf.saxon.om.NodeInfo;
15 import net.sf.saxon.om.One;
16 import net.sf.saxon.om.ZeroOrOne;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.tree.util.FastStringBuffer;
19 import net.sf.saxon.value.AtomicValue;
20 import net.sf.saxon.value.StringValue;
21
22 /**
23 * This class supports the generate-id() function with one argument
24 */
25
26 public class GenerateId_1 extends ScalarSystemFunction {
27
28
29 /**
30 * Determine the special properties of this expression. The generate-id()
31 * function is a special case: it is considered creative if its operand
32 * is creative, so that generate-id(f()) is not taken out of a loop
33 * @param arguments the expressions supplied as arguments in the function call
34 */
35
36 public int getSpecialProperties(Expression[] arguments) {
37 int p = super.getSpecialProperties(arguments);
38 return p & ~StaticProperty.NO_NODES_NEWLY_CREATED;
39 }
40
41 @Override
42 public ZeroOrOne<? extends AtomicValue> resultWhenEmpty() {
43 return One.string("");
44 }
45
46 @Override
47 public AtomicValue evaluate(Item arg, XPathContext context) throws XPathException {
48 return generateId((NodeInfo)arg);
49 }
50
51 public static StringValue generateId(NodeInfo node) {
52 FastStringBuffer buffer = new FastStringBuffer(FastStringBuffer.C16);
53 node.generateId(buffer);
54 buffer.condense();
55 return new StringValue(buffer);
56
57 }
58
59 public String getCompilerName() {
60 return "GenerateIdCompiler";
61 }
62
63 }
64