Search in sources :

Example 1 with ConfigKey

use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.

the class ConfigNode method recursiveChild.

/**
 * Set the value of a descendant.
 *
 * <p>Any intermediate leafs will be created as-needed.</p>
 *
 * @param key   The possibly-complex key to a descendant.
 * @param value The value to set.
 */
public void recursiveChild(ConfigKey key, Object value) {
    SimpleKey head = key.head();
    if (head == ConfigKey.EMPTY) {
        value(value);
    }
    ConfigKey rest = key.subkey(1);
    if (rest == ConfigKey.EMPTY) {
        child(head, value);
    } else {
        ConfigNode child = child(head);
        if (child == null) {
            child = new ConfigNode();
            child(head, child);
        }
        child.recursiveChild(rest, value);
    }
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey)

Example 2 with ConfigKey

use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.

the class ConfigNode method descendant.

ConfigNode descendant(ConfigKey key) {
    SimpleKey head = key.head();
    if (head == ConfigKey.EMPTY) {
        return this;
    }
    ConfigKey rest = key.subkey(1);
    ConfigNode child = child(head);
    if (child == null) {
        return null;
    }
    return child.descendant(rest);
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey)

Example 3 with ConfigKey

use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.

the class ConfigNode method allKeysRecursively.

/**
 * Retrieve all descendent keys.
 *
 * @return A stream of all descendent keys.
 */
public Stream<ConfigKey> allKeysRecursively() {
    Stream<ConfigKey> str = Stream.empty();
    if (this.value != null) {
        str = Stream.of(ConfigKey.EMPTY);
    }
    str = Stream.concat(str, this.children.entrySet().stream().flatMap((kv) -> {
        ConfigKey key = kv.getKey();
        Object value = kv.getValue();
        if (value instanceof ConfigNode) {
            return ((ConfigNode) value).allKeysRecursively().map(childKey -> key.append(childKey));
        }
        return Stream.empty();
    }));
    return str;
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey)

Example 4 with ConfigKey

use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.

the class EnvironmentConfigNodeFactory method load.

protected static void load(ConfigNode config, Map<String, String> input) {
    Set<String> names = input.keySet();
    for (String name : names) {
        if (name.startsWith("swarm.")) {
            String value = input.get(name);
            ConfigKey key = ConfigKey.parse(name);
            config.recursiveChild(key, value);
        }
    }
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey)

Example 5 with ConfigKey

use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.

the class ConfigKeyTest method testOneSegmentInsideDelim.

@Test
public void testOneSegmentInsideDelim() {
    ConfigKey key = ConfigKey.parse("[foo]");
    assertThat(key.head().name()).isEqualTo("foo");
    assertThat(key.name()).isEqualTo("foo");
    assertThat(key).isInstanceOf(SimpleKey.class);
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) Test(org.junit.Test)

Aggregations

ConfigKey (org.wildfly.swarm.spi.api.config.ConfigKey)26 SimpleKey (org.wildfly.swarm.spi.api.config.SimpleKey)7 Test (org.junit.Test)6 List (java.util.List)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Any (javax.enterprise.inject.Any)3 Instance (javax.enterprise.inject.Instance)3 Inject (javax.inject.Inject)3 Field (java.lang.reflect.Field)2 HashSet (java.util.HashSet)2 Consumer (java.util.function.Consumer)2 Interface (org.wildfly.swarm.container.Interface)2 OutboundSocketBinding (org.wildfly.swarm.spi.api.OutboundSocketBinding)2 SocketBinding (org.wildfly.swarm.spi.api.SocketBinding)2 SocketBindingGroup (org.wildfly.swarm.spi.api.SocketBindingGroup)2 Configurable (org.wildfly.swarm.spi.api.annotations.Configurable)2 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)2 ConfigurationManager (com.netflix.config.ConfigurationManager)1