Interface VarFunction
- All Known Implementing Classes:
ArithmeticFunctions.Abs,ArithmeticFunctions.Add,ArithmeticFunctions.Divide,ArithmeticFunctions.Max,ArithmeticFunctions.Min,ArithmeticFunctions.Modulo,ArithmeticFunctions.Multiply,ArithmeticFunctions.Subtract,BooleanFunctions.And,BooleanFunctions.Eq,BooleanFunctions.Gt,BooleanFunctions.Gte,BooleanFunctions.Lt,BooleanFunctions.Lte,BooleanFunctions.Neq,BooleanFunctions.Not,BooleanFunctions.Or,BooleanFunctions.Xor,ConditionalFunctions.Coalesce,ConditionalFunctions.If,ConditionalFunctions.NotEmpty,ConditionalFunctions.Switch,DateFunctions.FormatDate,DateFunctions.Now,DateFunctions.ParseDate,EncodingFunctions.Base64Decode,EncodingFunctions.Base64Encode,EncodingFunctions.HtmlEscape,EncodingFunctions.HtmlUnescape,EncodingFunctions.UrlDecode,EncodingFunctions.UrlEncode,JsonFunctions.Get,JsonFunctions.JsonPath,JsonFunctions.Keys,JsonFunctions.Size,JsonFunctions.Values,RandomFunctions.Rand,RandomFunctions.RandChoice,RandomFunctions.RandInt,RandomFunctions.RandLong,RandomFunctions.RandString,RandomFunctions.Uuid,RegexFunctions.Extract,RegexFunctions.Match,RegexFunctions.ReplaceRegex,StringFunctions.Concat,StringFunctions.Contains,StringFunctions.EndsWith,StringFunctions.Format,StringFunctions.Join,StringFunctions.Len,StringFunctions.Lower,StringFunctions.PathToken,StringFunctions.Repeat,StringFunctions.Replace,StringFunctions.Reverse,StringFunctions.Split,StringFunctions.StartsWith,StringFunctions.StripLeading,StringFunctions.StripSlashes,StringFunctions.StripTrailing,StringFunctions.Substring,StringFunctions.Trim,StringFunctions.Upper,TypeConversionFunctions.ToBool,TypeConversionFunctions.ToDouble,TypeConversionFunctions.ToInt,TypeConversionFunctions.ToLong,TypedFunction
#{...} script-evaluation functions.
A VarFunction is invoked when an SVL template contains a
$X{...} variables. Functions
compose freely with ${...} lookups and other #{...} calls; arguments are
pre-resolved by the runtime before invoke is called.
Naming note:
Named VarFunction rather than the shorter Function because Juneau's
serializer/parser/test code makes heavy use of Function and
routinely co-imports org.apache.juneau.commons.svl.*; a bare Function type in
this package would trigger ambiguous-reference errors across many callers. The chosen name
also matches the existing Var/VarResolver/VarTemplate/VarResolverSession
naming family.
Implementations can register through any of four discovery channels (later wins on name collision):
- The built-in catalog auto-registered by
VarResolver.DEFAULT. META-INF/services/org.apache.juneau.commons.svl.VarFunction(JavaServiceLoader).BeanStore.getBeans(VarFunction.class)on the resolver's bean store.- Explicit registrations via
VarResolver.Builder.functions(...).
For typed reflection-based dispatch (the recommended path), extend
TypedFunction — it derives minArity(), maxArity(), and per-arg
coercion automatically from the subclass's invoke(...) method signature, eliminating
the per-function plumbing.
Example:
See Also:
-
Method Summary
Modifier and TypeMethodDescriptioninvoke(VarResolverSession session, List<Object> args) Invokes this function with already-resolved, type-coerced arguments.intmaxArity()Maximum argument count this function accepts.intminArity()Minimum argument count this function accepts.name()The function's invocation name as it appears between#{}and the opening parenthesis in the template.
-
Method Details
-
name
The function's invocation name as it appears between#{}and the opening parenthesis in the template. Must consist of ASCII letters, digits, and underscores; must begin with a letter.- Returns:
- The invocation name. Never
nullor empty.
-
minArity
int minArity()Minimum argument count this function accepts.- Returns:
- The minimum number of args.
0means the function may be called with no args. Returns-1for "any number of args" — equivalent to declaringminArity == 0 && maxArity == Integer.MAX_VALUE.
-
maxArity
int maxArity()Maximum argument count this function accepts.- Returns:
- The maximum number of args, or
Integer.MAX_VALUEfor unbounded variadic functions.
-
invoke
Invokes this function with already-resolved, type-coerced arguments.The runtime resolves each
#{...}arg template against the session, then coerces the resolved string to the target Java type viaArgCoercer. The resultingList<Object>is passed in here.- Parameters:
session- The current resolver session. Must not benull.args- The coerced arguments. Size is in[minArity(), maxArity()]. Each element is the type the function expects per its signature; for variadic /Object-typed slots, elements remainString.- Returns:
- The function's result as a
String. May be empty but should not benull(the runtime treatsnullas the empty string for SVL output).
-