1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.utils;
  58. /**
  59. * The standard SAX implementation of LocatorImpl is not serializable,
  60. * limiting its utility as "a persistent snapshot of a locator".
  61. * This is a quick hack to make it so. Note that it makes more sense
  62. * in many cases to set up fields to hold this data rather than pointing
  63. * at another object... but that decision should be made on architectural
  64. * grounds rather than serializability.
  65. *<p>
  66. * It isn't clear whether subclassing LocatorImpl and adding serialization
  67. * methods makes more sense than copying it and just adding Serializable
  68. * to its interface. Since it's so simple, I've taken the latter approach
  69. * for now.
  70. *
  71. * @see org.xml.sax.helpers.LocatorImpl
  72. * @see org.xml.sax.Locator Locator
  73. * @since XalanJ2
  74. * @author Joe Kesselman
  75. * @version 1.0
  76. */
  77. public class SerializableLocatorImpl
  78. implements org.xml.sax.Locator, java.io.Serializable
  79. {
  80. /**
  81. * Zero-argument constructor.
  82. *
  83. * <p>SAX says "This will not normally be useful, since the main purpose
  84. * of this class is to make a snapshot of an existing Locator." In fact,
  85. * it _is_ sometimes useful when you want to construct a new Locator
  86. * pointing to a specific location... which, after all, is why the
  87. * setter methods are provided.
  88. * </p>
  89. */
  90. public SerializableLocatorImpl ()
  91. {
  92. }
  93. /**
  94. * Copy constructor.
  95. *
  96. * <p>Create a persistent copy of the current state of a locator.
  97. * When the original locator changes, this copy will still keep
  98. * the original values (and it can be used outside the scope of
  99. * DocumentHandler methods).</p>
  100. *
  101. * @param locator The locator to copy.
  102. */
  103. public SerializableLocatorImpl (org.xml.sax.Locator locator)
  104. {
  105. setPublicId(locator.getPublicId());
  106. setSystemId(locator.getSystemId());
  107. setLineNumber(locator.getLineNumber());
  108. setColumnNumber(locator.getColumnNumber());
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Implementation of org.xml.sax.Locator
  112. ////////////////////////////////////////////////////////////////////
  113. /**
  114. * Return the saved public identifier.
  115. *
  116. * @return The public identifier as a string, or null if none
  117. * is available.
  118. * @see org.xml.sax.Locator#getPublicId
  119. * @see #setPublicId
  120. */
  121. public String getPublicId ()
  122. {
  123. return publicId;
  124. }
  125. /**
  126. * Return the saved system identifier.
  127. *
  128. * @return The system identifier as a string, or null if none
  129. * is available.
  130. * @see org.xml.sax.Locator#getSystemId
  131. * @see #setSystemId
  132. */
  133. public String getSystemId ()
  134. {
  135. return systemId;
  136. }
  137. /**
  138. * Return the saved line number (1-based).
  139. *
  140. * @return The line number as an integer, or -1 if none is available.
  141. * @see org.xml.sax.Locator#getLineNumber
  142. * @see #setLineNumber
  143. */
  144. public int getLineNumber ()
  145. {
  146. return lineNumber;
  147. }
  148. /**
  149. * Return the saved column number (1-based).
  150. *
  151. * @return The column number as an integer, or -1 if none is available.
  152. * @see org.xml.sax.Locator#getColumnNumber
  153. * @see #setColumnNumber
  154. */
  155. public int getColumnNumber ()
  156. {
  157. return columnNumber;
  158. }
  159. ////////////////////////////////////////////////////////////////////
  160. // Setters for the properties (not in org.xml.sax.Locator)
  161. ////////////////////////////////////////////////////////////////////
  162. /**
  163. * Set the public identifier for this locator.
  164. *
  165. * @param publicId The new public identifier, or null
  166. * if none is available.
  167. * @see #getPublicId
  168. */
  169. public void setPublicId (String publicId)
  170. {
  171. this.publicId = publicId;
  172. }
  173. /**
  174. * Set the system identifier for this locator.
  175. *
  176. * @param systemId The new system identifier, or null
  177. * if none is available.
  178. * @see #getSystemId
  179. */
  180. public void setSystemId (String systemId)
  181. {
  182. this.systemId = systemId;
  183. }
  184. /**
  185. * Set the line number for this locator (1-based).
  186. *
  187. * @param lineNumber The line number, or -1 if none is available.
  188. * @see #getLineNumber
  189. */
  190. public void setLineNumber (int lineNumber)
  191. {
  192. this.lineNumber = lineNumber;
  193. }
  194. /**
  195. * Set the column number for this locator (1-based).
  196. *
  197. * @param columnNumber The column number, or -1 if none is available.
  198. * @see #getColumnNumber
  199. */
  200. public void setColumnNumber (int columnNumber)
  201. {
  202. this.columnNumber = columnNumber;
  203. }
  204. ////////////////////////////////////////////////////////////////////
  205. // Internal state.
  206. ////////////////////////////////////////////////////////////////////
  207. /**
  208. * The public ID.
  209. * @serial
  210. */
  211. private String publicId;
  212. /**
  213. * The system ID.
  214. * @serial
  215. */
  216. private String systemId;
  217. /**
  218. * The line number.
  219. * @serial
  220. */
  221. private int lineNumber;
  222. /**
  223. * The column number.
  224. * @serial
  225. */
  226. private int columnNumber;
  227. }
  228. // end of LocatorImpl.java