ScriptCommandDefinition.java :  » Database-Client » SQL-Workbench » workbench » sql » Java Open Source

Java Open Source » Database Client » SQL Workbench 
SQL Workbench » workbench » sql » ScriptCommandDefinition.java
/*
 * ScriptCommandDefinition.java
 *
 * This file is part of SQL Workbench/J, http://www.sql-workbench.net
 *
 * Copyright 2002-2008, Thomas Kellerer
 * No part of this code maybe reused without the permission of the author
 *
 * To contact the author please send an email to: support@sql-workbench.net
 *
 */
package workbench.sql;

import workbench.util.StringUtil;

/**
 * @author  support@sql-workbench.net
 */
public class ScriptCommandDefinition
{
  private final String command;
  private final int textStartPosInScript;
  private final int textEndPosInScript;
  
  private int whiteSpaceStart = -1;
  
  private int indexInScript;
  
  public ScriptCommandDefinition(String c, int start, int end)
  {
    this(c, start, end, -1);
  }
  
  public ScriptCommandDefinition(String c, int start, int end, int index)
  {
    this.command = StringUtil.rtrim(c);
    this.textStartPosInScript = start;
    this.textEndPosInScript = end;
    this.indexInScript = index;
  }
  
  public void setWhitespaceStart(int start)
  {
    if (start != this.textStartPosInScript)
    {
      this.whiteSpaceStart = start;
    }
  }
  
  public String getSQL() { return this.command; }

  /**
   * Returns the start of this command in the source script
   * including potential whitespace characters before the 
   * real command. If setWhitespaceStart() has not been 
   * called, this is identical to getStartPositionInScript()
   * @return
   */
  public int getWhitespaceStart() 
  { 
    if (whiteSpaceStart != -1) return whiteSpaceStart;
    return this.textStartPosInScript; 
  }
  
  public int getStartPositionInScript() 
  { 
    return this.textStartPosInScript; 
  }
  
  public int getEndPositionInScript() 
  { 
    return this.textEndPosInScript; 
  }
  
  public int getIndexInScript() { return this.indexInScript; }
  public void setIndexInScript(int index) { this.indexInScript = index; }
  
  public String toString() { return this.command; }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.