Class Code
-
- All Implemented Interfaces:
DataObject
,FastSerializable
,Immutable
,Serializable
public final class Code extends AbstractLazyEncodedByteArray implements FastSerializable, Immutable
A Code used to identify a TCAP Operation or Error. This one type encompasses the choices in ITU TCAP and the choices in ANSI TCAP.The ITU cases are specified in ASN.1 as follows from X.880 module Remote-Operations-Information-Objects {joint-iso-itu-t remote-operations(4) informationObjects(5) version1(0)}.
Code ::= CHOICE { local INTEGER, global OBJECT IDENTIFIER }
The ANSI cases are specified in ASN.1 as follows from T1.114 p3-26.
OperationCode ::= CHOICE { national [PRIVATE 16] IMPLICIT INTEGER -32768..32767, private [PRIVATE 17] IMPLICIT INTEGER } ErrorCode ::= CHOICE { national [PRIVATE 19] INTEGER -128..127, private [PRIVATE 20] INTEGER }
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Code.Choice
Enumeration of discriminating values.
-
Field Summary
-
Fields inherited from class com.opencloud.slee.resources.cgin.AbstractLazyEncodedDataObject
isDecoded
-
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 Constructor Description Code()
Constructs a new Code object with no fields set.Code(byte[] data)
Constructs a new Code object from network-encoded data.Code(byte[] data, int start, int len)
Constructs a new Code object from part of network-encoded data.Code(DataInput in)
Constructs a new Code object from data deserialized from a stream that was written bytoStream(DataOutput)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkFieldsSet()
Checks that all mandatory fields are present.Code
clone()
Constructs a copy of this object and everything reachable from it.static Code
copyOf(Code from)
Creates a new object of this type, cloning the values of common fields from the given object of any subclass of the same base type.void
decode()
Computes the decoded form of the state from the encoded form.void
encode()
Computes the encoded form of the state from the decoded form.protected boolean
encodedIsInvalid()
Determines whether the encoded form is invalid.Code.Choice
getChoice()
Gets the discriminant for which choice is chosen.static int
getContainedLength(byte[] data, int start, int len)
Determines the length of the encoded value that commences at offsetstart
in the givendata
.byte[]
getEncodedForm()
Gets the encoded form.static FieldAccessor[]
getFieldAccessors()
Gets a new array of the accessors for fields of this type.Map<String,Object>
getFieldsMap(boolean withAbsents)
Gets a Map from :discriminant-name to field-value.ObjectID
getGlobal()
Gets the value of the ITU global object identifier alternative.int
getLocal()
Gets the value of the ITU local integer alternative.int
getNational()
Gets the value of the ANSI national integer alternative.int
getPrivate()
Gets the value of the ANSI private integer alternative.boolean
isGlobalChosen()
Tests whether the choice is global.boolean
isLocalChosen()
Tests whether the choice is local.boolean
isNationalChosen()
Tests whether the choice is national.boolean
isPrivateChosen()
Tests whether the choice is private.Code
setGlobal(ObjectID value)
Sets the value of the ITU global object identifier alternative.Code
setLocal(int value)
Sets the value of the ITU local integer alternative.Code
setNational(int value)
Sets the value of the ANSI national integer alternative.Code
setPrivate(int value)
Sets the value of the ANSI private integer alternative.void
toStream(DataOutput out)
Serializes this object to a stream in a form suitable for reading byCode(DataInput)
.-
Methods inherited from class com.opencloud.slee.resources.cgin.AbstractLazyEncodedDataObject
checkDecode, checkModifyAndDecode
-
Methods inherited from class com.opencloud.util.AbstractFieldsObject
equals, hashCode, toString
-
Methods inherited from class com.opencloud.util.AbstractDataObject
checkModify, isReadOnly, setReadOnly
-
-
-
-
Constructor Detail
-
Code
public Code()
Constructs a new Code object with no fields set.
-
Code
public Code(byte[] data)
Constructs a new Code object from network-encoded data. The data is not decoded and might not be decodable.- Parameters:
data
- network-encoded data- Throws:
NullPointerException
- if data is null
-
Code
public Code(byte[] data, int start, int len)
Constructs a new Code object from part of network-encoded data. The part starts at indexstart
and islen
bytes long. The data is not decoded and might not be decodable.- Parameters:
data
- network-encoded datastart
- starting offset of network-encoded data in byte arraylen
- default length if not predictable- Throws:
NullPointerException
- if data is nullIllegalArgumentException
- if len is negative
-
Code
public Code(DataInput in) throws IOException
Constructs a new Code object from data deserialized from a stream that was written bytoStream(DataOutput)
.- Parameters:
in
- the stream to read from- Throws:
EOFException
- if reading is pre-empted by end-of-fileIOException
- if the data cannot be read
-
-
Method Detail
-
toStream
public void toStream(DataOutput out) throws IOException
Serializes this object to a stream in a form suitable for reading byCode(DataInput)
.- Specified by:
toStream
in interfaceFastSerializable
- Parameters:
out
- the stream to write to- Throws:
IOException
- if an I/O error occurs
-
getChoice
public Code.Choice getChoice() throws DecodeException
Gets the discriminant for which choice is chosen.- Returns:
- enumerated constant
- Throws:
DecodeException
- if encoded state cannot be decoded
-
isLocalChosen
public boolean isLocalChosen() throws DecodeException
Tests whether the choice is local.- Returns:
- true if chosen, false if not
- Throws:
DecodeException
- if encoded state cannot be decoded
-
isGlobalChosen
public boolean isGlobalChosen() throws DecodeException
Tests whether the choice is global.- Returns:
- true if chosen, false if not
- Throws:
DecodeException
- if encoded state cannot be decoded
-
isNationalChosen
public boolean isNationalChosen() throws DecodeException
Tests whether the choice is national.- Returns:
- true if chosen, false if not
- Throws:
DecodeException
- if encoded state cannot be decoded
-
isPrivateChosen
public boolean isPrivateChosen() throws DecodeException
Tests whether the choice is private.- Returns:
- true if chosen, false if not
- Throws:
DecodeException
- if encoded state cannot be decoded
-
checkFieldsSet
public void checkFieldsSet() throws EncodeException
Checks that all mandatory fields are present. Should be called immediately before all calls to encode().- Specified by:
checkFieldsSet
in classAbstractLazyEncodedDataObject<byte[]>
- Throws:
EncodeException
- if any mandatory field is not present
-
getLocal
public int getLocal() throws DecodeException
Gets the value of the ITU local integer alternative.- Returns:
- int representation of the ITU local integer alternative, if choice is the ITU local integer alternative
- Throws:
DecodeException
- if encoded state cannot be decoded
-
getGlobal
public ObjectID getGlobal() throws DecodeException
Gets the value of the ITU global object identifier alternative.- Returns:
- ObjectID representation of the ITU global object identifier alternative, if choice is the ITU global object identifier alternative, else null
- Throws:
DecodeException
- if encoded state cannot be decoded
-
getNational
public int getNational() throws DecodeException
Gets the value of the ANSI national integer alternative.- Returns:
- int representation of the ANSI national integer alternative, if choice is the ANSI national integer alternative
- Throws:
DecodeException
- if encoded state cannot be decoded
-
getPrivate
public int getPrivate() throws DecodeException
Gets the value of the ANSI private integer alternative.- Returns:
- int representation of the ANSI private integer alternative, if choice is the ANSI private integer alternative
- Throws:
DecodeException
- if encoded state cannot be decoded
-
setLocal
public Code setLocal(int value) throws IllegalStateException
Sets the value of the ITU local integer alternative.- Parameters:
value
- int representation of the ITU local integer alternative- Returns:
- this
- Throws:
IllegalStateException
-
setGlobal
public Code setGlobal(ObjectID value) throws IllegalStateException
Sets the value of the ITU global object identifier alternative.- Parameters:
value
- ObjectID representation of the ITU global object identifier alternative- Returns:
- this
- Throws:
IllegalStateException
-
setNational
public Code setNational(int value) throws IllegalStateException
Sets the value of the ANSI national integer alternative.- Parameters:
value
- int representation of the ANSI national integer alternative- Returns:
- this
- Throws:
IllegalStateException
-
setPrivate
public Code setPrivate(int value) throws IllegalStateException
Sets the value of the ANSI private integer alternative.- Parameters:
value
- int representation of the ANSI private integer alternative- Returns:
- this
- Throws:
IllegalStateException
-
copyOf
public static Code copyOf(Code from)
Creates a new object of this type, cloning the values of common fields from the given object of any subclass of the same base type.- Parameters:
from
- the object from which to copy- Returns:
- Code
-
clone
public Code clone()
Constructs a copy of this object and everything reachable from it.- Specified by:
clone
in interfaceDataObject
- Specified by:
clone
in classAbstractDataObject
- Returns:
- copy of object
-
getFieldAccessors
public static FieldAccessor[] getFieldAccessors()
Gets a new array of the accessors for fields of this type.- Returns:
- FieldAccessor[]
-
getFieldsMap
public Map<String,Object> getFieldsMap(boolean withAbsents)
Gets a Map from :discriminant-name to field-value. If choice is not set, returns a Map from : to AbstractFieldsObject.FIELD_UNINITIALISED. For a field of primitive type, the field-value is boxed. For a field of String type, the encoded form is used if the String cannot be decoded. For a type that represents an OCTET STRING that cannot be decoded, a map from "encodedValue:" to the byte array value is returned.- Specified by:
getFieldsMap
in classAbstractFieldsObject
- Parameters:
withAbsents
- the value of this parameter is ignored- Returns:
- Map from :discriminant-name to field-value
-
encodedIsInvalid
protected boolean encodedIsInvalid()
Determines whether the encoded form is invalid.- Returns:
- boolean
-
getEncodedForm
public byte[] getEncodedForm() throws EncodeException
Gets the encoded form.- Returns:
- encoded form
- Throws:
EncodeException
- if encoding fails
-
getContainedLength
public static int getContainedLength(byte[] data, int start, int len)
Determines the length of the encoded value that commences at offsetstart
in the givendata
. The value is not fully decoded and might not be decodable. Values of this type are of variable length, so the given length is returned if the data is long enough, otherwise 0 is returned.- Parameters:
data
- network-encoded datastart
- index into data where value commenceslen
- length in data to be considered- Returns:
- len, or 0 if encoded value is not long enough
-
encode
public void encode()
Description copied from class:AbstractLazyEncodedDataObject
Computes 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.- Specified by:
encode
in classAbstractLazyEncodedDataObject<byte[]>
- Throws:
UnsupportedOperationException
- as encoding is to TCAP representation, not byte[]; see ASN1Utils
-
decode
public void decode()
Description copied from class:AbstractLazyEncodedDataObject
Computes 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 setisDecoded
to true.- Specified by:
decode
in classAbstractLazyEncodedDataObject<byte[]>
- Throws:
UnsupportedOperationException
- as decoding is from TCAP representation, not byte[]; see ASN1Utils
-
-