Package include.dbcommunication

Source Code of include.dbcommunication.DesktopUpdater

package include.dbcommunication;

import javax.naming.*;

import database.Configuration;
import include.auth.Validation;

import village.webservice.user.Window;
import village.webservice.VillageServiceInterfaceProxy;

public class DesktopUpdater {

  /**
   * Function changes desktop configuration.
   *
   * @param sid    session identifier
   * @param windows  array of windows
   * @return      true if desktop was updated correctly
   */
  public Boolean updateDesktop(String sid, Window windows[]) {
   
    Configuration conf = null;
    boolean result = false;
    include.net.Server serv = new include.net.Server();
    String server = null;
    String rid = null;
    Integer dbSid = null;
    Validation val = new Validation();
    String login = val.validate(sid);
   
    System.out.println("[DesktopUpdater] Executing function 'updateDesktop'.");
   
    try {
      InitialContext ctx = new InitialContext();
      conf = (Configuration) ctx.lookup("ear3/CMPConfiguration/local");
    } catch (NamingException e) {
      e.printStackTrace();
    }
   
    server = sid.substring(sid.indexOf('@') + 1);
     
    if (serv.isMyName(server)) {
       
      System.out.println("[DesktopUpdater] Local execution.");
     
      if (login != null) {
     
        System.out.println("[DesktopUpdater] Session is valid.");
       
        result = true;
       
        if (login.indexOf('@') != -1)
          login = login.substring(0, login.indexOf('@'));
       
        for (Integer i = 0; i < windows.length; i++) {
       
          rid = windows[i].getRid();
          dbSid = Integer.parseInt(sid.substring(0, sid.indexOf('@')));

         
          int tmpId = conf.getId(rid, login);
          result = result && conf.move(tmpId, windows[i].getX(), windows[i].getY());
          result = result && conf.resize(tmpId, windows[i].getW(), windows[i].getH());
          if (!windows[i].getBar().equals(conf.getWindow(tmpId).isMinimized()))
            result = result && conf.reminimize(tmpId);
          if (!windows[i].getFullscreen().equals(conf.getWindow(tmpId).isMaximized()))
            result = result && conf.remaximize(tmpId);
        }
      } else
        System.out.println("[DesktopUpdater] Session is invalid.");
     
     
    } else {
       
      System.out.println("[DesktopUpdater] Remote execution.");
      VillageServiceInterfaceProxy prox = new VillageServiceInterfaceProxy();
     
      village.webservice.VillageServiceInterface iface =
        prox.setEndpoint("http://"+server+prox.villagePort+prox.villageSuffix);

      try {
        result = iface.updateDesktop(sid, windows);       
      } catch(Exception cex){
        cex.printStackTrace();
      }
    }
 
    System.out.println("[DesktopUpdater] Function 'updateDesktop' returned value: '" + result + "'");
   
    return result;
  }
}
TOP

Related Classes of include.dbcommunication.DesktopUpdater

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.