package include.dbcommunication;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import village.webservice.VillageServiceInterfaceProxy;
import database.Configuration;
public class WindowRemover {
/**
* Function removes window from desktop.
*
* @param sid session identifier
* @param rid information which window should be remover
* @return true if window was removed correctly
*/
public Boolean removeWindow(String sid, String rid){
Configuration conf = null;
boolean result = false;
include.net.Server serv = new include.net.Server();
String server;
include.auth.Validation val = new include.auth.Validation();
String login = val.validate(sid);
System.out.println("[WindowRemover] Executing function 'removeWindow'. Parameters:");
System.out.println("[WindowRemover] sid: '" + sid + "'");
System.out.println("[WindowRemover] rid: '" + rid + "'");
server = sid.substring(sid.indexOf('@') + 1);
if (serv.isMyName(server)) {
System.out.println("[WindowRemover] Local execution.");
if (login != null) {
System.out.println("[WindowRemover] Session is valid");
try {
InitialContext ctx = new InitialContext();
conf = (Configuration) ctx.lookup("ear3/CMPConfiguration/local");
} catch (NamingException e) {
e.printStackTrace();
}
if (login.indexOf('@') != -1)
login = login.substring(0, login.indexOf('@'));
result = conf.remove(conf.getId(rid, login));
} else
System.out.println("[WindowRemover] Session is invalid");
} else {
System.out.println("[WindowRemover] Remote execution.");
VillageServiceInterfaceProxy prox = new VillageServiceInterfaceProxy();
village.webservice.VillageServiceInterface iface =
prox.setEndpoint("http://"+server+prox.villagePort+prox.villageSuffix);
try {
result = iface.deleteRoom(sid, rid);
} catch(Exception cex){
cex.printStackTrace();
}
}
System.out.println("[WindowRemover] Function 'removeWindow' returned value: '" + result + "'");
return result;
}
}