import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import javax.xml.xpath.*;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;

/**
 * Manage information about how to run a program.
 * 
 */
public class RunConfiguration {
	public static final int FILE_SUBMITTED = 1;
	private String name;
	private String[] arguments;
	private int inputFileFlags;
	private String inputFile;
	private String outputFile;
	
	public RunConfiguration()
	{
		arguments = new String[0];
	}
	
	/**
	 * Create a new run configuration for a program.
	 * @param e - root XML node for this run configuration
	 * @throws XPathExpressionException
	 */
	public RunConfiguration(Node e) throws XPathExpressionException
	{
		XPathFactory factory = XPathFactory.newInstance();
		XPath xpath = factory.newXPath();
		
		Node n = (Node)xpath.evaluate("name", e, XPathConstants.NODE);
		if (n != null)
			name = n.getTextContent();

		NodeList nl = (NodeList)xpath.evaluate("argument", e, XPathConstants.NODESET);
		arguments = new String[nl.getLength()];
		for (int i = 0; i < nl.getLength(); i++)
		{
			arguments[i] = nl.item(i).getTextContent();
		}
		
		n = (Node)xpath.evaluate("inputFile", e, XPathConstants.NODE);
		if (n != null)
		{
			inputFile = n.getTextContent();
			inputFileFlags = 0;
			if (n.hasAttributes())
			{
				NamedNodeMap attrs = n.getAttributes();
				Node an = attrs.getNamedItem("type");
				if (an.getTextContent().equalsIgnoreCase("submitted"))
				{
					inputFileFlags = FILE_SUBMITTED;
				}
			}
		}

		n = (Node)xpath.evaluate("outputFile", e, XPathConstants.NODE);
		if (n != null)
			outputFile = n.getTextContent();
	}
	
	/**
	 * Set the array of arguments to be passed to a program.
	 * @param newArgs
	 */
	public void setArguments(String[] newArgs)
	{
		arguments = newArgs;
	}
	
	/**
	 * Set the name of an input file for the program's stdin.
	 * @param newInputFile
	 */
	public void setInputFile(String newInputFile)
	{
		inputFile = newInputFile;
	}
	
	public void setOutputFile(String newOutputFile)
	{
		outputFile = newOutputFile;
	}
	
	public String[] getArguments()
	{
		return arguments;
	}
	
	public String getName()
	{
		return name;
	}
	
	public FileInputStream openInputFile(String subdir) throws FileNotFoundException
	{
		if (inputFile == null)
			return null;
		String path = inputFile;
		if (inputFileFlags == FILE_SUBMITTED)
			path = subdir + File.separator + inputFile;
		return new FileInputStream(path);
	}
		
	public FileOutputStream openOutputFile(String subdir) throws FileNotFoundException
	{
		if (outputFile == null)
			return null;
		return new FileOutputStream(subdir + File.separator + outputFile);
	}
}

@@ -2069,201 +2069,738 @@
 %0A%09%0A%09
-public void setOutputFile(String newOutputFile)%0A%09%7B%0A%09%09outputFile = newOutputFile;%0A%09%7D%0A%09%0A%09public String%5B%5D getArguments()%0A%09%7B%0A%09%09return arguments;%0A%09%7D%0A%09%0A%09public String getName()%0A%09%7B%0A%09%09return name;%0A%09%7D%0A%09
+/**%0A%09 * Set the name of the output file.%0A%09 * @param newOutputFile filename to use for output%0A%09 */%0A%09public void setOutputFile(String newOutputFile)%0A%09%7B%0A%09%09outputFile = newOutputFile;%0A%09%7D%0A%0A%09/**%0A%09 * Obtain the arguments array to use for the program.%0A%09 * @return arguments array%0A%09 */%0A%09public String%5B%5D getArguments()%0A%09%7B%0A%09%09return arguments;%0A%09%7D%0A%09%0A%09/**%0A%09 * Get the name of the program.%0A%09 * @return program name%0A%09 */%0A%09public String getName()%0A%09%7B%0A%09%09return name;%0A%09%7D%0A%09%0A%09/**%0A%09 * Open the input file to be used for standard input when the program is run.%0A%09 * @param subdir If inputFileFlags is FILE_SUBMITTED, the student's directory%0A%09 *  containing the input file%0A%09 * @return input stream from the input file%0A%09 * @throws FileNotFoundException%0A%09 */
 %0A%09pu
@@ -3078,16 +3078,245 @@
 ;%0A%09%7D%0A%09%09%0A
+%09/**%0A%09 * Open the output file to contain standard output from the program.%0A%09 * @param subdir The student's directory to contain the output file.%0A%09 * @return output stream to the output file%0A%09 * @throws FileNotFoundException%0A%09 */%0A
 %09public 

Add missing javadoc comments for several methods in RunConfiguration.