Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 1 | /* |
| 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. Hall | 27d7012 | 2010-05-28 15:39:06 +0000 | [diff] [blame^] | 19 | package org.apache.felix.service.command; |
Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 20 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 21 | import java.io.InputStream; |
| 22 | import java.io.PrintStream; |
Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 23 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 24 | public 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. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 33 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 34 | /** |
| 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. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 41 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 42 | /** |
| 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. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 52 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 53 | /** |
| 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. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 62 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 63 | /** |
| 64 | * Get the value of a variable. |
| 65 | * |
| 66 | * @param name |
| 67 | * @return |
| 68 | */ |
| 69 | Object get(String name); |
Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 70 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 71 | /** |
| 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. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 78 | |
Guillaume Nodet | c35dd9e | 2009-06-22 22:27:13 +0000 | [diff] [blame] | 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); |
Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 90 | |
Derek Baum | 137d340 | 2009-12-20 11:12:13 +0000 | [diff] [blame] | 91 | /** |
| 92 | * Convert an object to another type. |
| 93 | */ |
| 94 | |
| 95 | Object convert(Class<?> type, Object instance); |
Richard S. Hall | af656a0 | 2009-06-11 16:07:20 +0000 | [diff] [blame] | 96 | } |