1 16 package org.apache.cocoon.util.location; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.lang.ObjectUtils; 21 22 28 public class LocationImpl implements Location, Serializable { 29 private final String uri; 30 private final int line; 31 private final int column; 32 private final String description; 33 34 static final LocationImpl UNKNOWN = new LocationImpl(null, null, -1, -1); 36 37 42 public LocationImpl(String description, String uri) { 43 this(description, uri, -1, -1); 44 } 45 46 53 public LocationImpl(String description, String uri, int line, int column) { 54 if (uri == null || uri.length() == 0) { 55 this.uri = null; 56 this.line = -1; 57 this.column = -1; 58 } else { 59 this.uri = uri; 60 this.line = line; 61 this.column = column; 62 } 63 64 if (description != null && description.length() == 0) { 65 description = null; 66 } 67 this.description = description; 68 } 69 70 75 public LocationImpl(Location location) { 76 this(location.getDescription(), location.getURI(), location.getLineNumber(), location.getColumnNumber()); 77 } 78 79 82 public LocationImpl(String description, Location location) { 83 this(description, location.getURI(), location.getLineNumber(), location.getColumnNumber()); 84 } 85 86 96 public static LocationImpl get(Location location) { 97 if (location instanceof LocationImpl) { 98 return (LocationImpl)location; 99 } else if (location == null) { 100 return UNKNOWN; 101 } else { 102 return new LocationImpl(location); 103 } 104 } 105 106 111 public String getDescription() { 112 return this.description; 113 } 114 115 120 public String getURI() { 121 return this.uri; 122 } 123 124 129 public int getLineNumber() { 130 return this.line; 131 } 132 133 138 public int getColumnNumber() { 139 return this.column; 140 } 141 142 public boolean equals(Object obj) { 143 if (obj == this) { 144 return true; 145 } 146 147 if (obj instanceof Location) { 148 Location other = (Location)obj; 149 return this.line == other.getLineNumber() && this.column == other.getColumnNumber() 150 && ObjectUtils.equals(this.uri, other.getURI()) 151 && ObjectUtils.equals(this.description, other.getDescription()); 152 } 153 154 return false; 155 } 156 157 public int hashCode() { 158 int hash = line ^ column; 159 if (uri != null) hash ^= uri.hashCode(); 160 if (description != null) hash ^= description.hashCode(); 161 162 return hash; 163 } 164 165 public String toString() { 166 return LocationUtils.toString(this); 167 } 168 169 172 private Object readResolve() { 173 return this.equals(Location.UNKNOWN) ? Location.UNKNOWN : this; 174 } 175 } 176 | Popular Tags |