|
12 | 12 |
|
13 | 13 | import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte; |
14 | 14 | import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint; |
15 | | -import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ulong; |
16 | 15 | import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort; |
17 | 16 |
|
18 | 17 | import java.lang.reflect.Array; |
@@ -78,71 +77,6 @@ public class ExampleNamespace extends ManagedNamespaceWithLifecycle { |
78 | 77 |
|
79 | 78 | public static final String NAMESPACE_URI = "urn:eclipse:milo:hello-world"; |
80 | 79 |
|
81 | | - private static final Object[][] STATIC_SCALAR_NODES = |
82 | | - new Object[][] { |
83 | | - {"Boolean", NodeIds.Boolean, Variant.ofBoolean(false)}, |
84 | | - {"Byte", NodeIds.Byte, Variant.ofByte(ubyte(0x00))}, |
85 | | - {"SByte", NodeIds.SByte, Variant.ofSByte((byte) 0x00)}, |
86 | | - {"Integer", NodeIds.Integer, Variant.ofInt32(32)}, |
87 | | - {"Int16", NodeIds.Int16, Variant.ofInt16((short) 16)}, |
88 | | - {"Int32", NodeIds.Int32, Variant.ofInt32(32)}, |
89 | | - {"Int64", NodeIds.Int64, Variant.ofInt64(64L)}, |
90 | | - {"UInteger", NodeIds.UInteger, Variant.ofUInt32(uint(32))}, |
91 | | - {"UInt16", NodeIds.UInt16, Variant.ofUInt16(ushort(16))}, |
92 | | - {"UInt32", NodeIds.UInt32, Variant.ofUInt32(uint(32))}, |
93 | | - {"UInt64", NodeIds.UInt64, Variant.ofUInt64(ulong(64L))}, |
94 | | - {"Float", NodeIds.Float, Variant.ofFloat(3.14f)}, |
95 | | - {"Double", NodeIds.Double, Variant.ofDouble(3.14d)}, |
96 | | - {"String", NodeIds.String, Variant.ofString("string value")}, |
97 | | - {"DateTime", NodeIds.DateTime, Variant.ofDateTime(DateTime.now())}, |
98 | | - {"Guid", NodeIds.Guid, Variant.ofGuid(UUID.randomUUID())}, |
99 | | - { |
100 | | - "ByteString", |
101 | | - NodeIds.ByteString, |
102 | | - Variant.ofByteString(new ByteString(new byte[] {0x01, 0x02, 0x03, 0x04})) |
103 | | - }, |
104 | | - {"XmlElement", NodeIds.XmlElement, Variant.ofXmlElement(new XmlElement("<a>hello</a>"))}, |
105 | | - { |
106 | | - "LocalizedText", |
107 | | - NodeIds.LocalizedText, |
108 | | - Variant.ofLocalizedText(LocalizedText.english("localized text")) |
109 | | - }, |
110 | | - { |
111 | | - "QualifiedName", |
112 | | - NodeIds.QualifiedName, |
113 | | - Variant.ofQualifiedName(new QualifiedName(1234, "defg")) |
114 | | - }, |
115 | | - {"NodeId", NodeIds.NodeId, Variant.ofNodeId(new NodeId(1234, "abcd"))}, |
116 | | - {"Variant", NodeIds.BaseDataType, Variant.ofInt32(32)}, |
117 | | - {"Duration", NodeIds.Duration, Variant.ofDouble(1.0)}, |
118 | | - {"UtcTime", NodeIds.UtcTime, Variant.ofDateTime(DateTime.now())}, |
119 | | - }; |
120 | | - |
121 | | - private static final Object[][] STATIC_ARRAY_NODES = |
122 | | - new Object[][] { |
123 | | - {"BooleanArray", NodeIds.Boolean, false}, |
124 | | - {"ByteArray", NodeIds.Byte, ubyte(0)}, |
125 | | - {"SByteArray", NodeIds.SByte, (byte) 0x00}, |
126 | | - {"Int16Array", NodeIds.Int16, (short) 16}, |
127 | | - {"Int32Array", NodeIds.Int32, 32}, |
128 | | - {"Int64Array", NodeIds.Int64, 64L}, |
129 | | - {"UInt16Array", NodeIds.UInt16, ushort(16)}, |
130 | | - {"UInt32Array", NodeIds.UInt32, uint(32)}, |
131 | | - {"UInt64Array", NodeIds.UInt64, ulong(64L)}, |
132 | | - {"FloatArray", NodeIds.Float, 3.14f}, |
133 | | - {"DoubleArray", NodeIds.Double, 3.14d}, |
134 | | - {"StringArray", NodeIds.String, "string value"}, |
135 | | - {"DateTimeArray", NodeIds.DateTime, DateTime.now()}, |
136 | | - {"GuidArray", NodeIds.Guid, UUID.randomUUID()}, |
137 | | - { |
138 | | - "ByteStringArray", NodeIds.ByteString, new ByteString(new byte[] {0x01, 0x02, 0x03, 0x04}) |
139 | | - }, |
140 | | - {"XmlElementArray", NodeIds.XmlElement, new XmlElement("<a>hello</a>")}, |
141 | | - {"LocalizedTextArray", NodeIds.LocalizedText, LocalizedText.english("localized text")}, |
142 | | - {"QualifiedNameArray", NodeIds.QualifiedName, new QualifiedName(1234, "defg")}, |
143 | | - {"NodeIdArray", NodeIds.NodeId, new NodeId(1234, "abcd")} |
144 | | - }; |
145 | | - |
146 | 80 | private final Logger logger = LoggerFactory.getLogger(getClass()); |
147 | 81 |
|
148 | 82 | private volatile Thread eventThread; |
@@ -323,7 +257,7 @@ private void addArrayNodes(UaFolderNode rootNode) { |
323 | 257 | getNodeManager().addNode(arrayTypesFolder); |
324 | 258 | rootNode.addOrganizes(arrayTypesFolder); |
325 | 259 |
|
326 | | - for (Object[] os : STATIC_ARRAY_NODES) { |
| 260 | + for (Object[] os : ExampleData.STATIC_ARRAY_NODES) { |
327 | 261 | String name = (String) os[0]; |
328 | 262 | NodeId typeId = (NodeId) os[1]; |
329 | 263 | Object value = os[2]; |
@@ -372,7 +306,7 @@ private void addScalarNodes(UaFolderNode rootNode) { |
372 | 306 | getNodeManager().addNode(scalarTypesFolder); |
373 | 307 | rootNode.addOrganizes(scalarTypesFolder); |
374 | 308 |
|
375 | | - for (Object[] os : STATIC_SCALAR_NODES) { |
| 309 | + for (Object[] os : ExampleData.STATIC_SCALAR_NODES) { |
376 | 310 | String name = (String) os[0]; |
377 | 311 | NodeId typeId = (NodeId) os[1]; |
378 | 312 | Variant variant = (Variant) os[2]; |
@@ -454,11 +388,8 @@ private void addAdminReadableNodes(UaFolderNode rootNode) { |
454 | 388 | .addLast( |
455 | 389 | new RestrictedAccessFilter( |
456 | 390 | identity -> { |
457 | | - if (identity instanceof Identity.UsernameIdentity) { |
458 | | - Identity.UsernameIdentity usernameIdentity = |
459 | | - (Identity.UsernameIdentity) identity; |
460 | | - |
461 | | - if (usernameIdentity.getUsername().equals("admin")) { |
| 391 | + if (identity instanceof Identity.UsernameIdentity ui) { |
| 392 | + if (ui.getUsername().equals("admin")) { |
462 | 393 | return AccessLevel.READ_WRITE; |
463 | 394 | } else { |
464 | 395 | return AccessLevel.NONE; |
@@ -500,11 +431,8 @@ private void addAdminWritableNodes(UaFolderNode rootNode) { |
500 | 431 | .addLast( |
501 | 432 | new RestrictedAccessFilter( |
502 | 433 | identity -> { |
503 | | - if (identity instanceof Identity.UsernameIdentity) { |
504 | | - Identity.UsernameIdentity usernameIdentity = |
505 | | - (Identity.UsernameIdentity) identity; |
506 | | - |
507 | | - if (usernameIdentity.getUsername().equals("admin")) { |
| 434 | + if (identity instanceof Identity.UsernameIdentity ui) { |
| 435 | + if (ui.getUsername().equals("admin")) { |
508 | 436 | return AccessLevel.READ_WRITE; |
509 | 437 | } else { |
510 | 438 | return AccessLevel.NONE; |
|
0 commit comments