org.graylog2.bindings.NamedConfigParametersOverrideModule Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog2.bindings;
import com.github.joschi.jadconfig.Parameter;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Providers;
import org.reflections.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.github.joschi.jadconfig.ReflectionUtils.getAllFields;
import static com.github.joschi.jadconfig.ReflectionUtils.getFieldValue;
import static com.google.inject.name.Names.named;
import static org.graylog2.shared.utilities.StringUtils.f;
/**
* A Guice module which registers all fields of the provided objects annotated with {@link Parameter}
* as named bindings and optionally also adds bindings of the object instances themselves.
* For more flexibility, getter methods can also be used, which must be annotated with {@link NamedBindingOverride}.
* This class is based off {@link com.github.joschi.jadconfig.guice.NamedConfigParametersModule}
*
* @see com.google.inject.name.Named
*/
public class NamedConfigParametersOverrideModule extends AbstractModule {
private static final Logger LOG = LoggerFactory.getLogger(NamedConfigParametersOverrideModule.class);
private final Set
© 2015 - 2024 Weber Informatics LLC | Privacy Policy