001 /*
002 * Copyright (C) 2003-2009 eXo Platform SAS.
003 *
004 * This is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU Lesser General Public License as
006 * published by the Free Software Foundation; either version 2.1 of
007 * the License, or (at your option) any later version.
008 *
009 * This software is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public
015 * License along with this software; if not, write to the Free
016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018 */
019
020 package org.crsh.command;
021
022 import java.io.PrintWriter;
023
024 /**
025 * The invocation context provided to a command during the invocation phase. The invocation context provides the
026 * various interactions that a command can perform with its context during its invocation.
027 *
028 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
029 * @version $Revision$
030 */
031 public interface InvocationContext<C, P> extends CommandContext {
032
033 /**
034 * Returns the term width in chars. When the value is not positive it means the value could not be determined.
035 *
036 * @return the term width
037 */
038 int getWidth();
039
040 /**
041 * Returns a generic property.
042 *
043 * @param propertyName the property name
044 * @return the property value
045 */
046 String getProperty(String propertyName);
047
048 /**
049 * Display a message and read a line on the console.
050 *
051 * @param msg the message to display before reading a line
052 * @param echo wether or not the line read should be echoed when typing
053 * @return the line read
054 */
055 String readLine(String msg, boolean echo);
056
057 /**
058 * Returns the writer for the output.
059 *
060 * @return the writer
061 */
062 PrintWriter getWriter();
063
064 /**
065 * Returns true if the command is involved in a pipe operation and receives a stream.
066 *
067 * @return true if the command is involved in a pipe
068 */
069 boolean isPiped();
070
071 /**
072 * Returns an iterator over the stream of consumed items.
073 *
074 * @return the consumed items
075 * @throws IllegalStateException if the command is not involved in a pipe operation
076 */
077 Iterable<C> consume() throws IllegalStateException;
078
079 /**
080 * Produce an item.
081 *
082 * @param product the item product
083 */
084 void produce(P product);
085
086 }