// Path: org/knapsack/shell/pub/IKnapsackCommand.java
// public interface IKnapsackCommand {
// 	/**
// 	 * Command initialization.
// 	 * 
// 	 * @param arguments list of arguments passed to command.  Command name not included.
// 	 * @param context BundleContext
// 	 */
// 	public void initialize(List<String> arguments, BundleContext context);
// 
// 	/**
// 	 * @return List of arguments passed to command.
// 	 */
// 	public List<String> getArguments();
// 	
// 	/**
// 	 * Execute the command
// 	 * 
// 	 * @throws Exception
// 	 */
// 	public String execute() throws Exception;
// 
// 	/**
// 	 * @return true if the command and parameters are valid.
// 	 */
// 	public boolean isValid();
// 
// 	/**
// 	 * @return Name of command.
// 	 */
// 	public String getName();
// 
// 	/**
// 	 * @return A short textual description of command usage.
// 	 */
// 	public String getUsage();
// 
// 	/**
// 	 * @return A description of what the command does.
// 	 */
// 	public String getDescription();
// }


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.knapsack.shell.pub.IKnapsackCommand;
import org.osgi.framework.BundleException;
/*
 *    Copyright 2011 Ken Gilmer
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.knapsack.shell;



/**
 * Given an input String, find command to execute, execute, and return results.
 * 
 * @author kgilmer
 * 
 */
public class CommandExecutor {
	private final CommandParser parser;

	protected CommandExecutor(CommandParser parser) {
		this.parser = parser;
	}

	/**
	 * Executes the command entered by user.
	 * 
	 * @param line
	 * @param justCrlf
	 * @param pwErr
	 * @throws IOException
	 */
	public String executeCommand(String line) throws IOException {
		if (line == null) {
			// JVM is being shutdown
			return "";
		} else if (line.length() > 0) {
// Path: org/knapsack/shell/pub/IKnapsackCommand.java
// public interface IKnapsackCommand {
// 	/**
// 	 * Command initialization.
// 	 * 
// 	 * @param arguments list of arguments passed to command.  Command name not included.
// 	 * @param context BundleContext
// 	 */
// 	public void initialize(List<String> arguments, BundleContext context);
// 
// 	/**
// 	 * @return List of arguments passed to command.
// 	 */
// 	public List<String> getArguments();
// 	
// 	/**
// 	 * Execute the command
// 	 * 
// 	 * @throws Exception
// 	 */
// 	public String execute() throws Exception;
// 
// 	/**
// 	 * @return true if the command and parameters are valid.
// 	 */
// 	public boolean isValid();
// 
// 	/**
// 	 * @return Name of command.
// 	 */
// 	public String getName();
// 
// 	/**
// 	 * @return A short textual description of command usage.
// 	 */
// 	public String getUsage();
// 
// 	/**
// 	 * @return A description of what the command does.
// 	 */
// 	public String getDescription();
// }


// Path: org/knapsack/shell/CommandExecutor.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.knapsack.shell.pub.IKnapsackCommand;
import org.osgi.framework.BundleException;

/*
 *    Copyright 2011 Ken Gilmer
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.knapsack.shell;



/**
 * Given an input String, find command to execute, execute, and return results.
 * 
 * @author kgilmer
 * 
 */
public class CommandExecutor {
	private final CommandParser parser;

	protected CommandExecutor(CommandParser parser) {
		this.parser = parser;
	}

	/**
	 * Executes the command entered by user.
	 * 
	 * @param line
	 * @param justCrlf
	 * @param pwErr
	 * @throws IOException
	 */
	public String executeCommand(String line) throws IOException {
		if (line == null) {
			// JVM is being shutdown
			return "";
		} else if (line.length() > 0) {
			IKnapsackCommand cmd = parser.parse(line);