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
    • 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 index start and is len bytes long. The data is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        start - starting offset of network-encoded data in byte array
        len - default length if not predictable
        Throws:
        NullPointerException - if data is null
        IllegalArgumentException - if len is negative
    • Method Detail

      • 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
      • 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 interface DataObject
        Specified by:
        clone in class AbstractDataObject
        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 class AbstractFieldsObject
        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 offset start in the given data. 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 data
        start - index into data where value commences
        len - 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 class AbstractLazyEncodedDataObject<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 set isDecoded to true.
        Specified by:
        decode in class AbstractLazyEncodedDataObject<byte[]>
        Throws:
        UnsupportedOperationException - as decoding is from TCAP representation, not byte[]; see ASN1Utils