001 package org.crsh.shell.impl.remoting;
002
003 import org.crsh.shell.ShellProcess;
004 import org.crsh.shell.ShellProcessContext;
005 import org.crsh.shell.ShellResponse;
006
007 import java.io.IOException;
008
009 /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
010 class ClientProcessContext implements ShellProcessContext {
011
012 /** . */
013 final ClientAutomaton client;
014
015 /** . */
016 final ShellProcess process;
017
018 ClientProcessContext(ClientAutomaton client, ShellProcess process) {
019 this.client = client;
020 this.process = process;
021 }
022
023 public int getWidth() {
024 return client.getWidth();
025 }
026
027 public String getProperty(String name) {
028 return null;
029 }
030
031 public String readLine(String msg, boolean echo) {
032 try {
033 client.out.writeObject(ServerMessage.READLINE);
034 client.out.writeObject(msg);
035 client.out.writeObject(echo);
036 client.out.flush();
037 return (String)client.in.readObject();
038 }
039 catch (Exception e) {
040 return null;
041 }
042 }
043
044 public void end(ShellResponse response) {
045 try {
046 client.current = null;
047 client.out.writeObject(ServerMessage.END);
048 client.out.writeObject(response);
049 client.out.flush();
050 }
051 catch (IOException ignore) {
052 //
053 }
054 finally {
055 if (response instanceof ShellResponse.Close) {
056 client.close();
057 }
058 }
059 }
060 }