Package org.apache.felix.gogo.runtime
Class CommandSessionImpl
- java.lang.Object
-
- org.apache.felix.gogo.runtime.CommandSessionImpl
-
- All Implemented Interfaces:
AutoCloseable,CommandSession,Converter
public class CommandSessionImpl extends Object implements CommandSession, Converter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.felix.service.command.CommandSession
CommandSession.Utils
-
-
Field Summary
Fields Modifier and Type Field Description protected Channel[]channelsstatic StringCOMMANDSstatic StringCONSTANTSprotected OutputStreamerrprotected InputStreaminprotected OutputStreamoutprotected PrintStreamperrprotected PrintStreampoutstatic StringSESSION_CLOSEDprotected ConcurrentMap<String,Object>variablesstatic StringVARIABLES-
Fields inherited from interface org.apache.felix.service.command.CommandSession
OPTION_NO_GLOB
-
Fields inherited from interface org.apache.felix.service.command.Converter
CONVERTER_CLASSES, INSPECT, LINE, PART
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommandSessionImpl(CommandProcessorImpl shell, InputStream in, OutputStream out, OutputStream err)protectedCommandSessionImpl(CommandProcessorImpl shell, CommandSessionImpl parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassLoaderclassLoader()voidclassLoader(ClassLoader classLoader)voidclose()Close this command session.Objectconvert(Class<?> desiredType, Object in)Convert an object to another type.org.apache.felix.gogo.runtime.CommandSessionImpl.JobImplcreateJob(CharSequence command)PathcurrentDir()voidcurrentDir(Path path)static org.apache.felix.gogo.runtime.CommandSessionImpl.JobImplcurrentJob()ObjectdoConvert(Class<?> desiredType, Object in)Objectexecute(CharSequence commandline)Execute a program in this session.Objectexpr(CharSequence expr)org.apache.felix.gogo.runtime.CommandSessionImpl.JobImplforegroundJob()Get the current foreground job or null.CharSequenceformat(Object result, int inspect)Convert an object to string form (CharSequence).CharSequenceformat(Object target, int level, Converter escape)Convert an objet to a CharSequence object in the requested format.Objectget(String name)Get the value of a variable.PrintStreamgetConsole()Return the PrintStream for the console.InputStreamgetKeyboard()Return the input stream that is the first of the pipeline.ConcurrentMap<String,Object>getVariables()Objectinvoke(Object target, String name, List<Object> args)List<Job>jobs()List jobs.CommandProcessorprocessor()Objectput(String name, Object value)Set the value of a variable.Pathredirect(Path path, int mode)voidsetJobListener(JobListener listener)Set the job listener for this session.
-
-
-
Field Detail
-
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
-
CONSTANTS
public static final String CONSTANTS
- See Also:
- Constant Field Values
-
in
protected InputStream in
-
out
protected OutputStream out
-
pout
protected PrintStream pout
-
err
protected OutputStream err
-
perr
protected PrintStream perr
-
channels
protected Channel[] channels
-
variables
protected final ConcurrentMap<String,Object> variables
-
-
Constructor Detail
-
CommandSessionImpl
protected CommandSessionImpl(CommandProcessorImpl shell, CommandSessionImpl parent)
-
CommandSessionImpl
protected CommandSessionImpl(CommandProcessorImpl shell, InputStream in, OutputStream out, OutputStream err)
-
-
Method Detail
-
processor
public CommandProcessor processor()
-
getVariables
public ConcurrentMap<String,Object> getVariables()
-
currentDir
public Path currentDir()
- Specified by:
currentDirin interfaceCommandSession
-
currentDir
public void currentDir(Path path)
- Specified by:
currentDirin interfaceCommandSession
-
classLoader
public ClassLoader classLoader()
- Specified by:
classLoaderin interfaceCommandSession
-
classLoader
public void classLoader(ClassLoader classLoader)
- Specified by:
classLoaderin interfaceCommandSession
-
close
public void close()
Description copied from interface:CommandSessionClose this command session. After the session is closed, it will throw IllegalStateException when it is used.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCommandSession
-
execute
public Object execute(CharSequence commandline) throws Exception
Description copied from interface:CommandSessionExecute a program in this session.- Specified by:
executein interfaceCommandSession- Returns:
- the result of the execution
- Throws:
Exception
-
getKeyboard
public InputStream getKeyboard()
Description copied from interface:CommandSessionReturn 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:
getKeyboardin interfaceCommandSession- 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:CommandSessionGet the value of a variable.- Specified by:
getin interfaceCommandSession- Returns:
-
put
public Object put(String name, Object value)
Description copied from interface:CommandSessionSet the value of a variable.- Specified by:
putin interfaceCommandSession- Parameters:
name- Name of the variable.value- Value of the variable
-
getConsole
public PrintStream getConsole()
Description copied from interface:CommandSessionReturn 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:
getConsolein interfaceCommandSession- Returns:
-
format
public CharSequence format(Object target, int level, Converter escape) throws Exception
Description copied from interface:ConverterConvert an objet to a CharSequence object in the requested format. The format can be INSPECT, LINE, or PART. Other values must throw IllegalArgumentException.
-
convert
public Object convert(Class<?> desiredType, Object in)
Description copied from interface:CommandSessionConvert an object to another type.- Specified by:
convertin interfaceCommandSession- Specified by:
convertin interfaceConverter- Parameters:
desiredType- The type that the returned object can be assigned toin- 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:CommandSessionConvert 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:
formatin interfaceCommandSession- Returns:
-
expr
public Object expr(CharSequence expr)
-
invoke
public Object invoke(Object target, String name, List<Object> args) throws Exception
- Throws:
Exception
-
jobs
public List<Job> jobs()
Description copied from interface:CommandSessionList jobs. Always return a non-null list.- Specified by:
jobsin interfaceCommandSession
-
currentJob
public static org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl currentJob()
-
foregroundJob
public org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl foregroundJob()
Description copied from interface:CommandSessionGet the current foreground job or null.- Specified by:
foregroundJobin interfaceCommandSession
-
setJobListener
public void setJobListener(JobListener listener)
Description copied from interface:CommandSessionSet the job listener for this session.- Specified by:
setJobListenerin interfaceCommandSession
-
createJob
public org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl createJob(CharSequence command)
-
-