KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > util > EventLocation


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * 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, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39 package com.sun.xml.fastinfoset.util;
40
41 import javax.xml.stream.Location;
42
43
44 public class EventLocation implements Location{
45     String JavaDoc _systemId = null;
46     String JavaDoc _publicId = null;
47     int _column = -1;
48     int _line = -1;
49     int _charOffset = -1;
50     
51     EventLocation() {
52     }
53     
54     //explicitly create a nil location
55
public static Location getNilLocation() {
56         return new EventLocation();
57     }
58     /**
59     * Return the line number where the current event ends,
60     * returns -1 if none is available.
61     * @return the current line number
62     */

63     public int getLineNumber(){
64         return _line;
65     }
66     /**
67     * Return the column number where the current event ends,
68     * returns -1 if none is available.
69     * @return the current column number
70     */

71     public int getColumnNumber() {
72         return _column;
73     }
74     
75   /**
76    * Return the byte or character offset into the input source this location
77    * is pointing to. If the input source is a file or a byte stream then
78    * this is the byte offset into that stream, but if the input source is
79    * a character media then the offset is the character offset.
80    * Returns -1 if there is no offset available.
81    * @return the current offset
82    */

83     public int getCharacterOffset(){
84         return _charOffset;
85     }
86     
87     /**
88     * Returns the public ID of the XML
89     * @return the public ID, or null if not available
90     */

91     public String JavaDoc getPublicId(){
92         return _publicId;
93     }
94     
95   /**
96    * Returns the system ID of the XML
97    * @return the system ID, or null if not available
98    */

99     public String JavaDoc getSystemId(){
100         return _systemId;
101     }
102     
103     public void setLineNumber(int line) {
104         _line = line;
105     }
106     public void setColumnNumber(int col) {
107         _column = col;
108     }
109     public void setCharacterOffset(int offset) {
110         _charOffset = offset;
111     }
112     public void setPublicId(String JavaDoc id) {
113         _publicId = id;
114     }
115     public void setSystemId(String JavaDoc id) {
116         _systemId = id;
117     }
118     
119     public String JavaDoc toString(){
120         StringBuffer JavaDoc sbuffer = new StringBuffer JavaDoc() ;
121         sbuffer.append("Line number = " + _line);
122         sbuffer.append("\n") ;
123         sbuffer.append("Column number = " + _column);
124         sbuffer.append("\n") ;
125         sbuffer.append("System Id = " + _systemId);
126         sbuffer.append("\n") ;
127         sbuffer.append("Public Id = " + _publicId);
128         sbuffer.append("\n") ;
129         sbuffer.append("CharacterOffset = " + _charOffset);
130         sbuffer.append("\n") ;
131         return sbuffer.toString();
132     }
133     
134 }
135
136
Popular Tags