use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.
the class ManagedAddressSpace method getInvocationHandler.
/**
* Get the {@link MethodInvocationHandler} for the method identified by {@code methodId}, if it exists.
*
* @param objectId the {@link NodeId} identifying the object the method will be invoked on.
* @param methodId the {@link NodeId} identifying the method.
* @return the {@link MethodInvocationHandler} for {@code methodId}, if it exists.
*/
protected Optional<MethodInvocationHandler> getInvocationHandler(NodeId objectId, NodeId methodId) {
return nodeManager.getNode(objectId).flatMap(node -> {
UaMethodNode methodNode = null;
if (node instanceof UaObjectNode) {
UaObjectNode objectNode = (UaObjectNode) node;
methodNode = objectNode.findMethodNode(methodId);
} else if (node instanceof UaObjectTypeNode) {
UaObjectTypeNode objectTypeNode = (UaObjectTypeNode) node;
methodNode = objectTypeNode.findMethodNode(methodId);
}
if (methodNode != null) {
return Optional.of(methodNode.getInvocationHandler());
} else {
return Optional.empty();
}
});
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.
the class NodeFactory method createNodeTree.
public Tree<UaNode> createNodeTree(NodeId rootNodeId, NodeId typeDefinitionId, InstantiationCallback instantiationCallback) throws UaException {
AddressSpaceManager addressSpaceManager = context.getServer().getAddressSpaceManager();
if (!addressSpaceManager.getManagedNode(typeDefinitionId).isPresent()) {
throw new UaException(StatusCodes.Bad_NodeIdUnknown, "unknown type definition: " + typeDefinitionId);
}
NamespaceTable namespaceTable = context.getServer().getNamespaceTable();
InstanceDeclarationHierarchy idh;
try {
idh = IDH_CACHE.get(typeDefinitionId, () -> {
LoggerFactory.getLogger(NodeFactory.class).debug("InstanceDeclarationHierarchy cache " + "miss for typeDefinitionId={}", typeDefinitionId);
return InstanceDeclarationHierarchy.create(addressSpaceManager, namespaceTable, typeDefinitionId);
});
} catch (ExecutionException e) {
throw new UaException(StatusCodes.Bad_InternalError, e);
}
NodeTable nodeTable = idh.getNodeTable();
ReferenceTable referenceTable = idh.getReferenceTable();
Map<BrowsePath, UaNode> nodes = new HashMap<>();
for (Map.Entry<BrowsePath, NodeId> entry : nodeTable.nodes.entrySet()) {
BrowsePath browsePath = entry.getKey();
NodeId nodeId = entry.getValue();
UaNode node = addressSpaceManager.getManagedNode(nodeId).orElse(null);
if (browsePath.parent == null) {
if (node instanceof UaObjectTypeNode) {
UaNode instance = instanceFromTypeDefinition(rootNodeId, (UaObjectTypeNode) node);
nodes.put(browsePath, instance);
} else if (node instanceof UaVariableTypeNode) {
UaNode instance = instanceFromTypeDefinition(rootNodeId, (UaVariableTypeNode) node);
nodes.put(browsePath, instance);
} else {
throw new UaException(StatusCodes.Bad_InternalError);
}
} else {
// Non-root Nodes are all instance declarations
NodeId instanceNodeId = instanceNodeId(rootNodeId, browsePath);
if (node instanceof UaMethodNode) {
UaMethodNode declaration = (UaMethodNode) node;
UaMethodNode instance = new UaMethodNode(context, instanceNodeId, declaration.getBrowseName(), declaration.getDisplayName(), declaration.getDescription(), declaration.getWriteMask(), declaration.getUserWriteMask(), declaration.isExecutable(), declaration.isUserExecutable());
nodes.put(browsePath, instance);
} else if (node instanceof UaObjectNode) {
UaObjectNode declaration = (UaObjectNode) node;
ExpandedNodeId instanceTypeDefinitionId = getTypeDefinition(referenceTable, browsePath);
UaNode typeDefinitionNode = addressSpaceManager.getManagedNode(instanceTypeDefinitionId).orElse(null);
if (typeDefinitionNode instanceof ObjectTypeNode) {
boolean optional = isOptionalDeclaration(declaration);
if (!optional || instantiationCallback.includeOptionalNode(typeDefinitionNode.getNodeId(), declaration.getBrowseName())) {
UaObjectNode instance = instanceFromTypeDefinition(instanceNodeId, (ObjectTypeNode) typeDefinitionNode);
instance.setBrowseName(declaration.getBrowseName());
instance.setDisplayName(declaration.getDisplayName());
instance.setDescription(declaration.getDescription());
instance.setWriteMask(declaration.getWriteMask());
instance.setUserWriteMask(declaration.getUserWriteMask());
instance.setEventNotifier(declaration.getEventNotifier());
nodes.put(browsePath, instance);
}
} else {
throw new UaException(StatusCodes.Bad_InternalError, "expected type definition for " + instanceTypeDefinitionId);
}
} else if (node instanceof UaVariableNode) {
UaVariableNode declaration = (UaVariableNode) node;
ExpandedNodeId instanceTypeDefinitionId = getTypeDefinition(referenceTable, browsePath);
UaNode typeDefinitionNode = addressSpaceManager.getManagedNode(instanceTypeDefinitionId).orElse(null);
if (typeDefinitionNode instanceof VariableTypeNode) {
boolean optional = isOptionalDeclaration(declaration);
if (!optional || instantiationCallback.includeOptionalNode(typeDefinitionNode.getNodeId(), declaration.getBrowseName())) {
UaVariableNode instance = instanceFromTypeDefinition(instanceNodeId, (VariableTypeNode) typeDefinitionNode);
instance.setBrowseName(declaration.getBrowseName());
instance.setDisplayName(declaration.getDisplayName());
instance.setDescription(declaration.getDescription());
instance.setWriteMask(declaration.getWriteMask());
instance.setUserWriteMask(declaration.getUserWriteMask());
instance.setValue(declaration.getValue());
instance.setDataType(declaration.getDataType());
instance.setValueRank(declaration.getValueRank());
instance.setArrayDimensions(declaration.getArrayDimensions());
instance.setAccessLevel(declaration.getAccessLevel());
instance.setUserAccessLevel(declaration.getUserAccessLevel());
nodes.put(browsePath, instance);
}
} else {
throw new UaException(StatusCodes.Bad_InternalError, "expected type definition for " + instanceTypeDefinitionId);
}
} else {
throw new UaException(StatusCodes.Bad_InternalError, "not an instance declaration: " + node);
}
}
}
nodes.forEach((browsePath, node) -> {
List<ReferenceTable.RefRow> references = referenceTable.getReferences(browsePath);
references.forEach(t -> {
NodeId referenceTypeId = t.nodeId;
ReferenceTable.RefTarget target = t.target;
if (!Identifiers.HasModellingRule.equals(referenceTypeId)) {
if (target.targetNodeId != null) {
node.addReference(new Reference(node.getNodeId(), referenceTypeId, target.targetNodeId, true));
} else {
BrowsePath targetPath = target.targetPath;
UaNode targetNode = nodes.get(targetPath);
if (targetNode != null) {
node.addReference(new Reference(node.getNodeId(), referenceTypeId, targetNode.getNodeId().expanded(), true));
}
}
}
});
context.getNodeManager().addNode(node);
});
Tree<UaNode> nodeTree = nodeTable.getBrowsePathTree().map(nodes::get);
notifyInstantiationCallback(nodeTree, instantiationCallback);
return nodeTree;
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.
the class VendorServerInfoNodes method addVendorServerInfoNodes.
private static void addVendorServerInfoNodes(UaNodeContext context) {
Optional<UaNode> maybeVendorServerInfo = context.getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server_VendorServerInfo);
maybeVendorServerInfo.ifPresent(node -> {
UaObjectNode vendorServerInfo = (UaObjectNode) node;
// standard Java API
addVendorInfoPlainJava(context, vendorServerInfo);
// JMX API
addVendorInfoJmx(context, vendorServerInfo);
// com.sun API
addVendorInfoSunJmx(context, vendorServerInfo);
});
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.
the class NodeFactory method notifyInstantiationCallback.
protected void notifyInstantiationCallback(Tree<UaNode> nodeTree, InstantiationCallback instantiationCallback) {
nodeTree.traverseWithParent((node, parentNode) -> {
if (parentNode instanceof UaObjectNode && node instanceof UaMethodNode) {
UaMethodNode methodNode = (UaMethodNode) node;
instantiationCallback.onMethodAdded((UaObjectNode) parentNode, methodNode);
} else if (node instanceof UaObjectNode) {
UaObjectNode objectNode = (UaObjectNode) node;
ObjectTypeNode objectTypeNode = objectNode.getTypeDefinitionNode();
instantiationCallback.onObjectAdded(parentNode, objectNode, objectTypeNode.getNodeId());
} else if (node instanceof UaVariableNode) {
UaVariableNode variableNode = (UaVariableNode) node;
VariableTypeNode variableTypeNode = variableNode.getTypeDefinitionNode();
instantiationCallback.onVariableAdded(parentNode, variableNode, variableTypeNode.getNodeId());
}
});
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.
the class NodeFactory method instanceFromTypeDefinition.
protected UaObjectNode instanceFromTypeDefinition(NodeId nodeId, ObjectTypeNode typeDefinitionNode) {
NodeId typeDefinitionId = typeDefinitionNode.getNodeId();
// Use a specialized instance if one is registered, otherwise fallback to UaObjectNode.
ObjectTypeManager.ObjectNodeConstructor ctor = objectTypeManager.getNodeFactory(typeDefinitionId).orElse(UaObjectNode::new);
return ctor.apply(context, nodeId, typeDefinitionNode.getBrowseName(), typeDefinitionNode.getDisplayName(), typeDefinitionNode.getDescription(), typeDefinitionNode.getWriteMask(), typeDefinitionNode.getUserWriteMask());
}
Aggregations