UAObject.ts 1.4 KB

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