Search in sources :

Example 1 with NodeClass

use of org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass in project milo by eclipse.

the class AddressSpace method createNodeFromBaseAttributes.

private CompletableFuture<? extends UaNode> createNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    StatusCode nodeIdStatusCode = baseAttributeValues.get(0).getStatusCode();
    if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
        return failedUaFuture(nodeIdStatusCode);
    }
    Integer nodeClassValue = (Integer) baseAttributeValues.get(1).getValue().getValue();
    if (nodeClassValue == null) {
        return failedUaFuture(StatusCodes.Bad_NodeClassInvalid);
    }
    NodeClass nodeClass = NodeClass.from(nodeClassValue);
    if (nodeClass == null) {
        return failedUaFuture(StatusCodes.Bad_NodeClassInvalid);
    }
    switch(nodeClass) {
        case DataType:
            return createDataTypeNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case Method:
            return createMethodNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case Object:
            return createObjectNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case ObjectType:
            return createObjectTypeNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case ReferenceType:
            return createReferenceTypeNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case Variable:
            return createVariableNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case VariableType:
            return createVariableTypeNodeFromBaseAttributes(nodeId, baseAttributeValues);
        case View:
            return createViewNodeFromBaseAttributes(nodeId, baseAttributeValues);
        default:
            throw new IllegalArgumentException("NodeClass: " + nodeClass);
    }
}
Also used : UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 2 with NodeClass

use of org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass in project milo by eclipse.

the class AddressSpace method browseNodesAsync.

/**
 * Browse from {@code nodeId} using {@code browseOptions}.
 * <p>
 * This call completes asynchronously.
 *
 * @param nodeId        the {@link NodeId} to start the browse from.
 * @param browseOptions the {@link BrowseOptions} to use.
 * @return a CompletableFuture that completes successfully with a List of {@link UaNode}s
 * referenced by {@code node} given the currently configured {@link BrowseOptions} or completes
 * exceptionally if a service-level error occurs.
 */
public CompletableFuture<List<? extends UaNode>> browseNodesAsync(NodeId nodeId, BrowseOptions browseOptions) {
    BrowseDescription browseDescription = new BrowseDescription(nodeId, browseOptions.getBrowseDirection(), browseOptions.getReferenceTypeId(), browseOptions.isIncludeSubtypes(), browseOptions.getNodeClassMask(), uint(BrowseResultMask.All.getValue()));
    CompletableFuture<List<ReferenceDescription>> browse = BrowseHelper.browse(client, browseDescription, browseOptions.getMaxReferencesPerNode());
    return browse.thenCompose(references -> {
        List<CompletableFuture<? extends UaNode>> cfs = references.stream().map(reference -> {
            NodeClass nodeClass = reference.getNodeClass();
            ExpandedNodeId xNodeId = reference.getNodeId();
            ExpandedNodeId xTypeDefinitionId = reference.getTypeDefinition();
            switch(nodeClass) {
                case Object:
                case Variable:
                    {
                        CompletableFuture<CompletableFuture<? extends UaNode>> ff = toNodeIdAsync(xNodeId).thenCombine(toNodeIdAsync(xTypeDefinitionId), (targetNodeId, typeDefinitionId) -> {
                            if (nodeClass == NodeClass.Object) {
                                return getObjectNodeAsync(targetNodeId, typeDefinitionId);
                            } else {
                                return getVariableNodeAsync(targetNodeId, typeDefinitionId);
                            }
                        });
                        return unwrap(ff).exceptionally(ex -> {
                            logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
                            return null;
                        });
                    }
                default:
                    {
                        // TODO specialized getNode for other NodeClasses?
                        return toNodeIdAsync(xNodeId).thenCompose(this::getNodeAsync).exceptionally(ex -> {
                            logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
                            return null;
                        });
                    }
            }
        }).collect(Collectors.toList());
        return sequence(cfs);
    });
}
Also used : BuiltinReferenceType(org.eclipse.milo.opcua.stack.core.BuiltinReferenceType) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) UaDataTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaDataTypeNode) LoggerFactory(org.slf4j.LoggerFactory) UaObjectTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Objects(java.util.Objects) UaVariableTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableTypeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Optional(java.util.Optional) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) CompletableFuture(java.util.concurrent.CompletableFuture) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) ArrayList(java.util.ArrayList) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Logger(org.slf4j.Logger) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) ObjectNodeConstructor(org.eclipse.milo.opcua.sdk.client.ObjectTypeManager.ObjectNodeConstructor) UaException(org.eclipse.milo.opcua.stack.core.UaException) Preconditions(com.google.common.base.Preconditions) UaReferenceTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaReferenceTypeNode) Collections(java.util.Collections) UaViewNode(org.eclipse.milo.opcua.sdk.client.nodes.UaViewNode) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) CompletableFuture(java.util.concurrent.CompletableFuture) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) List(java.util.List) ArrayList(java.util.ArrayList) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Example 3 with NodeClass

