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 de.smartics.util.lang.Arg;
19  import de.smartics.util.lang.BlankArgumentException;
20  
21  /**
22   * Contains information about the source a exception code is defined in.
23   */
24  public final class SourceInfo
25  {
26    // ********************************* Fields *********************************
27  
28    // --- constants ------------------------------------------------------------
29  
30    // --- members --------------------------------------------------------------
31  
32    /**
33     * The name of the element that defines the exception code.
34     */
35    private final String elementName;
36  
37    /**
38     * The line number where the exception code declaration begins.
39     */
40    private final int lineNumber;
41  
42    // ****************************** Initializer *******************************
43  
44    // ****************************** Constructors ******************************
45  
46    /**
47     * Default constructor.
48     *
49     * @param elementName the name of the element that defines the exception code.
50     * @param lineNumber the line number where the exception code declaration
51     *          begins.
52     * @throws BlankArgumentException if {@code elementName} is blank.
53     */
54    public SourceInfo(final String elementName, final int lineNumber)
55      throws BlankArgumentException
56    {
57      this.elementName = Arg.checkNotBlank("elementName", elementName);
58      this.lineNumber = lineNumber;
59    }
60  
61    // ****************************** Inner Classes *****************************
62  
63    // ********************************* Methods ********************************
64  
65    // --- init -----------------------------------------------------------------
66  
67    // --- get&set --------------------------------------------------------------
68  
69    /**
70     * Returns the name of the element that defines the exception code.
71     *
72     * @return the name of the element that defines the exception code.
73     */
74    public String getElementName()
75    {
76      return elementName;
77    }
78  
79    /**
80     * Returns the line number where the exception code declaration begins.
81     *
82     * @return the line number where the exception code declaration begins.
83     */
84    public int getLineNumber()
85    {
86      return lineNumber;
87    }
88  
89    // --- business -------------------------------------------------------------
90  
91    // --- object basics --------------------------------------------------------
92  
93    /**
94     * Returns the string representation of the object.
95     *
96     * @return the string representation of the object.
97     */
98    @Override
99    public String toString()
100   {
101     return elementName + ':' + lineNumber;
102   }
103 }