io.rxmicro.config.internal.model.MapConfigProperties Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2020. https://rxmicro.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.rxmicro.config.internal.model;
import io.rxmicro.config.AsMapConfig;
import io.rxmicro.logger.Logger;
import io.rxmicro.logger.LoggerFactory;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import static io.rxmicro.common.util.ExCollectors.toOrderedSet;
import static io.rxmicro.common.util.ExCollectors.toUnmodifiableOrderedMap;
import static io.rxmicro.common.util.Formats.format;
import static io.rxmicro.common.util.Strings.capitalize;
import static io.rxmicro.config.internal.Converters.convertWithoutTypeDefinition;
import static io.rxmicro.config.internal.model.AbstractDefaultConfigValueBuilder.getCurrentDefaultConfigValueStorage;
import static java.util.Map.entry;
/**
* @author nedis
* @since 0.7
*/
public final class MapConfigProperties extends ConfigProperties {
private static final Logger LOGGER = LoggerFactory.getLogger(MapConfigProperties.class);
private final AsMapConfig asMapConfig;
private final Map data = new LinkedHashMap<>();
public MapConfigProperties(final String namespace,
final AsMapConfig asMapConfig) {
super(namespace);
this.asMapConfig = asMapConfig;
}
@Override
protected Logger getLogger() {
return LOGGER;
}
@Override
protected void loadDefaultConfigValues(final DebugMessageBuilder debugMessageBuilder) {
final String prefix = namespace + ".";
final Set> resolvedEntries = new LinkedHashSet<>();
final DefaultConfigValueStorage storage = getCurrentDefaultConfigValueStorage();
if (storage.hasDefaultStringValuesStorage()) {
for (final Map.Entry entry : storage.getDefaultStringValuesStorage().entrySet()) {
if (entry.getKey().startsWith(prefix)) {
resolvedEntries.add(entry(entry.getKey().substring(prefix.length()), entry.getValue()));
}
}
}
if (storage.hasDefaultSupplierValuesStorage()) {
for (final Map.Entry> entry : storage.getDefaultSupplierValuesStorage().entrySet()) {
if (entry.getKey().startsWith(prefix)) {
resolvedEntries.add(entry(entry.getKey().substring(prefix.length()), String.valueOf(entry.getValue().get())));
}
}
}
addResolvedEntries(resolvedEntries, "default config storage", debugMessageBuilder);
}
@Override
protected void loadResource(final Supplier>> propertiesSupplier,
final String resourceType,
final String resourceName,
final boolean useFullName,
final DebugMessageBuilder debugMessageBuilder) {
final Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy