@itwin/core-backend
Version:
iTwin.js backend components
70 lines • 3.6 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Schema
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ECSchemaXmlContext = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_common_1 = require("@itwin/core-common");
const NativePlatform_1 = require("./internal/NativePlatform");
/** Context used when deserializing a [Schema]($ecschema-metadata) from an XML file.
* A schema may contain references to other schemas, which may reside elsewhere on the local disk than the referencing schema.
* The context maintains a list of directories ("search paths") to search for referenced schemas. Directories can be appended to the list via [[addSchemaPath]].
* When a referenced schema needs to be located, the list of directories is searched in the order in which each was added.
* Once located, the schema is cached to avoid performing repeated lookups in the file system.
* @see [[readSchemaFromXmlFile]] to deserialize a schema.
* @public @preview
*/
class ECSchemaXmlContext {
_nativeContext;
/** Construct a context with an empty list of search paths. */
constructor() {
this._nativeContext = new NativePlatform_1.IModelNative.platform.ECSchemaXmlContext();
}
/** @internal */
get nativeContext() {
(0, core_bentley_1.assert)(undefined !== this._nativeContext);
return this._nativeContext;
}
/** Append a directory to the list of directories that will be searched to locate referenced schemas.
* The directories are searched in the order in which they were added to the list.
* @param searchPath The absolute path to the directory to search.
*/
addSchemaPath(searchPath) {
this.nativeContext.addSchemaPath(searchPath);
}
/** Set the last locater to be used when trying to find a schema
* @param locater Locater that should be used as the last locater when trying to find a schema
* @internal
*/
setSchemaLocater(locater) {
this.nativeContext.setSchemaLocater(locater);
}
/** Adds a schema locator to the beginning of the list of locators used to search for schemas.
* This schema locator will be prioritized over other locators when searching for schemas in the current context.
* @param locater Locater to add to the current context
* @internal
*/
setFirstSchemaLocater(locater) {
this.nativeContext.setFirstSchemaLocater(locater);
}
/** Deserialize a [Schema]($ecschema-metadata) from an ECSchemaXML-formatted file.
* @param filePath The absolute path of the XML file.
* @returns The JSON representation of the schema, as a [SchemaProps]($ecschema-metadata).
* @throws [[IModelError]] if there is a problem reading schema from the XML file
*/
readSchemaFromXmlFile(filePath) {
const response = this.nativeContext.readSchemaFromXmlFile(filePath);
if (response.error) {
throw new core_common_1.IModelError(response.error.status, response.error.message);
}
(0, core_bentley_1.assert)(undefined !== response.result);
return JSON.parse(response.result);
}
}
exports.ECSchemaXmlContext = ECSchemaXmlContext;
//# sourceMappingURL=ECSchemaXmlContext.js.map
;