public static Field[] parseFieldInstructions(
     GroupValue groupDef, TemplateRegistry registry, ConversionContext context) {
   SequenceValue instructions = groupDef.getSequence("Instructions");
   Field[] fields = new Field[instructions.getLength()];
   for (int i = 0; i < fields.length; i++) {
     GroupValue fieldDef = instructions.get(i).getGroup(0);
     FieldInstructionConverter converter = context.getConverter(fieldDef.getGroup());
     if (converter == null)
       throw new IllegalStateException(
           "Encountered unknown group "
               + fieldDef.getGroup()
               + "while processing field instructions "
               + groupDef.getGroup());
     fields[i] = converter.convert(fieldDef, registry, context);
   }
   return fields;
 }
 public Field convert(
     GroupValue fieldDef, TemplateRegistry templateRegistry, ConversionContext context) {
   String name = fieldDef.getString("Name");
   String namespace = "";
   if (fieldDef.isDefined("Ns")) namespace = fieldDef.getString("Ns");
   Field[] fields = parseFieldInstructions(fieldDef, templateRegistry, context);
   boolean optional = fieldDef.getBool("Optional");
   Group group = new Group(new QName(name, namespace), fields, optional);
   if (fieldDef.isDefined("TypeRef")) {
     GroupValue typeRef = fieldDef.getGroup("TypeRef");
     String typeRefName = typeRef.getString("Name");
     String typeRefNs = ""; // context.getNamespace();
     if (typeRef.isDefined("Ns")) typeRefNs = typeRef.getString("Ns");
     group.setTypeReference(new QName(typeRefName, typeRefNs));
   }
   if (fieldDef.isDefined("AuxId")) {
     group.setId(fieldDef.getString("AuxId"));
   }
   return group;
 }