Merge branch 'release/5.34.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationState.java
index ad26a9f1f78bf221eb4c1035c03764baa6d204e1..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;
@@ -117,7 +117,7 @@ public class CdmApplicationState {
     }
 
     public static void dispose() {
-        getInstance().setCurrentDataChangeService(null);
+        setCurrentDataChangeService(null);
         getInstance().setAppConfig(null);
         getInstance().setSecurityContext(null);
         cdmApplicationState = null;
@@ -141,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) {
-                    throw new CdmApplicationException(iae);
-                } catch (IllegalAccessException iae) {
+                    @SuppressWarnings("unchecked")
+                    T service = (T) method.invoke(configuration);
+                    return service;
+                } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException iae) {
                     throw new CdmApplicationException(iae);
-                } catch (InvocationTargetException ite) {
-                    throw new CdmApplicationException(ite);
                 }
             }
         }
-        return service;
+        return null;
     }
 
     /**
@@ -219,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();
@@ -238,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) {