|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.prosysopc.ua.DataTypeConverter
public class DataTypeConverter
A converter class, used to convert UA values between different data types.
Note that this class is not meant to be instantiated directly. On the client side, UaClient.getAddressSpace().getDataTypeConverter() will return the relevant converter.
On the server side, the converter is available from UaServer.getNodeManagerRoot().getDataTypeConverter().
| Constructor Summary | |
|---|---|
DataTypeConverter(UaAddressSpace addressSpace)
Creates a new DataTypeConverter, using a given NodeMap that is used to look up the UaDataType nodes that are used. |
|
| Method Summary | |
|---|---|
protected Boolean |
booleanValue(Object value)
Returns the value of the specified Variant as a boolean |
org.opcfoundation.ua.builtintypes.Variant |
convert(org.opcfoundation.ua.builtintypes.Variant value,
Class<?> toClass)
Convert a variant value to a new Variant of the specified dataType. |
org.opcfoundation.ua.builtintypes.Variant |
convert(org.opcfoundation.ua.builtintypes.Variant value,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
Convert a variant value to a new Variant of the specified dataType. |
org.opcfoundation.ua.builtintypes.Variant |
convert(org.opcfoundation.ua.builtintypes.Variant value,
UaDataType dataType)
Convert a variant value to a new Variant of the specified dataType. |
protected Object |
convertValue(Object value,
Class<?> fromClass,
Class<?> toClass)
|
protected Object |
convertVariant(org.opcfoundation.ua.builtintypes.Variant value,
Class<?> fromClass,
Class<?> toClass)
|
UaDataType |
getDataTypeForJavaClass(Class<?> clazz)
Returns a UA data type that corresponds to a Java class. |
UaDataType[] |
getDataTypesForJavaClass(Class<?> clazz)
Returns the UA data type that corresponds to a Java class. |
boolean |
isNullable(org.opcfoundation.ua.builtintypes.NodeId dataType)
Returns true for all data types, i.e. they are all accepting null values. |
protected Object |
numberToInteger(Number number,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
|
protected Object |
numberToInteger(Number number,
UaDataType dataType)
Converts a Number to a UA integer value |
org.opcfoundation.ua.builtintypes.Variant |
parseVariant(String string,
Class<?> javaClass)
Parse a string to a Variant of the specified data type. |
org.opcfoundation.ua.builtintypes.Variant |
parseVariant(String string,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
Parse a string to a Variant of the specified data type. |
org.opcfoundation.ua.builtintypes.Variant |
parseVariant(String string,
UaDataType dataType)
Parse a string to a Variant of the specified data type. |
protected Number |
toNumber(Object value,
Class<?> toClass)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DataTypeConverter(UaAddressSpace addressSpace)
nodeMap - | Method Detail |
|---|
public org.opcfoundation.ua.builtintypes.Variant convert(org.opcfoundation.ua.builtintypes.Variant value,
Class<?> toClass)
throws org.opcfoundation.ua.common.ServiceResultException
The type conversions work in principle, according to the Conversion Rules specified in [OPC UA Part4. Table 113].
value - the value to convert.toClass - Java class type, which defines the desired data type
org.opcfoundation.ua.common.ServiceResultException - if the conversion fails
public org.opcfoundation.ua.builtintypes.Variant convert(org.opcfoundation.ua.builtintypes.Variant value,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
throws org.opcfoundation.ua.common.ServiceResultException
The type conversions work in principle, according to the Conversion Rules specified in [OPC UA Part4. Table 113].
The conversions rely on UaDataType nodes that define the proper JavaClass. This is true for the types in the default address space, both in the server and client nodes of the OPCUA Java SDK.
If you define your own data types, make sure that they inherit from the correct base data types or define the JavaClass for each node yourself.
value - the value to convert.dataTypeId - the NodeId of the UA Data Type to convert to.
org.opcfoundation.ua.common.ServiceResultException - if the conversion fails
public org.opcfoundation.ua.builtintypes.Variant convert(org.opcfoundation.ua.builtintypes.Variant value,
UaDataType dataType)
throws org.opcfoundation.ua.common.ServiceResultException
The type conversions work in principle, according to the Conversion Rules specified in [OPC UA Part4. Table 113].
The conversions rely on UaDataType nodes that define the proper JavaClass. This is true for the types in the default address space, both in the server and client nodes of the OPCUA Java SDK.
If you define your own data types, make sure that they inherit from the correct base data types or define the JavaClass for each node yourself.
value - the value to convert.dataType - the UA Data Type to convert to.
org.opcfoundation.ua.common.ServiceResultException - if the conversion failspublic UaDataType getDataTypeForJavaClass(Class<?> clazz)
clazz - the Java class
IllegalArgumentException - if a suitable data type is not foundpublic UaDataType[] getDataTypesForJavaClass(Class<?> clazz)
clazz - the Java class
IllegalArgumentException - if a suitable data type is not foundpublic boolean isNullable(org.opcfoundation.ua.builtintypes.NodeId dataType)
dataType -
public org.opcfoundation.ua.builtintypes.Variant parseVariant(String string,
Class<?> javaClass)
The method will try to find the UaDataType that corresponds to the javaClass. If no UaDataType node is found, the value is treated as a string value.
string - string to parsejavaClass - Java class type, which defines the desired data type.
IllegalArgumentException - if the parsing fails
NullPointerException - if string is null
public org.opcfoundation.ua.builtintypes.Variant parseVariant(String string,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
If dataTypeId does not correspond to a UaDataType node, the value is treated as a string value.
string - string to parsedataTypeId - NodeId of the data type to create: This must correspond to a UaDataType node
in the NodeMap used by the converter.
IllegalArgumentException - if the parsing fails
NullPointerException - if string is null
public org.opcfoundation.ua.builtintypes.Variant parseVariant(String string,
UaDataType dataType)
Uses the JavaClass property of dataType to determine the target class. The conversion is done using that types parse-method, for example, Integr.parseInt(). The JavaClass of the default types are predefined.
string - string to parse. Must not be nulldataType - data type to create. The JavaClass of the data type must be defined: the
conversion will be done using this class.
IllegalArgumentException - if the parsing fails
NullPointerException - if string is null
protected Boolean booleanValue(Object value)
throws org.opcfoundation.ua.common.ServiceResultException
boolean
org.opcfoundation.ua.common.ServiceResultException - if the value is not null, but cannot be cast to boolean
protected Object convertValue(Object value,
Class<?> fromClass,
Class<?> toClass)
throws org.opcfoundation.ua.common.ServiceResultException
value - fromClass - fromClass - toClass - o -
org.opcfoundation.ua.common.ServiceResultException - if the conversion fails
protected Object convertVariant(org.opcfoundation.ua.builtintypes.Variant value,
Class<?> fromClass,
Class<?> toClass)
throws org.opcfoundation.ua.common.ServiceResultException
value - fromClass - toClass -
org.opcfoundation.ua.common.ServiceResultException
protected Object numberToInteger(Number number,
org.opcfoundation.ua.builtintypes.NodeId dataTypeId)
protected Object numberToInteger(Number number,
UaDataType dataType)
number - dataType -
protected Number toNumber(Object value,
Class<?> toClass)
throws ClassCastException
value - toClass -
ClassCastException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||