1 5 package javax.xml.bind.helpers; 6 7 import java.net.URL ; 8 import java.net.MalformedURLException ; 9 import java.text.MessageFormat ; 10 11 import javax.xml.bind.ValidationEventLocator; 12 import org.w3c.dom.Node ; 13 import org.xml.sax.Locator ; 14 import org.xml.sax.SAXParseException ; 15 16 32 public class ValidationEventLocatorImpl implements ValidationEventLocator 33 { 34 37 public ValidationEventLocatorImpl() { 38 } 39 40 52 public ValidationEventLocatorImpl( Locator loc ) { 53 if( loc == null ) { 54 throw new IllegalArgumentException ( 55 Messages.format( Messages.MUST_NOT_BE_NULL, "loc" ) ); 56 } 57 58 this.url = toURL(loc.getSystemId()); 59 this.columnNumber = loc.getColumnNumber(); 60 this.lineNumber = loc.getLineNumber(); 61 } 62 63 75 public ValidationEventLocatorImpl( SAXParseException e ) { 76 if( e == null ) { 77 throw new IllegalArgumentException ( 78 Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) ); 79 } 80 81 this.url = toURL(e.getSystemId()); 82 this.columnNumber = e.getColumnNumber(); 83 this.lineNumber = e.getLineNumber(); 84 } 85 86 96 public ValidationEventLocatorImpl(Node _node) { 97 if( _node == null ) { 98 throw new IllegalArgumentException ( 99 Messages.format( Messages.MUST_NOT_BE_NULL, "_node" ) ); 100 } 101 102 this.node = _node; 103 } 104 105 115 public ValidationEventLocatorImpl(Object _object) { 116 if( _object == null ) { 117 throw new IllegalArgumentException ( 118 Messages.format( Messages.MUST_NOT_BE_NULL, "_object" ) ); 119 } 120 121 this.object = _object; 122 } 123 124 125 private static URL toURL( String systemId ) { 126 try { 127 return new URL (systemId); 128 } catch( MalformedURLException e ) { 129 return null; } 132 } 133 134 private URL url = null; 135 private int offset = -1; 136 private int lineNumber = -1; 137 private int columnNumber = -1; 138 private Object object = null; 139 private Node node = null; 140 141 142 145 public URL getURL() { 146 return url; 147 } 148 149 154 public void setURL( URL _url ) { 155 this.url = _url; 156 } 157 158 161 public int getOffset() { 162 return offset; 163 } 164 165 170 public void setOffset( int _offset ) { 171 this.offset = _offset; 172 } 173 174 177 public int getLineNumber() { 178 return lineNumber; 179 } 180 181 186 public void setLineNumber( int _lineNumber ) { 187 this.lineNumber = _lineNumber; 188 } 189 190 193 public int getColumnNumber() { 194 return columnNumber; 195 } 196 197 202 public void setColumnNumber( int _columnNumber ) { 203 this.columnNumber = _columnNumber; 204 } 205 206 209 public Object getObject() { 210 return object; 211 } 212 213 218 public void setObject( Object _object ) { 219 this.object = _object; 220 } 221 222 225 public Node getNode() { 226 return node; 227 } 228 229 234 public void setNode( Node _node ) { 235 this.node = _node; 236 } 237 238 244 public String toString() { 245 return MessageFormat.format("[node={0},object={1},url={2},line={3},col={4},offset={5}]", 246 getNode(), 247 getObject(), 248 getURL(), 249 String.valueOf(getLineNumber()), 250 String.valueOf(getColumnNumber()), 251 String.valueOf(getOffset())); 252 } 253 } 254 | Popular Tags |