/************************************************************************* * * * SignServer: The OpenSource Automated Signing Server * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.signserver.test.random; import java.rmi.RemoteException; import javax.naming.NamingException; import org.apache.log4j.Logger; import org.signserver.common.ServiceLocator; import org.signserver.ejb.interfaces.IGlobalConfigurationSession; import org.signserver.ejb.interfaces.IWorkerSession; import org.signserver.statusrepo.IStatusRepositorySession; /** * Helper class with methods useful for many Command implementations. * * @author Markus KilÄs * @version $Id: AdminCommandHelper.java 2672 2012-09-19 08:47:17Z netmackan $ */ public class AdminCommandHelper { /** Logger for this class. */ private static Logger LOG = Logger.getLogger(AdminCommandHelper.class); /** The global configuration session. */ private IGlobalConfigurationSession.IRemote globalConfig; /** The SignSession. */ private IWorkerSession.IRemote signsession; /** The StatusRepositorySession. */ private IStatusRepositorySession.IRemote statusRepository; /** * Gets GlobalConfigurationSession Remote. * @return SignServerSession * @throws RemoteException in case the lookup failed */ public IGlobalConfigurationSession.IRemote getGlobalConfigurationSession() throws RemoteException { if (globalConfig == null) { try { globalConfig = ServiceLocator.getInstance().lookupRemote( IGlobalConfigurationSession.IRemote.class); } catch (NamingException e) { LOG.error("Error instanciating the GlobalConfigurationSession.", e); throw new RemoteException("Error instanciating the GlobalConfigurationSession", e); } } return globalConfig; } /** * Gets StatusRepositorySession Remote. * @return SignServerSession * @throws RemoteException in case the lookup failed */ public IStatusRepositorySession.IRemote getStatusRepositorySession() throws RemoteException { if (statusRepository == null) { try { statusRepository = ServiceLocator.getInstance().lookupRemote( IStatusRepositorySession.IRemote.class); } catch (NamingException e) { LOG.error("Error instanciating the StatusRepositorySession.", e); throw new RemoteException( "Error instanciating the StatusRepositorySession", e); } } return statusRepository; } /** * Gets SignServerSession Remote. * @return SignServerSession * @throws RemoteException in case the lookup failed */ public IWorkerSession.IRemote getWorkerSession() throws RemoteException { if (signsession == null) { try { signsession = ServiceLocator.getInstance().lookupRemote( IWorkerSession.IRemote.class); } catch (NamingException e) { LOG.error("Error looking up signserver interface"); throw new RemoteException("Error looking up signserver interface", e); } } return signsession; } }