isRequired

The isRequired method has the following signature:

   public static boolean isRequired (String elemName)
      throws Asn1InvalidElemException

The method returns true when the element given by elemName is required to be present in the given SEQUENCE or SET and false when it is not. In the event that the named element is not a member of the structure, the Asn1InvalidElemException is thrown.

The following ASN.1, taken from a slightly-modified version of the Employee sample program, provides a good example:

   PersonnelRecord ::= [APPLICATION 0] IMPLICIT SET {
      name                 Name,
      title        [0]     IA5String,
      number               EmployeeNumber,
      dateOfHire   [1]     Date,
      nameOfSpouse [2]     Name,
      children     [3]     IMPLICIT SEQUENCE OF ChildInformation,
      salary      INTEGER (0..10000) OPTIONAL
   }

There are seven total elements: one is optional and the others are required. The generated code is straightforward:

   public static boolean isRequired (String elemName)
      throws Asn1InvalidElemException
   {
      if (elemName.equals("salary")) {
         return false;
      }
      else if (elemName.equals("name")) {
         return true;
      }
      else if (elemName.equals("number")) {
         return true;
      }
      else if (elemName.equals("title")) {
         return true;
      }
      else if (elemName.equals("dateOfHire")) {
         return true;
      }
      else if (elemName.equals("nameOfSpouse")) {
         return true;
      }
      else if (elemName.equals("children")) {
         return true;
      }

      throw new Asn1InvalidElemException(elemName);
   }