1 21 22 package com.izforge.izpack.util; 23 24 import java.net.InetAddress ; 25 import java.net.ServerSocket ; 26 27 import com.izforge.izpack.panels.ProcessingClient; 28 import com.izforge.izpack.panels.Validator; 29 30 38 public class PortValidator implements Validator 39 { 40 41 public boolean validate(ProcessingClient client) 42 { 43 InetAddress inet = null; 44 String host = "localhost"; 45 boolean retValue = false; 46 int numfields = client.getNumFields(); 47 48 for (int i = 0; i < numfields; i++) 49 { 50 String value = client.getFieldContents(i); 51 52 if ((value == null) || (value.length() == 0)) { return false; } 53 54 try 55 { 56 inet = InetAddress.getByName(host); 57 ServerSocket socket = new ServerSocket (Integer.parseInt(value), 0, inet); 58 retValue = socket.getLocalPort() > 0; 59 if (!retValue) 60 { 61 break; 62 } 63 socket.close(); 64 } 65 catch (Exception ex) 66 { 67 retValue = false; 68 } 69 } 70 return retValue; 71 } 72 73 } 74 | Popular Tags |