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 try { 025 client.out.writeObject(ServerMessage.GET_WIDTH); 026 client.out.flush(); 027 return (Integer)client.in.readObject(); 028 } 029 catch (Exception e) { 030 return 80; 031 } 032 } 033 034 public String getProperty(String name) { 035 return null; 036 } 037 038 public String readLine(String msg, boolean echo) { 039 try { 040 client.out.writeObject(ServerMessage.READLINE); 041 client.out.writeObject(msg); 042 client.out.writeObject(echo); 043 client.out.flush(); 044 return (String)client.in.readObject(); 045 } 046 catch (Exception e) { 047 return null; 048 } 049 } 050 051 public void end(ShellResponse response) { 052 try { 053 client.current = null; 054 client.out.writeObject(ServerMessage.END); 055 client.out.writeObject(response); 056 client.out.flush(); 057 } 058 catch (IOException ignore) { 059 // 060 } 061 finally { 062 if (response instanceof ShellResponse.Close) { 063 client.close(); 064 } 065 } 066 } 067 }