KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > SourceLocator


1 /* *****************************************************************************
2  * SourceLocator.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11 import org.jdom.Namespace;
12
13 /** Holds XML Element source meta-information; start and end line-number, source file
14  *
15  * @author Henry Minsky
16  */

17 public class SourceLocator {
18     String JavaDoc pathname;
19     /** Name to use in user messages. */
20     String JavaDoc messagePathname;
21     int startLineNumber;
22     int startColumnNumber;
23     int endLineNumber;
24     int endColumnNumber;
25     
26     /** A string that shouldn't occur in a filename. */
27     private static String JavaDoc serializationSeparator = "[]";
28     
29     static SourceLocator fromString(String JavaDoc string) {
30         SourceLocator locator = new SourceLocator();
31         java.util.StringTokenizer JavaDoc st = new java.util.StringTokenizer JavaDoc(string, serializationSeparator);
32         locator.pathname = st.nextToken();
33         locator.messagePathname = st.nextToken();
34         locator.startLineNumber = Integer.parseInt(st.nextToken());
35         locator.startColumnNumber = Integer.parseInt(st.nextToken());
36         locator.endLineNumber = Integer.parseInt(st.nextToken());
37         locator.endColumnNumber = Integer.parseInt(st.nextToken());
38         return locator;
39     }
40     
41     public String JavaDoc toString() {
42         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
43         buffer.append(pathname);
44         buffer.append(serializationSeparator);
45         buffer.append(messagePathname);
46         buffer.append(serializationSeparator);
47         buffer.append(startLineNumber);
48         buffer.append(serializationSeparator);
49         buffer.append(startColumnNumber);
50         buffer.append(serializationSeparator);
51         buffer.append(endLineNumber);
52         buffer.append(serializationSeparator);
53         buffer.append(endColumnNumber);
54         return buffer.toString();
55     }
56
57     public void setPathname(String JavaDoc pathname, String JavaDoc messagePathname) {
58         if (this.pathname != null && !this.pathname.equals(pathname)) {
59             throw new RuntimeException JavaDoc("element start and end don't match");
60         }
61         if (this.messagePathname != null && !this.messagePathname.equals(messagePathname)) {
62             throw new RuntimeException JavaDoc("element start and end don't match");
63         }
64         this.pathname = pathname;
65         this.messagePathname = messagePathname;
66     }
67 }
68
69
Popular Tags