build static method
Future<ExternalDataInstance>
build(
- ResourceResolver resolver,
- String instanceSrc,
- String instanceId, {
- ExternalInstanceParser? parser,
- bool placeholderIfMissing = true,
Loads the instance instanceId from instanceSrc with parser
(default: ExternalInstanceParser with its CSV and GeoJSON parsers),
reading files through resolver.
Instance providers are asked for a partial instance first; it's completed when evaluation reaches a partial element.
With placeholderIfMissing false a missing file throws
ResourceNotFoundException instead, as JavaRosa's readExternal
(deserializing a cached form) does.
Implementation
static Future<ExternalDataInstance> build(
ResourceResolver resolver,
String instanceSrc,
String instanceId, {
ExternalInstanceParser? parser,
bool placeholderIfMissing = true,
}) async {
final instanceParser = parser ?? ExternalInstanceParser();
TreeElement? root;
TreeElement Function()? reload;
try {
(root, reload) = await instanceParser.parseWithReload(
resolver,
instanceId,
instanceSrc,
partial: true,
);
} on ResourceNotFoundException {
if (!placeholderIfMissing) rethrow;
root = null;
}
final usePlaceholder = root == null || !root.hasChildren;
return ExternalDataInstance._(
usePlaceholder ? TreeElement(placeholderName, 0) : root,
instanceId,
instanceSrc,
isUsingPlaceholder: usePlaceholder,
reload: usePlaceholder ? null : reload,
);
}