Merge branch 'release/5.34.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationState.java
index 3208cc70e69b2cbb25cec0302547f10d74fa3509..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;
@@ -42,7 +42,6 @@ import eu.etaxonomy.taxeditor.session.DefaultNewEntityListener;
 /**
  * @author cmathew
  * @date 17 Jun 2015
- *
  */
 public class CdmApplicationState {
 
@@ -52,6 +51,7 @@ public class CdmApplicationState {
 
     private ICdmDataChangeService dataChangeService;
 
+    //FIXME SecurityContextHolder.getContext()
     private SecurityContext securityContext;
 
     private static CdmServiceCacher cdmServiceCacher;
@@ -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,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,7 +126,6 @@ public class CdmApplicationState {
         cdmlibLastModified = null;
     }
 
-
     /**
      * 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
@@ -166,29 +141,22 @@ 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;
     }
 
-
     /**
      * @see #getService(Class)
      * As ICommonService is not extending IService we need a specific request here
@@ -197,37 +165,28 @@ public class CdmApplicationState {
         ICdmRepository configuration = getCurrentAppConfig();
 
         return configuration.getCommonService();
-
     }
 
     public static IIOService getIOService() {
         ICdmRepository configuration = getCurrentAppConfig();
 
         return ((CdmApplicationRemoteController)configuration).getIOService();
-
     }
 
     public static ILongRunningTasksService getLongRunningTasksService() {
         ICdmRepository configuration = getCurrentAppConfig();
 
         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();
-
     }
 
     public static CdmServiceCacher getCdmServiceCacher() {
@@ -255,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();
@@ -274,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) {