1 package eu.sydisnet.blog.samples.deltaspike.cdi12.boundary;
2
3 import eu.sydisnet.blog.samples.deltaspike.cdi12.control.MessageFormatter;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6
7 import javax.annotation.PostConstruct;
8 import javax.annotation.PreDestroy;
9 import javax.enterprise.context.Dependent;
10 import javax.inject.Inject;
11 import java.lang.invoke.MethodHandles;
12
13
14
15
16
17
18
19
20
21 @Dependent
22 public class DependentHelloService {
23
24
25
26
27 private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
28
29
30
31
32 private static final String UNKNOWN_USERNAME = "M. John Doe";
33
34
35
36
37 private String defaultMessage;
38
39
40
41
42 @Inject
43 private MessageFormatter messageFormatter;
44
45
46
47
48
49
50 @PostConstruct
51 void initBean() {
52 defaultMessage = "Welcome %s !";
53
54 LOG.info(String.format("##### %s stopped !", MethodHandles.lookup().lookupClass().getSimpleName()));
55 }
56
57
58
59
60
61
62
63
64 @PreDestroy
65 void tearDown() {
66 LOG.info(String.format("##### %s stopped !", MethodHandles.lookup().lookupClass().getSimpleName()));
67 }
68
69
70
71
72
73
74
75 public String sayHello(final String userName) {
76 if (userName == null || userName.isEmpty()) {
77 return messageFormatter.format(defaultMessage, UNKNOWN_USERNAME);
78 }
79
80 return messageFormatter.format(defaultMessage, userName);
81 }
82 }