diff --git a/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample1.java b/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample1.java index 3e81a4994..e9501d179 100644 --- a/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample1.java +++ b/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 the Eclipse Milo Authors + * Copyright (c) 2025 the Eclipse Milo Authors * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -18,9 +18,10 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.eclipse.milo.opcua.sdk.client.OpcUaClient; -import org.eclipse.milo.opcua.sdk.core.types.DynamicEnum; -import org.eclipse.milo.opcua.sdk.core.types.DynamicOptionSet; -import org.eclipse.milo.opcua.sdk.core.types.DynamicStruct; +import org.eclipse.milo.opcua.sdk.core.types.DynamicEnumType; +import org.eclipse.milo.opcua.sdk.core.types.DynamicOptionSetType; +import org.eclipse.milo.opcua.sdk.core.types.DynamicStructType; +import org.eclipse.milo.opcua.sdk.core.types.DynamicType; import org.eclipse.milo.opcua.stack.core.encoding.EncodingContext; import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy; import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString; @@ -64,25 +65,25 @@ public void run(OpcUaClient client, CompletableFuture future) throw private void readWriteReadPerson(OpcUaClient client) throws Exception { NodeId nodeId = NodeId.parse("ns=3;s=Person1"); - DynamicStruct value = readScalarValue(client, nodeId); + DynamicStructType value = (DynamicStructType) readScalarValue(client, nodeId); logger.info("Person1: {}", value); Random r = new Random(); - DynamicEnum gender = (DynamicEnum) value.getMembers().get("Gender"); + DynamicEnumType gender = (DynamicEnumType) value.getMembers().get("Gender"); value.getMembers().put("Name", "Fat Boy" + r.nextInt(100)); - value.getMembers().put("Gender", new DynamicEnum(gender.getDataType(), r.nextInt(2))); + value.getMembers().put("Gender", new DynamicEnumType(gender.getDataType(), r.nextInt(2))); StatusCode status = writeValue(client, nodeId, value); System.out.println("write status: " + status); - value = readScalarValue(client, nodeId); + value = (DynamicStructType) readScalarValue(client, nodeId); logger.info("Person1': {}", value); } private void readWriteReadWorkOrder(OpcUaClient client) throws Exception { NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Scalar.WorkOrder"); - DynamicStruct value = readScalarValue(client, nodeId); + DynamicStructType value = (DynamicStructType) readScalarValue(client, nodeId); logger.info("WorkOrder: {}", value); value.getMembers().put("ID", UUID.randomUUID()); @@ -90,14 +91,14 @@ private void readWriteReadWorkOrder(OpcUaClient client) throws Exception { StatusCode status = writeValue(client, nodeId, value); System.out.println("write status: " + status); - value = readScalarValue(client, nodeId); + value = (DynamicStructType) readScalarValue(client, nodeId); logger.info("WorkOrder': {}", value); } private void readWriteCarExtras(OpcUaClient client) throws Exception { NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Scalar.CarExtras"); - DynamicOptionSet value = (DynamicOptionSet) readScalarValue(client, nodeId); + DynamicOptionSetType value = (DynamicOptionSetType) readScalarValue(client, nodeId); logger.info("CarExtras: {}", value); byte b = requireNonNull(value.getValue().bytes())[0]; @@ -106,14 +107,14 @@ private void readWriteCarExtras(OpcUaClient client) throws Exception { StatusCode status = writeValue(client, nodeId, value); System.out.println("write status: " + status); - value = (DynamicOptionSet) readScalarValue(client, nodeId); + value = (DynamicOptionSetType) readScalarValue(client, nodeId); logger.info("CarExtras': {}", value); } private void readWorkOrderArray(OpcUaClient client) throws Exception { NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Arrays.WorkOrder"); - DynamicStruct[] value = readArrayValue(client, nodeId); + DynamicType[] value = readArrayValue(client, nodeId); logger.info("WorkOrderArray:"); for (int i = 0; i < value.length; i++) { @@ -121,18 +122,17 @@ private void readWorkOrderArray(OpcUaClient client) throws Exception { } } - private static DynamicStruct readScalarValue(OpcUaClient client, NodeId nodeId) throws Exception { + private static DynamicType readScalarValue(OpcUaClient client, NodeId nodeId) throws Exception { DataValue dataValue = client.readValues(0.0, TimestampsToReturn.Neither, List.of(nodeId)).get(0); ExtensionObject xo = (ExtensionObject) dataValue.getValue().getValue(); assert xo != null; - return (DynamicStruct) xo.decode(client.getDynamicEncodingContext()); + return (DynamicType) xo.decode(client.getDynamicEncodingContext()); } - private static DynamicStruct[] readArrayValue(OpcUaClient client, NodeId nodeId) - throws Exception { + private static DynamicType[] readArrayValue(OpcUaClient client, NodeId nodeId) throws Exception { DataValue dataValue = client.readValues(0.0, TimestampsToReturn.Neither, List.of(nodeId)).get(0); @@ -141,13 +141,12 @@ private static DynamicStruct[] readArrayValue(OpcUaClient client, NodeId nodeId) EncodingContext ctx = client.getDynamicEncodingContext(); - return Arrays.stream(xos) - .map(xo -> (DynamicStruct) xo.decode(ctx)) - .toArray(DynamicStruct[]::new); + return Arrays.stream(xos).map(xo -> (DynamicType) xo.decode(ctx)).toArray(DynamicType[]::new); } - private static StatusCode writeValue(OpcUaClient client, NodeId nodeId, DynamicStruct value) + private static StatusCode writeValue(OpcUaClient client, NodeId nodeId, DynamicType value) throws Exception { + ExtensionObject xo = ExtensionObject.encodeDefaultBinary( client.getDynamicEncodingContext(), value, value.getDataType().getBinaryEncodingId()); diff --git a/opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/DynamicMatrixTestTypeTest.java b/opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/DynamicMatrixTestTypeTest.java index 93b72d185..7aa6fd233 100644 --- a/opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/DynamicMatrixTestTypeTest.java +++ b/opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/DynamicMatrixTestTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 the Eclipse Milo Authors + * Copyright (c) 2025 the Eclipse Milo Authors * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode; -import org.eclipse.milo.opcua.sdk.core.types.DynamicStruct; +import org.eclipse.milo.opcua.sdk.core.types.DynamicStructType; import org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest; import org.eclipse.milo.opcua.sdk.test.MatrixTestType; import org.eclipse.milo.opcua.stack.core.UaException; @@ -38,7 +38,7 @@ public void read() throws UaException { ExtensionObject xo = (ExtensionObject) value.getValue().getValue(); assert xo != null; - DynamicStruct decoded = (DynamicStruct) xo.decode(client.getDynamicEncodingContext()); + DynamicStructType decoded = (DynamicStructType) xo.decode(client.getDynamicEncodingContext()); assertEquals( MatrixTestType.TYPE_ID, decoded.getTypeId().absolute(client.getNamespaceTable()).orElseThrow()); diff --git a/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java b/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java index 7bde03e22..a7e8fec50 100644 --- a/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java +++ b/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 the Eclipse Milo Authors + * Copyright (c) 2025 the Eclipse Milo Authors * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -39,7 +39,7 @@ import org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscription; import org.eclipse.milo.opcua.sdk.client.subscriptions.PublishingManager; import org.eclipse.milo.opcua.sdk.client.typetree.DataTypeTreeBuilder; -import org.eclipse.milo.opcua.sdk.core.types.DynamicCodecFactory; +import org.eclipse.milo.opcua.sdk.core.types.codec.DynamicCodecFactory; import org.eclipse.milo.opcua.sdk.core.typetree.DataType; import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree; import org.eclipse.milo.opcua.stack.core.AttributeId; diff --git a/opc-ua-sdk/sdk-core/pom.xml b/opc-ua-sdk/sdk-core/pom.xml index 146a589ed..ac3eece4a 100644 --- a/opc-ua-sdk/sdk-core/pom.xml +++ b/opc-ua-sdk/sdk-core/pom.xml @@ -1,6 +1,6 @@