SEQUENCE OF

The ASN.1 SEQUENCE OF type is converted to a Java class that extends the Asn1Type run-time base class. An array public member variable named elements is generated to hold the elements of the defined type.

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

ASN.1 Production

<name> ::= SEQUENCE OF <type>

XSD Types

Elements or content group definitions containing the minOccurs and/or maxOccurs facets. Also, <xsd:list> types use this model.

Generated Java class

   public class <name> extends Asn1Type {
      public <type>[] elements

      public <type> () {
         elements = null;
      }
      
      public <type> (int numRecords) {
         elements = new <type> [numRecords];
      }
      
      public void decode () { ... }
      public int encode () { ... }
      public void print () { ... }
   }

The compiler first generates a public member variable to hold the SEQUENCE OF elements. The decision was made to make the variable public to make it easier to populate for encoding. The alternative was to use protected or private variables with get/set methods for setting or examining the values. It was felt that this approach would be too cumbersome for setting values in deeply nested constructed types.

Two constructors are generated: a default constructor and a constructor that takes a number of elements argument. The default constructor will set the elements variable to null. The second constructor will allocate space for the given number of elements. The recommended way to populate a variable of this type for encoding is to use the second form of the constructor to allocate the required number of elements and then directly set the element object values. For example, to populate the following construct:

   IntSeq ::= SEQUENCE OF INTEGER

with 3 integers, the following code could be used:

   IntSeq intSeq = new IntSeq (3);
   intSeq.elements[0] = new Asn1Integer (1);
   intSeq.elements[1] = new Asn1Integer (2);
   intSeq.elements[2] = new Asn1Integer (3);

Note that each of the integer element values is wrapped in an Asn1Integer wrapper class.