-
Notifications
You must be signed in to change notification settings - Fork 208
/
CustomAttributeClass.ts
80 lines (71 loc) · 3.38 KB
/
CustomAttributeClass.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Metadata
*/
import { CustomAttributeClassProps } from "../Deserialization/JsonProps";
import {
containerTypeToString, CustomAttributeContainerType, ECClassModifier, parseCustomAttributeContainerType, SchemaItemType,
} from "../ECObjects";
import { ECObjectsError, ECObjectsStatus } from "../Exception";
import { ECClass } from "./Class";
import { Schema } from "./Schema";
/**
* A Typescript class representation of an ECCustomAttributeClass.
* @beta
*/
export class CustomAttributeClass extends ECClass {
public override readonly schemaItemType!: SchemaItemType.CustomAttributeClass; // eslint-disable-line
protected _containerType?: CustomAttributeContainerType;
public get containerType(): CustomAttributeContainerType {
if (undefined === this._containerType)
throw new ECObjectsError(ECObjectsStatus.InvalidContainerType, `The CustomAttributeClass ${this.name} does not have a CustomAttributeContainerType.`);
return this._containerType;
}
constructor(schema: Schema, name: string, modifier?: ECClassModifier) {
super(schema, name, modifier);
this.schemaItemType = SchemaItemType.CustomAttributeClass;
}
/**
* Save this CustomAttributeClasses properties to an object for serializing to JSON.
* @param standalone Serialization includes only this object (as opposed to the full schema).
* @param includeSchemaVersion Include the Schema's version information in the serialized object.
*/
public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): CustomAttributeClassProps {
const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;
schemaJson.appliesTo = containerTypeToString(this.containerType);
return schemaJson as CustomAttributeClassProps;
}
/** @internal */
public override async toXml(schemaXml: Document): Promise<Element> {
const itemElement = await super.toXml(schemaXml);
itemElement.setAttribute("appliesTo", containerTypeToString(this.containerType));
return itemElement;
}
public override fromJSONSync(customAttributeProps: CustomAttributeClassProps) {
super.fromJSONSync(customAttributeProps);
const containerType = parseCustomAttributeContainerType(customAttributeProps.appliesTo);
if (undefined === containerType)
throw new ECObjectsError(ECObjectsStatus.InvalidContainerType, `${containerType} is not a valid CustomAttributeContainerType.`);
this._containerType = containerType;
}
public override async fromJSON(customAttributeProps: CustomAttributeClassProps) {
this.fromJSONSync(customAttributeProps);
}
/**
* @alpha Used in schema editing.
*/
protected setContainerType(containerType: CustomAttributeContainerType) {
this._containerType = containerType;
}
}
/**
* @internal
* An abstract class used for Schema editing.
*/
export abstract class MutableCAClass extends CustomAttributeClass {
public abstract override setContainerType(containerType: CustomAttributeContainerType): void;
public abstract override setDisplayLabel(displayLabel: string): void;
}