use of org.eclipse.milo.opcua.sdk.core.nodes.Node in project milo by eclipse.
the class AttributeReader method getEncodingId.
@Nullable
private static NodeId getEncodingId(AttributeContext context, UaServerNode node, QualifiedName encodingName) {
// TODO avoid dynamic lookup by registering codecs with their associated DataType and Encoding name
NodeId dataTypeId;
if (node instanceof VariableNode) {
dataTypeId = ((VariableNode) node).getDataType();
} else if (node instanceof VariableTypeNode) {
dataTypeId = ((VariableTypeNode) node).getDataType();
} else {
return null;
}
AddressSpaceManager addressSpaceManager = context.getServer().getAddressSpaceManager();
UaNode dataTypeNode = addressSpaceManager.getManagedNode(dataTypeId).orElse(null);
if (dataTypeNode != null) {
return dataTypeNode.getReferences().stream().filter(r -> r.isForward() && Identifiers.HasEncoding.equals(r.getReferenceTypeId())).flatMap(r -> opt2stream(addressSpaceManager.getManagedNode(r.getTargetNodeId()))).filter(n -> encodingName.equals(n.getBrowseName())).map(Node::getNodeId).findFirst().orElse(null);
} else {
return null;
}
}
use of org.eclipse.milo.opcua.sdk.core.nodes.Node in project milo by eclipse.
the class UaObjectNode method findMethodDeclarationId.
/**
* Find the NodeId of the MethodNode on the type definition with the same name as {@code methodName}.
*
* @param methodName the name of the MethodNode to search for.
* @return the NodeId of the MethodNode on the type definition with the same name as {@code methodName}. Will be
* {@link NodeId#NULL_VALUE} if not found.
*/
private NodeId findMethodDeclarationId(NodeId typeDefinitionId, QualifiedName methodName) {
AddressSpaceManager asm = getNodeContext().getServer().getAddressSpaceManager();
NamespaceTable namespaceTable = getNodeContext().getServer().getNamespaceTable();
NodeId nodeId = asm.getManagedReferences(typeDefinitionId).stream().filter(HAS_COMPONENT_PREDICATE.or(HAS_ORDERED_COMPONENT_PREDICATE)).flatMap(r -> opt2stream(getManagedNode(r.getTargetNodeId()))).filter(n -> (n instanceof UaMethodNode) && Objects.equals(n.getBrowseName(), methodName)).findFirst().map(Node::getNodeId).orElse(NodeId.NULL_VALUE);
if (nodeId.isNull()) {
NodeId parentTypeId = asm.getManagedReferences(typeDefinitionId).stream().filter(Reference.SUBTYPE_OF).flatMap(r -> opt2stream(r.getTargetNodeId().toNodeId(namespaceTable))).findFirst().orElse(null);
if (parentTypeId != null) {
return findMethodDeclarationId(parentTypeId, methodName);
} else {
return nodeId;
}
} else {
return nodeId;
}
}
use of org.eclipse.milo.opcua.sdk.core.nodes.Node in project milo by eclipse.
the class UaMethodNode method getModellingRuleNode.
public Optional<ObjectNode> getModellingRuleNode() {
Node node = getReferences().stream().filter(HAS_MODELLING_RULE_PREDICATE).findFirst().flatMap(r -> getManagedNode(r.getTargetNodeId())).orElse(null);
ObjectNode objectNode = (node instanceof ObjectNode) ? (ObjectNode) node : null;
return Optional.ofNullable(objectNode);
}
use of org.eclipse.milo.opcua.sdk.core.nodes.Node in project milo by eclipse.
the class UaVariableNode method getModellingRuleNode.
public Optional<ObjectNode> getModellingRuleNode() {
Node node = getReferences().stream().filter(HAS_MODELLING_RULE_PREDICATE).findFirst().flatMap(r -> getManagedNode(r.getTargetNodeId())).orElse(null);
ObjectNode objectNode = (node instanceof ObjectNode) ? (ObjectNode) node : null;
return Optional.ofNullable(objectNode);
}
use of org.eclipse.milo.opcua.sdk.core.nodes.Node in project milo by eclipse.
the class UaNode method getComponentAsync.
protected CompletableFuture<? extends UaNode> getComponentAsync(QualifiedName browseName, NodeClass nodeClass) {
UInteger nodeClassMask = uint(nodeClass.getValue());
UInteger resultMask = uint(BrowseResultMask.All.getValue());
CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasComponent, false, nodeClassMask, resultMask));
return future.thenCompose(result -> {
List<ReferenceDescription> references = l(result.getReferences());
Optional<CompletableFuture<? extends UaNode>> node = references.stream().filter(r -> browseName.equals(r.getBrowseName())).flatMap(r -> {
Optional<CompletableFuture<? extends UaNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id));
return opt2stream(opt);
}).findFirst();
return node.orElse(failedUaFuture(StatusCodes.Bad_NotFound));
});
}
Aggregations