1 18 19 package org.apache.tools.ant; 20 21 import java.io.Serializable ; 22 import org.apache.tools.ant.util.FileUtils; 23 import org.xml.sax.Locator ; 24 25 31 public class Location implements Serializable { 32 33 34 private String fileName; 35 36 private int lineNumber; 37 38 private int columnNumber; 39 40 41 public static final Location UNKNOWN_LOCATION = new Location(); 42 43 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 44 45 48 private Location() { 49 this(null, 0, 0); 50 } 51 52 60 public Location(String fileName) { 61 this(fileName, 0, 0); 62 } 63 64 72 public Location(Locator loc) { 73 this(loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()); 74 } 75 76 88 public Location(String fileName, int lineNumber, int columnNumber) { 89 if (fileName != null && fileName.startsWith("file:")) { 90 this.fileName = FILE_UTILS.fromURI(fileName); 91 } else { 92 this.fileName = fileName; 93 } 94 this.lineNumber = lineNumber; 95 this.columnNumber = columnNumber; 96 } 97 98 102 public String getFileName() { 103 return fileName; 104 } 105 106 110 public int getLineNumber() { 111 return lineNumber; 112 } 113 114 118 public int getColumnNumber() { 119 return columnNumber; 120 } 121 122 132 public String toString() { 133 StringBuffer buf = new StringBuffer (); 134 135 if (fileName != null) { 136 buf.append(fileName); 137 138 if (lineNumber != 0) { 139 buf.append(":"); 140 buf.append(lineNumber); 141 } 142 143 buf.append(": "); 144 } 145 146 return buf.toString(); 147 } 148 149 156 public boolean equals(Object other) { 157 if (this == other) { 158 return true; 159 } 160 if (other == null) { 161 return false; 162 } 163 if (!(other.getClass() == getClass())) { 164 return false; 165 } 166 return toString().equals(other.toString()); 167 } 168 169 174 public int hashCode() { 175 return toString().hashCode(); 176 } 177 } 178 | Popular Tags |