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));
}
}
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));
}
}
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());
}
}
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;
}
}
Aggregations