/*
 * InputPosition.java July 2006
 *
 * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General 
 * Public License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA  02111-1307  USA
 */

package simple.xml.stream;

import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.Location;

/**
 * The <code>InputPosition</code> object is used to acquire the line
 * number within the XML document. This allows debugging to be done
 * when a problem occurs with the source document. This object can 
 * be converted to a string using the <code>toString</code> method.
 *
 * @author Niall Gallagher
 */ 
class InputPosition implements Position {

   /**
    * This is the XML event that the position is acquired for.
    */         
   private XMLEvent source;
        
   /**
    * Constructor for the <code>InputPosition</code> object. This is
    * used to create a position description if the provided event 
    * is not null. If the event is null the position given is -1.
    *
    * @param source this is the XML event to get the position of
    */ 
   public InputPosition(XMLEvent source) {
      this.source = source;
   }

   /**
    * This is the actual line number within the read XML document. 
    * The line number allows any problems within the source XML
    * document to be debugged if it does not match the schema. 
    * This will return -1 if the line number cannot be determined.
    *
    * @return this returns the line number of an XML event 
    */ 
   public int getLine() {
      if(source != null) {
         return getLocation().getLineNumber();
      }   
      return -1;
   }

   /**
    * This is used to acquire the location information from the
    * provided XML event. This is called only if the provided XML
    * event is not null. This provides the StAX line numbering.
    * 
    * @return this returns the StAX location information
    */ 
   private Location getLocation() {
      return source.getLocation();           
   }

   /**
    * This provides a textual description of the position the 
    * read cursor is at within the XML document. This allows the
    * position to be embedded within the exception thrown.
    *
    * @return this returns a textual description of the position
    */    
   public String toString() {
      return String.format("line %s", getLine());           
   }
}

@@ -1514,54 +1514,103 @@
 ll. 
-If the event is null the position given is -1.
+This will return -1 if the specified event does%0A    * not provide any location information.    
 %0A   
@@ -2128,24 +2128,68 @@
 getLine() %7B%0A
+      Location line = getLocation();%0A      %0A
       if(sou
@@ -2185,21 +2185,19 @@
      if(
-sourc
+lin
 e != nul
@@ -2217,29 +2217,20 @@
  return 
-getLocation()
+line
 .getLine
@@ -2578,24 +2578,54 @@
 ocation() %7B%0A
+      if(source != null) %7B%0A   
       return
@@ -2646,27 +2646,43 @@
 ation();
+%0A
       
+%7D%0A
      
+ return null;
 %0A   %7D%0A%0A 

Fix position