Skip to content

Commit aea5148

Browse files
committed
Weld: javadoc+checkstyle
1 parent 81768f8 commit aea5148

5 files changed

Lines changed: 82 additions & 21 deletions

File tree

docs/asciidoc/dependency-injection.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ include::modules/guice.adoc[]
1212

1313
include::modules/spring.adoc[]
1414

15-
include::di-weld.adoc[]
15+
include::modules/weld.adoc[]
File renamed without changes.

modules/jooby-weld/src/main/java/io/jooby/di/JoobyExtension.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.jooby.ServiceRegistry;
1515
import io.jooby.annotations.Path;
1616

17+
import javax.annotation.Nonnull;
1718
import javax.enterprise.context.ApplicationScoped;
1819
import javax.enterprise.event.Observes;
1920
import javax.enterprise.inject.literal.NamedLiteral;
@@ -25,29 +26,51 @@
2526
import javax.enterprise.inject.spi.ProcessAnnotatedType;
2627
import javax.enterprise.inject.spi.WithAnnotations;
2728
import javax.enterprise.inject.spi.configurator.BeanConfigurator;
28-
import javax.inject.Inject;
2929
import javax.inject.Provider;
3030
import java.lang.reflect.Type;
3131
import java.util.List;
3232
import java.util.Map;
3333
import java.util.Set;
3434
import java.util.function.Function;
3535

