Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error("nodeId " + node.nodeId.displayText() + " already registered " + node.nodeId.toString()
+ "\n" +
" in namespace " + this.namespaceUri + " index = " + this.index
+ "\n" +
" browseName = " + node.browseName.toString());
}
this._nodeid_index[indexName] = node;
if (node.nodeClass === NodeClass.ObjectType) {
this._registerObjectType(node as UAObjectType);
} else if (node.nodeClass === NodeClass.VariableType) {
this._registerVariableType(node as UAVariableType);
} else if (node.nodeClass === NodeClass.ReferenceType) {
this._registerReferenceType(node as UAReferenceType);
} else if (node.nodeClass === NodeClass.DataType) {
this._registerDataType(node as UADataType);
} else if (node.nodeClass === NodeClass.Object) {
//
} else if (node.nodeClass === NodeClass.Variable) {
//
} else if (node.nodeClass === NodeClass.Method) {
//
} else if (node.nodeClass === NodeClass.View) {
//
} else {
// tslint:disable-next-line:no-console
console.log("Invalid class Name", node.nodeClass);
throw new Error("Invalid class name specified");
}
}
export function addElement(
options: any /* ExtensionObjectConstructor | ExtensionObject | UAVariable*/,
uaArrayVariableNode: UADynamicVariableArray
): UAVariable {
assert(uaArrayVariableNode, " must provide an UAVariable containing the array");
// verify that arr has been created correctly
assert(!!uaArrayVariableNode.$$variableType && !!uaArrayVariableNode.$$dataType,
"did you create the array Node with createExtObjArrayNode ?");
assert(uaArrayVariableNode.$$dataType.nodeClass === NodeClass.DataType);
assert((uaArrayVariableNode.$$dataType as UADataType)._extensionObjectConstructor instanceof Function);
const addressSpace = uaArrayVariableNode.addressSpace;
let extensionObject: T;
let elVar = null;
let browseName;
if (options instanceof UAVariable) {
elVar = options;
extensionObject = elVar.$extensionObject; // get shared extension object
assert(extensionObject instanceof (uaArrayVariableNode.$$dataType as UADataType)._extensionObjectConstructor,
"the provided variable must expose a Extension Object of the expected type ");
// add a reference
uaArrayVariableNode.addReference({
isForward: true,
const addressSpace = self.addressSpace;
let definition;
const enumerationType = addressSpace.findDataType("Enumeration")!;
assert(enumerationType.nodeId instanceof NodeId);
assert(enumerationType instanceof UADataType);
const references = [
{ referenceType: "HasSubtype", isForward: false, nodeId: enumerationType.nodeId }
];
const opts = {
browseName: options.browseName,
definition,
description: options.description || null,
displayName: options.displayName || null,
isAbstract: false,
nodeClass: NodeClass.DataType,
references
};
const enumType = self._createNode(opts) as UADataType; // as UAEnumeration;
enumType.propagate_back_references();
if (_.isString(options.enumeration[0])) {
// enumeration is a array of string
definition = (options.enumeration as any).map((str: string, index: number) => coerceLocalizedText(str));
const value = new Variant({
arrayType: VariantArrayType.Array,
dataType: DataType.LocalizedText,
value: definition
});
assert(rootFolder.getFolderElementByName("Objects")!
.browseName.toString() === "Objects");
}
{
const dataTypeFolder = namespace0.addObject({
browseName: "DataType",
nodeId: resolveNodeId(ObjectIds.DataTypesFolder),
organizedBy: rootFolder
});
{
const doubleDataType = namespace0._createNode({
browseName: "Double",
nodeClass: NodeClass.DataType,
nodeId: resolveNodeId(DataTypeIds.Double),
organizedBy: dataTypeFolder
});
}
}
}
}
rootFolder.getFolderElementByName("Objects").browseName.toString().should.eql("Objects");
}
{
const dataTypeFolder = namespace0.addObject({
browseName: "DataType",
nodeId: resolveNodeId(ObjectIds.DataTypesFolder),
organizedBy: rootFolder
});
{
const doubleDataType = namespace0._createNode({
browseName: "Double",
nodeId: resolveNodeId(DataTypeIds.Double),
organisedBy: dataTypeFolder,
nodeClass: NodeClass.DataType
});
}
}
}
};
//assert(node.browseName.namespaceIndex === this.index,"browseName must belongs to this namespace");
const indexName = node.nodeId.toString();
if (this._nodeid_index.hasOwnProperty(indexName)) {
throw new Error("nodeId " + node.nodeId.displayText() + " already registered " + node.nodeId.toString());
}
this._nodeid_index[indexName] = node;
if (node.nodeClass === NodeClass.ObjectType) {
_registerObjectType(this, node);
} else if (node.nodeClass === NodeClass.VariableType) {
_registerVariableType(this, node);
} else if (node.nodeClass === NodeClass.ReferenceType) {
_registerReferenceType(this, node);
} else if (node.nodeClass === NodeClass.DataType) {
_registerDataType(this, node);
} else if (node.nodeClass === NodeClass.Object) {
} else if (node.nodeClass === NodeClass.Variable) {
} else if (node.nodeClass === NodeClass.Method) {
} else if (node.nodeClass === NodeClass.View) {
} else {
console.log("Invalid class Name", node.nodeClass);
throw new Error("Invalid class name specified");
}
};
public createDataType(options: CreateDataTypeOptions): UADataType {
assert(options.hasOwnProperty("isAbstract"));
assert(!options.hasOwnProperty("nodeClass"));
assert(options.hasOwnProperty("browseName"), "must provide a browseName");
const options1 = options as any;
options1.nodeClass = NodeClass.DataType;
options1.references = options.references || [];
if (options1.references.length === 0) {
if (!options1.superType) {
throw new Error("must provide a superType");
}
options1.superType = this.addressSpace.findDataType(options1.superType) as UADataType;
if (!options1.superType) {
throw new Error("cannot find superType");
}
options1.references.push({
isForward: false,
nodeId: options1.superType.nodeId,
referenceType: "HasSubtype"
});
}
} from "../source";
import { BaseNode } from "./base_node";
import { BaseNode_toString, ToStringBuilder, ToStringOption } from "./base_node_private";
import * as tools from "./tool_isSupertypeOf";
import { get_subtypeOf } from "./tool_isSupertypeOf";
import { get_subtypeOfObj } from "./tool_isSupertypeOf";
type ExtensionObjectConstructor = new (options: any) => ExtensionObject;
export interface UADataType {
_extensionObjectConstructor: ExtensionObjectConstructor;
}
export class UADataType extends BaseNode implements UADataTypePublic {
public readonly nodeClass = NodeClass.DataType;
public readonly definitionName: string = "";
/**
* returns true if this is a super type of baseType
*
* @example
*
* var dataTypeDouble = addressSpace.findDataType("Double");
* var dataTypeNumber = addressSpace.findDataType("Number");
* assert(dataTypeDouble.isSupertypeOf(dataTypeNumber));
* assert(!dataTypeNumber.isSupertypeOf(dataTypeDouble));
*
*/
public get subtypeOf(): NodeId | null {
return get_subtypeOf.call(this);
}
* @param baseType {UADataType}
* @return {Boolean} true if self is a Subtype of baseType
*
*
* @example
*
* var dataTypeDouble = addressSpace.findDataType("Double");
* var dataTypeNumber = addressSpace.findDataType("Number");
* assert(dataTypeDouble.isSupertypeOf(dataTypeNumber));
* assert(!dataTypeNumber.isSupertypeOf(dataTypeDouble));
*
*/
UADataType.prototype.isSupertypeOf = tools.construct_isSupertypeOf(UADataType);
UADataType.prototype.nodeClass = NodeClass.DataType;
UADataType.prototype._toString = function(str,options)
{
const self = this;
BaseNode.prototype._toString.call(self,str,options);
options.add(options.padding + " binaryEncodingNodeId: ".yellow +
(self.binaryEncodingNodeId ? self.binaryEncodingNodeId.toString() : "" ));
options.add(options.padding + " xmlEncodingNodeId : ".yellow +
(self.xmlEncodingNodeId ? self.xmlEncodingNodeId.toString() : "" ));
if (self.subtypeOfObj) {
options.add(options.padding + " subtypeOfObj : ".yellow +
(self.subtypeOfObj ? self.subtypeOfObj.browseName.toString() : "" ));
}
init: function (name, attrs) {
this.obj = {};
this.obj.nodeClass = NodeClass.DataType;
this.obj.isAbstract = ec.coerceBoolean(attrs.IsAbstract);
this.obj.nodeId = convertToNodeId(attrs.NodeId) || null;
this.obj.browseName = convertQualifiedName(attrs.BrowseName);
this.obj.displayName = "";
this.obj.description = "";
},
finish: function () {