TOC PREV NEXT INDEX


CHOICE



The ASN.1 CHOICE type is converted to a Java class that extends the Asn1Choice run-time base class. This base class contains protected member variables to hold the choice element object and a selector value to specify which item in the CHOICE was chosen. Methods are generated to get and set the base class members.

The following shows the basic mapping from ASN.1 type to Java class definition:

ASN.1 Production:
<name> ::= CHOICE {
 
   <element1-name> <element1-type>,
 
   <element2-name> <element2-type>,
 
   ...
 
}
 
Generated Java class:

public class <name> extends Asn1Choice {
 
   public final static byte _<ELEMENT1-NAME> 1
 
   public final static byte _<ELEMENT2-NAME> 2
 
   ...
 

 
   public <name> () { super(); }
 

 
   public String getElemName() { ... }
 

 
   public void set_<element1-name> () { ... }
 
   public void set_<element2-name> () { ... }
 
   ...
 
   public void decode () { ... }
 
   public int  encode () { ... }
 
   public void print () { ... }
 
}
 



Notes:


The compiler generates sequential identification constants for each of the defined elements in the CHOICE construct. The format used is the element names converted to all uppercase characters and preceded by an underscore. The constants represent the values returned by the base class getChoiceID method can therefore be used to determine what type of choice element was received in a decode operation.

The getElemName method is generated by the compiler and returns the name of the selected element.

A series of set_<element> methods are generated for setting the element value. In these declarations, <element> would be replaced with the actual element names. This is the only way an element value can be set for encoding; these methods ensure a consistent setting of both the element identifier and object reference values.

To access the value of a generated CHOICE object, the getChoiceID and getElement methods within the base class are used. This is generally done with an if or switch statement as follows:


         Asn1BMPString element;
 
         if (aliasAddress.getChoiceID() == AliasAddress._H323_ID) {
 
            element = (Asn1BMPString) aliasAddress.getElement();
 
         }
 

In this case, getChoiceID is invoked and the result tested to see if the expected value was received. If it was, the element is assigned using getElement with a cast operation.


Objective Systems, Inc.

102 Pickering Way, Suite #506
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com
TOC PREV NEXT INDEX

Copyright © 1997-2004 Objective Systems,Inc.
All Rights Reserved.


This document may be distributed in any form, electronic
or otherwise, provided that it is distributed in its entirety
and that the copyright and this notice are included.