简体   繁体   中英

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 ? As an example, in the NameSpaceExample there is a custom object type MyObjectType with components "foo" and "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". 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.

Any input is much appreciated!

You'll have to get them by surfing references or inferring the NodeId for now.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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