X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/cc712487ed34d0ecde5ab01c4bbb0acf0152c638..edb488c8372c449b9a99349bc481d9247b61bcb2:/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java index 8bee46bf9..b8754d1cf 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java @@ -1,4 +1,3 @@ -// $Id$ /** * Copyright (C) 2015 EDIT * European Distributed Institute of Taxonomy @@ -14,7 +13,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.net.URI; +import eu.etaxonomy.cdm.common.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Dictionary; @@ -34,6 +33,7 @@ import eu.etaxonomy.cdm.api.cache.CdmServiceCacher; import eu.etaxonomy.cdm.api.service.ICommonService; import eu.etaxonomy.cdm.api.service.IService; import eu.etaxonomy.cdm.api.service.ITestService; +import eu.etaxonomy.cdm.api.service.longrunningService.ILongRunningTasksService; import eu.etaxonomy.cdm.io.service.IIOService; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.taxeditor.service.ICachedCommonService; @@ -42,16 +42,16 @@ import eu.etaxonomy.taxeditor.session.DefaultNewEntityListener; /** * @author cmathew * @date 17 Jun 2015 - * */ public class CdmApplicationState { private static CdmApplicationState cdmApplicationState; - private ICdmApplicationConfiguration appConfig; + private ICdmRepository appConfig; private ICdmDataChangeService dataChangeService; + //FIXME SecurityContextHolder.getContext() private SecurityContext securityContext; private static CdmServiceCacher cdmServiceCacher; @@ -63,11 +63,10 @@ public class CdmApplicationState { if(cdmApplicationState == null) { cdmApplicationState = new CdmApplicationState(); } - return cdmApplicationState; } - public void setAppConfig(ICdmApplicationConfiguration appConfig) { + public void setAppConfig(ICdmRepository appConfig) { this.appConfig = appConfig; if(appConfig instanceof CdmApplicationRemoteController) { CdmBase.setNewEntityListener(new DefaultNewEntityListener()); @@ -76,28 +75,21 @@ public class CdmApplicationState { } } - public ICdmApplicationConfiguration getAppConfig() { + public ICdmRepository getAppConfig() { return appConfig; } - public static void setCurrentAppConfig(ICdmApplicationConfiguration appConfig) { + public static void setCurrentAppConfig(ICdmRepository appConfig) { getInstance().setAppConfig(appConfig); } - public static ICdmApplicationConfiguration getCurrentAppConfig() { + public static ICdmRepository getCurrentAppConfig() { return getInstance().getAppConfig(); } - /** - * @return the dataChangeService - */ public ICdmDataChangeService getDataChangeService() { return dataChangeService; } - - /** - * @param dataChangeService the dataChangeService to set - */ public void setDataChangeService(ICdmDataChangeService dataChangeService) { this.dataChangeService = dataChangeService; } @@ -110,38 +102,22 @@ public class CdmApplicationState { getInstance().setDataChangeService(dataChangeService); } - - - /** - * @return the securityContext - */ public SecurityContext getSecurityContext() { return securityContext; } - - /** - * @param securityContext the securityContext to set - */ public void setSecurityContext(SecurityContext securityContext) { this.securityContext = securityContext; } - /** - * @return the securityContext - */ public static SecurityContext getCurrentSecurityContext() { return getInstance().getSecurityContext(); } - - /** - * @param securityContext the securityContext to set - */ public static void setCurrentSecurityContext(SecurityContext securityContext) { getInstance().setSecurityContext(securityContext); } public static void dispose() { - getInstance().setCurrentDataChangeService(null); + setCurrentDataChangeService(null); getInstance().setAppConfig(null); getInstance().setSecurityContext(null); cdmApplicationState = null; @@ -150,9 +126,8 @@ public class CdmApplicationState { cdmlibLastModified = null; } - /** - * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service + * Generic method that will scan the getters of {@link ICdmRepository} for the given service * interface. If a matching getter is found the according service implementation is returned by * invoking the getter otherwise the method returns null. * @@ -162,64 +137,56 @@ public class CdmApplicationState { * @throws CdmApplicationException */ public static T getService(Class serviceClass) throws CdmApplicationException { - ICdmApplicationConfiguration configuration = getCurrentAppConfig(); - - Method[] methods = ICdmApplicationConfiguration.class.getDeclaredMethods(); + ICdmRepository configuration = getCurrentAppConfig(); - T service = null; + Method[] methods = ICdmRepository.class.getDeclaredMethods(); for (Method method : methods) { Type type = method.getGenericReturnType(); if (type.equals(serviceClass)) { try { - service = (T) method.invoke(configuration, null); - break; - } catch (IllegalArgumentException iae) { + @SuppressWarnings("unchecked") + T service = (T) method.invoke(configuration); + return service; + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException iae) { throw new CdmApplicationException(iae); - } catch (IllegalAccessException iae) { - throw new CdmApplicationException(iae); - } catch (InvocationTargetException ite) { - throw new CdmApplicationException(ite); } } } - - return service; + return null; } - /** * @see #getService(Class) * As ICommonService is not extending IService we need a specific request here */ public static ICommonService getCommonService() { - ICdmApplicationConfiguration configuration = getCurrentAppConfig(); + ICdmRepository configuration = getCurrentAppConfig(); return configuration.getCommonService(); - } public static IIOService getIOService() { - ICdmApplicationConfiguration configuration = getCurrentAppConfig(); + ICdmRepository configuration = getCurrentAppConfig(); return ((CdmApplicationRemoteController)configuration).getIOService(); - } + public static ILongRunningTasksService getLongRunningTasksService() { + ICdmRepository configuration = getCurrentAppConfig(); - public static ITestService getTestService() { - ICdmApplicationConfiguration configuration = getCurrentAppConfig(); + return ((CdmApplicationRemoteController)configuration).getLongRunningTasksService(); + } + public static ITestService getTestService() { + ICdmRepository configuration = getCurrentAppConfig(); return ((CdmApplicationRemoteController)configuration).getTestService(); - } public static ICachedCommonService getCachedCommonService() { - ICdmApplicationConfiguration configuration = getCurrentAppConfig(); - + ICdmRepository configuration = getCurrentAppConfig(); return ((CdmApplicationRemoteController)configuration).getCachedCommonService(); - } public static CdmServiceCacher getCdmServiceCacher() { @@ -246,8 +213,9 @@ public class CdmApplicationState { URL fileURL = bundle.getEntry(jar); File file = null; try { - String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");; - file = new File(new URI(urlString)); + String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20"); + + file = new File(new URI(urlString).getJavaUri()); JarFile jarFile = new JarFile(file); Manifest manifest = jarFile.getManifest(); Attributes attributes = manifest.getMainAttributes(); @@ -266,7 +234,10 @@ public class CdmApplicationState { throw new IllegalStateException(urise); } catch (IOException ioe) { throw new IllegalStateException(ioe); - } + } catch (IllegalArgumentException iae) { + String message = iae.getMessage().concat("uri" + jar); + throw new IllegalStateException(message); + } } } } catch (BundleException e) {