Browse Source

parse uadatatype.definition; bugfixes

Martin Kunz 1 month ago
parent
commit
e3c744f79b
3 changed files with 63 additions and 6 deletions
  1. 45 0
      src/ua/Definition.ts
  2. 9 6
      src/ua/UADataType.ts
  3. 9 0
      src/ua/UANodeSet.ts

+ 45 - 0
src/ua/Definition.ts

@@ -0,0 +1,45 @@
+import { XMLElem, type IToXML } from "@/util/XmlElem";
+import type { NamespaceTable } from "./NameSpaceTable";
+import type { IAddressSpace } from "./IAddressSpace";
+export class Definition implements IToXML {
+    public name:string;
+    public symbolicName:string|undefined;
+    public isUnion:boolean;
+    public IsOptionSet:boolean;
+    public baseType:string;
+
+    constructor(options: DefinitionOptions) {
+        this.name=options.name;
+        this.symbolicName=options.symbolicName;
+        this.isUnion=(options.isUnion===undefined?false:Boolean(options.isUnion));
+        this.IsOptionSet=(options.IsOptionSet===undefined?false:Boolean(options.IsOptionSet));
+        this.baseType=options.baseType||"";
+    }
+
+    toXML(_lnst:NamespaceTable, _gnst:NamespaceTable): XMLElem {
+        return new XMLElem("Definition")
+            .attr("Name", this.name)
+            .attr('SymbolicName', this.symbolicName)
+            .attr('IsUnion', this.isUnion)
+            .attr('IsOptionSet', this.IsOptionSet)
+            .attr('BaseType', this.baseType);
+    }
+
+    static  fromXML(xmlDefinition: any, _addressSpace: IAddressSpace): Definition{
+        return new Definition({
+            name: xmlDefinition['@_Name'],
+            symbolicName: xmlDefinition['@_SymbolicName'],
+            isUnion: xmlDefinition['@_IsUnion'],
+            IsOptionSet: xmlDefinition['@_IsOptionSet'],
+            baseType: xmlDefinition['@_BaseType']
+        });    
+    }
+}
+
+export interface DefinitionOptions{
+    name: string;
+    symbolicName?: string;
+    isUnion?: boolean;
+    IsOptionSet?: boolean;
+    baseType?:string;
+}

+ 9 - 6
src/ua/UADataType.ts

@@ -3,29 +3,32 @@ import { type UABaseNodeOptions } from "./UABaseNode";
 import type { NamespaceTable } from "./NameSpaceTable";
 import type { IAddressSpace } from "./IAddressSpace";
 import { UAType } from "./UAType";
+import { Definition } from "./Definition";
 export class UADataType extends UAType implements IToXML {
-//TODO definition
+    public definition?:Definition;
 
     constructor(options: UATypeOptions) {
         super(options);
         Object.assign(this, options);  
         this.nodeClass="UADataType";
+        this.definition=options.definition;
     }
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem=super.toXML(lnst, gnst);
         elem.name=this.nodeClass;
         elem.attr("Purpose", this.purpose);
         elem.attr('IsAbstract', this.isAbstract);
-
+        elem.elem("Definition", this.definition?.toXML(lnst,gnst));
         return elem;    
     }
-    static  fromXML(uaObject: any, addressSpace: IAddressSpace): UADataType{
-        const bn=super.fromXML(uaObject, addressSpace) as UATypeOptions
-
+    static  fromXML(xmlObject: any, addressSpace: IAddressSpace): UADataType{
+        const bn=super.fromXML(xmlObject, addressSpace) as UADataType;
+        if(xmlObject['Definition'])
+            bn.definition = Definition.fromXML(xmlObject['Definition'], addressSpace);
         return new UADataType(bn as UATypeOptions);    
     }
 }
 
 export interface UATypeOptions extends UABaseNodeOptions{
-
+    definition?:Definition;
 }

+ 9 - 0
src/ua/UANodeSet.ts

@@ -12,6 +12,7 @@ import { UAVariableType } from './UAVariableType';
 import type { AddressSpace } from './AddressSpace';
 import type { IAddressSpace } from './IAddressSpace';
 import { UAAlias } from './UAAlias';
+import { UADataType } from './UADataType';
 
 export class UANodeSet implements IToXML{
 
@@ -121,6 +122,10 @@ export class UANodeSet implements IToXML{
                     case 'UANodeSet.UAReferenceType.Description':
                     case 'UANodeSet.UAReferenceType.Category':
                     case 'UANodeSet.UAReferenceType.RolePermissions.RolePermission':
+                    case 'UANodeSet.UADataType':
+                    case 'UANodeSet.UADataType.References.Reference':
+                    case 'UANodeSet.UADataType.DisplayName':
+                    case 'UANodeSet.UADataType.Description':
                         return true;
                     default:
                         return false;
@@ -164,6 +169,10 @@ export class UANodeSet implements IToXML{
         for(const xmlVariableType of xmlVariableTypes) {
             nodes.push(UAVariableType.fromXML(xmlVariableType, addressSpace));
         }
+        const xmlDataTypes=xmlObj['UANodeSet']['UADataType']||[];
+        for(const xmlDataType of xmlDataTypes) {
+            nodes.push(UADataType.fromXML(xmlDataType, addressSpace));
+        }
         const uaNamespaceUris=xmlObj['UANodeSet']['NamespaceUris']||[];
         const nst=new NamespaceTable();
         for(const nsUri of uaNamespaceUris['Uri']||[]) {