Debian Codegraph @

net/sf/saxon/expr/instruct/OriginalFunction.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.expr.instruct;
9
10 import net.sf.saxon.expr.*;
11 import net.sf.saxon.functions.AbstractFunction;
12 import net.sf.saxon.om.Function;
13 import net.sf.saxon.om.Sequence;
14 import net.sf.saxon.om.StructuredQName;
15 import net.sf.saxon.trace.ExpressionPresenter;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.type.FunctionItemType;
18
19 /**
20 * This class represents a function invoked using xsl:original from within an xs:override element.
21 */
22 public class OriginalFunction extends AbstractFunction implements Function, ContextOriginator {
23
24 private UserFunction userFunction;
25 private Component component;
26
27 public OriginalFunction(Component component) {
28 this.component = component;
29 this.userFunction = (UserFunction)component.getActor();
30 }
31
32 /**
33 * Invoke the function
34 *
35 * @param context the XPath dynamic evaluation context
36 * @param args the actual arguments to be supplied
37 * @return the result of invoking the function
38 * @throws XPathException if a dynamic error occurs within the function
39 */
40 public Sequence<?> call(XPathContext context, Sequence[] args) throws XPathException {
41 XPathContextMajor c2 = userFunction.makeNewContext(context, this);
42 c2.setCurrentComponent(component);
43 return userFunction.call(c2, args);
44 }
45
46 /**
47 * Get the item type of the function item
48 *
49 * @return the function item's type
50 */
51 public FunctionItemType getFunctionItemType() {
52 return userFunction.getFunctionItemType();
53 }
54
55 /**
56 * Get the name of the function, or null if it is anonymous
57 *
58 * @return the function name, or null for an anonymous inline function
59 */
60 public StructuredQName getFunctionName() {
61 return userFunction.getFunctionName();
62 }
63
64 /**
65 * Get the arity of the function
66 *
67 * @return the number of arguments in the function signature
68 */
69 public int getArity() {
70 return userFunction.getArity();
71 }
72
73 /**
74 * Get a description of this function for use in error messages. For named functions, the description
75 * is the function name (as a lexical QName). For others, it might be, for example, "inline function",
76 * or "partially-applied ends-with function".
77 *
78 * @return a description of the function for use in error messages
79 */
80 public String getDescription() {
81 return userFunction.getDescription();
82 }
83
84 /**
85 * Get the name of the package containing the function
86 */
87
88 public String getContainingPackageName() {
89 return component.getContainingPackage().getPackageName();
90 }
91
92 public Component getComponent() {
93 return component;
94 }
95
96 @Override
97 public void export(ExpressionPresenter out) throws XPathException {
98 ExpressionPresenter.ExportOptions options = (ExpressionPresenter.ExportOptions) out.getOptions();
99 out.startElement("origF");
100 out.emitAttribute("name", getFunctionName());
101 out.emitAttribute("arity", ""+getArity());
102 out.emitAttribute("pack", options.packageMap.get(component.getContainingPackage())+"");
103 out.endElement();
104 }
105 }
106