public abstract class DOFType extends java.lang.Object implements DOFImmutable, java.io.Serializable
DOFValue
implementations, and are used by themselves in some routines (see
DOFInterface
).
Types in the OAL are immutable. This means that once completely defined they must not change.
Note the wording of "once completely defined", and see the documentation for isDefined()
and DOFType.Typedef.defineAs(org.opendof.core.oal.DOFType)
.
Classes that extend DOFType do at least the following: 1) represent a given DOF type,
as defined by the DOF Protocol Specification; and 2) represent a given implementation
of values of that type, which they are linked to through the getInstance(org.opendof.core.oal.DOFPacket)
method.
The linkage between a DOFType implementation and a DOFValue
implementation is always
one-to-one. The getInstance(org.opendof.core.oal.DOFPacket)
method returns a DOFValue
, and the DOFValue.getDOFType()
method
returns the original DOFType.
Classes that extend DOFType must be able to write and read their types to a DOFPacket
.
This requires that they follow the specification for their type.
This last requirement means that the easiest way to define a new type is by extending an existing
type. In this case, only the getInstance(org.opendof.core.oal.DOFPacket)
call must be overridden (and it must be overridden
to preserve the one-to-one association of type to value).DOFValue
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
DOFType.Context
Manages a set of type definitions that can refer to each other by using indexes.
|
static class |
DOFType.Nullable
Create a type that references another type or can take the value
null . |
static class |
DOFType.Typedef
Create a type that is defined in terms of another type.
|
Modifier and Type | Field and Description |
---|---|
static short |
ARRAY
The type identifier for an array.
|
static short |
BLOB
The type identifier for a binary large object.
|
static short |
BOOLEAN
The type identifier for a boolean.
|
static short |
DATETIME
The type identifier for a coordinated universal time (UTC).
|
static short |
FLOAT32
The type identifier for a single-precision float.
|
static short |
FLOAT64
The type identifier for a double-precision float.
|
static short |
GUID
The type identifier for a 16 byte globally unique identifier.
|
static short |
INT16
The type identifier for a signed short.
|
static short |
INT32
The type identifier for a signed integer.
|
static short |
INT64
The type identifier for a signed 64-bit integer.
|
static short |
INT8
The type identifier for a signed byte.
|
static short |
INTERFACEID
The type identifier for a DOF Interface Identifier.
|
static short |
NULLABLE
The type identifier for a nullable type.
|
static short |
OBJECTID
The type identifier for a DOF Object Identifier.
|
static short |
REFERENCE
The type identifier for a reference.
|
static short |
STRING
The type identifier for a string.
|
static short |
STRUCTURE
The type identifier for a structure.
|
static short |
UINT16
The type identifier for a unsigned short.
|
static short |
UINT32
The type identifier for a unsigned integer.
|
static short |
UINT64
The type identifier for a unsigned 64-bit integer.
|
static short |
UINT8
The type identifier for a unsigned byte.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
asBoolean(DOFValue value)
Returns the result's value as a boolean.
|
static byte |
asByte(DOFValue value)
Returns the result's value as a byte.
|
static byte[] |
asBytes(DOFValue value)
Returns the result's value as a byte array.
|
static java.util.Date |
asDate(DOFValue value)
Returns the result's value as a Date.
|
static DOFInterfaceID |
asDOFInterfaceID(DOFValue value)
Returns the result's value as a DOFInterfaceID.
|
static DOFObjectID |
asDOFObjectID(DOFValue value)
Returns the result's value as a DOFObjectID.
|
static double |
asDouble(DOFValue value)
Returns the result's value as a double.
|
static float |
asFloat(DOFValue value)
Returns the result's value as a float.
|
static int |
asInt(DOFValue value)
Returns the result's value as an int.
|
static long |
asLong(DOFValue value)
Returns the result's value as a Long.
|
static short |
asShort(DOFValue value)
Returns the result's value as a short.
|
static java.lang.String |
asString(DOFValue value)
Returns the result's value as a String.
|
static java.math.BigInteger |
asULong(DOFValue value)
Returns the result's value as a BigInteger.
|
boolean |
equals(java.lang.Object obj)
Return whether two types are equal.
|
static java.lang.String |
getCharSet(int mib_enum)
Return a Java encoding string based on a MIB enum assignment.
|
int |
getEncoding()
Get the string encoding for the type.
|
abstract DOFValue |
getInstance(DOFPacket packet)
|
int |
getMaxLength()
Get the maximum length of the type.
|
int |
getMinLength()
Get the minimum length of the type.
|
java.util.List<DOFType> |
getSubtypes()
Return a list of subtypes associated with this type.
|
short |
getTypeID()
Get the type identifier of this type.
|
int |
hashCode()
Return a hash code for the type.
|
static void |
isCompatibleWith(DOFType type,
DOFValue value)
Check for compatibility between a type and a value, properly handling the case where
the value is
null . |
boolean |
isDefined()
Return whether of not the type is fully defined.
|
static void |
marshal(DOFType type,
DOFValue value,
DOFPacket packet)
Write a DOFValue to a buffer, handling the case where the value is null.
|
java.lang.String |
toString()
Returns a description of the type.
|
public static final short INT8
public static final short UINT8
public static final short INT16
public static final short UINT16
public static final short INT32
public static final short UINT32
public static final short INT64
public static final short UINT64
public static final short FLOAT32
public static final short FLOAT64
public static final short DATETIME
public static final short BOOLEAN
public static final short OBJECTID
public static final short INTERFACEID
public static final short GUID
public static final short BLOB
public static final short STRING
public static final short STRUCTURE
public static final short ARRAY
public static final short REFERENCE
public static final short NULLABLE
public short getTypeID()
public abstract DOFValue getInstance(DOFPacket packet) throws DOFMarshalException
DOFValue
instance from a DOFPacket
.
When called the current buffer location will point at the first byte of data associated with the
type. On completion, the buffer location must point at the first byte after the data, meaning the
first unread byte.packet
- The buffer which contains the serialized form of the object. Must not be null.null
if the type is nullable.DOFMarshalException
- If there are errors in the data or the buffer. This is an exception to the rule that
non-RuntimeExceptions not be thrown from a constructor.public boolean isDefined()
DOFType.Typedef
, for example).
In this case the constructed type must return false
until it is fully defined.
While in the partially defined state the results of other method calls on the type may return invalid
results or throw exceptions. Care must be taken whenever working with a type that may be partially defined.
Further, certain uses of types may be prohibited if the type is not yet defined. These cases are mentioned
in the documentation as requiring fully defined types.
Once a type is fully defined it becomes immutable, meaning that it can never become partially defined again.true
if the type is fully defined, false
otherwise.public int getMaxLength()
public int getMinLength()
public java.util.List<DOFType> getSubtypes()
public int getEncoding()
getCharSet(int)
public static java.lang.String getCharSet(int mib_enum)
mib_enum
- The encoding specifier as MIB enum. See http://www.iana.org/assignments/character-sets.public static void marshal(DOFType type, DOFValue value, DOFPacket packet) throws DOFMarshalException, DOFErrorException
DOFValue
defines
its data format and can write itself out with the DOFValue.marshal(org.opendof.core.oal.DOFType, org.opendof.core.oal.DOFPacket)
method. However, it
is possible that the value is null
. In this case the method call cannot be made.
This method handles this case correctly, checking if the type can accept null
values.
If it is nullable then it writes the value out appropriately.type
- The type of the value. Must not be null.value
- The value to be written. May be null
only if the type is nullable.packet
- The packet to write the value to. Must not be null.DOFMarshalException
- Thrown on marshalling errors.DOFErrorException
- Thrown on type validation errors.public static void isCompatibleWith(DOFType type, DOFValue value) throws DOFErrorException
null
.type
- The type to check compatibility against. Must not be null.value
- The value to check, which may be null
.DOFErrorException
- Thrown if the value and type are not compatible.public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The type to compare against. May be null
.true
if the types are equal, false
otherwise or if type is null
.public int hashCode()
equals(java.lang.Object)
returns true
.hashCode
in class java.lang.Object
public static int asInt(DOFValue value)
DOFInt32
,
DOFInt16
, DOFUInt16
and all types accepted by asShort(org.opendof.core.oal.DOFValue)
.
value
- Value to return as int
Throws ClassCastException if called on a non-integer result.public static byte asByte(DOFValue value)
DOFInt8
.
value
- Value to return as byte
Throws ClassCastException if called on a non-byte result.public static short asShort(DOFValue value)
DOFUInt8
,
DOFInt16
and all types accepted by asByte(org.opendof.core.oal.DOFValue)
.
value
- Value to return as short
Throws ClassCastException if called on a non-short result.public static long asLong(DOFValue value)
DOFUInt32
, DOFInt64
and all types accepted by asInt(org.opendof.core.oal.DOFValue)
.
value
- Value to return as long
Throws ClassCastException if called on a non-long result.public static java.math.BigInteger asULong(DOFValue value)
DOFUInt64
and all types supported by asLong(org.opendof.core.oal.DOFValue)
.
Throws ClassCastException if called on a non-long result.value
- Value to return as unsigned longpublic static boolean asBoolean(DOFValue value)
DOFBoolean
.
value
- Value to return as boolean
Throws ClassCastException if called on a non-boolean result.public static float asFloat(DOFValue value)
DOFFloat32
.
value
- Value to return as float
Throws ClassCastException if called on a non-float result.public static double asDouble(DOFValue value)
DOFFloat64
and all types accepted by asFloat(org.opendof.core.oal.DOFValue)
.
value
- Value to return as double
Throws ClassCastException if called on a non-double result.public static java.util.Date asDate(DOFValue value)
DOFDateTime
.
value
- Value to return as Date
Throws ClassCastException if called on a non-Date result.public static DOFObjectID asDOFObjectID(DOFValue value)
DOFObjectID
.
value
- Value to return as DOFObjectID
Throws ClassCastException if called on a non-DOFObjectID result.public static DOFInterfaceID asDOFInterfaceID(DOFValue value)
DOFInterfaceID
.
value
- Value to return as DOFInterfaceID
Throws ClassCastException if called on a non-DOFInterfaceID result.public static byte[] asBytes(DOFValue value)
DOFBlob
.
value
- Value to return as byte array
Throws ClassCastException if called on a non-DOFBlob result.