001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package javax.xml.bind.helpers; 018 019 import java.net.URL; 020 import java.net.MalformedURLException; 021 022 import javax.xml.bind.ValidationEventLocator; 023 024 import org.w3c.dom.Node; 025 026 import org.xml.sax.SAXParseException; 027 import org.xml.sax.Locator; 028 029 public class ValidationEventLocatorImpl implements ValidationEventLocator { 030 031 private URL url; 032 private int offset = -1; 033 private int lineNumber = -1; 034 private int columnNumber = -1; 035 private Object object; 036 private Node node; 037 038 public ValidationEventLocatorImpl() { 039 } 040 041 public ValidationEventLocatorImpl(Locator loc) { 042 if (loc == null) { 043 throw new IllegalArgumentException("loc must not be null"); 044 } 045 url = toURL(loc.getSystemId()); 046 columnNumber = loc.getColumnNumber(); 047 lineNumber = loc.getLineNumber(); 048 } 049 050 public ValidationEventLocatorImpl(SAXParseException e) { 051 if (e == null) { 052 throw new IllegalArgumentException("e must not be null"); 053 } 054 url = toURL(e.getSystemId()); 055 columnNumber = e.getColumnNumber(); 056 lineNumber = e.getLineNumber(); 057 } 058 059 public ValidationEventLocatorImpl(Node node) { 060 if (node == null) { 061 throw new IllegalArgumentException("node must not be null"); 062 } 063 this.node = node; 064 } 065 066 public ValidationEventLocatorImpl(Object object) { 067 if (object == null) { 068 throw new IllegalArgumentException("object must not be null"); 069 } 070 this.object = object; 071 } 072 073 private static URL toURL(String systemId) { 074 try { 075 return new URL(systemId); 076 } 077 catch (MalformedURLException e) { 078 return null; 079 } 080 } 081 082 public URL getURL() { 083 return url; 084 } 085 086 public void setURL(URL url) { 087 this.url = url; 088 } 089 090 public int getOffset() { 091 return offset; 092 } 093 094 public void setOffset(int offset) { 095 this.offset = offset; 096 } 097 098 public int getLineNumber() { 099 return lineNumber; 100 } 101 102 public void setLineNumber(int lineNumber) { 103 this.lineNumber = lineNumber; 104 } 105 106 public int getColumnNumber() { 107 return columnNumber; 108 } 109 110 public void setColumnNumber(int columnNumber) { 111 this.columnNumber = columnNumber; 112 } 113 114 public Object getObject() { 115 return object; 116 } 117 118 public void setObject(Object object) { 119 this.object = object; 120 } 121 122 public Node getNode() { 123 return node; 124 } 125 126 public void setNode(Node node) { 127 this.node = node; 128 } 129 130 public String toString() { 131 return "[node=" + getNode() + ", " + 132 "object=" + getObject() + ", " + 133 "url=" + getURL() + ", " + 134 "line=" + String.valueOf(getLineNumber()) + "," + 135 "col=" + String.valueOf(getColumnNumber()) + "," + 136 "offset=" + String.valueOf(getOffset()) + "]"; 137 } 138 139 }