| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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.SystemFunctionCall; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.om.Item; |
| 15 |
import net.sf.saxon.om.Sequence; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.type.BuiltInAtomicType; |
| 18 |
import net.sf.saxon.value.AtomicValue; |
| 19 |
import net.sf.saxon.value.DateTimeValue; |
| 20 |
import net.sf.saxon.value.StringValue; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public abstract class DynamicContextAccessor extends SystemFunction { |
| 29 |
|
| 30 |
private AtomicValue boundValue; |
| 31 |
|
| 32 |
public void bindContext(XPathContext context) throws XPathException { |
| 33 |
boundValue = evaluate(context); |
| 34 |
} |
| 35 |
|
| 36 |
public abstract AtomicValue evaluate(XPathContext context) throws XPathException; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public AtomicValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 48 |
if (boundValue != null) { |
| 49 |
return boundValue; |
| 50 |
} else { |
| 51 |
return evaluate(context); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public Expression makeFunctionCall(Expression[] arguments) { |
| 57 |
return new SystemFunctionCall(this, arguments) { |
| 58 |
@Override |
| 59 |
public Item evaluateItem(XPathContext context) throws XPathException { |
| 60 |
|
| 61 |
return evaluate(context); |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public int getIntrinsicDependencies() { |
| 66 |
return StaticProperty.DEPENDS_ON_RUNTIME_ENVIRONMENT; |
| 67 |
} |
| 68 |
}; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
public static class ImplicitTimezone extends DynamicContextAccessor { |
| 73 |
@Override |
| 74 |
public AtomicValue evaluate(XPathContext context) throws XPathException { |
| 75 |
DateTimeValue now = DateTimeValue.getCurrentDateTime(context); |
| 76 |
return now.getComponent(AccessorFn.Component.TIMEZONE); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
public static class CurrentDateTime extends DynamicContextAccessor { |
| 81 |
@Override |
| 82 |
public AtomicValue evaluate(XPathContext context) throws XPathException { |
| 83 |
return DateTimeValue.getCurrentDateTime(context); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
public static class CurrentDate extends DynamicContextAccessor { |
| 88 |
@Override |
| 89 |
public AtomicValue evaluate(XPathContext context) throws XPathException { |
| 90 |
DateTimeValue now = DateTimeValue.getCurrentDateTime(context); |
| 91 |
return now.toDateValue(); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
public static class CurrentTime extends DynamicContextAccessor { |
| 96 |
@Override |
| 97 |
public AtomicValue evaluate(XPathContext context) throws XPathException { |
| 98 |
DateTimeValue now = DateTimeValue.getCurrentDateTime(context); |
| 99 |
return now.toTimeValue(); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
public static class DefaultLanguage extends DynamicContextAccessor { |
| 104 |
@Override |
| 105 |
public AtomicValue evaluate(XPathContext context) throws XPathException { |
| 106 |
String lang = context.getConfiguration().getDefaultLanguage(); |
| 107 |
return new StringValue(lang, BuiltInAtomicType.LANGUAGE); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
|