| 1 18 19 package com.martiansoftware.nailgun; 20 21 import java.io.InputStream ; 22 import java.io.PrintStream ; 23 import java.net.InetAddress ; 24 import java.net.NetworkInterface ; 25 import java.util.Properties ; 26 27 46 public class NGContext { 47 48 51 private Properties remoteEnvironment = null; 52 53 56 private InetAddress remoteHost = null; 57 58 61 private int remotePort = 0; 62 63 66 private String [] args = null; 67 68 71 private PrintStream exitStream = null; 72 73 76 private NGServer server = null; 77 78 81 private String command = null; 82 83 private String workingDirectory = null; 84 85 88 public InputStream in = null; 89 90 93 public PrintStream out = null; 94 95 98 public PrintStream err = null; 99 100 101 104 NGContext() { 105 super(); 106 } 107 108 void setExitStream(PrintStream exitStream) { 109 this.exitStream = exitStream; 110 } 111 112 void setPort(int remotePort) { 113 this.remotePort = remotePort; 114 } 115 116 void setCommand(String command) { 117 this.command = command; 118 } 119 120 125 public String getCommand() { 126 return (command); 127 } 128 129 void setWorkingDirectory(String workingDirectory) { 130 this.workingDirectory = workingDirectory; 131 } 132 133 139 public String getWorkingDirectory() { 140 return (workingDirectory); 141 } 142 143 void setEnv(Properties remoteEnvironment) { 144 this.remoteEnvironment = remoteEnvironment; 145 } 146 147 void setInetAddress(InetAddress remoteHost) { 148 this.remoteHost = remoteHost; 149 } 150 151 void setArgs(String [] args) { 152 this.args = args; 153 } 154 155 void setNGServer(NGServer server) { 156 this.server = server; 157 } 158 159 166 public Properties getEnv() { 167 return (remoteEnvironment); 168 } 169 170 174 public String getFileSeparator() { 175 return (remoteEnvironment.getProperty("NAILGUN_FILESEPARATOR")); 176 } 177 178 182 public String getPathSeparator() { 183 return (remoteEnvironment.getProperty("NAILGUN_PATHSEPARATOR")); 184 } 185 186 190 public InetAddress getInetAddress() { 191 return (remoteHost); 192 } 193 194 200 public String [] getArgs() { 201 return (args); 202 } 203 204 208 public NGServer getNGServer() { 209 return (server); 210 } 211 212 221 public void exit(int exitCode) { 222 exitStream.println(exitCode); 223 } 224 225 231 public int getPort() { 232 return (remotePort); 233 } 234 235 239 public void assertLoopbackClient() { 240 if (!getInetAddress().isLoopbackAddress()) { 241 throw (new SecurityException ("Client is not at loopback address.")); 242 } 243 } 244 245 249 public void assertLocalClient() { 250 NetworkInterface iface = null; 251 try { 252 iface = NetworkInterface.getByInetAddress(getInetAddress()); 253 } catch (java.net.SocketException se) { 254 throw (new SecurityException ("Unable to determine if client is local. Assuming he isn't.")); 255 } 256 257 if ((iface == null) && (!getInetAddress().isLoopbackAddress())) { 258 throw (new SecurityException ("Client is not local.")); 259 } 260 } 261 } | Popular Tags |