use of org.wildfly.swarm.spi.api.annotations.Configurable in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method scan.
protected void scan(ConfigKey prefix, Object instance, Class<?> curClass, boolean implicit) throws Exception {
if (curClass == null || curClass == Object.class || isBlacklisted(curClass)) {
return;
}
Field[] fields = curClass.getDeclaredFields();
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
if (isBlacklisted(field)) {
continue;
}
if (implicit || field.getAnnotation(Configurable.class) != null || field.getAnnotation(Configurables.class) != null) {
if (isConfigurableType(field.getType())) {
List<ConfigKey> names = namesFor(prefix, field);
boolean configured = false;
for (ConfigKey name : names) {
if (!seen(name)) {
ConfigurableHandle configurable = new ObjectBackedConfigurableHandle(name, instance, field);
this.configurables.add(configurable);
configured = configure(configurable);
}
if (configured) {
break;
}
}
}
}
}
}
if (!rescanning) {
Method[] methods = curClass.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Configurable.class)) {
ConfigKey subPrefix = prefix.append(nameFor(method));
if (method.getParameterCount() == 1) {
// configuration keys that imply we want it.
if (this.configView.hasKeyOrSubkeys(subPrefix)) {
Object lambda = createLambda(subPrefix, method);
if (lambda != null) {
method.invoke(instance, lambda);
}
}
} else if (method.getParameterCount() == 2) {
List<SimpleKey> keysWithConfiguration = this.configView.simpleSubkeys(subPrefix);
if (!keysWithConfiguration.isEmpty()) {
for (SimpleKey key : keysWithConfiguration) {
ConfigKey itemPrefix = subPrefix.append(key);
Object lambda = createLambda(itemPrefix, method);
if (lambda != null) {
method.invoke(instance, key.name(), lambda);
}
}
}
}
}
}
}
scan(prefix, instance, curClass.getSuperclass(), implicit);
}
use of org.wildfly.swarm.spi.api.annotations.Configurable in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method nameFor.
protected ConfigKey nameFor(Fraction fraction) throws Exception {
Configurable anno = fraction.getClass().getAnnotation(Configurable.class);
if (anno != null) {
return ConfigKey.parse(anno.value());
}
SimpleKey key = getKey(fraction);
if (key == null) {
key = new SimpleKey(fraction.getClass().getSimpleName().replace("Fraction", "").toLowerCase());
}
return ConfigKey.of("swarm").append(key);
}
use of org.wildfly.swarm.spi.api.annotations.Configurable in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method namesFor.
protected List<ConfigKey> namesFor(ConfigKey prefix, Field field) {
List<ConfigKey> names = new ArrayList<>();
Configurables plural = field.getAnnotation(Configurables.class);
if (plural != null) {
for (Configurable each : plural.value()) {
ConfigKey key = nameFor(prefix, each);
if (key != null) {
names.add(key);
}
}
} else {
Configurable[] annos = field.getAnnotationsByType(Configurable.class);
if (annos != null && annos.length > 0) {
for (Configurable anno : annos) {
ConfigKey key = nameFor(prefix, anno);
if (key != null) {
names.add(key);
}
}
} else {
ConfigKey key = handleDeploymentConfiguration(prefix.append(nameFor(field)));
names.add(key);
}
}
return names;
}
Aggregations