Class AbstractLazyEncodedDataObject<T>
- java.lang.Object
-
- com.opencloud.util.AbstractDataObject
-
- com.opencloud.util.AbstractFieldsObject
-
- AbstractEncodedDataObject<T>
-
- AbstractLazyEncodedDataObject<T>
-
- All Implemented Interfaces:
DataObject,Serializable
- Direct Known Subclasses:
AbstractLazyEncodedByteArray,AbstractLazyEncodedNamedInteger
public abstract class AbstractLazyEncodedDataObject<T> extends AbstractEncodedDataObject<T>
Class AbstractLazyEncodedDataObject represents a DataObject in which the state is represented in an encoded form or a decoded form, with conversions between the two forms done lazily (when needed). Having a decoded representation of the state is convenient if the positions of fields in the encoded representation can vary depending on the values of other fields that might not have been supplied yet. For example, the presence/absence of optional fields, and the lengths of variable-length fields, can both affect the positions of later fields. Once an object has been marked read-only, both encoded and decoded forms can co-exist.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanisDecodedWhether the state is in the decoded form.-
Fields inherited from class com.opencloud.slee.resources.cgin.AbstractEncodedDataObject
encoded
-
Fields inherited from class com.opencloud.util.AbstractFieldsObject
FIELD_ABSENT, FIELD_UNINITIALISED
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLazyEncodedDataObject()Constructs a new AbstractLazyEncodedDataObject.protectedAbstractLazyEncodedDataObject(byte[] data, int start, int len)Constructs a new AbstractLazyEncodedDataObject from part of given network-encoded data.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckDecode()Ensures that the state is in the decoded form.protected abstract voidcheckFieldsSet()Checks that all mandatory fields are present.protected voidcheckModifyAndDecode()For use before setting a field of the decoded representation: checks that the object has not been marked read-only, and ensures that the state is in the decoded form.protected abstract voiddecode()Computes the decoded form of the state from the encoded form.protected abstract voidencode()Computes the encoded form of the state from the decoded form.-
Methods inherited from class com.opencloud.util.AbstractFieldsObject
equals, getFieldsMap, hashCode, toString
-
Methods inherited from class com.opencloud.util.AbstractDataObject
checkModify, clone, isReadOnly, setReadOnly
-
-
-
-
Constructor Detail
-
AbstractLazyEncodedDataObject
protected AbstractLazyEncodedDataObject()
Constructs a new AbstractLazyEncodedDataObject. The state is in the decoded form, despite none of the fields having been set yet, as there is no encoded form.
-
AbstractLazyEncodedDataObject
protected AbstractLazyEncodedDataObject(byte[] data, int start, int len)Constructs a new AbstractLazyEncodedDataObject from part of given network-encoded data. The part starts at indexstartand islenbytes long. The state is in the encoded form: it is not decoded and might not be decodable.- Parameters:
data- network-encoded datastart- starting offset of network-encoded datalen- length of encoded data in bytes- Throws:
NullPointerException- if data is nullIllegalArgumentException- if len is negativeArrayIndexOutOfBoundsException- if the part is not within the data
-
-
Method Detail
-
checkFieldsSet
protected abstract void checkFieldsSet() throws EncodeExceptionChecks that all mandatory fields are present. Should be called immediately before all calls to encode().- Throws:
EncodeException- if any mandatory field is not present
-
encode
protected abstract void encode() throws EncodeExceptionComputes the encoded form of the state from the decoded form. Should check that individual field values are within appropriate ranges, and different fields have mutually consistent values, but needn't repeat the checks done by checkFieldsSet(). The computed encoded form should equal that from which the decoded form could have been calculated using decode(), i.e. encode o decode = id.- Throws:
EncodeException- if encoding fails
-
decode
protected abstract void decode() throws DecodeExceptionComputes the decoded form of the state from the encoded form. The computed decoded form should equal that from which the encoded form could have been calculated using encode(), i.e. decode o encode = id. If a field cannot be decoded without further information, such as a DigitCodec to be used for decoding a digit string, then the encoded form of that field should be copied and kept for decoding by that field's getter, which will be given the further information. The caller should setisDecodedto true.- Throws:
DecodeException- if decoding fails
-
checkDecode
protected void checkDecode() throws DecodeExceptionEnsures that the state is in the decoded form.- Throws:
DecodeException- if decoding fails
-
checkModifyAndDecode
protected void checkModifyAndDecode() throws IllegalStateException, DecodeExceptionFor use before setting a field of the decoded representation: checks that the object has not been marked read-only, and ensures that the state is in the decoded form.- Throws:
IllegalStateException- if the object is readonlyDecodeException- if decoding fails
-
-