private void validateSuperiority(ObjectClass superior, ArrayList<LocalizableMessage> errors) {
   if (superior.getNameOrOID().equalsIgnoreCase(objectClass.getNameOrOID())) {
     errors.add(ERR_CTRL_PANEL_OBJECTCLASS_CANNOT_BE_ITS_SUPERIOR.get());
     setPrimaryInvalid(lSuperior);
     return;
   }
   for (ObjectClass obj : superior.getSuperiorClasses()) {
     if (superior.getNameOrOID().equalsIgnoreCase(obj.getNameOrOID())) {
       errors.add(ERR_CTRL_PANEL_OBJECTCLASS_IS_SUPERIOR_OF_SUPERIOR.get(obj.getNameOrOID()));
       setPrimaryInvalid(lSuperior);
       return;
     }
     validateSuperiority(obj, errors);
   }
 }
  private void saveChanges(boolean modal, ArrayList<LocalizableMessage> errors) {
    for (JLabel label : labels) {
      setPrimaryValid(label);
    }
    String n = getObjectClassName();
    LocalizableMessageBuilder err = new LocalizableMessageBuilder();
    if (n.length() == 0) {
      errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_REQUIRED.get());
      setPrimaryInvalid(lName);
    } else if (!n.equalsIgnoreCase(objectClass.getNameOrOID())) {
      if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) {
        errors.add(ERR_CTRL_PANEL_INVALID_OBJECTCLASS_NAME.get(err));
        setPrimaryInvalid(lName);
        err = new LocalizableMessageBuilder();
      } else {
        LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema);
        if (elementType != null) {
          errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_ALREADY_IN_USE.get(n, elementType));
          setPrimaryInvalid(lName);
        }
      }
    }
    n = oid.getText().trim();
    if (n.length() > 0 && !n.equalsIgnoreCase(objectClass.getOID())) {
      if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) {
        errors.add(ERR_CTRL_PANEL_OID_NOT_VALID.get(err));
        setPrimaryInvalid(lOID);
        err = new LocalizableMessageBuilder();
      } else {
        LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema);
        if (elementType != null) {
          errors.add(ERR_CTRL_PANEL_OID_ALREADY_IN_USE.get(n, elementType));
          setPrimaryInvalid(lOID);
        }
      }
    }

    Collection<String> aliases = getAliases();
    Collection<String> oldAliases = getAliases(objectClass);

    if (!aliases.equals(oldAliases)) {
      for (String alias : aliases) {
        if (alias.trim().length() == 0) {
          errors.add(ERR_CTRL_PANEL_EMPTY_ALIAS.get());
          setPrimaryInvalid(lAliases);
        } else {
          boolean notPreviouslyDefined = true;
          for (String oldAlias : oldAliases) {
            if (oldAlias.equalsIgnoreCase(alias)) {
              notPreviouslyDefined = false;
              break;
            }
          }
          if (notPreviouslyDefined) {
            LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(alias, schema);
            if (elementType != null) {
              errors.add(ERR_CTRL_PANEL_ALIAS_ALREADY_IN_USE.get(n, elementType));
              setPrimaryInvalid(lAliases);
            }
          }
        }
      }
    }

    // validate the superiority.
    for (ObjectClass superior : getObjectClassSuperiors()) {
      validateSuperiority(superior, errors);
    }
    checkCompatibleSuperiors(getObjectClassSuperiors(), getObjectClassType(), errors);

    if (errors.isEmpty()) {
      ProgressDialog dlg =
          new ProgressDialog(
              Utilities.createFrame(),
              Utilities.getParentDialog(this),
              INFO_CTRL_PANEL_MODIFY_ATTRIBUTE_TITLE.get(),
              getInfo());

      ModifyObjectClassTask newTask =
          new ModifyObjectClassTask(getInfo(), dlg, objectClass, getNewObjectClass());
      for (ConfigurationElementCreatedListener listener :
          getConfigurationElementCreatedListeners()) {
        newTask.addConfigurationElementCreatedListener(listener);
      }
      for (Task task : getInfo().getTasks()) {
        task.canLaunch(newTask, errors);
      }
      if (errors.isEmpty()) {
        launchOperation(
            newTask,
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUMMARY.get(ocName),
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_COMPLETE.get(),
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUCCESSFUL.get(ocName),
            ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_SUMMARY.get(),
            ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_DETAILS.get(ocName),
            null,
            dlg);
        dlg.setVisible(true);
      }
    }

    if (!errors.isEmpty()) {
      displayErrorDialog(errors);
    }
  }