UAObjectType.ts 1.5 KB

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