Skip to content

Commit

Permalink
Refactor DataTypeTree to use abstract TypeTree, add ReferenceTypeTree (
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Sep 18, 2022
1 parent 6844d06 commit a6d1ded
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 111 deletions.
Expand Up @@ -13,12 +13,12 @@
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;

import org.eclipse.milo.opcua.sdk.client.DataTypeTreeBuilder;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.methods.UaMethod;
import org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode;
import org.eclipse.milo.opcua.sdk.core.types.DataType;
import org.eclipse.milo.opcua.sdk.core.types.DataTypeTree;
import org.eclipse.milo.opcua.sdk.client.typetree.DataTypeTreeBuilder;
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.UaException;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
Expand Down
Expand Up @@ -12,9 +12,9 @@

import java.util.Objects;

import org.eclipse.milo.opcua.sdk.client.DataTypeTreeBuilder;
import org.eclipse.milo.opcua.sdk.core.types.DataType;
import org.eclipse.milo.opcua.sdk.core.types.DataTypeTree;
import org.eclipse.milo.opcua.sdk.client.typetree.DataTypeTreeBuilder;
import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree;
import org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest;
import org.eclipse.milo.opcua.stack.core.BuiltinDataType;
import org.eclipse.milo.opcua.stack.core.NodeIds;
Expand Down Expand Up @@ -49,7 +49,7 @@ public void buildDataTypeTree() throws UaException {

@Test
public void testGetTree() {
dataTypeTree.getTree().traverseWithDepth((dataType, depth) -> {
dataTypeTree.getRoot().traverseWithDepth((dataType, depth) -> {
for (int i = 0; i < depth; i++) {
System.out.print("\t");
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void testGetEncodingIds() {

treeNode.traverse(dataType -> {
String name = dataType.getBrowseName().getName();

if (!Objects.equals(name, "Structure") && !Objects.equals(name, "MatrixTestType")) {
assertNotNull(dataType.getBinaryEncodingId());
assertNotNull(dataType.getXmlEncodingId());
Expand Down
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.sdk.server.types;

import org.eclipse.milo.opcua.sdk.core.typetree.ReferenceTypeTree;
import org.eclipse.milo.opcua.sdk.server.typetree.ReferenceTypeTreeBuilder;
import org.eclipse.milo.opcua.sdk.test.TestServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ReferenceTypeTreeBuilderTest {

private ReferenceTypeTree referenceTypeTree;

@BeforeAll
public void buildReferenceTypeTree() throws Exception {
referenceTypeTree = ReferenceTypeTreeBuilder.build(TestServer.create());
}

@Test
void traverseFromRoot() {
referenceTypeTree.getRoot().traverseWithDepth((dataType, depth) -> {
for (int i = 0; i < depth; i++) {
System.out.print("\t");
}
System.out.println(dataType.getBrowseName().toParseableString());
});
}

}
Expand Up @@ -13,9 +13,10 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.milo.opcua.sdk.client.session.SessionFsm;
import org.eclipse.milo.opcua.sdk.core.types.DataType;
import org.eclipse.milo.opcua.sdk.core.types.DataTypeTree;
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.typetree.DataType;
import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree;
import org.eclipse.milo.opcua.stack.client.UaStackClient;
import org.eclipse.milo.opcua.stack.core.NodeIds;
import org.eclipse.milo.opcua.stack.core.encoding.DataTypeCodec;
Expand Down
Expand Up @@ -13,7 +13,8 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.milo.opcua.sdk.client.session.SessionFsm;
import org.eclipse.milo.opcua.sdk.core.types.DataTypeTree;
import org.eclipse.milo.opcua.sdk.client.typetree.DataTypeTreeBuilder;
import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree;
import org.eclipse.milo.opcua.stack.client.UaStackClient;
import org.eclipse.milo.opcua.stack.core.util.Unit;

Expand Down
Expand Up @@ -8,16 +8,15 @@
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.sdk.core.types;
package org.eclipse.milo.opcua.sdk.client.typetree;

import java.util.Objects;
import java.util.StringJoiner;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.structured.DataTypeDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.StructureDefinition;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -31,7 +30,7 @@
* <li>{@link DataTypeDefinition} attribute value</li>>
* </ul>
*/
public class DataType {
class ClientDataType implements DataType {

private final QualifiedName browseName;
private final NodeId nodeId;
Expand All @@ -40,7 +39,7 @@ public class DataType {
private final NodeId jsonEncodingId;
private final DataTypeDefinition dataTypeDefinition;

public DataType(
public ClientDataType(
QualifiedName browseName,
NodeId nodeId,
NodeId binaryEncodingId,
Expand All @@ -57,81 +56,41 @@ public DataType(
this.dataTypeDefinition = dataTypeDefinition;
}

/**
* Get the Browse Name of this DataType.
*
* @return the Browse Name of this DataType.
*/
@Override
public QualifiedName getBrowseName() {
return browseName;
}

/**
* Get the {@link NodeId} of this DataType.
*
* @return the {@link NodeId} of this DataType.
*/
@Override
public NodeId getNodeId() {
return nodeId;
}

/**
* Get the {@link NodeId} of the Binary Encoding Node for this DataType, if it exists.
* <p>
* Only Structured DataTypes have encoding ids.
*
* @return the NodeId of the Binary Encoding Node for this DataType, if it exists.
*/
@Override
public @Nullable NodeId getBinaryEncodingId() {
return binaryEncodingId;
}

/**
* Get the {@link NodeId} of the XML Encoding Node for this DataType, if it exists.
* <p>
* Only Structured DataTypes have encoding ids.
*
* @return the NodeId of the XML Encoding Node for this DataType, if it exists.
*/
@Override
public @Nullable NodeId getXmlEncodingId() {
return xmlEncodingId;
}

/**
* Get the {@link NodeId} of the JSON Encoding Node for this DataType, if it exists.
* <p>
* Only Structured DataTypes have encoding ids.
*
* @return the {@link NodeId} of the JSON Encoding Node for this DataType, if it exists.
*/
@Override
public @Nullable NodeId getJsonEncodingId() {
return jsonEncodingId;
}

/**
* Get the {@link DataTypeDefinition} of this DataType.
* <p>
* Only Structured and Enumerated DataTypes have a {@link DataTypeDefinition}.
*
* @return the {@link DataTypeDefinition} of this DataType.
*/
@Override
public @Nullable DataTypeDefinition getDataTypeDefinition() {
return dataTypeDefinition;
}

public boolean isEnum() {
return dataTypeDefinition instanceof EnumDefinition;
}

public boolean isStruct() {
return dataTypeDefinition instanceof StructureDefinition;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DataType dataType = (DataType) o;
ClientDataType dataType = (ClientDataType) o;
return browseName.equals(dataType.browseName) &&
nodeId.equals(dataType.nodeId) &&
Objects.equals(binaryEncodingId, dataType.binaryEncodingId) &&
Expand All @@ -154,7 +113,7 @@ public int hashCode() {

@Override
public String toString() {
return new StringJoiner(", ", DataType.class.getSimpleName() + "{", "}")
return new StringJoiner(", ", ClientDataType.class.getSimpleName() + "{", "}")
.add("browseName=" + browseName)
.add("nodeId=" + nodeId)
.add("binaryEncodingId=" + binaryEncodingId)
Expand All @@ -163,4 +122,5 @@ public String toString() {
.add("dataTypeDefinition=" + dataTypeDefinition)
.toString();
}

}
Expand Up @@ -8,16 +8,19 @@
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.sdk.client;
package org.eclipse.milo.opcua.sdk.client.typetree;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;

import org.eclipse.milo.opcua.sdk.core.types.DataType;
import org.eclipse.milo.opcua.sdk.core.types.DataTypeTree;
import org.eclipse.milo.opcua.sdk.client.BrowseHelper;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.OpcUaSession;
import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree;
import org.eclipse.milo.opcua.stack.client.UaStackClient;
import org.eclipse.milo.opcua.stack.core.AttributeId;
import org.eclipse.milo.opcua.stack.core.NamespaceTable;
Expand Down Expand Up @@ -124,7 +127,7 @@ public static CompletableFuture<DataTypeTree> buildAsync(OpcUaClient client) {
public static CompletableFuture<DataTypeTree> buildAsync(UaStackClient client, OpcUaSession session) {
Tree<DataType> root = new Tree<>(
null,
new DataType(
new ClientDataType(
QualifiedName.parse("0:BaseDataType"),
NodeIds.BaseDataType,
null,
Expand Down Expand Up @@ -232,7 +235,7 @@ private static CompletableFuture<Unit> addChildren(
}
}

return new DataType(
return new ClientDataType(
dataTypeReference.getBrowseName(),
dataTypeId,
binaryEncodingId,
Expand Down
Expand Up @@ -10,6 +10,8 @@

package org.eclipse.milo.opcua.sdk.core.types;

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.encoding.DataTypeCodec;
import org.eclipse.milo.opcua.stack.core.types.structured.DataTypeDefinition;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition;
Expand Down
Expand Up @@ -12,6 +12,7 @@

import java.util.function.Function;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.stack.core.types.UaEnumeratedType;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.StringJoiner;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition;
Expand Down
Expand Up @@ -10,6 +10,7 @@

package org.eclipse.milo.opcua.sdk.core.types;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.stack.core.UaSerializationException;
import org.eclipse.milo.opcua.stack.core.encoding.EncodingContext;
import org.eclipse.milo.opcua.stack.core.encoding.GenericDataTypeCodec;
Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.eclipse.milo.opcua.stack.core.types.UaDataType;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;

Expand Down
Expand Up @@ -17,6 +17,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

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.BuiltinDataType;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.UaSerializationException;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import java.util.Arrays;
import java.util.LinkedHashMap;

import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
import org.jetbrains.annotations.Nullable;

public class DynamicUnion extends DynamicStruct {
Expand Down

0 comments on commit a6d1ded

Please sign in to comment.