36+
/**
37+
* Weld extension. Exposes {@link Environment}, {@link Config} and application services into weld
38+
* container.
39+
*
40+
* Also, scan and register MVC routes annotated with {@link Path} annotation at top level class.
41+
*
42+
* @author edgar
43+
* @since 2.0.0
44+
*/
3645
public class JoobyExtension implements Extension {
3746
private final Jooby app;
3847

39-
@Inject
40-
public JoobyExtension(Jooby application) {
48+
/**
49+
* Creates a new Jooby extension.
50+
*
51+
* @param application Application.
52+
*/
53+
public JoobyExtension(@Nonnull Jooby application) {
4154
this.app = application;
4255
}
4356

44-
public void registerMvc(
45-
@Observes @WithAnnotations(Path.class) ProcessAnnotatedType<?> controller) {
46-
this.app.mvc(controller.getAnnotatedType().getJavaClass());
57+
/**
58+
* Register MVC routes annotated with {@link Path}.
59+
*
60+
* @param c Weld callback.
61+
*/
62+
public void registerMvc(@Observes @WithAnnotations(Path.class) ProcessAnnotatedType<?> c) {
63+
this.app.mvc(c.getAnnotatedType().getJavaClass());
4764
}
4865

49-
public void configureServices(@Observes AfterBeanDiscovery beanDiscovery,
50-
BeanManager beanManager) {
66+
/**
67+
* Configure application services into a weld container.
68+
*
69+
* @param beanDiscovery Bean discovery.
70+
* @param beanManager Bean Manager.
71+
*/
72+
public void configureServices(@Nonnull @Observes AfterBeanDiscovery beanDiscovery,
73+
@Nonnull BeanManager beanManager) {
5174
ServiceRegistry registry = app.getServices();
5275
Set<Map.Entry<ServiceKey<?>, Provider<?>>> entries = registry.entrySet();
5376
for (Map.Entry<ServiceKey<?>, Provider<?>> entry : entries) {
@@ -56,13 +79,18 @@ public void configureServices(@Observes AfterBeanDiscovery beanDiscovery,
5679
}
5780
}
5881

59-
public void configureEnv(@Observes AfterBeanDiscovery beanDiscovery,
60-
BeanManager beanManager) {
82+
/**
83+
* Configure {@link Environment} and {@link Config} into a weld container.
84+
*
85+
* @param abd Bean discovery.
86+
* @param bm Bean Manager.
87+
*/
88+
public void configureEnv(@Observes AfterBeanDiscovery abd, BeanManager bm) {
6189
Environment environment = app.getEnvironment();
6290
Config config = environment.getConfig();
6391

64-
registerSingleton(beanDiscovery, beanManager, Config.class, null, config);
65-
registerSingleton(beanDiscovery, beanManager, Environment.class, null, environment);
92+
registerSingleton(abd, bm, Config.class, null, config);
93+
registerSingleton(abd, bm, Environment.class, null, environment);
6694

6795
for (Map.Entry<String, ConfigValue> configEntry : config.entrySet()) {
6896
final String configKey = configEntry.getKey();
@@ -78,9 +106,9 @@ public void configureEnv(@Observes AfterBeanDiscovery beanDiscovery,
78106
configType = boolean.class;
79107
}
80108
NamedLiteral literal = NamedLiteral.of(configKey);
81-
AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(configClass);
82-
InjectionTarget<?> target = beanManager.createInjectionTarget(annotatedType);
83-
beanDiscovery.addBean()
109+
AnnotatedType<?> annotatedType = bm.createAnnotatedType(configClass);
110+
InjectionTarget<?> target = bm.createInjectionTarget(annotatedType);
111+
abd.addBean()
84112
.addQualifier(literal)
85113
.addTypes(configType, Object.class)
86114
.name(configKey)

modules/jooby-weld/src/main/java/io/jooby/di/WeldModule.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,52 @@
1414

1515
import static org.jboss.weld.environment.se.Weld.SHUTDOWN_HOOK_SYSTEM_PROPERTY;
1616

17+
/**
18+
* Weld module: https://jooby.io/modules/weld.
19+
*
20+
* Jooby integrates the {@link io.jooby.ServiceRegistry} into the Weld DI framework.
21+
*
22+
* Usage:
23+
*
24+
* <pre>{@code
25+
* {
26+
*
27+
*
28+
* install(new WeldModule());
29+
*
30+
* }
31+
*
32+
* }</pre>
33+
*
34+
* Require calls are going to be resolve by Weld now.
35+
*
36+
* Weld scan the {@link Jooby#getBasePackage()}, unless you specify them explicitly.
37+
*
38+
* @author edgar
39+
* @since 2.0.0
40+
*/
1741
public class WeldModule implements Extension {
1842

1943
private WeldContainer container;
2044

2145
private String[] packages;
2246

47+
/**
48+
* Creates a new weld module.
49+
*
50+
* @param container Container to use.
51+
*/
2352
public WeldModule(@Nonnull WeldContainer container) {
2453
this.container = container;
2554
}
2655

56+
/**
57+
* Creates a new weld module.
58+
*
59+
* @param packages Packages to scan, when empty it uses the {@link Jooby#getBasePackage()}.
60+
*/
2761
public WeldModule(@Nonnull String... packages) {
2862
this.packages = packages;
29-
this.container = null;
3063
}
3164

3265
@Override public boolean lateinit() {
@@ -35,7 +68,7 @@ public WeldModule(@Nonnull String... packages) {
3568

3669
@Override public void install(@Nonnull Jooby application) {
3770
if (container == null) {
38-
if (packages == null || packages.length == 0) {
71+
if (packages.length == 0) {
3972
String basePackage = application.getBasePackage();
4073
if (basePackage == null) {
4174
throw new IllegalStateException("Weld requires at least one package to scan.");

modules/jooby-weld/src/main/java/io/jooby/di/WeldRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
import static javax.enterprise.inject.Any.Literal.INSTANCE;
1919

20-
public class WeldRegistry implements Registry {
20+
class WeldRegistry implements Registry {
2121

2222
private WeldContainer container;
2323

24-
public WeldRegistry(WeldContainer container) {
24+
WeldRegistry(WeldContainer container) {
2525
this.container = container;
2626
}
2727

@@ -33,7 +33,7 @@ public WeldRegistry(WeldContainer container) {
3333
return require(ServiceKey.key(type, name));
3434
}
3535

36-
@Nonnull @Override public <T> T require(ServiceKey<T> key) {
36+
@Nonnull @Override public <T> T require(ServiceKey<T> key) {
3737
try {
3838
return container.select(key.getType(), literal(key)).get();
3939
} catch (Exception cause) {

0 commit comments

Comments
 (0)