blob: 6aad74fb61f892930b9664c8460b156e004d5787 [file] [log] [blame]
Richard S. Hallaf656a02009-06-11 16:07:20 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Richard S. Hall27d70122010-05-28 15:39:06 +000019package org.apache.felix.service.command;
Richard S. Hallaf656a02009-06-11 16:07:20 +000020
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000021import java.io.InputStream;
22import java.io.PrintStream;
Richard S. Hallaf656a02009-06-11 16:07:20 +000023
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000024public interface CommandSession
25{
26 /**
27 * Execute a program in this session.
28 *
29 * @param commandline
30 * @return the result of the execution
31 */
32 Object execute(CharSequence commandline) throws Exception;
Richard S. Hallaf656a02009-06-11 16:07:20 +000033
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000034 /**
35 * Close this command session. After the session is closed, it will throw
36 * IllegalStateException when it is used.
37 *
38 * @param
39 */
40 void close();
Richard S. Hallaf656a02009-06-11 16:07:20 +000041
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000042 /**
43 * Return the input stream that is the first of the pipeline. This stream is
44 * sometimes necessary to communicate directly to the end user. For example,
45 * a "less" or "more" command needs direct input from the keyboard to
46 * control the paging.
47 *
48 * @return InpuStream used closest to the user or null if input is from a
49 * file.
50 */
51 InputStream getKeyboard();
Richard S. Hallaf656a02009-06-11 16:07:20 +000052
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000053 /**
54 * Return the PrintStream for the console. This must always be the stream
55 * "closest" to the user. This stream can be used to post messages that
56 * bypass the piping. If the output is piped to a file, then the object
57 * returned must be null.
58 *
59 * @return
60 */
61 PrintStream getConsole();
Richard S. Hallaf656a02009-06-11 16:07:20 +000062
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000063 /**
64 * Get the value of a variable.
65 *
66 * @param name
67 * @return
68 */
69 Object get(String name);
Richard S. Hallaf656a02009-06-11 16:07:20 +000070
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000071 /**
72 * Set the value of a variable.
73 *
74 * @param name Name of the variable.
75 * @param value Value of the variable
76 */
77 void put(String name, Object value);
Richard S. Hallaf656a02009-06-11 16:07:20 +000078
Guillaume Nodetc35dd9e2009-06-22 22:27:13 +000079 /**
80 * Convert an object to string form (CharSequence). The level is defined in
81 * the Converter interface, it can be one of INSPECT, LINE, PART. This
82 * function always returns a non null value. As a last resort, toString is
83 * called on the Object.
84 *
85 * @param target
86 * @param level
87 * @return
88 */
89 CharSequence format(Object target, int level);
Richard S. Hallaf656a02009-06-11 16:07:20 +000090
Derek Baum137d3402009-12-20 11:12:13 +000091 /**
92 * Convert an object to another type.
93 */
94
95 Object convert(Class<?> type, Object instance);
Richard S. Hallaf656a02009-06-11 16:07:20 +000096}