myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: java8 + cosmetics...
Date Wed, 02 Jan 2019 20:25:37 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


The following commit(s) were added to refs/heads/master by this push:
     new edf5a08  java8 + cosmetics...
edf5a08 is described below

commit edf5a081e614ade92bce9bfbe655586457e86e5d
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Wed Jan 2 21:25:53 2019 +0100

    java8 + cosmetics...
---
 .../myfaces/renderkit/_SharedRendererUtils.java    | 23 +++-------
 .../webapp/StartupServletContextListener.java      | 52 ++++++++--------------
 2 files changed, 25 insertions(+), 50 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/_SharedRendererUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/_SharedRendererUtils.java
index b662d3a..8d09a1b 100755
--- a/impl/src/main/java/org/apache/myfaces/renderkit/_SharedRendererUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/_SharedRendererUtils.java
@@ -232,25 +232,21 @@ class _SharedRendererUtils
                 else if (Collection.class.isAssignableFrom(modelType))
                 {
                     // component.getValue() will implement Collection at this point
-                    Collection<?> componentValue = (Collection<?>) component
-                            .getValue();
+                    Collection<?> componentValue = (Collection<?>) component.getValue();
                     // can we clone the Collection
                     if (componentValue instanceof Cloneable)
                     {
                         // clone method of Object is protected --> use reflection
                         try
                         {
-                            Method cloneMethod = componentValue.getClass()
-                                    .getMethod("clone");
-                            Collection<?> clone = (Collection<?>) cloneMethod
-                                    .invoke(componentValue);
+                            Method cloneMethod = componentValue.getClass().getMethod("clone");
+                            Collection<?> clone = (Collection<?>) cloneMethod.invoke(componentValue);
                             clone.clear();
                             targetForConvertedValues = clone;
                         }
                         catch (Exception e)
                         {
-                            log(facesContext, "Could not clone "
-                                    + componentValue.getClass().getName(), e);
+                            log(facesContext, "Could not clone " + componentValue.getClass().getName(),
e);
                         }
                     }
 
@@ -325,8 +321,7 @@ class _SharedRendererUtils
             Object value;
             if (converter != null)
             {
-                value = converter.getAsObject(facesContext, component,
-                        submittedValue[i]);
+                value = converter.getAsObject(facesContext, component, submittedValue[i]);
             }
             else
             {
@@ -371,8 +366,7 @@ class _SharedRendererUtils
         if (attribute instanceof ValueExpression)
         {
             // get the value of the ValueExpression
-            attribute = ((ValueExpression) attribute)
-                    .getValue(facesContext.getELContext());
+            attribute = ((ValueExpression) attribute).getValue(facesContext.getELContext());
         }
         // ... String that is a fully qualified Java class name
         if (attribute instanceof String)
@@ -383,10 +377,7 @@ class _SharedRendererUtils
             }
             catch (ClassNotFoundException cnfe)
             {
-                throw new FacesException(
-                        "Unable to find class "
-                                + attribute
-                                + " on the classpath.", cnfe);
+                throw new FacesException("Unable to find class " + attribute + " on the classpath.",
cnfe);
             }
 
         }
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
b/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
index e2a6b26..14baf98 100755
--- a/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
@@ -27,13 +27,12 @@ import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.ServiceLoader;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.myfaces.config.MyfacesConfig;
@@ -158,45 +157,30 @@ public class StartupServletContextListener implements ServletContextListener
     }
 
     /**
-     * loads the faces init plugins per reflection and Service loader
-     * in a jdk6 environment
-     *
-     * @return false in case of a failed attempt or no listeners found
-     *         which then will cause the jdk5 context.xml code to trigger
+     * Loads the faces init plugins per Service loader.
+     * 
+     * @return false if there are not plugins defined via ServiceLoader.
      */
     private boolean loadFacesInitPluginsViaServiceLoader()
-    {
-        try
-        {
-            Class serviceLoader = ClassUtils.getContextClassLoader().loadClass("java.util.ServiceLoader");
-            Method m = serviceLoader.getDeclaredMethod("load", Class.class, ClassLoader.class);
-            
-            Object loader = m.invoke(serviceLoader, StartupListener.class, ClassUtils.getContextClassLoader());
-            m = loader.getClass().getDeclaredMethod("iterator");
-            
-            Iterator<StartupListener> it = (Iterator<StartupListener>) m.invoke(loader);
-            List<StartupListener> listeners = new LinkedList<StartupListener>();
-            if (!it.hasNext())
-            {
-                return false;
-            }
-            while (it.hasNext())
-            {
-                listeners.add(it.next());
-            }
+    {   
+        ServiceLoader<StartupListener> loader = ServiceLoader.load(StartupListener.class,
+                ClassUtils.getContextClassLoader());
 
-            _servletContext.setAttribute(MyfacesConfig.FACES_INIT_PLUGINS, listeners);
-            return true;
-        }
-        catch (ClassNotFoundException e)
+        Iterator<StartupListener> it = (Iterator<StartupListener>) loader.iterator();
+        if (!it.hasNext())
         {
-
+            return false;
         }
-        catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException
e)
+        
+        List<StartupListener> listeners = new LinkedList<StartupListener>();
+        while (it.hasNext())
         {
-            log.log(Level.SEVERE, e.getMessage(), e);
+            listeners.add(it.next());
         }
-        return false;
+
+        _servletContext.setAttribute(MyfacesConfig.FACES_INIT_PLUGINS, listeners);
+        
+        return true;
     }
 
     /**


Mime
View raw message