IsRequired
Prev Chapter 18. Generated Metadata Methods Next

IsRequired

The IsRequired method has the following signature:

 public static bool 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 bool 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);
 }

Prev Up Next
Chapter 18. Generated Metadata Methods Home GetValueRange

AltStyle によって変換されたページ (->オリジナル) /