Skip to content

Commit 580bc5b

Browse files
committed
Fix minor inspections, move verbose static fields
1 parent b8316a1 commit 580bc5b

File tree

2 files changed

+100
-78
lines changed

2 files changed

+100
-78
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2025 the Eclipse Milo Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*/
10+
11+
package org.eclipse.milo.examples.server;
12+
13+
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte;
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+
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort;
17+
18+
import java.util.UUID;
19+
import org.eclipse.milo.opcua.stack.core.NodeIds;
20+
import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
21+
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
22+
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
23+
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
24+
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
25+
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
26+
import org.eclipse.milo.opcua.stack.core.types.builtin.XmlElement;
27+
28+
class ExampleData {
29+
30+
static final Object[][] STATIC_SCALAR_NODES =
31+
new Object[][] {
32+
{"Boolean", NodeIds.Boolean, Variant.ofBoolean(false)},
33+
{"Byte", NodeIds.Byte, Variant.ofByte(ubyte(0x00))},
34+
{"SByte", NodeIds.SByte, Variant.ofSByte((byte) 0x00)},
35+
{"Integer", NodeIds.Integer, Variant.ofInt32(32)},
36+
{"Int16", NodeIds.Int16, Variant.ofInt16((short) 16)},
37+
{"Int32", NodeIds.Int32, Variant.ofInt32(32)},
38+
{"Int64", NodeIds.Int64, Variant.ofInt64(64L)},
39+
{"UInteger", NodeIds.UInteger, Variant.ofUInt32(uint(32))},
40+
{"UInt16", NodeIds.UInt16, Variant.ofUInt16(ushort(16))},
41+
{"UInt32", NodeIds.UInt32, Variant.ofUInt32(uint(32))},
42+
{"UInt64", NodeIds.UInt64, Variant.ofUInt64(ulong(64L))},
43+
{"Float", NodeIds.Float, Variant.ofFloat(3.14f)},
44+
{"Double", NodeIds.Double, Variant.ofDouble(3.14d)},
45+
{"String", NodeIds.String, Variant.ofString("string value")},
46+
{"DateTime", NodeIds.DateTime, Variant.ofDateTime(DateTime.now())},
47+
{"Guid", NodeIds.Guid, Variant.ofGuid(UUID.randomUUID())},
48+
{
49+
"ByteString",
50+
NodeIds.ByteString,
51+
Variant.ofByteString(new ByteString(new byte[] {0x01, 0x02, 0x03, 0x04}))
52+
},
53+
{"XmlElement", NodeIds.XmlElement, Variant.ofXmlElement(new XmlElement("<a>hello</a>"))},
54+
{
55+
"LocalizedText",
56+
NodeIds.LocalizedText,
57+
Variant.ofLocalizedText(LocalizedText.english("localized text"))
58+
},
59+
{
60+
"QualifiedName",
61+
NodeIds.QualifiedName,
62+
Variant.ofQualifiedName(new QualifiedName(1234, "defg"))
63+
},
64+
{"NodeId", NodeIds.NodeId, Variant.ofNodeId(new NodeId(1234, "abcd"))},
65+
{"Variant", NodeIds.BaseDataType, Variant.ofInt32(32)},
66+
{"Duration", NodeIds.Duration, Variant.ofDouble(1.0)},
67+
{"UtcTime", NodeIds.UtcTime, Variant.ofDateTime(DateTime.now())},
68+
};
69+
70+
static final Object[][] STATIC_ARRAY_NODES =
71+
new Object[][] {
72+
{"BooleanArray", NodeIds.Boolean, false},
73+
{"ByteArray", NodeIds.Byte, ubyte(0)},
74+
{"SByteArray", NodeIds.SByte, (byte) 0x00},
75+
{"Int16Array", NodeIds.Int16, (short) 16},
76+
{"Int32Array", NodeIds.Int32, 32},
77+
{"Int64Array", NodeIds.Int64, 64L},
78+
{"UInt16Array", NodeIds.UInt16, ushort(16)},
79+
{"UInt32Array", NodeIds.UInt32, uint(32)},
80+
{"UInt64Array", NodeIds.UInt64, ulong(64L)},
81+
{"FloatArray", NodeIds.Float, 3.14f},
82+
{"DoubleArray", NodeIds.Double, 3.14d},
83+
{"StringArray", NodeIds.String, "string value"},
84+
{"DateTimeArray", NodeIds.DateTime, DateTime.now()},
85+
{"GuidArray", NodeIds.Guid, UUID.randomUUID()},
86+
{
87+
"ByteStringArray", NodeIds.ByteString, new ByteString(new byte[] {0x01, 0x02, 0x03, 0x04})
88+
},
89+
{"XmlElementArray", NodeIds.XmlElement, new XmlElement("<a>hello</a>")},
90+
{"LocalizedTextArray", NodeIds.LocalizedText, LocalizedText.english("localized text")},
91+
{"QualifiedNameArray", NodeIds.QualifiedName, new QualifiedName(1234, "defg")},
92+
{"NodeIdArray", NodeIds.NodeId, new NodeId(1234, "abcd")}
93+
};
94+
}

milo-examples/server-examples/src/main/java/org/eclipse/milo/examples/server/ExampleNamespace.java

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte;
1414
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;
1615
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort;
1716

1817
import java.lang.reflect.Array;
@@ -78,71 +77,6 @@ public class ExampleNamespace extends ManagedNamespaceWithLifecycle {
7877

7978
public static final String NAMESPACE_URI = "urn:eclipse:milo:hello-world";
8079

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-
14680
private final Logger logger = LoggerFactory.getLogger(getClass());
14781

14882
private volatile Thread eventThread;
@@ -323,7 +257,7 @@ private void addArrayNodes(UaFolderNode rootNode) {
323257
getNodeManager().addNode(arrayTypesFolder);
324258
rootNode.addOrganizes(arrayTypesFolder);
325259

326-
for (Object[] os : STATIC_ARRAY_NODES) {
260+
for (Object[] os : ExampleData.STATIC_ARRAY_NODES) {
327261
String name = (String) os[0];
328262
NodeId typeId = (NodeId) os[1];
329263
Object value = os[2];
@@ -372,7 +306,7 @@ private void addScalarNodes(UaFolderNode rootNode) {
372306
getNodeManager().addNode(scalarTypesFolder);
373307
rootNode.addOrganizes(scalarTypesFolder);
374308

375-
for (Object[] os : STATIC_SCALAR_NODES) {
309+
for (Object[] os : ExampleData.STATIC_SCALAR_NODES) {
376310
String name = (String) os[0];
377311
NodeId typeId = (NodeId) os[1];
378312
Variant variant = (Variant) os[2];
@@ -454,11 +388,8 @@ private void addAdminReadableNodes(UaFolderNode rootNode) {
454388
.addLast(
455389
new RestrictedAccessFilter(
456390
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")) {
462393
return AccessLevel.READ_WRITE;
463394
} else {
464395
return AccessLevel.NONE;
@@ -500,11 +431,8 @@ private void addAdminWritableNodes(UaFolderNode rootNode) {
500431
.addLast(
501432
new RestrictedAccessFilter(
502433
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")) {
508436
return AccessLevel.READ_WRITE;
509437
} else {
510438
return AccessLevel.NONE;

0 commit comments

Comments
 (0)