use of org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass in project milo by eclipse.

the class AddressSpace method newMethodNode.

private UaMethodNode newMethodNode(NodeId nodeId, List<DataValue> attributeValues) throws UaException {
    DataValue nodeIdDataValue = attributeValues.get(0);
    StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
    if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
        throw new UaException(nodeIdStatusCode);
    }
    try {
        NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
        Preconditions.checkArgument(nodeClass == NodeClass.Method, "expected NodeClass.Method, got NodeClass." + nodeClass);
        QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
        LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
        LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
        UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
        UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
        Boolean executable = (Boolean) attributeValues.get(7).getValue().getValue();
        Boolean userExecutable = (Boolean) attributeValues.get(8).getValue().getValue();
        return new UaMethodNode(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, executable, userExecutable);
    } catch (Throwable t) {
        throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
    }
}
Also used : NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Example 4 with NodeClass

use of org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass in project milo by eclipse.

the class AddressSpace method newReferenceTypeNode.

private UaReferenceTypeNode newReferenceTypeNode(NodeId nodeId, List<DataValue> attributeValues) throws UaException {
    DataValue nodeIdDataValue = attributeValues.get(0);
    StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
    if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
        throw new UaException(nodeIdStatusCode);
    }
    try {
        NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
        Preconditions.checkArgument(nodeClass == NodeClass.ReferenceType, "expected NodeClass.ReferenceType, got NodeClass." + nodeClass);
        QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
        LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
        LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
        UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
        UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
        Boolean isAbstract = (Boolean) attributeValues.get(7).getValue().getValue();
        Boolean symmetric = (Boolean) attributeValues.get(8).getValue().getValue();
        LocalizedText inverseName = getAttributeOrNull(attributeValues.get(9), LocalizedText.class);
        return new UaReferenceTypeNode(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, isAbstract, symmetric, inverseName);
    } catch (Throwable t) {
        throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
    }
}
Also used : NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaReferenceTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaReferenceTypeNode) UaException(org.eclipse.milo.opcua.stack.core.UaException) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Example 5 with NodeClass

use of org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass in project milo by eclipse.

the class AddressSpace method newObjectTypeNode.

private UaObjectTypeNode newObjectTypeNode(NodeId nodeId, List<DataValue> attributeValues) throws UaException {
    DataValue nodeIdDataValue = attributeValues.get(0);
    StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
    if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
        throw new UaException(nodeIdStatusCode);
    }
    try {
        NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
        Preconditions.checkArgument(nodeClass == NodeClass.ObjectType, "expected NodeClass.ObjectType, got NodeClass." + nodeClass);
        QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
        LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
        LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
        UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
        UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
        Boolean isAbstract = (Boolean) attributeValues.get(7).getValue().getValue();
        return new UaObjectTypeNode(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, isAbstract);
    } catch (Throwable t) {
        throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
    }
}
Also used : NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaObjectTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Aggregations

NodeClass (org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass)14 UaException (org.eclipse.milo.opcua.stack.core.UaException)13 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)13 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)13 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)12 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)10 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)10 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)6 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)4 UByte (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte)4 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)3 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 Consumer (java.util.function.Consumer)2