/*
* Copyright (c) 2019 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.namespaces.loader;
import java.io.StringReader;
import org.eclipse.milo.opcua.sdk.core.Reference;
import org.eclipse.milo.opcua.sdk.server.api.NodeManager;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.BaseDataVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.BuildInfoNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ConditionVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.DataTypeDescriptionNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.DataTypeDictionaryNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.FiniteStateVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.FiniteTransitionVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ProgramDiagnosticNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.PropertyNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SamplingIntervalDiagnosticsArrayNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SamplingIntervalDiagnosticsNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerDiagnosticsSummaryNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerStatusNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerVendorCapabilityNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsArrayNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionSecurityDiagnosticsArrayNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionSecurityDiagnosticsNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.StateVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SubscriptionDiagnosticsArrayNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SubscriptionDiagnosticsNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.TransitionVariableNode;
import org.eclipse.milo.opcua.sdk.server.model.nodes.variables.TwoStateVariableNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext;
import org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode;
import org.eclipse.milo.opcua.stack.core.serialization.OpcUaXmlStreamDecoder;
import org.eclipse.milo.opcua.stack.core.serialization.SerializationContext;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
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.builtin.Variant;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
public class UaVariableLoader {
private final SerializationContext serializationContext;
private final UaNodeContext context;
private final NodeManager<UaNode> nodeManager;
public UaVariableLoader(UaNodeContext context, NodeManager<UaNode> nodeManager) {
this.context = context;
this.nodeManager = nodeManager;
serializationContext = context.getServer().getSerializationContext();
}
private void buildNode0()
throws Exception {
UaVariableNode node = new DataTypeDescriptionNode(this.context, NodeId.parse("ns=0;i=8208"), new QualifiedName(0, "RedundantServerDataType"), new LocalizedText("en", "RedundantServerDataType"), LocalizedText.NULL_VALUE, UInteger.valueOf(0L), UInteger.valueOf(0L), new DataValue(Variant.NULL_VALUE), NodeId.parse("ns=0;i=12"), -1, new UInteger[]{}, UByte.valueOf(1), UByte.valueOf(1), 0.0D, false);
node.addReference(new Reference(NodeId.parse("ns=0;i=8208"), NodeId.parse("ns=0;i=39"), ExpandedNodeId.parse("svr=0;i=855"), NodeClass.Object, false));
node.addReference(new Reference(NodeId.parse("ns=0;i=8208"), NodeId.parse("ns=0;i=47"), ExpandedNodeId.parse("svr=0;i=7617"), NodeClass.Variable, false));
node.addReference(new Reference(NodeId.parse("ns=0;i=8208"), NodeId.parse("ns=0;i=40"), ExpandedNodeId.parse("svr=0;i=69"), NodeClass.VariableType, true));
node.addReference(new Reference(NodeId.parse("ns=0;i=8208"), NodeId.parse("ns=0;i=47"), ExpandedNodeId.parse("svr=0;i=7617"), NodeClass.Variable, false));
String valueXml;
OpcUaXmlStreamDecoder decoder = new OpcUaXmlStreamDecoder(serializationContext, new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:String xmlns=\"http://opcfoundation.org/BinarySchema/\" xmlns:ns2=\"http://opcfoundation.org/UA/2008/02/Types.xsd\" xmlns:ns3=\"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd\">RedundantServerDataType</ns2:String>"));
Object valueObject = decoder.readVariantValue();
DataValue value = new DataValue(new Variant(valueObject));
node.setValue(value);
this.nodeManager.addNode(node);
}
private void buildNode1()
throws Exception {
UaVariableNode node = new DataTypeDescriptionNode(this.context, NodeId.parse("ns=0;i=8211"), new QualifiedName(0, "SamplingIntervalDiagnosticsDataType"), new LocalizedText("en", "SamplingIntervalDiagnosticsDataType"), LocalizedText.NULL_VALUE, UInteger.valueOf(0L), UInteger.valueOf(0L), new DataValue(Variant.NULL_VALUE), NodeId.parse("ns=0;i=12"), -1, new UInteger[]{}, UByte.valueOf(1), UByte.valueOf(1), 0.0D, false);
node.addReference(new Reference(NodeId.parse("ns=0;i=8211"), NodeId.parse("ns=0;i=39"), ExpandedNodeId.parse("svr=0;i=858"), NodeClass.Object, false));
node.addReference(new Reference(NodeId.parse("ns=0;i=8211"), NodeId.parse("ns=0;i=47"), ExpandedNodeId.parse("svr=0;i=7617"), NodeClass.Variable, false));
node.addReference(new Reference(NodeId.parse("ns=0;i=8211"), NodeId.parse("ns=0;i=40"), ExpandedNodeId.parse("svr=0;i=69"), NodeClass.VariableType, true));
node.addReference(new Reference(NodeId.parse("ns=0;i=8211"), NodeId.parse("ns=0;i=47"), ExpandedNodeId.parse("svr=0;i=7617"), NodeClass.Variable, false));
String valueXml;
OpcUaXmlStreamDecoder decoder = new OpcUaXmlStreamDecoder(serializationContext, new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:String xmlns=\"http://opcfoundation.org/BinarySchema/\" xmlns:ns2=\"http://opcfoundation.org/UA/2008/02/Types.xsd\" xmlns:ns3=\"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd\">SamplingIntervalDiagnosticsDataType</ns2:String>"));
Object valueObject = decoder.readVariantValue();
DataValue value = new DataValue(new Variant(valueObject));
node.setValue(value);
this.nodeManager.addNode(node);
}
private void buildNode2()
throws Exception {
UaVariableNode node = new DataTypeDescriptionNode(this.context, NodeId.parse("ns=0;i=8214"), new QualifiedName(0, "ServerDiagnosticsSummaryDataType"), new LocalizedText("en", "ServerDiagnosticsSummaryDataType"), LocalizedText.NULL_VALUE, UInteger.valueOf(0L), UInteger.valueOf(0L), new DataValue(Variant.NULL_VALUE), NodeId.parse("ns=0;i=12"), -1, new UInteger[]{}, UByte.valueOf(1), UByte.valueOf(1), 0.0D, false);
node.addReference(new Reference(NodeId.parse("ns=0;i=8214"), NodeId.parse("ns=0;i=39"), Exp