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