1 package de.dlr.bt.stc.opcuaserver;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.eclipse.milo.opcua.sdk.server.nodes.UaNode;
10 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
11
12 import de.dlr.bt.stc.opcuaserver.STCNamespace.Folders;
13
14 public abstract class ANodeCreator implements INodeCreator {
15 private final List<String> basePath;
16 protected final STCNamespace namespace;
17
18 protected static final NodeId NULLNODEID = new NodeId(0, 0);
19
20 protected ANodeCreator(STCNamespace namespace, List<String> basePath) {
21 this.basePath = basePath;
22 this.namespace = namespace;
23 }
24
25 protected ANodeCreator(STCNamespace namespace, String firstPathElement, String... basePath) {
26 this.basePath = new ArrayList<>();
27 this.basePath.add(firstPathElement);
28 this.basePath.addAll(Arrays.asList(basePath));
29 this.namespace = namespace;
30 }
31
32 protected String[] nodePathInst(String... name) {
33 ArrayList<String> res = new ArrayList<>();
34 res.addAll(basePath);
35 res.addAll(Arrays.asList(name));
36
37 return res.toArray(String[]::new);
38 }
39
40 protected String[] nodePathType(String... name) {
41 ArrayList<String> res = new ArrayList<>();
42 res.addAll(basePath);
43 res.add("type");
44 res.addAll(Arrays.asList(name));
45
46 return res.toArray(String[]::new);
47 }
48
49 private final Map<Object, UaNode> rootNodes = new HashMap<>();
50
51 @Override
52 public void removeInstance(Object forNode, Folders folders) {
53 var rootNode = rootNodes.get(forNode);
54 if (rootNode != null) {
55 namespace.removeObjectNode(rootNode);
56 rootNodes.remove(forNode);
57 }
58 }
59
60 protected void addRootNode(Object forNode, UaNode rootNode) {
61 rootNodes.put(forNode, rootNode);
62 }
63 }