Search in sources :

Example 1 with ValueValidator

use of com.hazelcast.config.properties.ValueValidator in project hazelcast by hazelcast.

the class DefaultDiscoveryService method buildProperties.

private Map<String, Comparable> buildProperties(DiscoveryStrategyFactory factory, DiscoveryStrategyConfig config, String className) {
    Collection<PropertyDefinition> propertyDefinitions = factory.getConfigurationProperties();
    if (propertyDefinitions == null) {
        return Collections.emptyMap();
    }
    Map<String, Comparable> properties = config.getProperties();
    Map<String, Comparable> mappedProperties = new HashMap<String, Comparable>();
    for (PropertyDefinition propertyDefinition : propertyDefinitions) {
        String propertyKey = propertyDefinition.key();
        Comparable value = properties.get(propertyKey);
        if (value == null) {
            if (!propertyDefinition.optional()) {
                throw new HazelcastException("Missing property '" + propertyKey + "' on discovery strategy '" + className + "' configuration");
            }
            continue;
        }
        TypeConverter typeConverter = propertyDefinition.typeConverter();
        Comparable mappedValue = typeConverter.convert(value);
        ValueValidator validator = propertyDefinition.validator();
        if (validator != null) {
            validator.validate(mappedValue);
        }
        mappedProperties.put(propertyKey, mappedValue);
    }
    return mappedProperties;
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) HazelcastException(com.hazelcast.core.HazelcastException) HashMap(java.util.HashMap) ValueValidator(com.hazelcast.config.properties.ValueValidator) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition)

Aggregations

PropertyDefinition (com.hazelcast.config.properties.PropertyDefinition)1 ValueValidator (com.hazelcast.config.properties.ValueValidator)1 HazelcastException (com.hazelcast.core.HazelcastException)1 TypeConverter (com.hazelcast.core.TypeConverter)1 HashMap (java.util.HashMap)1