import { XMLElem } from "@/util/XmlElem"; import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode"; import type { NamespaceTable } from "./NameSpaceTable"; import type { IAddressSpace } from "./IAddressSpace"; export class UAMethod extends UABaseNode { constructor(options: UAMethodNodeOptions) { super(options); this.nodeClass="Method"; } static fromXML(uaMethod: any, addressSpace: IAddressSpace): UAMethod{ const bn=super.fromXML(uaMethod, addressSpace) return new UAMethod({nodeId: bn.nodeId, browseName: bn.browseName, displayName: bn.displayName, references: bn.references, addressSpace: addressSpace}); } toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem { const nid=UABaseNode.localNodeId(this.nodeId, lnst, gnst); const elem =new XMLElem('UAMethod'); elem.attr('NodeId', nid.toString()) .attr('BrowseName', this.browseName) .elem('DisplayName', this.displayName); const refs=elem.add(new XMLElem('References')) for(const ref of this.references) { if(ref.fromNode.nodeId.toString()==this.nodeId.toString()) //on load resolveReferences() duplicates references to both sides. skip them for export refs.add(ref.toXML(lnst, gnst)); } return elem; } getModellingRule(){ let res:any = ""; this.references.forEach((ref)=>{ if(ref.referenceType == "HasModellingRule"){ res = ref.toNode.displayName; } }) return res; } } export interface UAMethodNodeOptions extends UABaseNodeOptions{ }