Debian Codegraph @

src/test/java/org/apache/felix/gogo/runtime/Context.java

raw
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 */
19 package org.apache.felix.gogo.runtime;
20
21 import org.apache.felix.gogo.runtime.threadio.ThreadIOImpl;
22 import org.apache.felix.service.command.CommandSession;
23
24 public class Context extends CommandProcessorImpl
25 {
26 public static final String EMPTY = "";
27
28 private static final ThreadIOImpl threadio;
29 private final CommandSession session;
30
31 static
32 {
33 threadio = new ThreadIOImpl();
34 threadio.start();
35 }
36
37 public Context()
38 {
39 super(threadio);
40 addCommand("osgi", this, "addCommand");
41 addCommand("osgi", this, "removeCommand");
42 addCommand("osgi", this, "eval");
43 session = (CommandSessionImpl) createSession(System.in, System.out, System.err);
44 }
45
46 public Object execute(CharSequence source) throws Exception
47 {
48 Object result = new Exception();
49 try
50 {
51 return result = session.execute(source);
52 }
53 finally
54 {
55 System.err.println("execute<" + source + "> = ("
56 + (null == result ? "Null" : result.getClass().getSimpleName()) + ")("
57 + result + ")\n");
58 }
59 }
60
61 public void addCommand(String function, Object target)
62 {
63 addCommand("test", target, function);
64 }
65
66 public void set(String name, Object value)
67 {
68 session.put(name, value);
69 }
70
71 public Object get(String name)
72 {
73 return session.get(name);
74 }
75
76 }