UAReference.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { XMLElem, type IToXML } from "@/util/XmlElem";
  2. import type { NamespaceTable } from "./NameSpaceTable";
  3. import { assert } from "@/util/assert";
  4. import { NodeId, coerceNodeId } from "./NodeId";
  5. import { UABaseNode } from "./UABaseNode";
  6. export class UAReference implements IToXML{
  7. public fromNode:UABaseNode = UABaseNode.nullBaseNode;
  8. public toNode:UABaseNode = UABaseNode.nullBaseNode;
  9. constructor(public fromRef: NodeId,
  10. public referenceType: string,
  11. public toRef: NodeId,
  12. public isForward: boolean) {
  13. }
  14. reIndex(nst: NamespaceTable, onst: NamespaceTable) {
  15. const nsName=onst.getUri(this.toRef.namespace);
  16. assert(nsName!=undefined)
  17. const newIndex=nst.getIndex(nsName);
  18. assert(newIndex!=undefined)
  19. this.toRef.namespace=newIndex;
  20. }
  21. toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
  22. const nid=UABaseNode.localNodeId(this.toRef, lnst, gnst);
  23. return new XMLElem('Reference', nid.toString())
  24. .attr('ReferenceType', this.referenceType.toString())
  25. .attr('IsForward',this.isForward);
  26. }
  27. static fromXML(uaReference: any, fromRef: NodeId): UAReference {
  28. return new UAReference( fromRef,
  29. uaReference['@_ReferenceType'],
  30. coerceNodeId(uaReference['#text']),
  31. uaReference['@_IsForward']!="false");
  32. }
  33. }