01: /* *****************************************************************************
02: * SourceLocator.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.compiler;
11:
12: import org.jdom.Namespace;
13:
14: /** Holds XML Element source meta-information; start and end line-number, source file
15: *
16: * @author Henry Minsky
17: */
18: public class SourceLocator {
19: String pathname;
20: /** Name to use in user messages. */
21: String messagePathname;
22: int startLineNumber;
23: int startColumnNumber;
24: int endLineNumber;
25: int endColumnNumber;
26:
27: /** A string that shouldn't occur in a filename. */
28: private static String serializationSeparator = "[]";
29:
30: static SourceLocator fromString(String string) {
31: SourceLocator locator = new SourceLocator();
32: java.util.StringTokenizer st = new java.util.StringTokenizer(
33: string, serializationSeparator);
34: locator.pathname = st.nextToken();
35: locator.messagePathname = st.nextToken();
36: locator.startLineNumber = Integer.parseInt(st.nextToken());
37: locator.startColumnNumber = Integer.parseInt(st.nextToken());
38: locator.endLineNumber = Integer.parseInt(st.nextToken());
39: locator.endColumnNumber = Integer.parseInt(st.nextToken());
40: return locator;
41: }
42:
43: public String toString() {
44: StringBuffer buffer = new StringBuffer();
45: buffer.append(pathname);
46: buffer.append(serializationSeparator);
47: buffer.append(messagePathname);
48: buffer.append(serializationSeparator);
49: buffer.append(startLineNumber);
50: buffer.append(serializationSeparator);
51: buffer.append(startColumnNumber);
52: buffer.append(serializationSeparator);
53: buffer.append(endLineNumber);
54: buffer.append(serializationSeparator);
55: buffer.append(endColumnNumber);
56: return buffer.toString();
57: }
58:
59: public void setPathname(String pathname, String messagePathname) {
60: if (this .pathname != null && !this .pathname.equals(pathname)) {
61: throw new RuntimeException(
62: /* (non-Javadoc)
63: * @i18n.test
64: * @org-mes="element start and end don't match"
65: */
66: org.openlaszlo.i18n.LaszloMessages.getMessage(
67: SourceLocator.class.getName(), "051018-64"));
68: }
69: if (this .messagePathname != null
70: && !this .messagePathname.equals(messagePathname)) {
71: throw new RuntimeException(
72: /* (non-Javadoc)
73: * @i18n.test
74: * @org-mes="element start and end don't match"
75: */
76: org.openlaszlo.i18n.LaszloMessages.getMessage(
77: SourceLocator.class.getName(), "051018-64"));
78: }
79: this.pathname = pathname;
80: this.messagePathname = messagePathname;
81: }
82: }
|