/* * Copyright (c) 2003,2007 Declarative Engineering LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Declarative Engineering LLC * verson 1 which accompanies this distribution, and is available at * http://declarativeengineering.com/legal/DE_Developer_License_v1.txt */ package com.foundation.tcv.client.controller; import com.common.util.*; import com.common.debug.*; import com.foundation.controller.DecorationManager; public class ClientController extends AbstractController { private static ClientController singleton = new ClientController(); private SessionController sessionController = null; //TODO: Allow multiple session controllers.// /** * ClientController constructor. */ private ClientController() { super(); }//ClientController()// /** * Gets the one and only instance of this class. * @return The only object of this type. */ public static ClientController getSingleton() { return singleton; }//getSingleton()// /** * Gets the session controller. *
TODO: Replace this with a collection of session controllers, one for each server we connect to.
* @return The one and only session controller. */ public SessionController getSessionController() { return sessionController; }//getSessionController()// /** * Creates a connection to a server and opens the initial view. * @param serverAddresses The addresses (Address instances) to use while connecting to the server. * @param versionHandler The handler that is called if the server requires a different client version. The handler should be capable of downloading the new version. * @param eventSystem An object capable of processing events on the view system's event thread. * @return Whether the server was contacted and accepted the connection. This method will not throw exceptions. */ public boolean createSession(IList serverAddresses, IVersionHandler versionHandler, IViewSystem eventSystem) { try { sessionController = new SessionController(eventSystem); if(!sessionController.initialize(this, serverAddresses, versionHandler)) { Debug.log("Failed to connect to the server and initialize the first view."); sessionController = null; }//if// }//try// catch(Throwable e) { Debug.log(e); }//catch// return sessionController != null; }//connect()// /** * Forces the client to close all connections and cleanup. */ public void shutdown() { if(sessionController != null) { sessionController.shutdown(); }//if// ((com.foundation.tcv.client.application.AbstractClientApplication) getApplication()).shutdown(); }//shutdown()// /** * Destroys the session and exits the application if all sessions have been destroyed. * @param sessionController The removed session's controller. */ public void destroySession(SessionController sessionController) { this.sessionController = null; shutdown(); //TODO: When allowing multiple sessions we should only shutdown if all sessions are destroyed. We should also synchronize this.// }//destroySession()// /* (non-Javadoc) * @see com.foundation.controller.IController#getDecorationManager() */ public DecorationManager getDecorationManager() { return null; }//getDecorationManager()// }//ClientController//