@Override
  public void validate(DDMForm ddmForm) throws DDMFormValidationException {
    validateDDMFormLocales(ddmForm);

    validateDDMFormFields(
        ddmForm.getDDMFormFields(),
        new HashSet<String>(),
        ddmForm.getAvailableLocales(),
        ddmForm.getDefaultLocale());
  }
  protected void validateDDMFormLocales(DDMForm ddmForm) throws DDMFormValidationException {

    Locale defaultLocale = ddmForm.getDefaultLocale();

    if (defaultLocale == null) {
      throw new DDMFormValidationException(
          "The default locale property was never set for DDM form");
    }

    validateDDMFormAvailableLocales(ddmForm.getAvailableLocales(), defaultLocale);
  }
  @Override
  public String serialize(DDMForm ddmForm) {
    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    rootElement.addAttribute("available-locales", getAvailableLanguagesIds(ddmForm));
    rootElement.addAttribute("default-locale", LocaleUtil.toLanguageId(ddmForm.getDefaultLocale()));

    addDynamicElementElements(ddmForm.getDDMFormFields(), rootElement);

    return document.asXML();
  }