Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/helpers/LocatorImpl.java
48576 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// SAX default implementation for Locator.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: LocatorImpl.java,v 1.2 2004/11/03 22:53:09 jsuttor Exp $2930package org.xml.sax.helpers;3132import org.xml.sax.Locator;333435/**36* Provide an optional convenience implementation of Locator.37*38* <blockquote>39* <em>This module, both source code and documentation, is in the40* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>41* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>42* for further information.43* </blockquote>44*45* <p>This class is available mainly for application writers, who46* can use it to make a persistent snapshot of a locator at any47* point during a document parse:</p>48*49* <pre>50* Locator locator;51* Locator startloc;52*53* public void setLocator (Locator locator)54* {55* // note the locator56* this.locator = locator;57* }58*59* public void startDocument ()60* {61* // save the location of the start of the document62* // for future use.63* Locator startloc = new LocatorImpl(locator);64* }65*</pre>66*67* <p>Normally, parser writers will not use this class, since it68* is more efficient to provide location information only when69* requested, rather than constantly updating a Locator object.</p>70*71* @since SAX 1.072* @author David Megginson73* @see org.xml.sax.Locator Locator74*/75public class LocatorImpl implements Locator76{777879/**80* Zero-argument constructor.81*82* <p>This will not normally be useful, since the main purpose83* of this class is to make a snapshot of an existing Locator.</p>84*/85public LocatorImpl ()86{87}888990/**91* Copy constructor.92*93* <p>Create a persistent copy of the current state of a locator.94* When the original locator changes, this copy will still keep95* the original values (and it can be used outside the scope of96* DocumentHandler methods).</p>97*98* @param locator The locator to copy.99*/100public LocatorImpl (Locator locator)101{102setPublicId(locator.getPublicId());103setSystemId(locator.getSystemId());104setLineNumber(locator.getLineNumber());105setColumnNumber(locator.getColumnNumber());106}107108109110////////////////////////////////////////////////////////////////////111// Implementation of org.xml.sax.Locator112////////////////////////////////////////////////////////////////////113114115/**116* Return the saved public identifier.117*118* @return The public identifier as a string, or null if none119* is available.120* @see org.xml.sax.Locator#getPublicId121* @see #setPublicId122*/123public String getPublicId ()124{125return publicId;126}127128129/**130* Return the saved system identifier.131*132* @return The system identifier as a string, or null if none133* is available.134* @see org.xml.sax.Locator#getSystemId135* @see #setSystemId136*/137public String getSystemId ()138{139return systemId;140}141142143/**144* Return the saved line number (1-based).145*146* @return The line number as an integer, or -1 if none is available.147* @see org.xml.sax.Locator#getLineNumber148* @see #setLineNumber149*/150public int getLineNumber ()151{152return lineNumber;153}154155156/**157* Return the saved column number (1-based).158*159* @return The column number as an integer, or -1 if none is available.160* @see org.xml.sax.Locator#getColumnNumber161* @see #setColumnNumber162*/163public int getColumnNumber ()164{165return columnNumber;166}167168169170////////////////////////////////////////////////////////////////////171// Setters for the properties (not in org.xml.sax.Locator)172////////////////////////////////////////////////////////////////////173174175/**176* Set the public identifier for this locator.177*178* @param publicId The new public identifier, or null179* if none is available.180* @see #getPublicId181*/182public void setPublicId (String publicId)183{184this.publicId = publicId;185}186187188/**189* Set the system identifier for this locator.190*191* @param systemId The new system identifier, or null192* if none is available.193* @see #getSystemId194*/195public void setSystemId (String systemId)196{197this.systemId = systemId;198}199200201/**202* Set the line number for this locator (1-based).203*204* @param lineNumber The line number, or -1 if none is available.205* @see #getLineNumber206*/207public void setLineNumber (int lineNumber)208{209this.lineNumber = lineNumber;210}211212213/**214* Set the column number for this locator (1-based).215*216* @param columnNumber The column number, or -1 if none is available.217* @see #getColumnNumber218*/219public void setColumnNumber (int columnNumber)220{221this.columnNumber = columnNumber;222}223224225226////////////////////////////////////////////////////////////////////227// Internal state.228////////////////////////////////////////////////////////////////////229230private String publicId;231private String systemId;232private int lineNumber;233private int columnNumber;234235}236237// end of LocatorImpl.java238239240