Search in sources :

Example 1 with Setting

use of org.n52.faroe.annotation.Setting in project arctic-sea by 52North.

the class OwsServiceIdentificationFactory method setAbstract.

@Setting(OwsServiceIdentificationFactorySettings.ABSTRACT)
public void setAbstract(Object description) throws ConfigurationError {
    Validation.notNull("Service Identification Abstract", description);
    if (description instanceof MultilingualString) {
        this.abstrakt = (MultilingualString) description;
    } else if (description instanceof String) {
        this.abstrakt = createFromString(description);
    } else {
        throw new ConfigurationError(String.format("%s is not supported as abstract!", description.getClass().getName()));
    }
    setRecreate();
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Setting(org.n52.faroe.annotation.Setting)

Example 2 with Setting

use of org.n52.faroe.annotation.Setting in project arctic-sea by 52North.

the class OwsServiceIdentificationFactory method setTitle.

@Setting(OwsServiceIdentificationFactorySettings.TITLE)
public void setTitle(Object title) throws ConfigurationError {
    Validation.notNull("Service Identification Title", title);
    if (title instanceof MultilingualString) {
        this.title = (MultilingualString) title;
    } else if (title instanceof String) {
        this.title = createFromString(title);
    } else {
        throw new ConfigurationError(String.format("%s is not supported as title!", title.getClass().getName()));
    }
    setRecreate();
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Setting(org.n52.faroe.annotation.Setting)

Example 3 with Setting

use of org.n52.faroe.annotation.Setting in project arctic-sea by 52North.

the class ServiceConfiguration method setDefaultLanguage.

@Setting(I18NSettings.I18N_DEFAULT_LANGUAGE)
public void setDefaultLanguage(final String defaultLanguage) {
    Validation.notNullOrEmpty("Default language as three character string", defaultLanguage);
    this.defaultLanguage = new Locale(defaultLanguage);
}
Also used : Locale(java.util.Locale) Setting(org.n52.faroe.annotation.Setting)

Example 4 with Setting

use of org.n52.faroe.annotation.Setting in project arctic-sea by 52North.

the class SettingValueFactory method newBooleanSettingValue.

/**
 * Constructs a new {@code Boolean} setting value from the supplied key and string value.
 *
 * @param key         the setting key
 * @param stringValue the value as string
 *
 * @return the implementation specific {@code SettingValue}
 */
default SettingValue<Boolean> newBooleanSettingValue(String key, String stringValue) {
    Boolean value;
    if (nullOrEmpty(stringValue)) {
        return newBooleanSettingValue(key, Boolean.FALSE);
    }
    String lc = stringValue.trim().toLowerCase(Locale.ROOT);
    switch(lc) {
        case "true":
        case "yes":
        case "on":
        case "1":
            return newBooleanSettingValue(key, Boolean.TRUE);
        case "false":
        case "no":
        case "off":
        case "0":
            return newBooleanSettingValue(key, Boolean.FALSE);
        default:
            throw new ConfigurationError(String.format("'%s' is not a valid boolean value", stringValue));
    }
}
Also used : MultilingualString(org.n52.janmayen.i18n.MultilingualString)

Example 5 with Setting

use of org.n52.faroe.annotation.Setting in project arctic-sea by 52North.

the class SettingsServiceImpl method configure.

private void configure(Object object, boolean persist) throws ConfigurationError {
    Class<?> clazz = object.getClass();
    if (clazz.getAnnotation(Configurable.class) == null) {
        return;
    }
    LOG.debug("Configuring object {}", object);
    for (Method method : clazz.getMethods()) {
        Setting s = method.getAnnotation(Setting.class);
        if (s != null) {
            String key = s.value();
            if (key == null || key.isEmpty()) {
                throw new ConfigurationError(String.format("Invalid value for @Setting: '%s'", key));
            } else if (getDefinitionByKey(key) == null && s.required()) {
                throw noSettingDefinitionFound(key);
            } else if (method.getParameterTypes().length != 1) {
                throw new ConfigurationError(String.format("Method %s annotated with @Setting in %s has a invalid method signature", method, clazz));
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new ConfigurationError(String.format("Non-public method %s annotated with @Setting in %s", method, clazz));
            } else {
                configure(new ConfigurableObject(method, object, key, s.required()), persist);
            }
        }
    }
}
Also used : Setting(org.n52.faroe.annotation.Setting) Configurable(org.n52.faroe.annotation.Configurable) Method(java.lang.reflect.Method)

Aggregations

Setting (org.n52.faroe.annotation.Setting)4 MultilingualString (org.n52.janmayen.i18n.MultilingualString)3 ConfigurationError (org.n52.faroe.ConfigurationError)2 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 Configurable (org.n52.faroe.annotation.Configurable)1