blob: 6770689923c2ab0877b0ab6ff1f8368e0cc785b0 [file] [log] [blame]
Richard S. Hallfbd735b2009-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 */
19package org.osgi.service.command;
20
21import java.io.*;
22
23public interface CommandSession {
24 /**
25 * Execute a program in this session.
26 *
27 * @param commandline
28 * @return the result of the execution
29 */
30 Object execute(CharSequence commandline) throws Exception;
31
32 /**
33 * Close this command session. After the session is closed, it will throw
34 * IllegalStateException when it is used.
35 *
36 * @param
37 */
38 void close();
39
40 /**
41 * Return the input stream that is the first of the pipeline. This stream is
42 * sometimes necessary to communicate directly to the end user. For example,
43 * a "less" or "more" command needs direct input from the keyboard to
44 * control the paging.
45 *
46 * @return InpuStream used closest to the user or null if input is from a
47 * file.
48 */
49 InputStream getKeybord();
50
51 /**
52 * Return the PrintStream for the console. This must always be the stream
53 * "closest" to the user. This stream can be used to post messages that
54 * bypass the piping. If the output is piped to a file, then the object
55 * returned must be null.
56 *
57 * @return
58 */
59 PrintStream getConsole();
60
61 /**
62 * Get the value of a variable.
63 *
64 * @param name
65 * @return
66 */
67 Object get(String name);
68
69 /**
70 * Set the value of a variable.
71 *
72 * @param name
73 * Name of the variable.
74 * @param value
75 * Value of the variable
76 */
77 void put(String name, Object value);
78
79 /**
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);
90
91 /**
92 * Convert an object to another type.
93 */
94
95 Object convert(Class<?> type, Object instance);
96}