use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class MapConfigNodeFactory method load.
protected static void load(ConfigNode config, List<?> input) {
int num = input.size();
for (int i = 0; i < num; ++i) {
Object value = input.get(i);
ConfigNode child = load(value);
config.child(new SimpleKey("" + i), child);
}
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method scanSubresources.
protected void scanSubresources(ConfigKey prefix, Object instance) throws Exception {
Method method = getSubresourcesMethod(instance);
if (method == null) {
return;
}
Object subresources = method.invoke(instance);
Field[] fields = subresources.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(SubresourceInfo.class) == null && List.class.isAssignableFrom(field.getType())) {
continue;
}
field.setAccessible(true);
Object value = field.get(subresources);
ConfigKey subPrefix = prefix.append(nameFor(field));
if (seen(subPrefix)) {
continue;
}
if (value != null && value instanceof List) {
int index = 0;
Set<SimpleKey> seenKeys = new HashSet<>();
for (Object each : ((List) value)) {
SimpleKey key = getKey(each);
ConfigKey itemPrefix = null;
if (key != null) {
seenKeys.add(key);
itemPrefix = subPrefix.append(key);
} else {
itemPrefix = subPrefix.append("" + index);
}
scan(itemPrefix, each, true);
++index;
}
List<SimpleKey> keysWithConfiguration = this.configView.simpleSubkeys(subPrefix);
keysWithConfiguration.removeAll(seenKeys);
if (!keysWithConfiguration.isEmpty()) {
Method factoryMethod = getKeyedFactoryMethod(instance, field);
if (factoryMethod != null) {
for (SimpleKey key : keysWithConfiguration) {
ConfigKey itemPrefix = subPrefix.append(key);
Object lambda = createLambda(itemPrefix, factoryMethod);
if (lambda != null) {
factoryMethod.invoke(instance, key.name(), lambda);
}
}
}
}
} else {
// Singleton resources, without key
if (value == null) {
// configuration keys that imply we want it.
if (this.configView.hasKeyOrSubkeys(subPrefix)) {
Method factoryMethod = getNonKeyedFactoryMethod(instance, field);
if (factoryMethod != null) {
Object lambda = createLambda(subPrefix, factoryMethod);
if (lambda != null) {
factoryMethod.invoke(instance, lambda);
}
}
}
} else {
scan(subPrefix, value, true);
}
}
}
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class SocketBindingGroupExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
for (SimpleKey groupName : configuredGroups) {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
AtomicBoolean producerRequired = new AtomicBoolean(false);
if (groups.stream().noneMatch(e -> e.getQualifiers().stream().anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {
SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");
applyConfiguration(group);
if (producerRequired.get()) {
CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class).beanClass(SocketBindingGroupExtension.class).scope(ApplicationScoped.class).addQualifier(AnyLiteral.INSTANCE).addQualifier(new NamedLiteral(group.name())).createSupplier(() -> group).addType(SocketBindingGroup.class).addType(Object.class).build();
abd.addBean(interfaceBean);
}
}
}
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class ConfigNode method valueOf.
/**
* Retrieve a value.
*
* @param key The possibly-complex key of the value to retrieve.
* @return The value of {@code null} if none.
*/
public Object valueOf(ConfigKey key) {
SimpleKey head = key.head();
if (head == ConfigKey.EMPTY) {
if (this.value == null && this.children != null) {
return this;
}
return this.value;
}
ConfigNode child = child(head);
if (child != null) {
ConfigKey rest = key.subkey(1);
return child.valueOf(rest);
}
return null;
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class CompositeKeyTest method testSubkey.
@Test
public void testSubkey() {
CompositeKey key = new CompositeKey("foo", "bar", "baz");
assertThat(key.subkey(1).head()).isEqualTo(new SimpleKey("bar"));
assertThat(key.subkey(2).head()).isEqualTo(new SimpleKey("baz"));
assertThat(key.subkey(3).head()).isEqualTo(ConfigKey.EMPTY);
}
Aggregations