001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: SerializableLocatorImpl.java,v 1.5 2004/08/17 18:57:22 jycli Exp $
018: */
019: package org.apache.xml.utils;
020:
021: /**
022: * The standard SAX implementation of LocatorImpl is not serializable,
023: * limiting its utility as "a persistent snapshot of a locator".
024: * This is a quick hack to make it so. Note that it makes more sense
025: * in many cases to set up fields to hold this data rather than pointing
026: * at another object... but that decision should be made on architectural
027: * grounds rather than serializability.
028: *<p>
029: * It isn't clear whether subclassing LocatorImpl and adding serialization
030: * methods makes more sense than copying it and just adding Serializable
031: * to its interface. Since it's so simple, I've taken the latter approach
032: * for now.
033: *
034: * @see org.xml.sax.helpers.LocatorImpl
035: * @see org.xml.sax.Locator Locator
036: * @since XalanJ2
037: * @author Joe Kesselman
038: * @version 1.0
039: */
040: public class SerializableLocatorImpl implements org.xml.sax.Locator,
041: java.io.Serializable
042:
043: {
044: static final long serialVersionUID = -2660312888446371460L;
045:
046: /**
047: * Zero-argument constructor.
048: *
049: * <p>SAX says "This will not normally be useful, since the main purpose
050: * of this class is to make a snapshot of an existing Locator." In fact,
051: * it _is_ sometimes useful when you want to construct a new Locator
052: * pointing to a specific location... which, after all, is why the
053: * setter methods are provided.
054: * </p>
055: */
056: public SerializableLocatorImpl() {
057: }
058:
059: /**
060: * Copy constructor.
061: *
062: * <p>Create a persistent copy of the current state of a locator.
063: * When the original locator changes, this copy will still keep
064: * the original values (and it can be used outside the scope of
065: * DocumentHandler methods).</p>
066: *
067: * @param locator The locator to copy.
068: */
069: public SerializableLocatorImpl(org.xml.sax.Locator locator) {
070: setPublicId(locator.getPublicId());
071: setSystemId(locator.getSystemId());
072: setLineNumber(locator.getLineNumber());
073: setColumnNumber(locator.getColumnNumber());
074: }
075:
076: ////////////////////////////////////////////////////////////////////
077: // Implementation of org.xml.sax.Locator
078: ////////////////////////////////////////////////////////////////////
079:
080: /**
081: * Return the saved public identifier.
082: *
083: * @return The public identifier as a string, or null if none
084: * is available.
085: * @see org.xml.sax.Locator#getPublicId
086: * @see #setPublicId
087: */
088: public String getPublicId() {
089: return publicId;
090: }
091:
092: /**
093: * Return the saved system identifier.
094: *
095: * @return The system identifier as a string, or null if none
096: * is available.
097: * @see org.xml.sax.Locator#getSystemId
098: * @see #setSystemId
099: */
100: public String getSystemId() {
101: return systemId;
102: }
103:
104: /**
105: * Return the saved line number (1-based).
106: *
107: * @return The line number as an integer, or -1 if none is available.
108: * @see org.xml.sax.Locator#getLineNumber
109: * @see #setLineNumber
110: */
111: public int getLineNumber() {
112: return lineNumber;
113: }
114:
115: /**
116: * Return the saved column number (1-based).
117: *
118: * @return The column number as an integer, or -1 if none is available.
119: * @see org.xml.sax.Locator#getColumnNumber
120: * @see #setColumnNumber
121: */
122: public int getColumnNumber() {
123: return columnNumber;
124: }
125:
126: ////////////////////////////////////////////////////////////////////
127: // Setters for the properties (not in org.xml.sax.Locator)
128: ////////////////////////////////////////////////////////////////////
129:
130: /**
131: * Set the public identifier for this locator.
132: *
133: * @param publicId The new public identifier, or null
134: * if none is available.
135: * @see #getPublicId
136: */
137: public void setPublicId(String publicId) {
138: this .publicId = publicId;
139: }
140:
141: /**
142: * Set the system identifier for this locator.
143: *
144: * @param systemId The new system identifier, or null
145: * if none is available.
146: * @see #getSystemId
147: */
148: public void setSystemId(String systemId) {
149: this .systemId = systemId;
150: }
151:
152: /**
153: * Set the line number for this locator (1-based).
154: *
155: * @param lineNumber The line number, or -1 if none is available.
156: * @see #getLineNumber
157: */
158: public void setLineNumber(int lineNumber) {
159: this .lineNumber = lineNumber;
160: }
161:
162: /**
163: * Set the column number for this locator (1-based).
164: *
165: * @param columnNumber The column number, or -1 if none is available.
166: * @see #getColumnNumber
167: */
168: public void setColumnNumber(int columnNumber) {
169: this .columnNumber = columnNumber;
170: }
171:
172: ////////////////////////////////////////////////////////////////////
173: // Internal state.
174: ////////////////////////////////////////////////////////////////////
175:
176: /**
177: * The public ID.
178: * @serial
179: */
180: private String publicId;
181:
182: /**
183: * The system ID.
184: * @serial
185: */
186: private String systemId;
187:
188: /**
189: * The line number.
190: * @serial
191: */
192: private int lineNumber;
193:
194: /**
195: * The column number.
196: * @serial
197: */
198: private int columnNumber;
199:
200: }
201:
202: // end of LocatorImpl.java
|