View Javadoc
1   /*
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Intalio, Inc.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Intalio, Inc. Exolab is a registered
23   *    trademark of Intalio, Inc.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  package org.exolab.castor.xml.location;
46  
47  
48  /**
49   * A simple FileLocation class used for finer grained detail of exceptions.
50   *
51   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
52   * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $
53   */
54  public class FileLocation implements Location, java.io.Serializable {
55      /** SerialVersionUID */
56      private static final long serialVersionUID = 7112551880124131785L;
57      /** When a field is not available, this String is used to say so. */
58      private final static String NOT_AVAILABLE = "[not available]";
59  
60      /** Filename for the file represented by this FileLocation. */
61      private String _filename = null;
62      /** Line number in the file for this FileLocation. */
63      private int _line = -1;
64      /** Column number in the file for this FileLocation. */
65      private int _col  = -1;
66  
67      /**
68       * Creates a new FileLocation
69       */
70      public FileLocation() {
71          super();
72      }
73  
74      /**
75       * Creates a new FileLocation
76       *
77       * @param filename the name of the file
78       */
79      public FileLocation(final String filename) {
80          super();
81          this._filename = filename;
82      }
83  
84      /**
85       * Creates a new FileLocation.
86       *
87       * @param line the line number
88       * @param column the column number within the specified line
89       */
90      public FileLocation(final int line, final int column) {
91          super();
92          this._line = line;
93          this._col  = column;
94      }
95  
96      /**
97       * Creates a new FileLocation.
98       *
99       * @param filename the name of the file
100      * @param line the line number
101      * @param column the column number within the specified line
102      */
103     public FileLocation(final String filename, final int line, final int column) {
104         super();
105         this._filename = filename;
106         this._line     = line;
107         this._col      = column;
108     }
109 
110     /**
111      * Returns the column number for this FileLocation.
112      * @return the column number for this FileLocation.
113      */
114     public int getColumnNumber() {
115         return _col;
116     }
117 
118     /**
119      * Returns the name of the file to which this FileLocation refers.
120      * @return the name of the file to which this FileLocation refers.
121      */
122     public String getFilename() {
123         return _filename;
124     }
125 
126     /**
127      * Returns the line number for this FileLocation.
128      * @return the line number for this FileLocation.
129      */
130     public int getLineNumber() {
131         return _line;
132     }
133 
134     /**
135      * Sets the column number for this FileLocation.
136      * @param column the column number for this FileLocation
137      */
138     public void setColumnNumber(final int column) {
139         this._col = column;
140     }
141 
142     /**
143      * Sets the name of the file to which this FileLocation refers.
144      * @param filename the name of the file to which this FileLocation refers
145      */
146     public void setFilename(final String filename) {
147         this._filename = filename;
148     }
149 
150     /**
151      * Sets the line number for this FileLocation.
152      * @param line the line number for this FileLocation
153      */
154     public void setLineNumber(final int line) {
155         this._line = line;
156     } //-- setLineNumber
157 
158     /**
159      * Returns the String representation of this FileLocation.
160      * @return the String representation of this FileLocation.
161      */
162     public String toString() {
163         final StringBuffer sb = new StringBuffer("File: ");
164 
165         if (_filename != null) {
166             sb.append(_filename);
167         } else {
168             sb.append(NOT_AVAILABLE);
169         }
170 
171         sb.append("; line: ");
172         if (_line >= 0) {
173             sb.append(_line);
174         } else {
175             sb.append(NOT_AVAILABLE);
176         }
177 
178         sb.append("; column: ");
179         if (_col >= 0) {
180             sb.append(_col);
181         } else {
182             sb.append(NOT_AVAILABLE);
183         }
184 
185         return sb.toString();
186     }
187 
188 }