Skip to content
Snippets Groups Projects
Commit 31da9d5e authored by Bernhard Johannes Berger's avatar Bernhard Johannes Berger
Browse files

Added a method to create Components and let the framework do the type lookup and init call.

parent 62a84bc4
No related branches found
No related tags found
No related merge requests found
Pipeline #280182 passed
package de.evoal.core.api.cdi;
import de.evoal.core.api.utils.Requirements;
import de.evoal.languages.model.base.Instance;
import lombok.extern.slf4j.Slf4j;
import org.apache.deltaspike.core.api.provider.BeanProvider;
......@@ -61,6 +62,23 @@ public final class BeanFactory {
}
}
public static <T extends EvoalComponent<T>> T createComponent(final Class<T> type, final Instance configuration) {
Requirements.requireNotNull(type);
Requirements.requireNotNull(configuration);
final String name = configuration.getDefinition().getName();
log.info("Creating bean for instance of type {}.", name);
try {
return BeanProvider.getContextualReference(name, false, type)
.init(configuration);
} catch(final IllegalStateException | IllegalArgumentException e) {
log.error("Failed to create contextual reference of type '{}' with name '{}'.", type, name);
logInstantiationError(type, e);
throw e;
}
}
public static void injectFields(final Object instance) {
BeanProvider.injectFields(instance);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment