001: /*
002: * Fast Infoset ver. 0.1 software ("Software")
003: *
004: * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * Software is licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License. You may
008: * obtain a copy of the License at:
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations.
016: *
017: * Sun supports and benefits from the global community of open source
018: * developers, and thanks the community for its important contributions and
019: * open standards-based technology, which Sun has adopted into many of its
020: * products.
021: *
022: * Please note that portions of Software may be provided with notices and
023: * open source licenses from such communities and third parties that govern the
024: * use of those portions, and any licenses granted hereunder do not alter any
025: * rights and obligations you may have under such open source licenses,
026: * however, the disclaimer of warranty and limitation of liability provisions
027: * in this License will apply to all Software in this distribution.
028: *
029: * You acknowledge that the Software is not designed, licensed or intended
030: * for use in the design, construction, operation or maintenance of any nuclear
031: * facility.
032: *
033: * Apache License
034: * Version 2.0, January 2004
035: * http://www.apache.org/licenses/
036: *
037: */
038:
039: package com.sun.xml.fastinfoset.stax;
040:
041: import javax.xml.stream.Location;
042:
043: public class EventLocation implements Location {
044: String _systemId = null;
045: String _publicId = null;
046: int _column = -1;
047: int _line = -1;
048: int _charOffset = -1;
049:
050: EventLocation() {
051: }
052:
053: //explicitly create a nil location
054: public static Location getNilLocation() {
055: return new EventLocation();
056: }
057:
058: /**
059: * Return the line number where the current event ends,
060: * returns -1 if none is available.
061: * @return the current line number
062: */
063: public int getLineNumber() {
064: return _line;
065: }
066:
067: /**
068: * Return the column number where the current event ends,
069: * returns -1 if none is available.
070: * @return the current column number
071: */
072: public int getColumnNumber() {
073: return _column;
074: }
075:
076: /**
077: * Return the byte or character offset into the input source this location
078: * is pointing to. If the input source is a file or a byte stream then
079: * this is the byte offset into that stream, but if the input source is
080: * a character media then the offset is the character offset.
081: * Returns -1 if there is no offset available.
082: * @return the current offset
083: */
084: public int getCharacterOffset() {
085: return _charOffset;
086: }
087:
088: /**
089: * Returns the public ID of the XML
090: * @return the public ID, or null if not available
091: */
092: public String getPublicId() {
093: return _publicId;
094: }
095:
096: /**
097: * Returns the system ID of the XML
098: * @return the system ID, or null if not available
099: */
100: public String getSystemId() {
101: return _systemId;
102: }
103:
104: public void setLineNumber(int line) {
105: _line = line;
106: }
107:
108: public void setColumnNumber(int col) {
109: _column = col;
110: }
111:
112: public void setCharacterOffset(int offset) {
113: _charOffset = offset;
114: }
115:
116: public void setPublicId(String id) {
117: _publicId = id;
118: }
119:
120: public void setSystemId(String id) {
121: _systemId = id;
122: }
123:
124: public String toString() {
125: StringBuffer sbuffer = new StringBuffer();
126: sbuffer.append("Line number = " + _line);
127: sbuffer.append("\n");
128: sbuffer.append("Column number = " + _column);
129: sbuffer.append("\n");
130: sbuffer.append("System Id = " + _systemId);
131: sbuffer.append("\n");
132: sbuffer.append("Public Id = " + _publicId);
133: sbuffer.append("\n");
134: sbuffer.append("CharacterOffset = " + _charOffset);
135: sbuffer.append("\n");
136: return sbuffer.toString();
137: }
138:
139: }
|