Debian Codegraph @

net/sf/saxon/functions/registry/ExsltCommonFunctionSet.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.registry;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.functions.SystemFunction;
12 import net.sf.saxon.lib.NamespaceConstant;
13 import net.sf.saxon.om.Item;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.om.SequenceTool;
16 import net.sf.saxon.pattern.AnyNodeTest;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.type.*;
19 import net.sf.saxon.value.StringValue;
20
21
22 /**
23 * Implementation of the exslt-common function library. This is available in all Saxon versions.
24 */
25 public class ExsltCommonFunctionSet extends BuiltInFunctionSet {
26
27 private static ExsltCommonFunctionSet THE_INSTANCE = new ExsltCommonFunctionSet();
28
29 public static ExsltCommonFunctionSet getInstance() {
30 return THE_INSTANCE;
31 }
32
33 private ExsltCommonFunctionSet() {
34 init();
35 }
36
37 private void init() {
38
39 register("node-set", 1, NodeSetFn.class, AnyItemType.getInstance(), OPT, 0, 0)
40 .arg(0, AnyItemType.getInstance(), OPT, EMPTY);
41
42 register("object-type", 1, ObjectTypeFn.class, BuiltInAtomicType.STRING, ONE, 0, 0)
43 .arg(0, AnyItemType.getInstance(), ONE, null);
44
45 }
46
47 @Override
48 public String getNamespace() {
49 return NamespaceConstant.EXSLT_COMMON;
50 }
51
52 @Override
53 public String getConventionalPrefix() {
54 return "exsltCommon";
55 }
56
57 /**
58 * Implement exslt:node-set
59 */
60
61 public static class NodeSetFn extends SystemFunction {
62 public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {
63 return arguments[0];
64 }
65 }
66
67 /**
68 * Implement exslt:object-type
69 */
70
71 public static class ObjectTypeFn extends SystemFunction {
72 public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {
73 final TypeHierarchy th = context.getConfiguration().getTypeHierarchy();
74 Item value = arguments[0].head();
75 ItemType type = SequenceTool.getItemType(value, th);
76 if (th.isSubType(type, AnyNodeTest.getInstance())) {
77 return new StringValue("node-set");
78 } else if (th.isSubType(type, BuiltInAtomicType.STRING)) {
79 return new StringValue("string");
80 } else if (th.isSubType(type, NumericType.getInstance())) {
81 return new StringValue("number");
82 } else if (th.isSubType(type, BuiltInAtomicType.BOOLEAN)) {
83 return new StringValue("boolean");
84 } else {
85 return new StringValue(type.toString());
86 }
87 }
88 }
89
90
91
92 }
93
94 // Copyright (c) 2018 Saxonica Limited.