关于服务器端的实现:访问(和修改)由 NodeFactory 构建的特定节点实例的最佳方式是什么?例如,在 NameSpaceExample 中有一个自定义对象类型 MyObjectType,其中包含组件“foo”和“bar”。
// Define a new ObjectType called "MyObjectType".
UaObjectTypeNode objectTypeNode = UaObjectTypeNode.builder(server.getNodeMap())
.setNodeId(new NodeId(namespaceIndex, "ObjectTypes/MyObjectType"))
.setBrowseName(new QualifiedName(namespaceIndex, "MyObjectType"))
.setDisplayName(LocalizedText.english("MyObjectType"))
.setIsAbstract(false)
.build();
// "Foo" and "Bar" are members. These nodes are what are called "instance declarations" by the spec.
UaVariableNode foo = UaVariableNode.builder(server.getNodeMap())
.setNodeId(new NodeId(namespaceIndex, "ObjectTypes/MyObjectType.Foo"))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(new QualifiedName(namespaceIndex, "Foo"))
.setDisplayName(LocalizedText.english("Foo"))
.setDataType(Identifiers.Int16)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();
foo.setValue(new DataValue(new Variant(0)));
objectTypeNode.addComponent(foo);
UaVariableNode bar = UaVariableNode.builder(server.getNodeMap())
.setNodeId(new NodeId(namespaceIndex, "ObjectTypes/MyObjectType.Bar"))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(new QualifiedName(namespaceIndex, "Bar"))
.setDisplayName(LocalizedText.english("Bar"))
.setDataType(Identifiers.String)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();
bar.setValue(new DataValue(new Variant("bar")));
bar.addReference(new Reference(bar.getNodeId(), Identifiers.HasModellingRule, Identifiers.ModellingRule_MandatoryPlaceholder.expanded(), NodeClass.ObjectType, true));
objectTypeNode.addComponent(bar);
// Tell the ObjectTypeManager about our new type.
// This let's us use NodeFactory to instantiate instances of the type.
server.getObjectTypeManager().registerObjectType(
objectTypeNode.getNodeId(),
UaObjectNode.class,
UaObjectNode::new
);
// Add our ObjectTypeNode as a subtype of BaseObjectType.
server.getUaNamespace().addReference(
Identifiers.BaseObjectType,
Identifiers.HasSubtype,
true,
objectTypeNode.getNodeId().expanded(),
NodeClass.ObjectType
);
// Add the inverse SubtypeOf relationship.
objectTypeNode.addReference(new Reference(
objectTypeNode.getNodeId(),
Identifiers.HasSubtype,
Identifiers.BaseObjectType.expanded(),
NodeClass.ObjectType,
false
));
// Add it into the address space.
server.getNodeMap().addNode(objectTypeNode);
// Use NodeFactory to create instance of MyObjectType called "MyObject".
// NodeFactory takes care of recursively instantiating MyObject member nodes
// as well as adding all nodes to the address space.
UaObjectNode myObject = nodeFactory.createObject(
new NodeId(namespaceIndex, "HelloWorld/MyObject"),
new QualifiedName(namespaceIndex, "MyObject"),
LocalizedText.english("MyObject"),
objectTypeNode.getNodeId()
);
// Add forward and inverse references from the root folder.
rootFolder.addOrganizes(myObject);
myObject.addReference(new Reference(
myObject.getNodeId(),
Identifiers.Organizes,
rootFolder.getNodeId().expanded(),
rootFolder.getNodeClass(),
false
));
使用节点工厂创建 MyObjectType 的 MyObject 实例,该实例具有(由于类型定义)组件“foo”和“bar”。访问它们的最佳方式是什么?在客户端它会像
VariableNode node = client.getAddressSpace().createVariableNode(new NodeId(namespaceIndex, "HelloWorld/MyObject"));
我知道可以获取 MyObject 的引用并遵循它们,但必须有更好的方法。
非常感谢任何输入!