UAObjectType.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { XMLElem } from "@/util/XmlElem";
  2. import type { NamespaceTable } from "./NameSpaceTable";
  3. import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
  4. import type { IAddressSpace } from "./IAddressSpace";
  5. export class UAObjectType extends UABaseNode{
  6. public isAbstract: boolean;
  7. constructor(options: UAObjectTypeOptions) {
  8. super(options)
  9. this.isAbstract=options.isAbstract||false;
  10. }
  11. static fromXML(xmlObjType: any, addressSpace: IAddressSpace): UAObjectType{
  12. const bn=super.fromXML(xmlObjType, addressSpace)
  13. return new UAObjectType({nodeId: bn.nodeId,
  14. browseName: bn.browseName,
  15. displayName: bn.displayName,
  16. references: bn.references,
  17. isAbstract: xmlObjType['@_IsAbstract']==='true',
  18. addressSpace: addressSpace});
  19. }
  20. toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
  21. const nid=UABaseNode.localNodeId(this.nodeId, lnst, gnst);
  22. const elem =new XMLElem('UAObjectType');
  23. elem.attr('NodeId', nid.toString())
  24. .attr('BrowseName', this.browseName)
  25. .attr('IsAbstract', this.isAbstract)
  26. .elem('DisplayName', this.displayName);
  27. const refs=elem.add(new XMLElem('References'))
  28. for(const ref of this.references) {
  29. if(ref.fromNode.nodeId.toString()==this.nodeId.toString()) //on load resolveReferences() duplicates references to both sides. skip them for export
  30. refs.add(ref.toXML(lnst, gnst));
  31. }
  32. return elem;
  33. }
  34. }
  35. export interface UAObjectTypeOptions extends UABaseNodeOptions{
  36. isAbstract?: boolean
  37. }