Coverage Report - org.simpleframework.xml.stream.InputPosition
 
Classes in this File Line Coverage Branch Coverage Complexity
InputPosition
100%
5/5
N/A
1
 
 1  
 /*
 2  
  * InputPosition.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.stream;
 20  
 
 21  
 /**
 22  
  * The <code>InputPosition</code> object is used to acquire the line
 23  
  * number within the XML document. This allows debugging to be done
 24  
  * when a problem occurs with the source document. This object can 
 25  
  * be converted to a string using the <code>toString</code> method.
 26  
  *
 27  
  * @author Niall Gallagher
 28  
  */ 
 29  
 class InputPosition implements Position {
 30  
 
 31  
    /**
 32  
     * This is the XML event that the position is acquired for.
 33  
     */         
 34  
    private EventNode source;
 35  
         
 36  
    /**
 37  
     * Constructor for the <code>InputPosition</code> object. This is
 38  
     * used to create a position description if the provided event 
 39  
     * is not null. This will return -1 if the specified event does
 40  
     * not provide any location information.    
 41  
     *
 42  
     * @param source this is the XML event to get the position of
 43  
     */ 
 44  2248655
    public InputPosition(EventNode source) {
 45  2248655
       this.source = source;
 46  2248655
    }
 47  
 
 48  
    /**
 49  
     * This is the actual line number within the read XML document. 
 50  
     * The line number allows any problems within the source XML
 51  
     * document to be debugged if it does not match the schema. 
 52  
     * This will return -1 if the line number cannot be determined.
 53  
     *
 54  
     * @return this returns the line number of an XML event 
 55  
     */ 
 56  
    public int getLine() {  
 57  30
       return source.getLine();
 58  
    }
 59  
 
 60  
    /**
 61  
     * This provides a textual description of the position the 
 62  
     * read cursor is at within the XML document. This allows the
 63  
     * position to be embedded within the exception thrown.
 64  
     *
 65  
     * @return this returns a textual description of the position
 66  
     */    
 67  
    public String toString() {
 68  30
       return String.format("line %s", getLine());           
 69  
    }
 70  
 }