| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Callable; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.expr.instruct.UserFunction; |
| 13 |
import net.sf.saxon.om.Item; |
| 14 |
import net.sf.saxon.om.Sequence; |
| 15 |
import net.sf.saxon.om.StructuredQName; |
| 16 |
import net.sf.saxon.query.AnnotationList; |
| 17 |
import net.sf.saxon.query.XQueryFunctionLibrary; |
| 18 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 19 |
import net.sf.saxon.trans.SymbolicName; |
| 20 |
import net.sf.saxon.trans.XPathException; |
| 21 |
import net.sf.saxon.type.AnyFunctionType; |
| 22 |
import net.sf.saxon.type.FunctionItemType; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class CallableFunction extends AbstractFunction { |
| 29 |
|
| 30 |
private Callable callable; |
| 31 |
private SymbolicName.F name; |
| 32 |
private FunctionItemType type; |
| 33 |
private AnnotationList annotations; |
| 34 |
|
| 35 |
public CallableFunction(SymbolicName.F name, Callable callable, FunctionItemType type) { |
| 36 |
this.name = name; |
| 37 |
this.callable = callable; |
| 38 |
this.type = type; |
| 39 |
} |
| 40 |
|
| 41 |
public CallableFunction(int arity, Callable callable, FunctionItemType type) { |
| 42 |
this.name = new SymbolicName.F(new StructuredQName("", "anon", "anon"), arity); |
| 43 |
this.callable = callable; |
| 44 |
this.type = type; |
| 45 |
} |
| 46 |
|
| 47 |
public Callable getCallable() { |
| 48 |
return callable; |
| 49 |
} |
| 50 |
|
| 51 |
public void setCallable(Callable callable) { |
| 52 |
this.callable = callable; |
| 53 |
} |
| 54 |
|
| 55 |
public void setType(FunctionItemType type) { |
| 56 |
this.type = type; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public FunctionItemType getFunctionItemType() { |
| 65 |
if (type == AnyFunctionType.getInstance() && callable instanceof XQueryFunctionLibrary.UnresolvedCallable) { |
| 66 |
UserFunction uf = ((XQueryFunctionLibrary.UnresolvedCallable) callable).getFunction(); |
| 67 |
if (uf != null) { |
| 68 |
|
| 69 |
type = uf.getFunctionItemType(); |
| 70 |
} |
| 71 |
} |
| 72 |
return type; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public StructuredQName getFunctionName() { |
| 81 |
return name.getComponentName(); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public String getDescription() { |
| 92 |
return callable.toString(); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public int getArity() { |
| 101 |
return name.getArity(); |
| 102 |
} |
| 103 |
|
| 104 |
public void setAnnotations(AnnotationList annotations) { |
| 105 |
this.annotations = annotations; |
| 106 |
} |
| 107 |
|
| 108 |
public AnnotationList getAnnotations() { |
| 109 |
return annotations; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public Sequence<?> call(XPathContext context, Sequence[] args) throws XPathException { |
| 122 |
return callable.call(context, args); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
@Override |
| 132 |
public void export(ExpressionPresenter out) { |
| 133 |
throw new UnsupportedOperationException("A CallableFunction is a transient value that cannot be exported"); |
| 134 |
} |
| 135 |
} |