Author: tchemit Date: 2008-02-13 16:25:50 +0000 (Wed, 13 Feb 2008) New Revision: 928 Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ConnectAction.java Log: suppression des storage services du contexte de l'application : tout se passe dans StorageServiceHelper Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java 2008-02-13 16:09:09 UTC (rev 927) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java 2008-02-13 16:25:50 UTC (rev 928) @@ -18,8 +18,6 @@ * ##% */ package fr.cemagref.simexplorer.is.ui; -import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl; -import fr.cemagref.simexplorer.is.service.StorageService; import fr.cemagref.simexplorer.is.ui.actions.SimExplorerCommonActions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,12 +60,6 @@ /** le token pour la connexion au serveur distant */ protected String token; - /** le service de données distant */ - protected StorageService remoteStorageService; - - /** le service de données local */ - protected StorageService storageService; - /** * @return le parseur utilisé pour parser les options de la ligne de * commande. @@ -161,28 +153,6 @@ return token; } - /** @return le service de storage locale */ - public StorageService getLocalStorageService() { - if (storageService == null) { - storageService = new MockStorageServiceImpl(); - } - return storageService; - } - - /** @return le service de storage distant */ - public StorageService getRemoteStorageService() { - if (remoteStorageService == null) { - remoteStorageService = new MockStorageServiceImpl(); - } - return remoteStorageService; - } - - public StorageService getStorageService(boolean remote) { - StorageService service; - service = remote ? getRemoteStorageService() : getLocalStorageService(); - return service; - } - public void setQuit(boolean quit) { this.quit = quit; } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java 2008-02-13 16:09:09 UTC (rev 927) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java 2008-02-13 16:25:50 UTC (rev 928) @@ -25,6 +25,7 @@ import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl; import fr.cemagref.simexplorer.is.service.SimExplorerServiceException; import fr.cemagref.simexplorer.is.service.StorageService; +import fr.cemagref.simexplorer.is.service.StorageServiceClient; import javax.naming.Context; import javax.naming.InitialContext; @@ -41,6 +42,8 @@ */ public class StorageServiceHelper { + private final static boolean mock = true; + private final static String PROVIDER_URL = "java.naming.provider.url"; private final static String FACTORY_INITIAL = "java.naming.factory.initial"; private final static String FACTORY_URL_PKGS = "java.naming.factory.url.pkgs"; @@ -58,7 +61,7 @@ */ public static StorageService getService(SimExplorerContext context, boolean remote) { StorageService service; - service = remote ? getRemoteStorageService(context) : getLocalStorageService(context); + service = remote ? getRemoteStorageService(context) : getLocalStorageService(); return service; } @@ -171,13 +174,17 @@ } } - /** - * @param context le context de l'application - * @return le service de storage locale - */ - protected static StorageService getLocalStorageService(SimExplorerContext context) { + /** @return le service de storage locale */ + protected static StorageService getLocalStorageService() { if (storageService == null) { - storageService = initLocalStorageService(context.getConfig()); + if (mock) { + return storageService = new MockStorageServiceImpl(); + } + try { + storageService = new StorageServiceClient(); + } catch (Exception e) { + throw new SimExplorerRuntimeException(e); + } } return storageService; } @@ -188,51 +195,24 @@ */ protected static StorageService getRemoteStorageService(SimExplorerContext context) { if (remoteStorageService == null) { - remoteStorageService = initRemoteStorageService(context.getConfig()); - } - return remoteStorageService; - } - - /** - * Initialise le service local de Storage - * - * @param config la config de l'application - * @return le service local initialisé - * @throws SimExplorerRuntimeException si pb lors de l'init du service - */ - protected static StorageService initLocalStorageService(SimExplorerConfig config) throws SimExplorerRuntimeException { - StorageService service; - try { - service = new MockStorageServiceImpl(); - return service; - } catch (Exception e) { - throw new SimExplorerRuntimeException(e); - } - } - - /** - * Initialise le service distant de Storage - * - * @param config la config de l'application - * @return le service distant initialisé - * @throws SimExplorerRuntimeException si pb lors de l'init du service - */ - protected static StorageService initRemoteStorageService(SimExplorerConfig config) throws SimExplorerRuntimeException { - - try { - StorageService service; - Properties props = initProperties(config.getRemoteURI()); - Context context; + if (mock) { + return remoteStorageService = new MockStorageServiceImpl(); + } try { - context = new InitialContext(props); - } catch (Exception e) { - context = new InitialContext(); + Properties props = initProperties(context.getConfig().getRemoteURI()); + Context context2; + try { + context2 = new InitialContext(props); + } catch (Exception e) { + context2 = new InitialContext(); + } + remoteStorageService = (StorageService) context2.lookup("StorageService"); + } catch (NamingException e) { + // no remote service available + remoteStorageService = null; } - service = (StorageService) context.lookup("StorageService"); - return service; - } catch (NamingException e) { - throw new SimExplorerRuntimeException(e); } + return remoteStorageService; } protected static Properties initProperties(URI uri) { Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ConnectAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ConnectAction.java 2008-02-13 16:09:09 UTC (rev 927) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ConnectAction.java 2008-02-13 16:25:50 UTC (rev 928) @@ -22,6 +22,7 @@ import fr.cemagref.simexplorer.is.service.StorageService; import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUIRefreshHelper; +import fr.cemagref.simexplorer.is.ui.StorageServiceHelper; import java.awt.event.ActionEvent; @@ -70,7 +71,7 @@ @Override protected void doAction(ActionEvent e) throws Exception { super.doAction(e); - StorageService service = getContext().getRemoteStorageService(); + StorageService service = StorageServiceHelper.getService(getContext(),true); try { String token = service.loginUser(login, password);
participants (1)
-
tchemit@users.labs.libre-entreprise.org