Search in sources :

Example 11 with NodeClass

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

the class AddressSpace method newObjectNode.

private UaObjectNode newObjectNode(NodeId nodeId, NodeId typeDefinitionId, 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.Object, "expected NodeClass.Object, 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);
        UByte eventNotifier = (UByte) attributeValues.get(7).getValue().getValue();
        ObjectNodeConstructor constructor = client.getObjectTypeManager().getNodeConstructor(typeDefinitionId).orElse(UaObjectNode::new);
        return constructor.apply(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, eventNotifier);
    } catch (Throwable t) {
        throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
    }
}
Also used : UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) 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) ObjectNodeConstructor(org.eclipse.milo.opcua.sdk.client.ObjectTypeManager.ObjectNodeConstructor) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Example 12 with NodeClass

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

the class AddressSpace method newDataTypeNode.

private UaDataTypeNode newDataTypeNode(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.DataType, "expected NodeClass.DataType, 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 UaDataTypeNode(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) 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) UaDataTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaDataTypeNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Example 13 with NodeClass

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

the class AttributeReader method readAttribute.

public static DataValue readAttribute(AttributeContext context, UaServerNode node, AttributeId attributeId, @Nullable TimestampsToReturn timestamps, @Nullable String indexRange, @Nullable QualifiedName encodingName) {
    try {
        AttributeContext internalContext = new AttributeContext(context.getServer());
        NodeClass nodeClass = node.getNodeClass();
        if (attributeId == AttributeId.Value && nodeClass == NodeClass.Variable) {
            Set<AccessLevel> accessLevels = getAccessLevels(node, internalContext);
            if (!accessLevels.contains(AccessLevel.CurrentRead)) {
                throw new UaException(StatusCodes.Bad_NotReadable);
            }
            Set<AccessLevel> userAccessLevels = getUserAccessLevels(node, context);
            if (!userAccessLevels.contains(AccessLevel.CurrentRead)) {
                throw new UaException(StatusCodes.Bad_UserAccessDenied);
            }
        }
        if (encodingName != null && encodingName.isNotNull()) {
            if (attributeId != AttributeId.Value) {
                throw new UaException(StatusCodes.Bad_DataEncodingInvalid);
            }
            NodeId dataTypeId;
            if (node instanceof VariableNode) {
                dataTypeId = ((VariableNode) node).getDataType();
            } else if (node instanceof VariableTypeNode) {
                dataTypeId = ((VariableTypeNode) node).getDataType();
            } else {
                throw new UaException(StatusCodes.Bad_DataEncodingInvalid);
            }
            boolean structured = isStructureSubtype(context.getServer(), dataTypeId);
            if (!structured) {
                throw new UaException(StatusCodes.Bad_DataEncodingInvalid);
            }
        }
        final DataValue.Builder dvb = node.getAttribute(context, attributeId).copy();
        // Maybe transcode the structure...
        if (dvb.value.isNotNull()) {
            final Object valueObject = dvb.value.getValue();
            Class<?> valueClazz = valueObject.getClass();
            if (valueClazz.isArray() && ArrayUtil.getType(valueObject) == ExtensionObject.class) {
                Object newValue = transformArray(valueObject, (ExtensionObject xo) -> transcode(context, node, xo, encodingName), ExtensionObject.class);
                dvb.setValue(new Variant(newValue));
            } else if (valueClazz == ExtensionObject.class) {
                ExtensionObject xo = (ExtensionObject) valueObject;
                Object newValue = transcode(context, node, xo, encodingName);
                dvb.setValue(new Variant(newValue));
            }
        }
        // Apply index range if provided...
        if (indexRange != null) {
            NumericRange range = NumericRange.parse(indexRange);
            Object valueAtRange = NumericRange.readFromValueAtRange(dvb.value, range);
            dvb.setValue(new Variant(valueAtRange));
        }
        // Add or remove timestamps based on TimestampsToReturn...
        if (timestamps != null) {
            dvb.applyTimestamps(attributeId, timestamps);
        }
        return dvb.build();
    } catch (UaException e) {
        return new DataValue(e.getStatusCode());
    }
}
Also used : AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode)

Example 14 with NodeClass

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

the class UaNode method readNodeClass.

/**
 * Read the NodeClass attribute for this Node from the server and update the local attribute if
 * the operation succeeds.
 *
 * @return the {@link NodeClass} read from the server.
 * @throws UaException if a service- or operation-level error occurs.
 */
public NodeClass readNodeClass() throws UaException {
    DataValue value = readAttribute(AttributeId.NodeClass);
    StatusCode statusCode = value.getStatusCode();
    if (statusCode != null && statusCode.isBad()) {
        throw new UaException(statusCode, "read NodeClass failed");
    } else {
        Integer i = (Integer) value.getValue().getValue();
        NodeClass nodeClass = NodeClass.from(i);
        setNodeClass(nodeClass);
        return nodeClass;
    }
}
Also used : UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

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