UAMethod.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { XMLElem } from "@/util/XmlElem";
  2. import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
  3. import type { NamespaceTable } from "./NameSpaceTable";
  4. import type { IAddressSpace } from "./IAddressSpace";
  5. export class UAMethod extends UABaseNode {
  6. constructor(options: UAMethodNodeOptions) {
  7. super(options);
  8. this.nodeClass="Method";
  9. }
  10. static fromXML(uaMethod: any, addressSpace: IAddressSpace): UAMethod{
  11. const bn=super.fromXML(uaMethod, addressSpace)
  12. return new UAMethod({nodeId: bn.nodeId,
  13. browseName: bn.browseName,
  14. displayName: bn.displayName,
  15. references: bn.references,
  16. addressSpace: addressSpace});
  17. }
  18. toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
  19. const nid=UABaseNode.localNodeId(this.nodeId, lnst, gnst);
  20. const elem =new XMLElem('UAMethod');
  21. elem.attr('NodeId', nid.toString())
  22. .attr('BrowseName', this.browseName)
  23. .elem('DisplayName', this.displayName);
  24. const refs=elem.add(new XMLElem('References'))
  25. for(const ref of this.references) {
  26. if(ref.fromNode.nodeId.toString()==this.nodeId.toString()) //on load resolveReferences() duplicates references to both sides. skip them for export
  27. refs.add(ref.toXML(lnst, gnst));
  28. }
  29. return elem;
  30. }
  31. getModellingRule(){
  32. let res:any = "";
  33. this.references.forEach((ref)=>{
  34. if(ref.referenceType == "HasModellingRule"){
  35. res = ref.toNode.displayName;
  36. }
  37. })
  38. return res;
  39. }
  40. }
  41. export interface UAMethodNodeOptions extends UABaseNodeOptions{
  42. }