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