src/share/jaxws_classes/javax/xml/bind/helpers/ValidationEventLocatorImpl.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/helpers/ValidationEventLocatorImpl.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,273 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.bind.helpers;
    1.30 +
    1.31 +import java.net.URL;
    1.32 +import java.net.MalformedURLException;
    1.33 +import java.text.MessageFormat;
    1.34 +
    1.35 +import javax.xml.bind.ValidationEventLocator;
    1.36 +import org.w3c.dom.Node;
    1.37 +import org.xml.sax.Locator;
    1.38 +import org.xml.sax.SAXParseException;
    1.39 +
    1.40 +/**
    1.41 + * Default implementation of the ValidationEventLocator interface.
    1.42 + *
    1.43 + * <p>
    1.44 + * JAXB providers are allowed to use whatever class that implements
    1.45 + * the ValidationEventLocator interface. This class is just provided for a
    1.46 + * convenience.
    1.47 + *
    1.48 + * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul>
    1.49 + * @see javax.xml.bind.Validator
    1.50 + * @see javax.xml.bind.ValidationEventHandler
    1.51 + * @see javax.xml.bind.ValidationEvent
    1.52 + * @see javax.xml.bind.ValidationEventLocator
    1.53 + * @since JAXB1.0
    1.54 + */
    1.55 +public class ValidationEventLocatorImpl implements ValidationEventLocator
    1.56 +{
    1.57 +    /**
    1.58 +     * Creates an object with all fields unavailable.
    1.59 +     */
    1.60 +    public ValidationEventLocatorImpl() {
    1.61 +    }
    1.62 +
    1.63 +    /**
    1.64 +     * Constructs an object from an org.xml.sax.Locator.
    1.65 +     *
    1.66 +     * The object's ColumnNumber, LineNumber, and URL become available from the
    1.67 +     * values returned by the locator's getColumnNumber(), getLineNumber(), and
    1.68 +     * getSystemId() methods respectively. Node, Object, and Offset are not
    1.69 +     * available.
    1.70 +     *
    1.71 +     * @param loc the SAX Locator object that will be used to populate this
    1.72 +     * event locator.
    1.73 +     * @throws IllegalArgumentException if the Locator is null
    1.74 +     */
    1.75 +    public ValidationEventLocatorImpl( Locator loc ) {
    1.76 +        if( loc == null ) {
    1.77 +            throw new IllegalArgumentException(
    1.78 +                Messages.format( Messages.MUST_NOT_BE_NULL, "loc" ) );
    1.79 +        }
    1.80 +
    1.81 +        this.url = toURL(loc.getSystemId());
    1.82 +        this.columnNumber = loc.getColumnNumber();
    1.83 +        this.lineNumber = loc.getLineNumber();
    1.84 +    }
    1.85 +
    1.86 +    /**
    1.87 +     * Constructs an object from the location information of a SAXParseException.
    1.88 +     *
    1.89 +     * The object's ColumnNumber, LineNumber, and URL become available from the
    1.90 +     * values returned by the locator's getColumnNumber(), getLineNumber(), and
    1.91 +     * getSystemId() methods respectively. Node, Object, and Offset are not
    1.92 +     * available.
    1.93 +     *
    1.94 +     * @param e the SAXParseException object that will be used to populate this
    1.95 +     * event locator.
    1.96 +     * @throws IllegalArgumentException if the SAXParseException is null
    1.97 +     */
    1.98 +    public ValidationEventLocatorImpl( SAXParseException e ) {
    1.99 +        if( e == null ) {
   1.100 +            throw new IllegalArgumentException(
   1.101 +                Messages.format( Messages.MUST_NOT_BE_NULL, "e" ) );
   1.102 +        }
   1.103 +
   1.104 +        this.url = toURL(e.getSystemId());
   1.105 +        this.columnNumber = e.getColumnNumber();
   1.106 +        this.lineNumber = e.getLineNumber();
   1.107 +    }
   1.108 +
   1.109 +    /**
   1.110 +     * Constructs an object that points to a DOM Node.
   1.111 +     *
   1.112 +     * The object's Node becomes available.  ColumnNumber, LineNumber, Object,
   1.113 +     * Offset, and URL are not available.
   1.114 +     *
   1.115 +     * @param _node the DOM Node object that will be used to populate this
   1.116 +     * event locator.
   1.117 +     * @throws IllegalArgumentException if the Node is null
   1.118 +     */
   1.119 +    public ValidationEventLocatorImpl(Node _node) {
   1.120 +        if( _node == null ) {
   1.121 +            throw new IllegalArgumentException(
   1.122 +                Messages.format( Messages.MUST_NOT_BE_NULL, "_node" ) );
   1.123 +        }
   1.124 +
   1.125 +        this.node = _node;
   1.126 +    }
   1.127 +
   1.128 +    /**
   1.129 +     * Constructs an object that points to a JAXB content object.
   1.130 +     *
   1.131 +     * The object's Object becomes available. ColumnNumber, LineNumber, Node,
   1.132 +     * Offset, and URL are not available.
   1.133 +     *
   1.134 +     * @param _object the Object that will be used to populate this
   1.135 +     * event locator.
   1.136 +     * @throws IllegalArgumentException if the Object is null
   1.137 +     */
   1.138 +    public ValidationEventLocatorImpl(Object _object) {
   1.139 +        if( _object == null ) {
   1.140 +            throw new IllegalArgumentException(
   1.141 +                Messages.format( Messages.MUST_NOT_BE_NULL, "_object" ) );
   1.142 +        }
   1.143 +
   1.144 +        this.object = _object;
   1.145 +    }
   1.146 +
   1.147 +    /** Converts a system ID to an URL object. */
   1.148 +    private static URL toURL( String systemId ) {
   1.149 +        try {
   1.150 +            return new URL(systemId);
   1.151 +        } catch( MalformedURLException e ) {
   1.152 +            // TODO: how should we handle system id here?
   1.153 +            return null;    // for now
   1.154 +        }
   1.155 +    }
   1.156 +
   1.157 +    private URL url = null;
   1.158 +    private int offset = -1;
   1.159 +    private int lineNumber = -1;
   1.160 +    private int columnNumber = -1;
   1.161 +    private Object object = null;
   1.162 +    private Node node = null;
   1.163 +
   1.164 +
   1.165 +    /**
   1.166 +     * @see javax.xml.bind.ValidationEventLocator#getURL()
   1.167 +     */
   1.168 +    public URL getURL() {
   1.169 +        return url;
   1.170 +    }
   1.171 +
   1.172 +    /**
   1.173 +     * Set the URL field on this event locator.  Null values are allowed.
   1.174 +     *
   1.175 +     * @param _url the url
   1.176 +     */
   1.177 +    public void setURL( URL _url ) {
   1.178 +        this.url = _url;
   1.179 +    }
   1.180 +
   1.181 +    /**
   1.182 +     * @see javax.xml.bind.ValidationEventLocator#getOffset()
   1.183 +     */
   1.184 +    public int getOffset() {
   1.185 +        return offset;
   1.186 +    }
   1.187 +
   1.188 +    /**
   1.189 +     * Set the offset field on this event locator.
   1.190 +     *
   1.191 +     * @param _offset the offset
   1.192 +     */
   1.193 +    public void setOffset( int _offset ) {
   1.194 +        this.offset = _offset;
   1.195 +    }
   1.196 +
   1.197 +    /**
   1.198 +     * @see javax.xml.bind.ValidationEventLocator#getLineNumber()
   1.199 +     */
   1.200 +    public int getLineNumber() {
   1.201 +        return lineNumber;
   1.202 +    }
   1.203 +
   1.204 +    /**
   1.205 +     * Set the lineNumber field on this event locator.
   1.206 +     *
   1.207 +     * @param _lineNumber the line number
   1.208 +     */
   1.209 +    public void setLineNumber( int _lineNumber ) {
   1.210 +        this.lineNumber = _lineNumber;
   1.211 +    }
   1.212 +
   1.213 +    /**
   1.214 +     * @see javax.xml.bind.ValidationEventLocator#getColumnNumber()
   1.215 +     */
   1.216 +    public int getColumnNumber() {
   1.217 +        return columnNumber;
   1.218 +    }
   1.219 +
   1.220 +    /**
   1.221 +     * Set the columnNumber field on this event locator.
   1.222 +     *
   1.223 +     * @param _columnNumber the column number
   1.224 +     */
   1.225 +    public void setColumnNumber( int _columnNumber ) {
   1.226 +        this.columnNumber = _columnNumber;
   1.227 +    }
   1.228 +
   1.229 +    /**
   1.230 +     * @see javax.xml.bind.ValidationEventLocator#getObject()
   1.231 +     */
   1.232 +    public Object getObject() {
   1.233 +        return object;
   1.234 +    }
   1.235 +
   1.236 +    /**
   1.237 +     * Set the Object field on this event locator.  Null values are allowed.
   1.238 +     *
   1.239 +     * @param _object the java content object
   1.240 +     */
   1.241 +    public void setObject( Object _object ) {
   1.242 +        this.object = _object;
   1.243 +    }
   1.244 +
   1.245 +    /**
   1.246 +     * @see javax.xml.bind.ValidationEventLocator#getNode()
   1.247 +     */
   1.248 +    public Node getNode() {
   1.249 +        return node;
   1.250 +    }
   1.251 +
   1.252 +    /**
   1.253 +     * Set the Node field on this event locator.  Null values are allowed.
   1.254 +     *
   1.255 +     * @param _node the Node
   1.256 +     */
   1.257 +    public void setNode( Node _node ) {
   1.258 +        this.node = _node;
   1.259 +    }
   1.260 +
   1.261 +    /**
   1.262 +     * Returns a string representation of this object in a format
   1.263 +     * helpful to debugging.
   1.264 +     *
   1.265 +     * @see Object#equals(Object)
   1.266 +     */
   1.267 +    public String toString() {
   1.268 +        return MessageFormat.format("[node={0},object={1},url={2},line={3},col={4},offset={5}]",
   1.269 +            getNode(),
   1.270 +            getObject(),
   1.271 +            getURL(),
   1.272 +            String.valueOf(getLineNumber()),
   1.273 +            String.valueOf(getColumnNumber()),
   1.274 +            String.valueOf(getOffset()));
   1.275 +    }
   1.276 +}

mercurial