KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > utils > SerializableLocatorImpl


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 org.apache.xml.utils;
20
21
22 /**
23  * The standard SAX implementation of LocatorImpl is not serializable,
24  * limiting its utility as "a persistent snapshot of a locator".
25  * This is a quick hack to make it so. Note that it makes more sense
26  * in many cases to set up fields to hold this data rather than pointing
27  * at another object... but that decision should be made on architectural
28  * grounds rather than serializability.
29  *<p>
30  * It isn't clear whether subclassing LocatorImpl and adding serialization
31  * methods makes more sense than copying it and just adding Serializable
32  * to its interface. Since it's so simple, I've taken the latter approach
33  * for now.
34  *
35  * @see org.xml.sax.helpers.LocatorImpl
36  * @see org.xml.sax.Locator Locator
37  * @since XalanJ2
38  * @author Joe Kesselman
39  * @version 1.0
40  */

41 public class SerializableLocatorImpl
42 implements org.xml.sax.Locator JavaDoc, java.io.Serializable JavaDoc
43
44 {
45     /**
46      * Zero-argument constructor.
47      *
48      * <p>SAX says "This will not normally be useful, since the main purpose
49      * of this class is to make a snapshot of an existing Locator." In fact,
50      * it _is_ sometimes useful when you want to construct a new Locator
51      * pointing to a specific location... which, after all, is why the
52      * setter methods are provided.
53      * </p>
54      */

55     public SerializableLocatorImpl ()
56     {
57     }
58     
59     
60     /**
61      * Copy constructor.
62      *
63      * <p>Create a persistent copy of the current state of a locator.
64      * When the original locator changes, this copy will still keep
65      * the original values (and it can be used outside the scope of
66      * DocumentHandler methods).</p>
67      *
68      * @param locator The locator to copy.
69      */

70     public SerializableLocatorImpl (org.xml.sax.Locator JavaDoc locator)
71     {
72         setPublicId(locator.getPublicId());
73         setSystemId(locator.getSystemId());
74         setLineNumber(locator.getLineNumber());
75         setColumnNumber(locator.getColumnNumber());
76     }
77     
78     
79     ////////////////////////////////////////////////////////////////////
80
// Implementation of org.xml.sax.Locator
81
////////////////////////////////////////////////////////////////////
82

83     
84     /**
85      * Return the saved public identifier.
86      *
87      * @return The public identifier as a string, or null if none
88      * is available.
89      * @see org.xml.sax.Locator#getPublicId
90      * @see #setPublicId
91      */

92     public String JavaDoc getPublicId ()
93     {
94         return publicId;
95     }
96     
97     
98     /**
99      * Return the saved system identifier.
100      *
101      * @return The system identifier as a string, or null if none
102      * is available.
103      * @see org.xml.sax.Locator#getSystemId
104      * @see #setSystemId
105      */

106     public String JavaDoc getSystemId ()
107     {
108         return systemId;
109     }
110     
111     
112     /**
113      * Return the saved line number (1-based).
114      *
115      * @return The line number as an integer, or -1 if none is available.
116      * @see org.xml.sax.Locator#getLineNumber
117      * @see #setLineNumber
118      */

119     public int getLineNumber ()
120     {
121         return lineNumber;
122     }
123     
124     
125     /**
126      * Return the saved column number (1-based).
127      *
128      * @return The column number as an integer, or -1 if none is available.
129      * @see org.xml.sax.Locator#getColumnNumber
130      * @see #setColumnNumber
131      */

132     public int getColumnNumber ()
133     {
134         return columnNumber;
135     }
136     
137     
138     ////////////////////////////////////////////////////////////////////
139
// Setters for the properties (not in org.xml.sax.Locator)
140
////////////////////////////////////////////////////////////////////
141

142     
143     /**
144      * Set the public identifier for this locator.
145      *
146      * @param publicId The new public identifier, or null
147      * if none is available.
148      * @see #getPublicId
149      */

150     public void setPublicId (String JavaDoc publicId)
151     {
152         this.publicId = publicId;
153     }
154     
155     
156     /**
157      * Set the system identifier for this locator.
158      *
159      * @param systemId The new system identifier, or null
160      * if none is available.
161      * @see #getSystemId
162      */

163     public void setSystemId (String JavaDoc systemId)
164     {
165         this.systemId = systemId;
166     }
167     
168     
169     /**
170      * Set the line number for this locator (1-based).
171      *
172      * @param lineNumber The line number, or -1 if none is available.
173      * @see #getLineNumber
174      */

175     public void setLineNumber (int lineNumber)
176     {
177         this.lineNumber = lineNumber;
178     }
179     
180     
181     /**
182      * Set the column number for this locator (1-based).
183      *
184      * @param columnNumber The column number, or -1 if none is available.
185      * @see #getColumnNumber
186      */

187     public void setColumnNumber (int columnNumber)
188     {
189         this.columnNumber = columnNumber;
190     }
191     
192     
193     ////////////////////////////////////////////////////////////////////
194
// Internal state.
195
////////////////////////////////////////////////////////////////////
196

197     /**
198      * The public ID.
199      * @serial
200      */

201     private String JavaDoc publicId;
202     
203     /**
204      * The system ID.
205      * @serial
206      */

207     private String JavaDoc systemId;
208     
209     /**
210      * The line number.
211      * @serial
212      */

213     private int lineNumber;
214     
215     /**
216      * The column number.
217      * @serial
218      */

219     private int columnNumber;
220     
221 }
222
223 // end of LocatorImpl.java
224
Popular Tags