gt:     final String[] args = getArguments();
context: /*******************************************************************************
   * Copyright (c) 2014, 2016  Diamond Light Source Ltd., 
   *                          Kichwa Coders & iSencia Belgium NV.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   *
   * Contributors:
   *    DLS, Kichwa Coders - initial API and implementation and/or initial documentation
   *    Erwin De Ley - extraction from DAWN to ease reuse in other contexts
   *******************************************************************************/
  package org.eclipse.triquetrum.python.service.util.cmdline;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.StringTokenizer;
  import java.util.Vector;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  /**
   * Commandline objects help handling command lines specifying processes to
   * execute. The class can be used to define a command line as nested elements or
   * as a helper to define a command line by an application.
   * <p>
   * <code>
   * &lt;someelement&gt;<br>
   * &nbsp;&nbsp;&lt;acommandline executable="/executable/to/run"&gt;<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument value="argument 1" /&gt;<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument line="argument_1 argument_2 argument_3" /&gt;<br>
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument value="argument 4" /&gt;<br>
   * &nbsp;&nbsp;&lt;/acommandline&gt;<br>
   * &lt;/someelement&gt;<br>
   * </code> The element <code>someelement</code> must provide a method
   * <code>createAcommandline</code> which returns an instance of this class.
   * 
   * @author thomas.haas@softwired-inc.com
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   */
  public class Commandline implements Cloneable {
  
    private static final Logger LOG = LoggerFactory.getLogger(Commandline.class);
  
    private Vector arguments = new Vector();
    private String executable = null;
    private File workingDir = null;
  
    public Commandline(String toProcess) {
      super();
      String[] tmp = new String[0];
      try {
        tmp = translateCommandline(toProcess);
      } catch (CommandLineException e) {
        LOG.error("Error translating Commandline.", e);
      }
      if (tmp != null && tmp.length > 0) {
        setExecutable(tmp[0]);
        for (int i = 1; i < tmp.length; i++) {
          createArgument().setValue(tmp[i]);
        }
      }
    }
  
    public Commandline() {
      super();
    }
  
    protected File getWorkingDir() {
      return workingDir;
    }
  
    /**
     * Used for nested xml command line definitions.
     */
    public static class Argument {
  
      private String[] parts;
  
      /**
       * Sets a single commandline argument.
       * 
       * @param value a single commandline argument.
       */
      public void setValue(String value) {
        parts = new String[] { value };
      }
  
      /**
       * Line to split into several commandline arguments.
       * 
       * @param line line to split into several commandline arguments
       */
      public void setLine(String line) {
        if (line == null) {
          return;
        }
        try {
          parts = translateCommandline(line);
        } catch (CommandLineException e) {
          LOG.error("Error translating Commandline.", e);
        }
      }
  
      /**
       * Sets a single commandline argument to the absolute filename of the given
       * file.
       * 
       * @param value a single commandline argument.
       */
      public void setFile(File value) {
        parts = new String[] { value.getAbsolutePath() };
      }
  
      /**
       * Returns the parts this Argument consists of.
       */
      public String[] getParts() {
        return parts;
      }
    }
  
    /**
     * Class to keep track of the position of an Argument.
     */
    // <p>This class is there to support the srcfile and targetfile
    // elements of &lt;execon&gt; and &lt;transform&gt; - don't know
    // whether there might be additional use cases.</p> --SB
    public class Marker {
  
      private int position;
      private int realPos = -1;
  
      Marker(int position) {
        this.position = position;
      }
  
      /**
       * Return the number of arguments that preceeded this marker.
       * <p>
       * The name of the executable - if set - is counted as the very first
       * argument.
       * </p>
       */
      public int getPosition() {
        if (realPos == -1) {
          realPos = (executable == null ? 0 : 1);
          for (int i = 0; i < position; i++) {
            Argument arg = (Argument) arguments.elementAt(i);
            realPos += arg.getParts().length;
          }
        }
        return realPos;
      }
    }
  
    /**
     * Creates an argument object.
     * <p>
     * Each commandline object has at most one instance of the argument class.
     * This method calls <code>this.createArgument(false)</code>.
     * </p>
     * 
     * @see #createArgument(boolean)
     * @return the argument object.
     */
    public Argument createArgument() {
      return this.createArgument(false);
    }
  
    /**
     * Creates an argument object and adds it to our list of args.
     * <p>
     * Each commandline object has at most one instance of the argument class.
     * </p>
     * 
     * @param insertAtStart if true, the argument is inserted at the beginning of
     *          the list of args, otherwise it is appended.
     */
    public Argument createArgument(boolean insertAtStart) {
      Argument argument = new Argument();
      if (insertAtStart) {
        arguments.insertElementAt(argument, 0);
      } else {
        arguments.addElement(argument);
      }
      return argument;
    }
  
    /**
     * Sets the executable to run.
     */
    public void setExecutable(String executable) {
      if (executable == null || executable.length() == 0) {
        return;
      }
      this.executable = executable.replace('/', File.separatorChar).replace('\\', File.separatorChar);
    }
  
    public String getExecutable() {
      return executable;
    }
  
    public void addArguments(String[] line) {
      for (int i = 0; i < line.length; i++) {
        createArgument().setValue(line[i]);
      }
    }
  
    /**
     * Returns the executable and all defined arguments.
     */
    public String[] getCommandline() {
  