Merge branch 'release/5.34.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationState.java
index 979d43cac95a4683b63a4c8fdaa467137cd227d6..b8754d1cf69b3679983fd05926b5963bb4ed561a 100644 (file)
@@ -13,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;
@@ -63,7 +63,6 @@ public class CdmApplicationState {
         if(cdmApplicationState == null) {
             cdmApplicationState = new CdmApplicationState();
         }
-
         return cdmApplicationState;
     }
 
@@ -88,16 +87,9 @@ public class CdmApplicationState {
         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,36 +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;
@@ -163,25 +141,20 @@ public class CdmApplicationState {
 
         Method[] methods = ICdmRepository.class.getDeclaredMethods();
 
-        T service = null;
-
         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;
     }
 
     /**
@@ -206,17 +179,13 @@ public class CdmApplicationState {
         return ((CdmApplicationRemoteController)configuration).getLongRunningTasksService();
     }
 
-
-
     public static ITestService getTestService() {
         ICdmRepository configuration = getCurrentAppConfig();
-
         return ((CdmApplicationRemoteController)configuration).getTestService();
     }
 
     public static ICachedCommonService getCachedCommonService() {
         ICdmRepository configuration = getCurrentAppConfig();
-
         return ((CdmApplicationRemoteController)configuration).getCachedCommonService();
     }
 
@@ -245,7 +214,8 @@ public class CdmApplicationState {
                     File file = null;
                     try {
                         String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");
-                        file = new File(new URI(urlString));
+                        
+                        file = new File(new URI(urlString).getJavaUri());
                         JarFile jarFile = new JarFile(file);
                         Manifest manifest = jarFile.getManifest();
                         Attributes attributes = manifest.getMainAttributes();
@@ -264,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) {