Search in sources :

Example 1 with AddressSpaceManager

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);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Optional(java.util.Optional) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Optional(java.util.Optional) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) List(java.util.List) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Test(org.testng.annotations.Test)

Example 2 with AddressSpaceManager

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);
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with AddressSpaceManager

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;
    }
}
Also used : DataTypeEncoding(org.eclipse.milo.opcua.stack.core.types.DataTypeEncoding) OpcUaDefaultBinaryEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultBinaryEncoding) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) AttributeUtil.getAccessLevels(org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getAccessLevels) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) OpcUaDefaultXmlEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultXmlEncoding) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ArrayUtil(org.eclipse.milo.opcua.stack.core.util.ArrayUtil) Set(java.util.Set) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Nullable(org.jetbrains.annotations.Nullable) AttributeUtil.getUserAccessLevels(org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getUserAccessLevels) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) ArrayUtil.transformArray(org.eclipse.milo.opcua.stack.core.util.ArrayUtil.transformArray) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AddressSpaceManager

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);
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test) ObjectTypeInitializer(org.eclipse.milo.opcua.sdk.server.model.ObjectTypeInitializer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Answer(org.mockito.stubbing.Answer) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) BeforeTest(org.testng.annotations.BeforeTest) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) VariableTypeInitializer(org.eclipse.milo.opcua.sdk.server.model.VariableTypeInitializer) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Nullable(org.jetbrains.annotations.Nullable) Mockito(org.mockito.Mockito) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Optional(java.util.Optional) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Assert.assertTrue(org.testng.Assert.assertTrue) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) AnalogItemTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Optional(java.util.Optional) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) List(java.util.List) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with AddressSpaceManager

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;
    }
}
Also used : HAS_EVENT_SOURCE_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_EVENT_SOURCE_PREDICATE) ORGANIZES_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.ORGANIZES_PREDICATE) ObjectNode(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNode) NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) AttributeFilterChain(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilterChain) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) ObjectNodeProperties(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNodeProperties) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) AttributeFilter(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilter) HAS_NOTIFIER_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_NOTIFIER_PREDICATE) HAS_TYPE_DEFINITION_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_TYPE_DEFINITION_PREDICATE) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) HAS_COMPONENT_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_COMPONENT_PREDICATE) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) Collectors(java.util.stream.Collectors) Unsigned.ubyte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte) NamingRuleType(org.eclipse.milo.opcua.stack.core.types.enumerated.NamingRuleType) HAS_ORDERED_COMPONENT_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_ORDERED_COMPONENT_PREDICATE) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) HAS_PROPERTY_PREDICATE(org.eclipse.milo.opcua.sdk.core.Reference.HAS_PROPERTY_PREDICATE) ObjectTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.ObjectTypeNode) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Preconditions(com.google.common.base.Preconditions) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)

Aggregations

AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)7 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)6 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)5 Reference (org.eclipse.milo.opcua.sdk.core.Reference)4 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)4 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)4 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)4 List (java.util.List)3 Optional (java.util.Optional)3 UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)3 NodeManager (org.eclipse.milo.opcua.sdk.server.api.NodeManager)3 NodeLoader (org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader)3 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)3 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)3 Nullable (org.jetbrains.annotations.Nullable)3 Node (org.eclipse.milo.opcua.sdk.core.nodes.Node)2 ObjectTypeNode (org.eclipse.milo.opcua.sdk.core.nodes.ObjectTypeNode)2 VariableTypeNode (org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode)2 StreamUtil.opt2stream (org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream)2 ObjectTypeManager (org.eclipse.milo.opcua.sdk.server.ObjectTypeManager)2