Using the symbol resolver
An EFX expression refers to the data of a notice by the identifiers of the SDK, such as BT-21-Procedure or
ND-Lot. The SymbolResolver gives the translator the metadata of each of them: its path in the notice, its type,
its parent node, whether it is repeatable, and the codes of a codelist. Every translator needs one.
Using SdkSymbolResolver (default)
The toolkit provides SdkSymbolResolver, which reads this metadata from the files of an SDK on disk: the fields and
nodes in fields/fields.json, and the codelists in codelists. Use it whenever your notices follow the eForms SDK.
Get an instance from the ComponentFactory of the toolkit, with the version of the SDK and the folder that holds
the SDKs:
SymbolResolver resolver = ComponentFactory.getSymbolResolver("2.0.0", "", Path.of("eforms-sdk"));
The folder contains one subfolder for each version of the SDK, named after the version, with the files of the SDK in
it, for example eforms-sdk/2.0.0/fields/fields.json. The second argument is the qualifier, which selects a variant
of the component when several are registered for the same version. Use an empty text for the default one.
SdkSymbolResolver reads the metadata once and keeps it in memory. The ComponentFactory creates one resolver for
each version and qualifier, and gives the same instance to every later call. So the resolver reads the metadata only
once, even when you create many translators.
You usually do not call ComponentFactory.getSymbolResolver yourself in your application code, but in the
createSymbolResolver method of your TranslatorDependencyFactory (see
Assembling and running a translator).
The paths that SdkSymbolResolver gives are XPath paths, as written in the SDK. They suit a script generator that
writes XPath. A script generator for another language must either convert these paths into its own syntax, or work
with a symbol resolver of its own.
When you need a custom implementation
Write your own SymbolResolver when the metadata does not come from the files of an SDK, or when the paths must be
in another syntax. For example:
-
your application keeps the metadata in a database or another store of its own;
-
the notices are not XML, so the paths are, for example, JSON paths;
-
you add metadata of your own to that of the SDK.
When the metadata comes from another store, but the paths are XPath paths, extend XPathSymbolResolver, the
abstract base class of SdkSymbolResolver. It holds all the logic, and you implement only the methods that load the
fields, nodes, codelists, data types and notice subtypes (see
Implementation).
For other paths, implement SymbolResolver yourself.
Your class implements SymbolResolver. So that the ComponentFactory can find it, it has the annotation
@SdkComponent(versions = {"2"}, componentType = SdkComponentType.SYMBOL_RESOLVER, qualifier = "…"), with a
qualifier of your own. Without a qualifier, it would clash with SdkSymbolResolver, which the toolkit registers
without one (see
Component registration). You can also extend
SdkSymbolResolver, and override only the methods that you need to change.
Keep the following in mind:
-
The translator relies on the metadata that your resolver returns for its type checking. The type of a field, and whether it is repeatable from a context, must be the same as in the SDK. Otherwise, the translator rejects valid expressions, and accepts invalid ones.
-
Your resolver returns paths as
PathExpressionobjects of the class that matches the type of the field and its repeatability from the context, such asStringPathorStringSequencePath. The translator takes the type and the number of values from this class, not fromisFieldRepeatableFromContext. It passes the scripts of the paths as they are to your script generator, which uses them to build expressions. -
Relative paths start from a context node. The translator asks for them with the identifier of the context.
-
The
ComponentFactoryshares one resolver between all the translations of an SDK version.XPathSymbolResolveris not thread-safe, so do not run these translations in parallel threads unless you synchronise them, or make your own resolver thread-safe.
Quick reference: interface methods
The methods of SymbolResolver, in groups:
- Paths
-
getAbsolutePathOfField,getAbsolutePathOfNode: the path from the root of the notice.getRelativePathOfField,getRelativePathOfNode: the path from a context node.getRelativePath: a path made relative to a context path.getRootNodeId,getRootPath: the root node of the notice and its path. - Types and structure
-
getTypeOfField: the SDK type of a field, such astextoramount.getParentNodeOfField: the node that holds a field.isFieldRepeatableFromContext,isNodeRepeatableFromContext: whether a field or node can have several values or occurrences from a given context node (see Repeatability). The path methods use the same rules to choose the class of the paths that they return. - Codelists
-
getRootCodelistOfField: the codelist of a code field.expandCodelist: the codes of a codelist. - Attribute fields
-
isAttributeField,getAttributeNameFromAttributeField,getAttributeFieldIdOfField,getFieldIdOfAttributeField,getAbsolutePathOfFieldWithoutTheAttribute: the fields that are stored in an XML attribute of another field, such as the currency of an amount.getAttributeFieldCodelistIdFromDataType: the codelist of the attribute that a data type defines, such astimeperiodfor the unit of aduration. - Privacy
-
getPrivacyCodeOfField,getPrivacySettingOfField,getPrivacyMask: the withholding of a field from publication (see References). - Notice subtypes
-
getAllNoticeSubtypes: the notice subtypes of the SDK, which theINclause of rules uses.
For the exact parameters, see the Javadoc of the interface. For an explanation of how SdkSymbolResolver works
inside, see Symbol resolver architecture.
See also: