myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] 02/02: refactored
Date Sun, 18 Aug 2019 21:14:43 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git

commit 92b1c4670be784109bd22f18900199381de2a480
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Sun Aug 18 23:14:34 2019 +0200

    refactored
---
 .../spi/impl/DefaultFacesFlowProviderFactory.java  |  3 +-
 .../spi/impl/DefaultServiceProviderFinder.java     | 77 +++++++++-------------
 .../spi/impl/DefaultStateCacheProviderFactory.java | 10 +--
 .../spi/impl/DefaultViewScopeProviderFactory.java  |  3 +-
 4 files changed, 35 insertions(+), 58 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java
b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java
index c40e012..5b65794 100644
--- a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java
+++ b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesFlowProviderFactory.java
@@ -61,8 +61,7 @@ public class DefaultFacesFlowProviderFactory extends FacesFlowProviderFactory
             {
                 if (ExternalSpecifications.isCDIAvailable(externalContext))
                 {
-                    returnValue = (FacesFlowProvider) ClassUtils.newInstance(
-                            DefaultCDIFacesFlowProvider.class.getName());
+                    returnValue = new DefaultCDIFacesFlowProvider();
                 }
                 else
                 {
diff --git a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
index 5bfa7e0..ccb5f85 100644
--- a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
+++ b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
@@ -55,8 +55,7 @@ public class DefaultServiceProviderFinder extends ServiceProviderFinder
         Enumeration<URL> profiles = null;
         try
         {
-            profiles = ClassUtils.getContextClassLoader().getResources(
-                    META_INF_SERVICES + spiClass);
+            profiles = ClassUtils.getContextClassLoader().getResources(META_INF_SERVICES
+ spiClass);
         }
         catch (IOException e)
         {
@@ -88,66 +87,52 @@ public class DefaultServiceProviderFinder extends ServiceProviderFinder
         }
         
         Set<URL> urls = getURLs(spiClass);
-
         if (!urls.isEmpty())
         {
-            List<String> results = new LinkedList<String>();
+            List<String> results = new LinkedList<>();
             for (URL url : urls)
             {
-                InputStream is = null;
-    
                 try
                 {
-                    try
+                    try (InputStream is = openStreamWithoutCache(url))
                     {
-                        is = openStreamWithoutCache(url);
-                        if (is != null)
+                        // This code is needed by EBCDIC and other
+                        // strange systems.  It's a fix for bugs
+                        // reported in xerces
+                        BufferedReader rd;
+                        try
                         {
-                            // This code is needed by EBCDIC and other
-                            // strange systems.  It's a fix for bugs
-                            // reported in xerces
-                            BufferedReader rd;
-                            try
-                            {
-                                rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-                            }
-                            catch (java.io.UnsupportedEncodingException e)
-                            {
-                                rd = new BufferedReader(new InputStreamReader(is));
-                            }
-    
-                            try
+                            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                        }
+                        catch (java.io.UnsupportedEncodingException e)
+                        {
+                            rd = new BufferedReader(new InputStreamReader(is));
+                        }
+
+                        try
+                        {
+                            String serviceImplName;
+                            while ((serviceImplName = rd.readLine()) != null)
                             {
-                                String serviceImplName;
-                                while ((serviceImplName = rd.readLine()) != null)
+                                int idx = serviceImplName.indexOf('#');
+                                if (idx >= 0)
                                 {
-                                    int idx = serviceImplName.indexOf('#');
-                                    if (idx >= 0)
-                                    {
-                                        serviceImplName = serviceImplName.substring(0, idx);
-                                    }
-                                    serviceImplName = serviceImplName.trim();
-    
-                                    if (serviceImplName.length() != 0)
-                                    {
-                                        results.add(serviceImplName);
-                                    }
+                                    serviceImplName = serviceImplName.substring(0, idx);
                                 }
-                            }
-                            finally
-                            {
-                                if (rd != null)
+                                serviceImplName = serviceImplName.trim();
+
+                                if (serviceImplName.length() != 0)
                                 {
-                                    rd.close();
+                                    results.add(serviceImplName);
                                 }
                             }
                         }
-                    }
-                    finally
-                    {
-                        if (is != null)
+                        finally
                         {
-                            is.close();
+                            if (rd != null)
+                            {
+                                rd.close();
+                            }
                         }
                     }
                 }
diff --git a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultStateCacheProviderFactory.java
b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultStateCacheProviderFactory.java
index d3d7a36..077e06e 100644
--- a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultStateCacheProviderFactory.java
+++ b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultStateCacheProviderFactory.java
@@ -53,14 +53,8 @@ public class DefaultStateCacheProviderFactory extends StateCacheProviderFactory
     @Override
     public StateCacheProvider getStateCacheProvider(ExternalContext externalContext)
     {
-        StateCacheProvider stateCacheProvider
-                = (StateCacheProvider) externalContext.getApplicationMap().get(STATE_CACHE_PROVIDER_INSTANCE);
-        if (stateCacheProvider == null)
-        {
-            stateCacheProvider = createStateCacheProvider(externalContext);
-            externalContext.getApplicationMap().put(STATE_CACHE_PROVIDER_INSTANCE, stateCacheProvider);
-        }
-        return stateCacheProvider;
+        return (StateCacheProvider) externalContext.getApplicationMap().computeIfAbsent(STATE_CACHE_PROVIDER_INSTANCE,
+                k -> createStateCacheProvider(externalContext));
     }
     
     @Override
diff --git a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultViewScopeProviderFactory.java
b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultViewScopeProviderFactory.java
index 0337dda..0b4e094 100644
--- a/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultViewScopeProviderFactory.java
+++ b/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultViewScopeProviderFactory.java
@@ -20,7 +20,6 @@ package org.apache.myfaces.spi.impl;
 
 import javax.faces.context.ExternalContext;
 import org.apache.myfaces.cdi.view.CDIViewScopeProviderImpl;
-import org.apache.myfaces.util.lang.ClassUtils;
 import org.apache.myfaces.spi.ViewScopeProvider;
 import org.apache.myfaces.spi.ViewScopeProviderFactory;
 import org.apache.myfaces.util.ExternalSpecifications;
@@ -46,7 +45,7 @@ public class DefaultViewScopeProviderFactory extends ViewScopeProviderFactory
         {
             if (ExternalSpecifications.isCDIAvailable(externalContext))
             {
-                returnValue = (ViewScopeProvider) ClassUtils.newInstance(CDIViewScopeProviderImpl.class.getName());
+                returnValue = new CDIViewScopeProviderImpl();
             }
 
             // cache the result on the ApplicationMap


Mime
View raw message