Package com.netflix.governator.annotations

Examples of com.netflix.governator.annotations.Configuration


        this.configurationDocumentation = configurationDocumentation;
    }

    void assignConfiguration(Object obj, Field field, Map<String, String> contextOverrides) throws Exception
    {
        Configuration configuration = field.getAnnotation(Configuration.class);
        String configurationName = configuration.value();
        ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName, contextOverrides));

        Object value = null;

        boolean has = configurationProvider.has(key);
        if ( has )
        {
            try
            {
                if ( Supplier.class.isAssignableFrom(field.getType()) )
                {
                    ParameterizedType type = (ParameterizedType)field.getGenericType();
                    Type actualType = type.getActualTypeArguments()[0];
                    Class<?> actualClass;
                    if (actualType instanceof Class) {
                        actualClass = (Class<?>) actualType;
                    } else if (actualType instanceof ParameterizedType) {
                        actualClass = (Class<?>) ((ParameterizedType) actualType).getRawType();
                    } else {
                        throw new UnsupportedOperationException("Supplier parameter type " + actualType
                                + " not supported (" + field.getName() + ")");
                    }
                    Supplier<?> current = (Supplier<?>)field.get(obj);
                    value = getConfigurationSupplier(field, key, actualClass, current);
                    if ( value == null )
                    {
                        log.error("Field type not supported: " + actualClass + " (" + field.getName() + ")");
                        field = null;
                    }
                }
                else
                {
                    Supplier<?> supplier = getConfigurationSupplier(field, key, field.getType(), Suppliers.ofInstance(field.get(obj)));
                    if ( supplier == null )
                    {
                        log.error("Field type not supported: " + field.getType() + " (" + field.getName() + ")");
                        field = null;
                    }
                    else
                    {
                        value = supplier.get();
                    }
                }
            }
            catch ( IllegalArgumentException e )
            {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
            catch ( ConversionException e )
            {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        }

        if ( field != null )
        {
            String defaultValue;
            if ( Supplier.class.isAssignableFrom(field.getType()) )
            {
                defaultValue = String.valueOf(((Supplier<?>)field.get(obj)).get());
            }
            else
            {
                defaultValue = String.valueOf(field.get(obj));
            }

            String documentationValue;
            if ( has )
            {
                field.set(obj, value);

                documentationValue = String.valueOf(value);
                if ( Supplier.class.isAssignableFrom(field.getType()) )
                {
                    documentationValue = String.valueOf(((Supplier<?>)value).get());
                }
                else
                {
                    documentationValue = String.valueOf(documentationValue);
                }
            }
            else
            {
                documentationValue = "";
            }
            configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue, documentationValue, configuration.documentation());
        }
    }
View Full Code Here


   
    static <T> Map<String, Supplier<?>> getMethodSuppliers(Class<T> configClass, DynamicPropertyFactory propertyFactory, AbstractConfiguration configuration) {
        final Map<String, Supplier<?>> properties = Maps.newHashMap();
       
        for (Method method : configClass.getMethods()) {
            Configuration c = method.getAnnotation(Configuration.class);
            if (c == null)
                continue;
            String defaultValue = null;
            DefaultValue dv = method.getAnnotation(DefaultValue.class);
            if (dv != null)
View Full Code Here

    static void assignFieldValues(final Object obj, Class<?> type, DynamicPropertyFactory propertyFactory, AbstractConfiguration configuration) throws Exception {
       
        // Iterate through all fields and set initial value as well as set up dynamic properties
        // where necessary
        for (final Field field : type.getFields()) {
            Configuration c = field.getAnnotation(Configuration.class);
            if (c == null)
                continue;
           
            String defaultValue = field.get(obj).toString();
            String name         = ConfigurationProxyUtils.getPropertyName(field, c);
View Full Code Here

TOP

Related Classes of com.netflix.governator.annotations.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.