Fri, 23 Aug 2013 09:57:21 +0100
8022885: Update JAX-WS RI integration to 2.2.9-b14140
8013016: Rebase 8009009 against the latest jdk8/jaxws
Reviewed-by: alanb, chegar
ohair@286 | 1 | /* |
mkos@397 | 2 | * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package javax.xml.bind.helpers; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.net.URL; |
ohair@286 | 29 | import java.net.MalformedURLException; |
ohair@286 | 30 | import java.text.MessageFormat; |
ohair@286 | 31 | |
ohair@286 | 32 | import javax.xml.bind.ValidationEventLocator; |
ohair@286 | 33 | import org.w3c.dom.Node; |
ohair@286 | 34 | import org.xml.sax.Locator; |
ohair@286 | 35 | import org.xml.sax.SAXParseException; |
ohair@286 | 36 | |
ohair@286 | 37 | /** |
ohair@286 | 38 | * Default implementation of the ValidationEventLocator interface. |
ohair@286 | 39 | * |
ohair@286 | 40 | * <p> |
ohair@286 | 41 | * JAXB providers are allowed to use whatever class that implements |
ohair@286 | 42 | * the ValidationEventLocator interface. This class is just provided for a |
ohair@286 | 43 | * convenience. |
ohair@286 | 44 | * |
ohair@286 | 45 | * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul> |
ohair@286 | 46 | * @see javax.xml.bind.Validator |
ohair@286 | 47 | * @see javax.xml.bind.ValidationEventHandler |
ohair@286 | 48 | * @see javax.xml.bind.ValidationEvent |
ohair@286 | 49 | * @see javax.xml.bind.ValidationEventLocator |
ohair@286 | 50 | * @since JAXB1.0 |
ohair@286 | 51 | */ |
ohair@286 | 52 | public class ValidationEventLocatorImpl implements ValidationEventLocator |
ohair@286 | 53 | { |
ohair@286 | 54 | /** |
ohair@286 | 55 | * Creates an object with all fields unavailable. |
ohair@286 | 56 | */ |
ohair@286 | 57 | public ValidationEventLocatorImpl() { |
ohair@286 | 58 | } |
ohair@286 | 59 | |
ohair@286 | 60 | /** |
ohair@286 | 61 | * Constructs an object from an org.xml.sax.Locator. |
ohair@286 | 62 | * |
ohair@286 | 63 | * The object's ColumnNumber, LineNumber, and URL become available from the |
ohair@286 | 64 | * values returned by the locator's getColumnNumber(), getLineNumber(), and |
ohair@286 | 65 | * getSystemId() methods respectively. Node, Object, and Offset are not |
ohair@286 | 66 | * available. |
ohair@286 | 67 | * |
ohair@286 | 68 | * @param loc the SAX Locator object that will be used to populate this |
ohair@286 | 69 | * event locator. |
ohair@286 | 70 | * @throws IllegalArgumentException if the Locator is null |
ohair@286 | 71 | */ |
ohair@286 | 72 | public ValidationEventLocatorImpl( Locator loc ) { |
ohair@286 | 73 | if( loc == null ) { |
ohair@286 | 74 | throw new IllegalArgumentException( |
ohair@286 | 75 | Messages.format( Messages.MUST_NOT_BE_NULL, "loc" ) ); |
ohair@286 | 76 | } |
ohair@286 | 77 | |
ohair@286 | 78 | this.url = toURL(loc.getSystemId()); |
ohair@286 | 79 | this.columnNumber = loc.getColumnNumber(); |
ohair@286 | 80 | this.lineNumber = loc.getLineNumber(); |
ohair@286 | 81 | } |
ohair@286 | 82 | |
ohair@286 | 83 | /** |
ohair@286 | 84 | * Constructs an object from the location information of a SAXParseException. |
ohair@286 | 85 | * |
ohair@286 | 86 | * The object's ColumnNumber, LineNumber, and URL become available from the |
ohair@286 | 87 | * values returned by the locator's getColumnNumber(), getLineNumber(), and |
ohair@286 | 88 | * getSystemId() methods respectively. Node, Object, and Offset are not |
ohair@286 | 89 | * available. |
ohair@286 | 90 | * |
ohair@286 | 91 | * @param e the SAXParseException object that will be used to populate this |
ohair@286 | 92 | * event locator. |
ohair@286 | 93 | * @throws IllegalArgumentException if the SAXParseException is null |
ohair@286 | 94 | */ |
ohair@286 | 95 | public ValidationEventLocatorImpl( SAXParseException e ) { |
ohair@286 | 96 | if( e == null ) { |
ohair@286 | 97 | throw new IllegalArgumentException( |
ohair@286 | 98 | Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) ); |
ohair@286 | 99 | } |
ohair@286 | 100 | |
ohair@286 | 101 | this.url = toURL(e.getSystemId()); |
ohair@286 | 102 | this.columnNumber = e.getColumnNumber(); |
ohair@286 | 103 | this.lineNumber = e.getLineNumber(); |
ohair@286 | 104 | } |
ohair@286 | 105 | |
ohair@286 | 106 | /** |
ohair@286 | 107 | * Constructs an object that points to a DOM Node. |
ohair@286 | 108 | * |
ohair@286 | 109 | * The object's Node becomes available. ColumnNumber, LineNumber, Object, |
ohair@286 | 110 | * Offset, and URL are not available. |
ohair@286 | 111 | * |
ohair@286 | 112 | * @param _node the DOM Node object that will be used to populate this |
ohair@286 | 113 | * event locator. |
ohair@286 | 114 | * @throws IllegalArgumentException if the Node is null |
ohair@286 | 115 | */ |
ohair@286 | 116 | public ValidationEventLocatorImpl(Node _node) { |
ohair@286 | 117 | if( _node == null ) { |
ohair@286 | 118 | throw new IllegalArgumentException( |
ohair@286 | 119 | Messages.format( Messages.MUST_NOT_BE_NULL, "_node" ) ); |
ohair@286 | 120 | } |
ohair@286 | 121 | |
ohair@286 | 122 | this.node = _node; |
ohair@286 | 123 | } |
ohair@286 | 124 | |
ohair@286 | 125 | /** |
ohair@286 | 126 | * Constructs an object that points to a JAXB content object. |
ohair@286 | 127 | * |
ohair@286 | 128 | * The object's Object becomes available. ColumnNumber, LineNumber, Node, |
ohair@286 | 129 | * Offset, and URL are not available. |
ohair@286 | 130 | * |
ohair@286 | 131 | * @param _object the Object that will be used to populate this |
ohair@286 | 132 | * event locator. |
ohair@286 | 133 | * @throws IllegalArgumentException if the Object is null |
ohair@286 | 134 | */ |
ohair@286 | 135 | public ValidationEventLocatorImpl(Object _object) { |
ohair@286 | 136 | if( _object == null ) { |
ohair@286 | 137 | throw new IllegalArgumentException( |
ohair@286 | 138 | Messages.format( Messages.MUST_NOT_BE_NULL, "_object" ) ); |
ohair@286 | 139 | } |
ohair@286 | 140 | |
ohair@286 | 141 | this.object = _object; |
ohair@286 | 142 | } |
ohair@286 | 143 | |
ohair@286 | 144 | /** Converts a system ID to an URL object. */ |
ohair@286 | 145 | private static URL toURL( String systemId ) { |
ohair@286 | 146 | try { |
ohair@286 | 147 | return new URL(systemId); |
ohair@286 | 148 | } catch( MalformedURLException e ) { |
ohair@286 | 149 | // TODO: how should we handle system id here? |
ohair@286 | 150 | return null; // for now |
ohair@286 | 151 | } |
ohair@286 | 152 | } |
ohair@286 | 153 | |
ohair@286 | 154 | private URL url = null; |
ohair@286 | 155 | private int offset = -1; |
ohair@286 | 156 | private int lineNumber = -1; |
ohair@286 | 157 | private int columnNumber = -1; |
ohair@286 | 158 | private Object object = null; |
ohair@286 | 159 | private Node node = null; |
ohair@286 | 160 | |
ohair@286 | 161 | |
ohair@286 | 162 | /** |
ohair@286 | 163 | * @see javax.xml.bind.ValidationEventLocator#getURL() |
ohair@286 | 164 | */ |
ohair@286 | 165 | public URL getURL() { |
ohair@286 | 166 | return url; |
ohair@286 | 167 | } |
ohair@286 | 168 | |
ohair@286 | 169 | /** |
ohair@286 | 170 | * Set the URL field on this event locator. Null values are allowed. |
ohair@286 | 171 | * |
ohair@286 | 172 | * @param _url the url |
ohair@286 | 173 | */ |
ohair@286 | 174 | public void setURL( URL _url ) { |
ohair@286 | 175 | this.url = _url; |
ohair@286 | 176 | } |
ohair@286 | 177 | |
ohair@286 | 178 | /** |
ohair@286 | 179 | * @see javax.xml.bind.ValidationEventLocator#getOffset() |
ohair@286 | 180 | */ |
ohair@286 | 181 | public int getOffset() { |
ohair@286 | 182 | return offset; |
ohair@286 | 183 | } |
ohair@286 | 184 | |
ohair@286 | 185 | /** |
ohair@286 | 186 | * Set the offset field on this event locator. |
ohair@286 | 187 | * |
ohair@286 | 188 | * @param _offset the offset |
ohair@286 | 189 | */ |
ohair@286 | 190 | public void setOffset( int _offset ) { |
ohair@286 | 191 | this.offset = _offset; |
ohair@286 | 192 | } |
ohair@286 | 193 | |
ohair@286 | 194 | /** |
ohair@286 | 195 | * @see javax.xml.bind.ValidationEventLocator#getLineNumber() |
ohair@286 | 196 | */ |
ohair@286 | 197 | public int getLineNumber() { |
ohair@286 | 198 | return lineNumber; |
ohair@286 | 199 | } |
ohair@286 | 200 | |
ohair@286 | 201 | /** |
ohair@286 | 202 | * Set the lineNumber field on this event locator. |
ohair@286 | 203 | * |
ohair@286 | 204 | * @param _lineNumber the line number |
ohair@286 | 205 | */ |
ohair@286 | 206 | public void setLineNumber( int _lineNumber ) { |
ohair@286 | 207 | this.lineNumber = _lineNumber; |
ohair@286 | 208 | } |
ohair@286 | 209 | |
ohair@286 | 210 | /** |
ohair@286 | 211 | * @see javax.xml.bind.ValidationEventLocator#getColumnNumber() |
ohair@286 | 212 | */ |
ohair@286 | 213 | public int getColumnNumber() { |
ohair@286 | 214 | return columnNumber; |
ohair@286 | 215 | } |
ohair@286 | 216 | |
ohair@286 | 217 | /** |
ohair@286 | 218 | * Set the columnNumber field on this event locator. |
ohair@286 | 219 | * |
ohair@286 | 220 | * @param _columnNumber the column number |
ohair@286 | 221 | */ |
ohair@286 | 222 | public void setColumnNumber( int _columnNumber ) { |
ohair@286 | 223 | this.columnNumber = _columnNumber; |
ohair@286 | 224 | } |
ohair@286 | 225 | |
ohair@286 | 226 | /** |
ohair@286 | 227 | * @see javax.xml.bind.ValidationEventLocator#getObject() |
ohair@286 | 228 | */ |
ohair@286 | 229 | public Object getObject() { |
ohair@286 | 230 | return object; |
ohair@286 | 231 | } |
ohair@286 | 232 | |
ohair@286 | 233 | /** |
ohair@286 | 234 | * Set the Object field on this event locator. Null values are allowed. |
ohair@286 | 235 | * |
ohair@286 | 236 | * @param _object the java content object |
ohair@286 | 237 | */ |
ohair@286 | 238 | public void setObject( Object _object ) { |
ohair@286 | 239 | this.object = _object; |
ohair@286 | 240 | } |
ohair@286 | 241 | |
ohair@286 | 242 | /** |
ohair@286 | 243 | * @see javax.xml.bind.ValidationEventLocator#getNode() |
ohair@286 | 244 | */ |
ohair@286 | 245 | public Node getNode() { |
ohair@286 | 246 | return node; |
ohair@286 | 247 | } |
ohair@286 | 248 | |
ohair@286 | 249 | /** |
ohair@286 | 250 | * Set the Node field on this event locator. Null values are allowed. |
ohair@286 | 251 | * |
ohair@286 | 252 | * @param _node the Node |
ohair@286 | 253 | */ |
ohair@286 | 254 | public void setNode( Node _node ) { |
ohair@286 | 255 | this.node = _node; |
ohair@286 | 256 | } |
ohair@286 | 257 | |
ohair@286 | 258 | /** |
ohair@286 | 259 | * Returns a string representation of this object in a format |
ohair@286 | 260 | * helpful to debugging. |
ohair@286 | 261 | * |
ohair@286 | 262 | * @see Object#equals(Object) |
ohair@286 | 263 | */ |
ohair@286 | 264 | public String toString() { |
ohair@286 | 265 | return MessageFormat.format("[node={0},object={1},url={2},line={3},col={4},offset={5}]", |
ohair@286 | 266 | getNode(), |
ohair@286 | 267 | getObject(), |
ohair@286 | 268 | getURL(), |
ohair@286 | 269 | String.valueOf(getLineNumber()), |
ohair@286 | 270 | String.valueOf(getColumnNumber()), |
ohair@286 | 271 | String.valueOf(getOffset())); |
ohair@286 | 272 | } |
ohair@286 | 273 | } |