ref #6612 adding RegistrationService to remoting configuration
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationState.java
index e9e489a53666ed112d83fa96a41385b61e67c993..796727a2c1b049f3d44da581d006ac5cf19d1262 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2015 EDIT
 * European Distributed Institute of Taxonomy
@@ -14,6 +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 java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Dictionary;
@@ -47,7 +47,7 @@ public class CdmApplicationState {
 
     private static CdmApplicationState cdmApplicationState;
 
-    private ICdmApplicationConfiguration appConfig;
+    private ICdmRepository appConfig;
 
     private ICdmDataChangeService dataChangeService;
 
@@ -66,7 +66,7 @@ public class CdmApplicationState {
         return cdmApplicationState;
     }
 
-    public void setAppConfig(ICdmApplicationConfiguration appConfig) {
+    public void setAppConfig(ICdmRepository appConfig) {
         this.appConfig = appConfig;
         if(appConfig instanceof CdmApplicationRemoteController) {
             CdmBase.setNewEntityListener(new DefaultNewEntityListener());
@@ -75,15 +75,15 @@ 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();
     }
 
@@ -151,7 +151,7 @@ public class CdmApplicationState {
 
 
     /**
-     * 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 <code>null</code>.
      *
@@ -161,9 +161,9 @@ public class CdmApplicationState {
      * @throws CdmApplicationException
      */
     public static <T extends IService> T getService(Class<T> serviceClass) throws CdmApplicationException {
-        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
+        ICdmRepository configuration = getCurrentAppConfig();
 
-        Method[] methods = ICdmApplicationConfiguration.class.getDeclaredMethods();
+        Method[] methods = ICdmRepository.class.getDeclaredMethods();
 
         T service = null;
 
@@ -193,14 +193,14 @@ public class CdmApplicationState {
      * 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();
 
@@ -208,14 +208,14 @@ public class CdmApplicationState {
 
 
     public static ITestService getTestService() {
-        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
+        ICdmRepository configuration = getCurrentAppConfig();
 
         return ((CdmApplicationRemoteController)configuration).getTestService();
 
     }
 
     public static ICachedCommonService getCachedCommonService() {
-        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
+        ICdmRepository configuration = getCurrentAppConfig();
 
         return ((CdmApplicationRemoteController)configuration).getCachedCommonService();
 
@@ -245,7 +245,8 @@ public class CdmApplicationState {
                     URL fileURL = bundle.getEntry(jar);
                     File file = null;
                     try {
-                        file = new File(FileLocator.resolve(fileURL).toURI());
+                        String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");
+                        file = new File(new URI(urlString));
                         JarFile jarFile = new JarFile(file);
                         Manifest manifest = jarFile.getManifest();
                         Attributes attributes = manifest.getMainAttributes();
@@ -256,6 +257,7 @@ public class CdmApplicationState {
                         cdmlibVersion = attributes.getValue("Bundle-Version");
                         cdmlibLastModified = attributes.getValue("Bnd-LastModified");
 
+                        jarFile.close();
                         if(cdmlibVersion == null || cdmlibLastModified == null) {
                             throw new IllegalStateException("Invalid cdmlib manifest info");
                         }