View Javadoc
1   package eu.sydisnet.blog.samples.deltaspike.cdi12.control;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   import javax.annotation.PostConstruct;
7   import javax.annotation.PreDestroy;
8   import javax.enterprise.context.Dependent;
9   import java.lang.invoke.MethodHandles;
10  
11  /**
12   * Component in charge of formatting a message.
13   *
14   * @author sydisnet
15   * @version 1.0.0
16   */
17  @Dependent
18  public class MessageFormatter {
19  
20      /**
21       * Static Logger.
22       */
23      private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
24  
25      /**
26       * Method called by the CDI container when the bean is retrieved from
27       * {@link javax.enterprise.inject.spi.BeanManager}. See the JSR 250 Callback {@link javax.annotation.PostConstruct}
28       * annotation.
29       */
30      @PostConstruct
31      void initBean() {
32          LOG.info(String.format("##### %s started !", MethodHandles.lookup().lookupClass().getSimpleName()));
33      }
34  
35      /**
36       * Method called by the CDI container before the destruction of the bean from the
37       * {@link javax.enterprise.inject.spi.BeanManager}. See the JSR 250 Callback {@link javax.annotation.PreDestroy}
38       * annotation.
39       */
40      @PreDestroy
41      void tearDown() {
42          LOG.info(String.format("##### %s stopped !", MethodHandles.lookup().lookupClass().getSimpleName()));
43      }
44  
45      /**
46       * Service in charge of formatting a template message.
47       *
48       * @param template the message template to process
49       * @param param the element to add to the message template
50       * @return the processed message
51       */
52      public String format(final String template, final String param) {
53          String result = String.format(template, param);
54  
55          return result;
56      }
57  }