class PluginNameValidator implements Validator {

    protected void validateName(final String name,
                                final ValidatorWithReasonCallback callback) {
        final String nameWithoutExtension = (name.lastIndexOf(".") >= 0
                ? name.substring(0,
                                 name.lastIndexOf(".")) : name);
        final RuleValidator nameValidator = getNameValidator();

        if (!nameValidator.isValid(nameWithoutExtension)) {
            callback.onFailure(nameValidator.getValidationError());
            return;
        }

        pluginServices.call(new RemoteCallback<Collection<Plugin>>() {
            @Override
            public void callback(final Collection<Plugin> plugins) {
                Set<Activity> activities = pluginsInfo.getAllPlugins(plugins);

                for (Activity activity : activities) {
                    if (activity.getName().equalsIgnoreCase(nameWithoutExtension)) {
                        callback.onFailure(ValidationErrorReason.DUPLICATED_NAME.name());
                        return;
                    }
                }

                callback.onSuccess();
            }
        }).listPlugins();
    }

}