/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.store;
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
/**
- * This implementation of ICdmDataRepository depends on hibernate sessions to store the data correctly
- * for the current session. No state is held in this class.
- *
- * Only methods that either get or manipulate data are exposed here. So this class acts as a facade
- * for the methods in cdmlib-service.
- *
+ * This implementation of ICdmDataRepository depends on hibernate sessions to
+ * store the data correctly for the current session. No state is held in this
+ * class.
+ *
+ * Only methods that either get or manipulate data are exposed here. So this
+ * class acts as a facade for the methods in cdmlib-service.
+ *
* @author n.hoffmann
* @created 17.03.2009
* @version 1.0
*/
-public class CdmStore{
-
- private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource("/eu/etaxonomy/cdm/editorApplicationContext.xml", TaxeditorStorePlugin.class);
+public class CdmStore {
+
+ private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
+ "/eu/etaxonomy/cdm/editorApplicationContext.xml",
+ TaxeditorStorePlugin.class);
private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
-
+
private static CdmStore instance;
-
- private CdmApplicationController applicationController;
-
- private static LoginManager loginManager;
-
- private static ImportManager importManager;
-
- private static ExportManager exportManager;
-
- private static ContextManager contextManager;
-
+
+ private final CdmApplicationController applicationController;
+
+ private static LoginManager loginManager = new LoginManager();
+
+ private static ContextManager contextManager = new ContextManager();;
+
private static TermManager termManager = new TermManager();
-
- private static SearchManager searchManager;
-
- private static EditorManager editorManager;
-
+
+ private static SearchManager searchManager = new SearchManager();
+
+ private static EditorManager editorManager = new EditorManager();
+
private static CdmStoreConnector job;
-
+
private Language language;
-
+
private ICdmDataSource cdmDatasource;
-
+
private boolean isConnected;
-
+
/**
- * <p>getDefault</p>
- *
+ * <p>
+ * getDefault
+ * </p>
+ *
* @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
*/
- protected static CdmStore getDefault(){
- if(instance != null && instance.isConnected){
+ protected static CdmStore getDefault() {
+ if (instance != null && instance.isConnected) {
return instance;
- }else if(instance == null || !instance.isConnected){
-
- StoreUtil.warningDialog("Application is not connected to a datastore", instance, "The requested operation is only available when " +
- "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
-
+ } else if (instance == null || !instance.isConnected) {
+
+ StoreUtil
+ .warningDialog(
+ "Application is not connected to a datastore",
+ instance,
+ "The requested operation is only available when "
+ + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
+
StoreUtil.showView(CdmDataSourceViewPart.ID);
-
- }
-
+
+ }
+
throw new RuntimeException();
}
-
+
/**
* Initialize the with the last edited datasource
*/
public static void connect() {
-
- ICdmDataSource datasource = CdmDataSourceRepository.getCurrentDataSource();
-
+
+ ICdmDataSource datasource = CdmDataSourceRepository
+ .getCurrentDataSource();
+
connect(datasource);
}
-
+
/**
* Initialize with a specific datasource
- *
- * @param datasource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
+ *
+ * @param datasource
+ * a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
*/
public static void connect(ICdmDataSource datasource) {
- connect(datasource, DEFAULT_DB_SCHEMA_VALIDATION, DEFAULT_APPLICATION_CONTEXT);
+ connect(datasource, DEFAULT_DB_SCHEMA_VALIDATION,
+ DEFAULT_APPLICATION_CONTEXT);
}
-
+
/**
* Initialize and provide
*
* @param dbSchemaValidation
* @param applicationContextBean
*/
- private static void connect(final ICdmDataSource datasource, final DbSchemaValidation dbSchemaValidation, final Resource applicationContextBean){
+ private static void connect(final ICdmDataSource datasource,
+ final DbSchemaValidation dbSchemaValidation,
+ final Resource applicationContextBean) {
StoreUtil.info("Connecting to datasource: " + datasource);
-
- job = new CdmStoreConnector(Display.getDefault(), datasource, dbSchemaValidation, applicationContextBean);
+
+ job = new CdmStoreConnector(Display.getDefault(), datasource,
+ dbSchemaValidation, applicationContextBean);
job.setUser(true);
job.setPriority(Job.BUILD);
job.schedule();
-
+
}
- public static boolean isConnecting(){
+ public static boolean isConnecting() {
return job != null && job.getState() == Job.RUNNING;
}
/**
* Closes the current application context
- *
- * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+ *
+ * @param monitor
+ * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
*/
- public static void close(final IProgressMonitor monitor){
- Display.getDefault().asyncExec(new Runnable(){
- /* (non-Javadoc)
+ public static void close(final IProgressMonitor monitor) {
+ Display.getDefault().asyncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
getContextManager().notifyContextAboutToStop(monitor);
- if((monitor == null || (!monitor.isCanceled()) && isActive())){
+ if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
getContextManager().notifyContextStop(monitor);
- if(instance.getApplicationController() != null){
+ if (instance.getApplicationController() != null) {
instance.getApplicationController().close();
}
instance.close();
isConnected = false;
cdmDatasource = null;
}
-
- static void setInstance(CdmApplicationController applicationController, ICdmDataSource dataSource){
+
+ static void setInstance(CdmApplicationController applicationController,
+ ICdmDataSource dataSource) {
instance = new CdmStore(applicationController, dataSource);
}
-
- private CdmStore(CdmApplicationController applicationController, ICdmDataSource dataSource){
+
+ private CdmStore(CdmApplicationController applicationController,
+ ICdmDataSource dataSource) {
this.applicationController = applicationController;
this.cdmDatasource = dataSource;
isConnected = true;
}
-
+
/**
- * All calls to the datastore require
+ * All calls to the datastore require
*
* @return
*/
- private CdmApplicationController getApplicationController(){
- try{
+ private CdmApplicationController getApplicationController() {
+ try {
return applicationController;
- }catch(Exception e){
+ } catch (Exception e) {
StoreUtil.error(CdmStore.class, e);
}
return null;
}
-
+
/**
- * <p>getCurrentApplicationController</p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} object.
+ * <p>
+ * getCurrentApplicationController
+ * </p>
+ *
+ * @return a
+ * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController}
+ * object.
*/
- public static CdmApplicationController getCurrentApplicationController(){
- if(getDefault() != null){
+ public static CdmApplicationController getCurrentApplicationController() {
+ if (getDefault() != null) {
return getDefault().getApplicationController();
}
return null;
*/
/**
- * Creates a new conversation, binds resources to the conversation and
- * start a transaction for this conversation.
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * Creates a new conversation, binds resources to the conversation and start
+ * a transaction for this conversation.
+ *
+ * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
+ * object.
*/
public static ConversationHolder createConversation() {
- ConversationHolder conversation = getCurrentApplicationController().NewConversation();
-
+ ConversationHolder conversation = getCurrentApplicationController()
+ .NewConversation();
+
conversation.startTransaction();
return conversation;
}
-
+
/**
- * Generic method that will return an implementation of the given service interface
- * or <code>null</code> if the
+ * Generic method that will return an implementation of the given service
+ * interface or <code>null</code> if the
*
* @param <T>
* @param serviceClass
* @return
*/
- public static <T extends IService> T getService(Class<T> serviceClass){
- ICdmApplicationConfiguration controller = getCurrentApplicationController();
-
- Method[] methods = ICdmApplicationConfiguration.class.getDeclaredMethods();
-
+ public static <T extends IService> T getService(Class<T> serviceClass) {
+ ICdmApplicationConfiguration configuration = getCurrentApplicationController();
+
+ Method[] methods = ICdmApplicationConfiguration.class
+ .getDeclaredMethods();
+
T service = null;
-
- for(Method method : methods){
+
+ for (Method method : methods) {
Type type = method.getGenericReturnType();
-
- if(type.equals(serviceClass)){
+
+ if (type.equals(serviceClass)) {
try {
- service = (T) method.invoke(controller, null);
+ service = (T) method.invoke(configuration, null);
break;
} catch (IllegalArgumentException e) {
StoreUtil.error(CdmStore.class, e);
}
}
}
-
+
return service;
}
-
+
/**
- * <p>getAuthenticationManager</p>
- *
- * @return a {@link org.springframework.security.authentication.ProviderManager} object.
+ * <p>
+ * getAuthenticationManager
+ * </p>
+ *
+ * @return a
+ * {@link org.springframework.security.authentication.ProviderManager}
+ * object.
*/
- public static ProviderManager getAuthenticationManager() { return getCurrentApplicationController().getAuthenticationManager();}
-
+ public static ProviderManager getAuthenticationManager() {
+ return getCurrentApplicationController().getAuthenticationManager();
+ }
+
/**
- * <p>getGeoService</p>
- *
+ * <p>
+ * getGeoService
+ * </p>
+ *
* @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
*/
- public static IEditGeoService getGeoService(){
- return (IEditGeoService) getCurrentApplicationController().getBean("editGeoService");
+ public static IEditGeoService getGeoService() {
+ return (IEditGeoService) getCurrentApplicationController().getBean(
+ "editGeoService");
}
-
+
/*
* LANGUAGE
*/
-
+
/**
- * <p>getDefaultLanguage</p>
- *
+ * <p>
+ * getDefaultLanguage
+ * </p>
+ *
* @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
*/
- public static Language getDefaultLanguage(){
- if(getDefault().getLanguage() == null){
+ public static Language getDefaultLanguage() {
+ if (getDefault().getLanguage() == null) {
getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
}
return getDefault().getLanguage();
}
/**
- * <p>setDefaultLanguage</p>
- *
- * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
+ * <p>
+ * setDefaultLanguage
+ * </p>
+ *
+ * @param language
+ * a {@link eu.etaxonomy.cdm.model.common.Language} object.
*/
- public static void setDefaultLanguage(Language language){
+ public static void setDefaultLanguage(Language language) {
getDefault().setLanguage(language);
}
-
+
/**
* @return the language
*/
}
/**
- * @param language the language to set
+ * @param language
+ * the language to set
*/
private void setLanguage(Language language) {
this.language = language;
}
-
+
/*
* LOGIN
*/
-
+
/**
- * <p>Getter for the field <code>loginManager</code>.</p>
- *
+ * <p>
+ * Getter for the field <code>loginManager</code>.
+ * </p>
+ *
* @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
*/
- public static LoginManager getLoginManager(){
- if(loginManager == null){
- loginManager = new LoginManager();
- }
+ public static LoginManager getLoginManager() {
return loginManager;
}
-
+
/**
- * <p>Getter for the field <code>contextManager</code>.</p>
- *
+ * <p>
+ * Getter for the field <code>contextManager</code>.
+ * </p>
+ *
* @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
*/
- public static ContextManager getContextManager(){
- if(contextManager == null){
- contextManager = new ContextManager();
- }
+ public static ContextManager getContextManager() {
return contextManager;
}
-
- public static TermManager getTermManager(){
+
+ public static TermManager getTermManager() {
return termManager;
}
-
- public static SearchManager getSearchManager(){
- if(searchManager == null){
- searchManager = new SearchManager();
- }
+
+ public static SearchManager getSearchManager() {
return searchManager;
}
-
+
public static EditorManager getEditorManager() {
- if(editorManager == null){
- editorManager = new EditorManager();
- }
-
return editorManager;
}
-
+
/*
* IMPORT/EXPORT FACTORIES
*/
-
+
/**
- * <p>Getter for the field <code>importHandler</code>.</p>
- *
+ * <p>
+ * Getter for the field <code>importHandler</code>.
+ * </p>
+ *
* @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
*/
- public static ImportManager getImportManager(){
- if(importManager == null){
- importManager = ImportManager.NewInstance(getCurrentApplicationController());
- }
- return importManager;
+ public static ImportManager getImportManager() {
+ return ImportManager.NewInstance(getCurrentApplicationController());
}
-
+
/**
- * <p>Getter for the field <code>exportHandler</code>.</p>
- *
+ * <p>
+ * Getter for the field <code>exportHandler</code>.
+ * </p>
+ *
* @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
*/
- public static ExportManager getExportManager(){
- if(exportManager == null){
- exportManager = ExportManager.NewInstance(getCurrentApplicationController());
- }
- return exportManager;
+ public static ExportManager getExportManager() {
+ return ExportManager.NewInstance(getCurrentApplicationController());
}
-
+
/**
* Whether this CdmStore is currently connected to a datasource
- *
+ *
* @return a boolean.
*/
- public static boolean isActive(){
+ public static boolean isActive() {
return instance != null && instance.isConnected;
}
/**
- * <p>getDataSource</p>
- *
+ * <p>
+ * getDataSource
+ * </p>
+ *
* @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
*/
- public static ICdmDataSource getDataSource(){
- if(isActive()){
+ public static ICdmDataSource getDataSource() {
+ if (isActive()) {
return instance.getDatasource();
}
return null;
}
-
+
/**
* @return
*/