UAMethod.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { XMLElem } from "@/util/XmlElem";
  2. import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
  3. import type { NamespaceTable } from "./NameSpaceTable";
  4. export class UAMethod extends UABaseNode {
  5. constructor(options: UAMethodNodeOptions) {
  6. super(options);
  7. this.nodeClass="Method";
  8. }
  9. static fromXML(uaMethod: any): UAMethod{
  10. const bn=super.fromXML(uaMethod)
  11. return new UAMethod({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('UAMethod');
  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. getModellingRule(){
  30. let res:any = "";
  31. this.references.forEach((ref)=>{
  32. if(ref.referenceType == "HasModellingRule"){
  33. res = ref.toNode.displayName;
  34. }
  35. })
  36. return res;
  37. }
  38. }
  39. export interface UAMethodNodeOptions extends UABaseNodeOptions{
  40. }