简体   繁体   English

如何访问由Eclipse Milo服务器端的NodeFactory构建的节点实例?

[英]How do i access Node Instances which were built by the NodeFactory on the Server Side in Eclipse Milo?

Concerning the implementation on the server side: Which is the best way to access (and modify) specific node instances which were built by the NodeFactory ? 关于服务器端的实现:哪种是访问(和修改)由NodeFactory生成的特定节点实例的最佳方法? As an example, in the NameSpaceExample there is a custom object type MyObjectType with components "foo" and "bar". 例如,在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
    ));

With the node factory an instance MyObject of MyObjectType is created which has (due to the type definiton) the components "foo" and "bar". 使用节点工厂,将创建MyObjectType的实例MyObject,该实例具有(由于类型定义)组件“ foo”和“ bar”。 Which is the best way to access them ? 哪种是最好的访问方式? On the client Side it would be something like 在客户端,它会像

VariableNode node = client.getAddressSpace().createVariableNode(new NodeId(namespaceIndex, "HelloWorld/MyObject"));

I know it is possible to get the references of MyObject and follow them but there must be a better way. 我知道可以获取MyObject的引用并遵循它们,但是必须有更好的方法。

Any input is much appreciated! 任何输入,不胜感激!

You'll have to get them by surfing references or inferring the NodeId for now. 您现在必须通过浏览引用或推断NodeId来获取它们。

The new NodeFactory work is done and waiting in a PR for to the 0.3 branch, so hopefully it won't be too long until you can use the NodeFactory implementation. 新的NodeFactory工作已经完成,并在PR中等待0.3分支,因此希望在您可以使用NodeFactory实现之前不会太久。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM