View Javadoc

1   /*
2    * Copyright 2007-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.exceptions.report.data;
17  
18  import com.thoughtworks.qdox.model.JavaClass;
19  import com.thoughtworks.qdox.model.JavaField;
20  
21  import de.smartics.exceptions.core.Code;
22  import de.smartics.exceptions.report.message.PlaceHolderInfo;
23  import de.smartics.util.lang.Arg;
24  
25  /**
26   * Information collected on an exception code. This is the information about an
27   * enumeration element of a code class.
28   */
29  public final class ExceptionCodeReportItem
30  {
31    // ********************************* Fields *********************************
32  
33    // --- constants ------------------------------------------------------------
34  
35    // --- members --------------------------------------------------------------
36  
37    /**
38     * The instance of the code.
39     */
40    private final Code code;
41  
42    /**
43     * The Javadoc information collected at class level.
44     */
45    private final JavaClass typeJavadoc;
46  
47    /**
48     * The Javadoc information collected at field level.
49     */
50    private final JavaField javadoc;
51  
52    /**
53     * The descriptions of the place holders.
54     */
55    private final PlaceHolderInfo placeHolderInfo;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    /**
62     * Default constructor.
63     *
64     * @param code the instance of the code.
65     * @param typeJavadoc the Javadoc information collected at class level.
66     * @param javadoc the Javadoc information collected at field level.
67     * @param placeHolderInfo the descriptions of the place holders.
68     * @throws NullPointerException if any of the arguments is <code>null</code>.
69     */
70    public ExceptionCodeReportItem(final Code code, final JavaClass typeJavadoc,
71        final JavaField javadoc, final PlaceHolderInfo placeHolderInfo)
72      throws NullPointerException
73    {
74      this.code = Arg.checkNotNull("code", code);
75      this.typeJavadoc = Arg.checkNotNull("typeJavadoc", typeJavadoc);
76      this.javadoc = Arg.checkNotNull("javadoc", javadoc);
77      this.placeHolderInfo = Arg.checkNotNull("placeHolderInfo", placeHolderInfo);
78    }
79  
80    // ****************************** Inner Classes *****************************
81  
82    // ********************************* Methods ********************************
83  
84    // --- init -----------------------------------------------------------------
85  
86    // --- get&set --------------------------------------------------------------
87  
88    /**
89     * Returns the descriptions of the place holders.
90     *
91     * @return the descriptions of the place holders.
92     */
93    public PlaceHolderInfo getPlaceHolderInfo()
94    {
95      return placeHolderInfo;
96    }
97  
98    /**
99     * Returns the comment to the report item type.
100    *
101    * @return the comment to the report item type.
102    */
103   public String getTypeComment()
104   {
105     return typeJavadoc.getComment();
106   }
107 
108   /**
109    * Returns the unique name of the report item.
110    *
111    * @return the unique name of the report item.
112    */
113   public String getName()
114   {
115     return code.getDisplayId();
116   }
117 
118   /**
119    * Returns the instance of the code.
120    *
121    * @return the instance of the code.
122    */
123   public Code getCode()
124   {
125     return code;
126   }
127 
128   /**
129    * Returns the comment to the report item.
130    *
131    * @return the comment to the report item.
132    */
133   public String getComment()
134   {
135     return javadoc.getComment();
136   }
137 
138   /**
139    * Returns the fully qualified name of the type that declares the code.
140    *
141    * @return the fully qualified name of the type that declares the code.
142    */
143   public String getDeclaringTypeName()
144   {
145     return typeJavadoc.getFullyQualifiedName();
146   }
147 
148   /**
149    * Returns the Javadoc information collected at class level.
150    *
151    * @return the Javadoc information collected at class level.
152    */
153   public JavaClass getTypeJavadoc()
154   {
155     return typeJavadoc;
156   }
157 
158   /**
159    * Returns the Javadoc information collected at field level.
160    *
161    * @return the Javadoc information collected at field level.
162    */
163   public JavaField getJavadoc()
164   {
165     return javadoc;
166   }
167 
168   /**
169    * Returns the source code information about the declaration of the exception
170    * code.
171    *
172    * @return the source code information about the declaration of the exception
173    *         code.
174    */
175   public SourceInfo getSource()
176   {
177     final String name = javadoc.getName();
178     final int lineNumber = javadoc.getLineNumber();
179     final SourceInfo info = new SourceInfo(name, lineNumber);
180     return info;
181   }
182 
183   // --- business -------------------------------------------------------------
184 
185   // --- object basics --------------------------------------------------------
186 
187 }