Package org.apache.felix.gogo.runtime

# Class CommandSessionImpl

java.lang.Object
org.apache.felix.gogo.runtime.CommandSessionImpl

All Implemented Interfaces:
  `CommandSession`, `Converter`

public class CommandSessionImpl extends Object implements CommandSession, Converter

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`COMMANDS`
`protected InputStream`
`in`
`protected PrintStream`
`out`
`static final String`
`SESSION_CLOSED`
`protected final Map<String,Object>`
`variables`
`static final String`
`VARIABLES`

### Fields inherited from interface org.apache.felix.service.command.Converter

`CONVERTER_CLASSES, INSPECT, LINE, PART`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`CommandSessionImpl(CommandProcessorImpl shell, InputStream in, PrintStream out, PrintStream err)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close this command session.
`Object`
`convert(Class<?> desiredType, Object in)`
Convert an object to another type.
`Object`
`execute(CharSequence commandline)`
Execute a program in this session.
`Object`
`expr(CharSequence expr)`
`CharSequence`
`format(Object result, int inspect)`
Convert an object to string form (CharSequence).
`CharSequence`
`format(Object target, int level, Converter escape)`
Convert an objet to a CharSequence object in the requested format.
`Object`
`get(String name)`
Get the value of a variable.
`PrintStream`
`getConsole()`
Return the PrintStream for the console.
`InputStream`
`getKeyboard()`
Return the input stream that is the first of the pipeline.
`void`
`put(String name, Object value)`
Set the value of a variable.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### SESSION_CLOSED

public static final String SESSION_CLOSED

See Also:
  - Constant Field Values

### VARIABLES

public static final String VARIABLES

See Also:
  - Constant Field Values

### COMMANDS

public static final String COMMANDS

See Also:
  - Constant Field Values

### in

protected InputStream in

### out

protected PrintStream out

### variables

protected final Map<String,Object> variables

## Constructor Details

### CommandSessionImpl

protected CommandSessionImpl(CommandProcessorImpl shell, InputStream in, PrintStream out, PrintStream err)

## Method Details

### close

public void close()
Description copied from interface: `CommandSession`
Close this command session. After the session is closed, it will throw IllegalStateException when it is used.

Specified by:
  `close` in interface `CommandSession`

### execute

public Object execute(CharSequence commandline) throws Exception
Description copied from interface: `CommandSession`
Execute a program in this session.

Specified by:
  `execute` in interface `CommandSession`
Parameters:
  `commandline` -
Returns:
  the result of the execution
Throws:
  `Exception`

### getKeyboard

public InputStream getKeyboard()
Description copied from interface: `CommandSession`
Return the input stream that is the first of the pipeline. This stream is sometimes necessary to communicate directly to the end user. For example, a "less" or "more" command needs direct input from the keyboard to control the paging.

Specified by:
  `getKeyboard` in interface `CommandSession`
Returns:
  InpuStream used closest to the user or null if input is from a file.

### get

public Object get(String name)
Description copied from interface: `CommandSession`
Get the value of a variable.

Specified by:
  `get` in interface `CommandSession`
Parameters:
  `name` -
Returns:

### put

public void put(String name, Object value)
Description copied from interface: `CommandSession`
Set the value of a variable.

Specified by:
  `put` in interface `CommandSession`
Parameters:
  `name` - Name of the variable.
  `value` - Value of the variable

### getConsole

public PrintStream getConsole()
Description copied from interface: `CommandSession`
Return the PrintStream for the console. This must always be the stream "closest" to the user. This stream can be used to post messages that bypass the piping. If the output is piped to a file, then the object returned must be null.

Specified by:
  `getConsole` in interface `CommandSession`
Returns:

### format

public CharSequence format(Object target, int level, Converter escape) throws Exception
Description copied from interface: `Converter`
Convert an objet to a CharSequence object in the requested format. The format can be INSPECT, LINE, or PART. Other values must throw IllegalArgumentException.

Specified by:
  `format` in interface `Converter`
Parameters:
  `target` - The object to be converted to a String
  `level` - One of INSPECT, LINE, or PART.
  `escape` - Use this object to format sub ordinate objects.
Returns:
  A printed object of potentially multiple lines
Throws:
  `Exception`

### convert

public Object convert(Class<?> desiredType, Object in)
Description copied from interface: `CommandSession`
Convert an object to another type.

Specified by:
  `convert` in interface `CommandSession`
Specified by:
  `convert` in interface `Converter`
Parameters:
  `desiredType` - The type that the returned object can be assigned to
  `in` - The object that must be converted
Returns:
  An object that can be assigned to the desired type or null.

### format

public CharSequence format(Object result, int inspect)
Description copied from interface: `CommandSession`
Convert an object to string form (CharSequence). The level is defined in the Converter interface, it can be one of INSPECT, LINE, PART. This function always returns a non null value. As a last resort, toString is called on the Object.

Specified by:
  `format` in interface `CommandSession`
Parameters:
  `result` -
  `inspect` -
Returns:

### expr

public Object expr(CharSequence expr)