Search in sources :

Example 1 with Tree

use of org.eclipse.milo.opcua.stack.core.util.Tree in project milo by eclipse.

the class DataTypeTreeBuilder method addChildren.

private static CompletableFuture<Unit> addChildren(Tree<DataTypeTree.DataType> tree, UaStackClient client, OpcUaSession session, NamespaceTable namespaceTable) {
    CompletableFuture<List<ReferenceDescription>> subtypes = browseSafe(client, session, new BrowseDescription(tree.getValue().getNodeId(), BrowseDirection.Forward, Identifiers.HasSubtype, false, uint(NodeClass.DataType.getValue()), uint(BrowseResultMask.All.getValue())));
    CompletableFuture<List<DataTypeTree.DataType>> dataTypesFuture = subtypes.thenCompose(references -> {
        Stream<CompletableFuture<DataTypeTree.DataType>> dataTypeFutures = references.stream().map(dataTypeReference -> {
            NodeId dataTypeId = dataTypeReference.getNodeId().toNodeId(namespaceTable).orElse(NodeId.NULL_VALUE);
            CompletableFuture<List<ReferenceDescription>> encodings = browseSafe(client, session, new BrowseDescription(dataTypeId, BrowseDirection.Forward, Identifiers.HasEncoding, false, uint(NodeClass.Object.getValue()), uint(BrowseResultMask.All.getValue())));
            return encodings.thenApply(encodingReferences -> {
                NodeId binaryEncodingId = null;
                NodeId xmlEncodingId = null;
                for (ReferenceDescription r : encodingReferences) {
                    if (r.getBrowseName().equals(OpcUaDefaultBinaryEncoding.ENCODING_NAME)) {
                        binaryEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
                    } else if (r.getBrowseName().equals(OpcUaDefaultXmlEncoding.ENCODING_NAME)) {
                        xmlEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
                    }
                }
                return new DataTypeTree.DataType(dataTypeReference.getBrowseName(), dataTypeId, binaryEncodingId, xmlEncodingId);
            });
        });
        return FutureUtils.sequence(dataTypeFutures);
    });
    return dataTypesFuture.thenCompose(dataTypes -> {
        Stream<CompletableFuture<Unit>> futures = dataTypes.stream().map(tree::addChild).map(childNode -> addChildren(childNode, client, session, namespaceTable));
        return FutureUtils.sequence(futures);
    }).thenApply(v -> Unit.VALUE);
}
Also used : OpcUaDefaultBinaryEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultBinaryEncoding) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) CompletableFuture(java.util.concurrent.CompletableFuture) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) Tree(org.eclipse.milo.opcua.stack.core.util.Tree) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) OpcUaDefaultXmlEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultXmlEncoding) DataTypeTree(org.eclipse.milo.opcua.sdk.core.DataTypeTree) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) UaResponseMessage(org.eclipse.milo.opcua.stack.core.serialization.UaResponseMessage) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) Stream(java.util.stream.Stream) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) UaException(org.eclipse.milo.opcua.stack.core.UaException) Collections(java.util.Collections) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) CompletableFuture(java.util.concurrent.CompletableFuture) DataTypeTree(org.eclipse.milo.opcua.sdk.core.DataTypeTree) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) List(java.util.List) Stream(java.util.stream.Stream) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Stream (java.util.stream.Stream)1 DataTypeTree (org.eclipse.milo.opcua.sdk.core.DataTypeTree)1 UaStackClient (org.eclipse.milo.opcua.stack.client.UaStackClient)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)1 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)1 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 UaResponseMessage (org.eclipse.milo.opcua.stack.core.serialization.UaResponseMessage)1 OpcUaDefaultBinaryEncoding (org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultBinaryEncoding)1 OpcUaDefaultXmlEncoding (org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultXmlEncoding)1 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)1 BrowseDirection (org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection)1