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

Save This Page
Home » openjdk-7 » com.sun.org.apache.xml.internal » utils » [javadoc | source]