use of org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager in project milo by eclipse.
the class InstanceDeclarationHierarchyTest method test.
@Test
public void test() throws Exception {
NamespaceTable namespaceTable = new NamespaceTable();
UaNodeManager nodeManager = new UaNodeManager();
AddressSpaceManager addressSpaceManager = Mockito.mock(AddressSpaceManager.class);
Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(NodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0)));
Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(ExpandedNodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0), namespaceTable));
Mockito.when(addressSpaceManager.getManagedReferences(Mockito.any(NodeId.class))).then((Answer<List<Reference>>) invocationOnMock -> nodeManager.getReferences(invocationOnMock.getArgument(0)));
OpcUaServer server = Mockito.mock(OpcUaServer.class);
Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
UaNodeContext context = new UaNodeContext() {
@Override
public OpcUaServer getServer() {
return server;
}
@Override
public NodeManager<UaNode> getNodeManager() {
return nodeManager;
}
};
new NodeLoader(context, nodeManager).loadNodes();
InstanceDeclarationHierarchy idh = InstanceDeclarationHierarchy.create(addressSpaceManager, namespaceTable, Identifiers.AnalogItemType);
System.out.println(idh);
assertNotNull(idh);
}
use of org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager in project milo by eclipse.
the class UaNodeTest method setup.
@BeforeTest
public void setup() throws Exception {
server = Mockito.mock(OpcUaServer.class);
AddressSpaceManager addressSpaceManager = new AddressSpaceManager(server);
NamespaceTable namespaceTable = new NamespaceTable();
ObjectTypeManager objectTypeManager = new ObjectTypeManager();
VariableTypeManager variableTypeManager = new VariableTypeManager();
Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
Mockito.when(server.getObjectTypeManager()).thenReturn(objectTypeManager);
Mockito.when(server.getVariableTypeManager()).thenReturn(variableTypeManager);
UaNodeManager nodeManager = new UaNodeManager();
addressSpaceManager.register(nodeManager);
UaNodeContext nodeContext = new UaNodeContext() {
@Override
public OpcUaServer getServer() {
return server;
}
@Override
public NodeManager<UaNode> getNodeManager() {
return nodeManager;
}
};
new NodeLoader(nodeContext, nodeManager).loadNodes();
ObjectTypeInitializer.initialize(server.getNamespaceTable(), objectTypeManager);
VariableTypeInitializer.initialize(server.getNamespaceTable(), variableTypeManager);
}
use of org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager 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.server.api.AddressSpaceManager in project milo by eclipse.
the class NodeFactoryTest method setup.
@BeforeTest
public void setup() throws Exception {
server = Mockito.mock(OpcUaServer.class);
NamespaceTable namespaceTable = new NamespaceTable();
Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
nodeManager = new UaNodeManager();
AddressSpaceManager addressSpaceManager = Mockito.mock(AddressSpaceManager.class);
Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(NodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0)));
Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(ExpandedNodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0), namespaceTable));
Mockito.when(addressSpaceManager.getManagedReferences(Mockito.any(NodeId.class))).then((Answer<List<Reference>>) invocationOnMock -> nodeManager.getReferences(invocationOnMock.getArgument(0)));
Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
UaNodeContext context = new UaNodeContext() {
@Override
public OpcUaServer getServer() {
return server;
}
@Override
public NodeManager<UaNode> getNodeManager() {
return nodeManager;
}
};
new NodeLoader(context, nodeManager).loadNodes();
ObjectTypeManager objectTypeManager = new ObjectTypeManager();
ObjectTypeInitializer.initialize(server.getNamespaceTable(), objectTypeManager);
VariableTypeManager variableTypeManager = new VariableTypeManager();
VariableTypeInitializer.initialize(server.getNamespaceTable(), variableTypeManager);
nodeFactory = new NodeFactory(context, objectTypeManager, variableTypeManager);
}
use of org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager 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;
}
}
Aggregations