01: /*
02: * ScriptCommandDefinition.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql;
13:
14: import workbench.util.StringUtil;
15:
16: /**
17: * @author support@sql-workbench.net
18: */
19: public class ScriptCommandDefinition {
20: private final String command;
21: private final int textStartPosInScript;
22: private final int textEndPosInScript;
23:
24: private int whiteSpaceStart = -1;
25:
26: private int indexInScript;
27:
28: public ScriptCommandDefinition(String c, int start, int end) {
29: this (c, start, end, -1);
30: }
31:
32: public ScriptCommandDefinition(String c, int start, int end,
33: int index) {
34: this .command = StringUtil.rtrim(c);
35: this .textStartPosInScript = start;
36: this .textEndPosInScript = end;
37: this .indexInScript = index;
38: }
39:
40: public void setWhitespaceStart(int start) {
41: if (start != this .textStartPosInScript) {
42: this .whiteSpaceStart = start;
43: }
44: }
45:
46: public String getSQL() {
47: return this .command;
48: }
49:
50: /**
51: * Returns the start of this command in the source script
52: * including potential whitespace characters before the
53: * real command. If setWhitespaceStart() has not been
54: * called, this is identical to getStartPositionInScript()
55: * @return
56: */
57: public int getWhitespaceStart() {
58: if (whiteSpaceStart != -1)
59: return whiteSpaceStart;
60: return this .textStartPosInScript;
61: }
62:
63: public int getStartPositionInScript() {
64: return this .textStartPosInScript;
65: }
66:
67: public int getEndPositionInScript() {
68: return this .textEndPosInScript;
69: }
70:
71: public int getIndexInScript() {
72: return this .indexInScript;
73: }
74:
75: public void setIndexInScript(int index) {
76: this .indexInScript = index;
77: }
78:
79: public String toString() {
80: return this.command;
81: }
82: }
|