private NXobject getNexusObjectForMetadataType(NXentry entry, MetadataType type) {
    if (type == null) {
      return entry;
    }

    switch (type) {
      case ENTRY:
        return entry;
      case INSTRUMENT:
        return entry.getInstrument();
      case SAMPLE:
        return entry.getSample();
      case USER:
        return entry.getUser();
      default:
        throw new IllegalArgumentException("Unknown metadata type " + type);
    }
  }
  /** Validate group 'entry' of type NXentry. */
  private void validateGroup_entry(final NXentry group) throws Exception {
    // validate that the group is not null
    validateGroupNotNull("entry", NXentry.class, group);

    // validate field 'title' of unknown type.
    final IDataset title = group.getTitle();
    validateFieldNotNull("title)", title);

    // validate field 'start_time' of type NX_DATE_TIME.
    final IDataset start_time = group.getStart_time();
    validateFieldNotNull("start_time)", start_time);
    validateFieldType("start_time)", start_time, NX_DATE_TIME);

    // validate field 'end_time' of type NX_DATE_TIME.
    final IDataset end_time = group.getEnd_time();
    validateFieldNotNull("end_time)", end_time);
    validateFieldType("end_time)", end_time, NX_DATE_TIME);

    // validate field 'definition' of unknown type.
    final IDataset definition = group.getDefinition();
    validateFieldNotNull("definition)", definition);
    validateFieldEnumeration("definition", definition, "NXrefscan");

    // validate child group 'instrument' of type NXinstrument
    // $groupNameInBaseClass = instrument
    validateGroup_entry_instrument(group.getInstrument());

    // validate child group 'sample' of type NXsample
    // $groupNameInBaseClass = sample
    validateGroup_entry_sample(group.getSample());

    // validate child group 'control' of type NXmonitor
    // $groupNameInBaseClass = monitor
    validateGroup_entry_control(group.getMonitor());

    // validate child group 'data' of type NXdata
    // $groupNameInBaseClass = data
    validateGroup_entry_data(group.getData());
  }