// TODO get a factory or a stream writer - add more props
  public static OMElement serialize(RealmConfiguration realmConfig) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement rootElement =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_MANAGER));
    OMElement realmElement =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_REALM));
    String realmName = realmConfig.getRealmClassName();

    OMAttribute propAttr =
        factory.createOMAttribute(
            UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, realmName);
    realmElement.addAttribute(propAttr);

    rootElement.addChild(realmElement);

    OMElement mainConfig =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_CONFIGURATION));
    realmElement.addChild(mainConfig);

    OMElement addAdmin =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADD_ADMIN));
    OMElement adminUser =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADMIN_USER));
    OMElement adminUserNameElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_NAME));
    adminUserNameElem.setText(realmConfig.getAdminUserName());
    OMElement adminPasswordElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PASSWORD));
    addAdmin.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAddAdmin()));
    adminPasswordElem.setText(realmConfig.getAdminPassword());
    adminUser.addChild(adminUserNameElem);
    adminUser.addChild(adminPasswordElem);
    mainConfig.addChild(addAdmin);
    mainConfig.addChild(adminUser);

    OMElement adminRoleNameElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ADMIN_ROLE));
    adminRoleNameElem.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAdminRoleName()));
    mainConfig.addChild(adminRoleNameElem);

    OMElement systemUserNameElem =
        factory.createOMElement(
            new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_SYSTEM_USER_NAME));
    mainConfig.addChild(systemUserNameElem);

    // adding the anonymous user
    OMElement anonymousUserEle =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ANONYMOUS_USER));
    OMElement anonymousUserNameElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_NAME));
    OMElement anonymousPasswordElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_PASSWORD));
    anonymousUserEle.addChild(anonymousUserNameElem);
    anonymousUserEle.addChild(anonymousPasswordElem);
    mainConfig.addChild(anonymousUserEle);

    // adding the everyone role
    OMElement everyoneRoleNameElem =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_EVERYONE_ROLE));
    everyoneRoleNameElem.setText(
        UserCoreUtil.removeDomainFromName(realmConfig.getEveryOneRoleName()));
    mainConfig.addChild(everyoneRoleNameElem);

    // add the main config properties
    addPropertyElements(
        factory, mainConfig, null, realmConfig.getDescription(), realmConfig.getRealmProperties());
    // add the user store manager properties

    OMElement userStoreManagerElement =
        factory.createOMElement(
            new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER));
    realmElement.addChild(userStoreManagerElement);
    addPropertyElements(
        factory,
        userStoreManagerElement,
        realmConfig.getUserStoreClass(),
        realmConfig.getDescription(),
        realmConfig.getUserStoreProperties());

    RealmConfiguration secondaryRealmConfiguration = null;
    secondaryRealmConfiguration = realmConfig.getSecondaryRealmConfig();
    while (secondaryRealmConfiguration != null) {
      OMElement secondaryElement =
          factory.createOMElement(
              new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER));
      realmElement.addChild(secondaryElement);
      addPropertyElements(
          factory,
          secondaryElement,
          secondaryRealmConfiguration.getUserStoreClass(),
          secondaryRealmConfiguration.getDescription(),
          secondaryRealmConfiguration.getUserStoreProperties());
      secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
    }

    // add the user authorization properties
    OMElement authorizerManagerElement =
        factory.createOMElement(new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_ATHZ_MANAGER));
    realmElement.addChild(authorizerManagerElement);
    addPropertyElements(
        factory,
        authorizerManagerElement,
        realmConfig.getAuthorizationManagerClass(),
        realmConfig.getDescription(),
        realmConfig.getAuthzProperties());

    return rootElement;
  }