View Javadoc

1   package org.apache.velocity.util.introspection;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import org.apache.velocity.runtime.log.Log;
23  
24  /**
25   *  Little class to carry in info such as template name, line and column
26   *  for information error reporting from the uberspector implementations
27   *
28   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
29   * @version $Id: Info.java 704179 2008-10-13 17:42:11Z nbubna $
30   */
31  public class Info
32  {
33      private int line;
34      private int column;
35      private String templateName;
36  
37      /**
38       * @param source Usually a template name.
39       * @param line The line number from <code>source</code>.
40       * @param column The column number from <code>source</code>.
41       */
42      public Info(String source, int line, int column)
43      {
44          this.templateName = source;
45          this.line = line;
46          this.column = column;
47      }
48  
49      /**
50       * Force callers to set the location information.
51       */
52      private Info()
53      {
54      }
55  
56      /**
57       * @return The template name.
58       */
59      public String getTemplateName()
60      {
61          return templateName;
62      }
63  
64      /**
65       * @return The line number.
66       */
67      public int getLine()
68      {
69          return line;
70      }
71  
72      /**
73       * @return The column number.
74       */
75      public int getColumn()
76      {
77          return column;
78      }
79  
80      /**
81       * Formats a textual representation of this object as <code>SOURCE
82       * [line X, column Y]</code>.
83       *
84       * @return String representing this object.
85       * @since 1.5
86       */
87      public String toString()
88      {
89          return Log.formatFileString(getTemplateName(), getLine(), getColumn());
90      }
91  }