Skip to content

Add specialized filter on system property #87

Open
@charphi

Description

@charphi

Allow to filter providers using a system property.

Examples:

  • javax.net.ssl.trustStoreType=Windows-ROOT
  • jdk.tls.disabledAlgorithms=SSLv3, RC4
  • https.cipherSuites=SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,SSL_DHE_DSS_WITH_DES_CBC_SHA

The following code ...

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface Translator {

    String translate(String text);

    String getName();

    @ServiceFilter
    default boolean isEnabled() {
        return FILTER_ON_PROPERTY.apply(getName());
    }

    static Predicate<String> FILTER_ON_PROPERTY = getFilter("translators", ',', true, true, false);
}

static Predicate<String> getFilter(String key, char separator, boolean onMatch, boolean onMiss, boolean caseSensitive) {
    String property = System.getProperty(key);
    if (property == null) return value -> onMiss;
    String[] values = property.split(String.valueOf(separator), -1);
    return value -> Stream.of(values).anyMatch(caseSensitive ? value::equals : value::equalsIgnoreCase) ^ onMatch;
}

... could be simplified as :

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface Translator {

    String translate(String text);

    @ServiceFilterOnProperty(key = "translators", separator = ',', onMatch = true, onMiss = true, caseSensitive = false)
    String getName();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions