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