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.report.data; 17 18 import de.smartics.util.lang.Arguments; 19 import de.smartics.util.lang.BlankArgumentException; 20 21 /** 22 * Contains information about the source the property 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's type. 34 */ 35 private final String elementTypeName; 36 37 /** 38 * The name of the element that defines the property. 39 */ 40 private final String elementName; 41 42 /** 43 * The line number where the definition of the property begins. 44 */ 45 private final int lineNumber; 46 47 // ****************************** Initializer ******************************* 48 49 // ****************************** Constructors ****************************** 50 51 /** 52 * Default constructor. 53 * 54 * @param elementTypeName the name of the element's type. 55 * @param elementName the name of the element that defines the property. 56 * @param lineNumber the line number where the definition of the property 57 * begins. 58 * @throws BlankArgumentException if either {@code elementTypeName} or 59 * {@code elementName} is blank. 60 */ 61 public SourceInfo(final String elementTypeName, final String elementName, 62 final int lineNumber) throws BlankArgumentException 63 { 64 Arguments.checkNotBlank("elementTypeName", "elementTypeName"); 65 Arguments.checkNotBlank("elementName", "elementName"); 66 67 this.elementTypeName = elementTypeName; 68 this.elementName = elementName; 69 this.lineNumber = lineNumber; 70 } 71 72 // ****************************** Inner Classes ***************************** 73 74 // ********************************* Methods ******************************** 75 76 // --- init ----------------------------------------------------------------- 77 78 // --- get&set -------------------------------------------------------------- 79 80 /** 81 * Returns the name of the element's type. 82 * 83 * @return the name of the element's type. 84 */ 85 public String getElementTypeName() 86 { 87 return elementTypeName; 88 } 89 90 /** 91 * Returns the name of the element that defines the property. 92 * 93 * @return the name of the element that defines the property. 94 */ 95 public String getElementName() 96 { 97 return elementName; 98 } 99 100 /** 101 * Returns the line number where the definition of the property begins. 102 * 103 * @return the line number where the definition of the property begins. 104 */ 105 public int getLineNumber() 106 { 107 return lineNumber; 108 } 109 110 // --- business ------------------------------------------------------------- 111 112 /** 113 * Returns the element identifier that consists of the type and the element 114 * name. 115 * 116 * @return the unique identifier of the declaring element. 117 */ 118 public String getElementId() 119 { 120 return elementTypeName + '.' + elementName; 121 } 122 123 // --- object basics -------------------------------------------------------- 124 125 /** 126 * Returns the string representation of the object. 127 * 128 * @return the string representation of the object. 129 */ 130 @Override 131 public String toString() 132 { 133 return elementTypeName + '#' + elementName + ':' + lineNumber; 134 } 135 }