Search in sources :

Example 1 with DataTypeCodec

use of org.eclipse.milo.opcua.stack.core.serialization.codecs.DataTypeCodec in project milo by eclipse.

the class OpcUaXmlStreamDecoder method readMessage.

@Override
public UaMessage readMessage(String field) throws UaSerializationException {
    if (currentNode(field)) {
        Node node = currentNode;
        String typeName = node.getLocalName();
        DataTypeCodec codec = context.getDataTypeManager().getCodec(Namespaces.OPC_UA_XSD, String.format("//xs:element[@name='%s']", typeName));
        if (codec instanceof OpcUaXmlDataTypeCodec<?>) {
            currentNode = node.getFirstChild();
            try {
                return (UaMessage) ((OpcUaXmlDataTypeCodec<?>) codec).decode(context, this);
            } finally {
                currentNode = node.getNextSibling();
            }
        } else {
            throw new UaSerializationException(StatusCodes.Bad_DecodingError, "no codec registered: " + typeName);
        }
    } else {
        // TODO could be better if we passed Class<?> into method
        return null;
    }
}
Also used : UaSerializationException(org.eclipse.milo.opcua.stack.core.UaSerializationException) Node(org.w3c.dom.Node) OpcUaXmlDataTypeCodec(org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaXmlDataTypeCodec) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) OpcUaXmlDataTypeCodec(org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaXmlDataTypeCodec) DataTypeCodec(org.eclipse.milo.opcua.stack.core.serialization.codecs.DataTypeCodec)

Aggregations

UaSerializationException (org.eclipse.milo.opcua.stack.core.UaSerializationException)1 DataTypeCodec (org.eclipse.milo.opcua.stack.core.serialization.codecs.DataTypeCodec)1 OpcUaXmlDataTypeCodec (org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaXmlDataTypeCodec)1 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)1 Node (org.w3c.dom.Node)1