Author: tchemit Date: 2008-02-20 18:51:53 +0000 (Wed, 20 Feb 2008) New Revision: 1147 Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorer.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerConfig.java 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 Log: move to swing package Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorer.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorer.java 2008-02-20 18:51:21 UTC (rev 1146) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorer.java 2008-02-20 18:51:53 UTC (rev 1147) @@ -1,194 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui; - -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerMainUI; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab; -import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction; -import fr.cemagref.simexplorer.is.ui.swing.util.ErrorDialog; -import org.codelutin.i18n.I18n; -import org.codelutin.option.ui.ConfigTableModel; -import org.codelutin.option.ui.ConfigUI; - -import java.awt.event.ActionEvent; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; - -/** - * L'application principale - * - * @author chemit - */ -public class SimExplorer { - - /** le context principal de l'application */ - protected static SimExplorerContext context; - - /** l'ui principale de l'application */ - protected static SimExplorerMainUI ui; - - /** le dialogue pour afficher les erreurs */ - protected static ErrorDialog errorDialog; - - public static SimExplorerContext getContext() { - checkInitContext(); - return context; - } - - public static SimExplorerMainUI getUI() { - checkInitContext(); - if (ui == null) { - ui = new SimExplorerMainUI(); - } - return ui; - } - - public static void showError(Exception e) { - if (errorDialog == null) { - errorDialog = new ErrorDialog(); - } - errorDialog.getErrorMessage().setText(e.getMessage()); - StringWriter w = new StringWriter(); - e.printStackTrace(new PrintWriter(w)); - errorDialog.getErrorStack().setText(w.toString()); - errorDialog.getErrorStack().setCaretPosition(0); - errorDialog.pack(); - errorDialog.setVisible(true); - } - - public static void disposeUI() { - ui = null; - SimExplorerActionManager.resetCache(); - ConfigUI.reloadUI(); - errorDialog = null; - SimExplorerTab.getFactory().resetCache(); - // remove listeners on detail tab model - for (SimExplorerTab tab : SimExplorerTab.values()) { - tab.removePropertyChangeListeners(); - } - // on nettoye les ui cachees dans les actions - SimExplorerActionManager.disposeUI(); - } - - /** - * initialisation de l'application : - * <p/> - * chargement du context - * - * @param args les arguments passés à l'application - */ - public static void init(String... args) { - - // init context - context = new SimExplorerContext(); - - // init i18n - I18n.initISO88591(); - - // init parser - context.initParser(args); - - // init config - context.initConfig(); - - // save config - try { - context.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** Lancement de l'ui après init de l'application. */ - public static void launch() { - - // init ui - SimExplorerMainUI mainUI = getUI(); - - SimExplorerConfig conf = getContext().getConfig(); - - if (conf.isShowLocalTab()) { - // show local tab - mainUI.getToggleTab_local().doClick(); - } - if (conf.isAutoConnect()) { - try { - // try to connect - mainUI.getConnect().getAction().actionPerformed(new ActionEvent(mainUI, 0, "connect")); - // action will update ui if everything is correct - if (context.isConnected() && conf.isShowRemoteTab()) { - // show remote tab - mainUI.getToggleTab_remote().doClick(); - } - } catch (Exception e) { - // ignore ? - System.err.println(e.getMessage()); - } - } - - // refresh ui accessibles actions - if (!context.isConnected()) { - getConnectAction(false).updateUI(); - } - - - mainUI.setVisible(true); - } - - public static SimExplorerAbstractAction getConnectAction(boolean isConnected) { - if (isConnected) { - return (SimExplorerAbstractAction) getUI().getConnect().getAction(); - } else { - return (SimExplorerAbstractAction) getUI().getUnconnect().getAction(); - } - } - - public static void main(String... args) throws Exception { - - // init application (parser,config,i18n,...) - init(args); - - // launch actions required - context.getParser().doAllActions(); - - // show edit config if first launch - if (SimExplorer.context.isFirstLaunch()) { - ConfigUI.showUI(context.getConfig(), ConfigTableModel.TypeModel.all); - } - - // launch ui only if required - if (!context.isQuit() && context.isLaunchUI()) { - launch(); - } - - } - - protected static void checkInitContext() { - if (context == null) { - throw new SimExplorerRuntimeException("context is null, you must init first the " + SimExplorer.class.getName() + " class via init method"); - } - } - - protected SimExplorer() { - // protected restricted access - } -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerConfig.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerConfig.java 2008-02-20 18:51:21 UTC (rev 1146) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerConfig.java 2008-02-20 18:51:53 UTC (rev 1147) @@ -1,132 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui; - -import fr.cemagref.simexplorer.is.ui.configs.SimExplorerAbstractConfigMain; -import fr.cemagref.simexplorer.is.ui.options.SimExplorerOptionConfig; -import fr.cemagref.simexplorer.is.ui.options.SimExplorerOptionConfigFile; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import org.codelutin.i18n.CountryEnum; -import org.codelutin.i18n.I18n; -import static org.codelutin.i18n.I18n._; -import org.codelutin.i18n.LanguageEnum; -import org.codelutin.option.ConfigPropertyKey; -import org.codelutin.option.OptionParser; - -import java.io.File; -import java.io.IOException; - -/** - * L'implantation concrete de la config principale - * - * @author chemit - */ -public class SimExplorerConfig extends SimExplorerAbstractConfigMain { - - public SimExplorerConfig() { - super(); - String home = System.getProperty("user.home"); - if (home == null) { - // this is a serious fatal error - throw new SimExplorerRuntimeException("simexplorer.error.user.home"); - } - doInit(); - } - - public void init() throws IOException { - log.info("start for category [" + category + "] -------------------------"); - - SimExplorerOptionParser parser = SimExplorer.getContext().getParser(); - initConfigFile(parser); - log.info("config file : " + getSource()); - // chargement des valeurs par défaut - loadFromDefaultValue(); - // après le chargement des valeurs par défaut - // la configuration n'est pas modifiée - clearModified(); - // surcharge à partir du fichier de configuration de l'utilisateur - loadFromSource(); - // surcharge à partir des propriétés système - loadFromSystem(); - // surcharge à partir des propriétés de la jvm - loadFromJvm(); - // surcharge à partir de l'option config de la ligne de commande - loadFromOptions(parser); - clearModified(); - for (String s : this.toString().split("\n")) { - log.debug(s); - } - log.info("end for category [" + category + "] ---------------------------"); - } - - protected void initConfigFile(OptionParser parser) { - File file; - if (parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY)) { - // surcharge config file - SimExplorerOptionConfigFile option = SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY.getOptions().get(0); - - file = option.getConfigFile(); - } else { - String home = System.getProperty("user.home", ""); - File root = new File(home); - file = new File(root, SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY.getDefaultValue().getName()); - if (!file.exists()) { - SimExplorer.getContext().setFirstLaunch(true); - try { - file.createNewFile(); - } catch (IOException e) { - throw new SimExplorerRuntimeException(e); - } - } - } - if (containsKey(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY)) { - setProperty(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY, file); - } - setSource(file); - } - - public void initI18n() { - I18n.initISO88591(getUserLanguage().name(), getUserCountry().name()); - } - - protected void loadFromOptions(SimExplorerOptionParser parser) { - if (!parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_OPTION_KEY)) { - return; - } - // surcharge config file - for (SimExplorerOptionConfig option : SimExplorerOptionParser.CONFIG_OPTION_KEY.getOptions()) { - if (getCategory().equals(SimExplorerOptionParser.MAIN_CONFIG_KEY.getCategory())) { - ConfigPropertyKey<?> propKey = getPropertyKey(option.getKey()); - if (propKey == null) { - // fatal error , could not found a matching configuration property - throw new SimExplorerRuntimeException(_("simexplorer.error.unfound.config.property", category, option.getKey())); - } - Object oldVal = propKey.getCurrentValue(); - setProperty(propKey, option.getValue()); - Object newVal = propKey.getCurrentValue(); - log.info(_("simexplorer.change.config.property", category, propKey, oldVal, newVal)); - } - } - } - - public void setI18n(LanguageEnum language, CountryEnum country) { - setUserLanguage(language); - setUserCountry(country); - } -} \ No newline at end of file Deleted: 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-20 18:51:21 UTC (rev 1146) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/SimExplorerContext.java 2008-02-20 18:51:53 UTC (rev 1147) @@ -1,197 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui; - -import fr.cemagref.simexplorer.is.ui.actions.SimExplorerCommonActions; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.option.ParserException; - -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -/** - * Le context de l'application, implanté en singleton. - * <p/> - * Contient la configuration de l'application, le parseur d'options,... - * - * @author chemit - */ -public class SimExplorerContext { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimExplorerContext.class); - - /** - * le parseur utilisé au démarrage pour récupérer les options passées - * par l'utilisateur. - */ - protected SimExplorerOptionParser parser; - - /** flag pour indiquer si 'lon veut quitter l'appli après les options */ - protected boolean quit; - - /** flag pour indiquer si l'on affiche ou non l'ui principale */ - protected boolean launchUI = true; - - /** - * flag pour indiquer une première utilisation de l'application (pas de - * fichier de configuration) - */ - protected boolean firstLaunch; - - /** le token pour la connexion au serveur distant */ - protected String token; - - /** - * @return le parseur utilisé pour parser les options de la ligne de - * commande. - */ - public SimExplorerOptionParser getParser() { - if (parser == null) { - // creation du parseur - parser = new SimExplorerOptionParser(); - // enregistrement des actions concretes - parser.registerActions(SimExplorerCommonActions.class); - // enregistrement des configs concretes - parser.registerConfig(SimExplorerConfig.class); - } - return parser; - } - - /** @return la configuration de l'application */ - public SimExplorerConfig getConfig() { - return (SimExplorerConfig) getParser().getMainConfig(); - } - - /** - * @return <code>true</code> si l'utilisateur est connecté, - * <code>false</code> sinon. - */ - public boolean isConnected() { - return !(token == null || token.isEmpty()); - } - - /** - * Sauvegarde la configuration courante de l'utilisateur. - * - * @throws IOException si problème lors de l'écriture du fichier de configuration - */ - public void save() throws IOException { - if (getConfig().getSource() == null) { - return; - } - BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getConfig().getSource())); - try { - getConfig().save(out); - } finally { - out.flush(); - out.close(); - } - } - - /** - * Sauvegarde la configuration de l'utilisateur sans soulever d'exception - * si un problème est survenu lors de l'opération. - */ - public void saveSafely() { - try { - save(); - } catch (Exception e) { - log.warn("simexplorer.error.unsafe.save.config" + e.getMessage(), e); - } - } - - /** - * @return <code>true</code> si on doit quitter l'application (uniquement utilisé - * lors du démarrage de l'application lors de l'exécution des options - * utilisateurs) - */ - public boolean isQuit() { - return quit; - } - - /** - * @return <code>true</code> si on doit lancer l'ui au démarrage de - * l'application, après avoir traité toutes les options utilisateurs - */ - public boolean isLaunchUI() { - return launchUI; - } - - /** - * @return <code>true</code> s'il s'agit de la première utilisation de - * l'application (aucun de fichier de configuration trouvé) - */ - public boolean isFirstLaunch() { - return firstLaunch; - } - - /** - * @return le token utilisé pour identifié l'utilisateur sur le serveur distant. - * <p/> - * <b>Si est null ou vide cela veut que l'utilisateur n'est pas connecté.</b> - */ - public String getToken() { - return token; - } - - public void setQuit(boolean quit) { - this.quit = quit; - } - - public void setLaunchUI(boolean launchUI) { - this.launchUI = launchUI; - } - - public void setFirstLaunch(boolean firstLaunch) { - this.firstLaunch = firstLaunch; - } - - public void setToken(String token) { - this.token = token; - } - - /** restricted access constructor */ - SimExplorerContext() { - - } - - /** - * Initialisation du parseur d'options. - * - * @param args les arguments passés au démarrage de l'application - */ - void initParser(String... args) { - try { - getParser().doParse(args); - } catch (ParserException e) { - throw new SimExplorerRuntimeException(e); - } catch (IOException e) { - throw new SimExplorerRuntimeException(e); - } - } - - /** Initialisation de la configuration utilisateur */ - void initConfig() { - getConfig().initI18n(); - } -} Deleted: 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-20 18:51:21 UTC (rev 1146) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java 2008-02-20 18:51:53 UTC (rev 1147) @@ -1,248 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui; - -import com.healthmarketscience.rmiio.SerializableInputStream; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.exceptions.UnreachableServiceException; -import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl; -import fr.cemagref.simexplorer.is.service.StorageService; -import fr.cemagref.simexplorer.is.service.StorageServiceClient; -import static fr.cemagref.simexplorer.is.service.StorageServiceHelper.STORAGE_SERVICE_LOOKUP_NAME; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.net.URI; -import java.util.Properties; - -/** - * Une classe pour encapsuler les appels aux services Storage et leur initialisation. - * - * @author chemit - */ -public class StorageServiceHelper { - - private final static boolean mock = false; - - 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"; - - /** le service de données distant */ - protected static StorageService remoteStorageService; - - /** le service de données local */ - protected static StorageService storageService; - - /** - * @param context le context de l'application - * @param remote flag pour indiquer le type de service recherché (local ou remote) - * @return le service instancié et initialisé - * @throws UnreachableServiceException si service non joignable - */ - public static StorageService getService(SimExplorerContext context, boolean remote) throws UnreachableServiceException { - StorageService service; - service = remote ? getRemoteStorageService(context) : getLocalStorageService(); - if (service == null) { - throw new UnreachableServiceException("could not find service " + (remote ? "remote" : "local")); - } - return service; - } - - public static int getCount(SimExplorerContext context, boolean remote, String query, boolean onlyLatest) { - StorageService service = getService(context, remote); - String token = context.getToken(); - int size; - try { - if (query == null || query.isEmpty()) { - size = service.findApplicationsCount(token, onlyLatest); - } else { - size = service.findFullTextCount(token, query, onlyLatest); - } - return size; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - public static String loginUser(SimExplorerContext context, boolean remote, String login, String hashPassword) throws UnreachableServiceException { - StorageService service = getService(context, remote); - try { - /*if (service == null) { - throw new UnreachableServiceException("could not find service " + (remote ? "remote" : "local")); - }*/ - String token; - token = service.loginUser(login, hashPassword); - return token; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - public static MetaData[] getData(SimExplorerContext context, boolean remote, boolean onlyLatest, String query, long newFirstIndex, int width, int rowOrder) { - StorageService service = getService(context, remote); - String token = context.getToken(); - try { - MetaData[] data; - if (query == null || query.isEmpty()) { - data = service.findApplications(token, onlyLatest, (int) newFirstIndex, width, rowOrder); - } else { - data = service.findFullText(token, query, onlyLatest, (int) newFirstIndex, width, rowOrder); - } - return data; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - - public static LoggableElement getElement(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - LoggableElement data; - data = getService(context, remote).getLoggableElement(context.getToken(), uuid, version); - return data; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - public static void deleteElement(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - getService(context, remote).deleteElement(context.getToken(), uuid, version); - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - public static MetaData getMetaData(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - MetaData metas; - metas = getService(context, remote).getMetadata(context.getToken(), uuid, version); - return metas; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - - public static BufferedInputStream retrieveElementFull(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - InputStream stream = getService(context, remote).retrieveElementFull(context.getToken(), uuid, version); - BufferedInputStream bis; - bis = new BufferedInputStream(stream); - return bis; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - public static BufferedInputStream retrieveElementData(SimExplorerContext context, boolean remote, String uuid, String version, Attachment attachment) { - try { - InputStream stream = getService(context, remote).retrieveElementData(context.getToken(), uuid, version, attachment); - BufferedInputStream bis; - bis = new BufferedInputStream(stream); - return bis; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - public static void importElement(SimExplorerContext context, boolean remote, File file) { - try { - SerializableInputStream zipStream; - zipStream = new SerializableInputStream(new FileInputStream(file)); - getService(context, remote).saveElement(context.getToken(), zipStream); - } catch (Exception e) { - throw new SimExplorerRuntimeException(e); - } - } - - public static Version[] getVersions(SimExplorerContext context, boolean remote, String uuid) { - try { - Version[] result; - result = getService(context, remote).getVersions(context.getToken(), uuid); - return result; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - /** @return le service de storage locale */ - protected static StorageService getLocalStorageService() { - if (storageService == null) { - if (mock) { - return storageService = new MockStorageServiceImpl(false); - } - try { - storageService = new StorageServiceClient(); - } catch (Exception e) { - throw new SimExplorerRuntimeException(e); - } - } - return storageService; - } - - /** - * @param context le context de l'application - * @return le service de storage distant - */ - protected static StorageService getRemoteStorageService(SimExplorerContext context) { - if (remoteStorageService == null) { - if (mock) { - return remoteStorageService = new MockStorageServiceImpl(true); - } - try { - Properties props = initProperties(context.getConfig().getRemoteURI()); - Context context2; - try { - context2 = new InitialContext(props); - } catch (Exception e) { - context2 = new InitialContext(); - } - remoteStorageService = (StorageService) context2.lookup(STORAGE_SERVICE_LOOKUP_NAME); - } catch (NamingException e) { - // no remote service available - remoteStorageService = null; - } - } - return remoteStorageService; - } - - protected static Properties initProperties(URI uri) { - Properties props = (Properties) System.getProperties().clone(); - props.put(PROVIDER_URL, uri.toString()); - props.put(FACTORY_INITIAL, "org.jnp.interfaces.NamingContextFactory"); - props.put(FACTORY_URL_PKGS, "org.jnp.interfaces"); - return props; - } - - protected StorageServiceHelper() { - // no instance - } -}