35 lines
790 B
Java
35 lines
790 B
Java
package ftp.sar.server;
|
|
|
|
import ftp.sar.exception.CannotConnectException;
|
|
import ftp.sar.validator.IpValidator;
|
|
|
|
public class ServerFactory {
|
|
|
|
public Server create(String ip, int port) {
|
|
if (!this.validate(ip)) {
|
|
return null;
|
|
}
|
|
|
|
Server server = this.createServer(ip, port);
|
|
|
|
ServerConnector connector = new ServerConnector();
|
|
try {
|
|
connector.readFileList(server);
|
|
} catch (CannotConnectException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return server;
|
|
}
|
|
|
|
private Server createServer(String ip, int port) {
|
|
return new Server(ip, port);
|
|
}
|
|
|
|
public boolean validate(String ip) {
|
|
IpValidator validator = new IpValidator();
|
|
|
|
return validator.validate(ip);
|
|
}
|
|
}
|