View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.integration.cdi.extension;
17  
18  import java.util.List;
19  
20  import javax.enterprise.inject.spi.Bean;
21  
22  import de.smartics.exceptions.i18n.message.MessageParam;
23  import de.smartics.properties.integration.cdi.ConfigurationValidationNumberCode;
24  
25  /**
26   * This MessageBean is used when a miss configuration happened. Either when no
27   * class could be found or too many classes with the marker annotation
28   * {@link de.smartics.properties.integration.cdi.Application}.
29   */
30  public class ConfigurationMessageBean extends
31      de.smartics.exceptions.i18n.AbstractMessageBean
32  {
33    // ********************************* Fields *********************************
34  
35    // --- constants ------------------------------------------------------------
36  
37    /**
38     * The class version identifier.
39     */
40    private static final long serialVersionUID = 1L;
41  
42    // --- members --------------------------------------------------------------
43  
44    /**
45     * The beans that have been annotated with the
46     * {@link de.smartics.properties.integration.cdi.Application} annotation.
47     */
48    @MessageParam
49    private final List<Bean<?>> annotatedBeans; // NOPMD
50  
51    // ****************************** Initializer *******************************
52  
53    // ****************************** Constructors ******************************
54  
55    /**
56     * Constructor when too many classes are annotated with the marker annotation
57     * {@link de.smartics.properties.integration.cdi.Application}.
58     *
59     * @param annotatedBeans the beans that have been annotated with the
60     *          {@link de.smartics.properties.integration.cdi.Application}
61     *          annotation.
62     */
63    public ConfigurationMessageBean(final List<Bean<?>> annotatedBeans)
64    {
65      this(ConfigurationValidationNumberCode.TOO_MANY_CLASSES_ANNOTATED,
66          annotatedBeans);
67    }
68  
69    /**
70     * Constructor used when no class could be found with the marker annotation
71     * {@link de.smartics.properties.integration.cdi.Application}.
72     */
73    public ConfigurationMessageBean()
74    {
75      this(ConfigurationValidationNumberCode.MARKER_ANNOTATION_NOT_FOUND, null);
76    }
77  
78    /**
79     * Internal constructor.
80     *
81     * @param code the number code.
82     * @param annotatedBeans the beans that have been annotated with the
83     *          {@link de.smartics.properties.integration.cdi.Application}
84     *          annotation.
85     */
86    private ConfigurationMessageBean(
87        final ConfigurationValidationNumberCode code,
88        final List<Bean<?>> annotatedBeans)
89    {
90      super(code);
91      this.annotatedBeans = annotatedBeans;
92    }
93  
94    // ****************************** Inner Classes *****************************
95  
96    // ********************************* Methods ********************************
97  
98    // --- init -----------------------------------------------------------------
99  
100   // --- get&set --------------------------------------------------------------
101 
102   // --- business -------------------------------------------------------------
103 
104   /**
105    * Creates a message bean for convenience.
106    *
107    * @return the message bean.
108    */
109   public static ConfigurationMessageBean noClassAnnotated()
110   {
111     return new ConfigurationMessageBean();
112   }
113 
114   /**
115    * Creates a message bean for convenience.
116    *
117    * @param annotatedBeans the annotated beans list.
118    * @return the message bean.
119    */
120   public static ConfigurationMessageBean tooManyClassesAnnotated(
121       final List<Bean<?>> annotatedBeans)
122   {
123     return new ConfigurationMessageBean(annotatedBeans);
124   }
125 
126   // --- object basics --------------------------------------------------------
127 
128 }