1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: SerializableLocatorImpl.java,v 1.4 2004/02/17 04:21:14 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.utils;
  20. /**
  21. * The standard SAX implementation of LocatorImpl is not serializable,
  22. * limiting its utility as "a persistent snapshot of a locator".
  23. * This is a quick hack to make it so. Note that it makes more sense
  24. * in many cases to set up fields to hold this data rather than pointing
  25. * at another object... but that decision should be made on architectural
  26. * grounds rather than serializability.
  27. *<p>
  28. * It isn't clear whether subclassing LocatorImpl and adding serialization
  29. * methods makes more sense than copying it and just adding Serializable
  30. * to its interface. Since it's so simple, I've taken the latter approach
  31. * for now.
  32. *
  33. * @see org.xml.sax.helpers.LocatorImpl
  34. * @see org.xml.sax.Locator Locator
  35. * @since XalanJ2
  36. * @author Joe Kesselman
  37. * @version 1.0
  38. */
  39. public class SerializableLocatorImpl
  40. implements org.xml.sax.Locator, java.io.Serializable
  41. {
  42. /**
  43. * Zero-argument constructor.
  44. *
  45. * <p>SAX says "This will not normally be useful, since the main purpose
  46. * of this class is to make a snapshot of an existing Locator." In fact,
  47. * it _is_ sometimes useful when you want to construct a new Locator
  48. * pointing to a specific location... which, after all, is why the
  49. * setter methods are provided.
  50. * </p>
  51. */
  52. public SerializableLocatorImpl ()
  53. {
  54. }
  55. /**
  56. * Copy constructor.
  57. *
  58. * <p>Create a persistent copy of the current state of a locator.
  59. * When the original locator changes, this copy will still keep
  60. * the original values (and it can be used outside the scope of
  61. * DocumentHandler methods).</p>
  62. *
  63. * @param locator The locator to copy.
  64. */
  65. public SerializableLocatorImpl (org.xml.sax.Locator locator)
  66. {
  67. setPublicId(locator.getPublicId());
  68. setSystemId(locator.getSystemId());
  69. setLineNumber(locator.getLineNumber());
  70. setColumnNumber(locator.getColumnNumber());
  71. }
  72. ////////////////////////////////////////////////////////////////////
  73. // Implementation of org.xml.sax.Locator
  74. ////////////////////////////////////////////////////////////////////
  75. /**
  76. * Return the saved public identifier.
  77. *
  78. * @return The public identifier as a string, or null if none
  79. * is available.
  80. * @see org.xml.sax.Locator#getPublicId
  81. * @see #setPublicId
  82. */
  83. public String getPublicId ()
  84. {
  85. return publicId;
  86. }
  87. /**
  88. * Return the saved system identifier.
  89. *
  90. * @return The system identifier as a string, or null if none
  91. * is available.
  92. * @see org.xml.sax.Locator#getSystemId
  93. * @see #setSystemId
  94. */
  95. public String getSystemId ()
  96. {
  97. return systemId;
  98. }
  99. /**
  100. * Return the saved line number (1-based).
  101. *
  102. * @return The line number as an integer, or -1 if none is available.
  103. * @see org.xml.sax.Locator#getLineNumber
  104. * @see #setLineNumber
  105. */
  106. public int getLineNumber ()
  107. {
  108. return lineNumber;
  109. }
  110. /**
  111. * Return the saved column number (1-based).
  112. *
  113. * @return The column number as an integer, or -1 if none is available.
  114. * @see org.xml.sax.Locator#getColumnNumber
  115. * @see #setColumnNumber
  116. */
  117. public int getColumnNumber ()
  118. {
  119. return columnNumber;
  120. }
  121. ////////////////////////////////////////////////////////////////////
  122. // Setters for the properties (not in org.xml.sax.Locator)
  123. ////////////////////////////////////////////////////////////////////
  124. /**
  125. * Set the public identifier for this locator.
  126. *
  127. * @param publicId The new public identifier, or null
  128. * if none is available.
  129. * @see #getPublicId
  130. */
  131. public void setPublicId (String publicId)
  132. {
  133. this.publicId = publicId;
  134. }
  135. /**
  136. * Set the system identifier for this locator.
  137. *
  138. * @param systemId The new system identifier, or null
  139. * if none is available.
  140. * @see #getSystemId
  141. */
  142. public void setSystemId (String systemId)
  143. {
  144. this.systemId = systemId;
  145. }
  146. /**
  147. * Set the line number for this locator (1-based).
  148. *
  149. * @param lineNumber The line number, or -1 if none is available.
  150. * @see #getLineNumber
  151. */
  152. public void setLineNumber (int lineNumber)
  153. {
  154. this.lineNumber = lineNumber;
  155. }
  156. /**
  157. * Set the column number for this locator (1-based).
  158. *
  159. * @param columnNumber The column number, or -1 if none is available.
  160. * @see #getColumnNumber
  161. */
  162. public void setColumnNumber (int columnNumber)
  163. {
  164. this.columnNumber = columnNumber;
  165. }
  166. ////////////////////////////////////////////////////////////////////
  167. // Internal state.
  168. ////////////////////////////////////////////////////////////////////
  169. /**
  170. * The public ID.
  171. * @serial
  172. */
  173. private String publicId;
  174. /**
  175. * The system ID.
  176. * @serial
  177. */
  178. private String systemId;
  179. /**
  180. * The line number.
  181. * @serial
  182. */
  183. private int lineNumber;
  184. /**
  185. * The column number.
  186. * @serial
  187. */
  188. private int columnNumber;
  189. }
  190. // end of LocatorImpl.java