View Javadoc

1   /*
2    * Copyright 2009-2012 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.maven.apidoc;
17  
18  import java.util.List;
19  
20  import de.smartics.analysis.javadoc.log.JavadocMessageLogger;
21  import de.smartics.analysis.javadoc.log.message.IssueMessage;
22  
23  /**
24   * A helper to control access to the filtered messages.
25   */
26  final class MessageHelper
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    // --- members --------------------------------------------------------------
33  
34    /**
35     * The configuration to control the report rendering.
36     */
37    private final JavadocMessageConfig messageConfig;
38  
39    /**
40     * The filtered error messages.
41     */
42    private final List<IssueMessage> errMessages;
43  
44    /**
45     * The filtered warn messages.
46     */
47    private final List<IssueMessage> warnMessages;
48  
49    /**
50     * The filtered notice messages.
51     */
52    private final List<IssueMessage> noticeMessages;
53  
54    // ****************************** Initializer *******************************
55  
56    // ****************************** Constructors ******************************
57  
58    /**
59     * Default constructor.
60     *
61     * @param messageConfig the configuration to control the report rendering.
62     * @param logger the information to render to the report.
63     */
64    public MessageHelper(final JavadocMessageConfig messageConfig,
65        final JavadocMessageLogger logger)
66    {
67      this.messageConfig = messageConfig;
68      this.errMessages = messageConfig.filter(logger.getErrMessages());
69      this.warnMessages = messageConfig.filter(logger.getWarnMessages());
70      this.noticeMessages = messageConfig.filter(logger.getNoticeMessages());
71    }
72  
73    // ****************************** Inner Classes *****************************
74  
75    // ********************************* Methods ********************************
76  
77    // --- init -----------------------------------------------------------------
78  
79    // --- get&set --------------------------------------------------------------
80  
81    /**
82     * Returns the filtered error messages.
83     *
84     * @return the filtered error messages.
85     */
86    public List<IssueMessage> getErrMessages()
87    {
88      return errMessages;
89    }
90  
91    /**
92     * Returns the filtered warn messages.
93     *
94     * @return the filtered warn messages.
95     */
96    public List<IssueMessage> getWarnMessages()
97    {
98      return warnMessages;
99    }
100 
101   /**
102    * Returns the filtered notice messages.
103    *
104    * @return the filtered notice messages.
105    */
106   public List<IssueMessage> getNoticeMessages()
107   {
108     return noticeMessages;
109   }
110 
111   // --- business -------------------------------------------------------------
112 
113   /**
114    * Checks if there are messages logged.
115    *
116    * @return <code>true</code> if at least one message has been logged,
117    *         <code>false</code> otherwise.
118    */
119   public boolean hasMessages()
120   {
121     return (!errMessages.isEmpty() || !warnMessages.isEmpty() || (messageConfig
122         .isNoticeMessagesRendered() && !noticeMessages.isEmpty()));
123   }
124 
125   // --- object basics --------------------------------------------------------
126 
127 }