You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2005/08/31 19:31:49 UTC

svn commit: r265536 - /myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java

Author: manolito
Date: Wed Aug 31 10:31:44 2005
New Revision: 265536

URL: http://svn.apache.org/viewcvs?rev=265536&view=rev
Log:
MYFACES-472 fixed

Modified:
    myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java

Modified: myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java?rev=265536&r1=265535&r2=265536&view=diff
==============================================================================
--- myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/impl/trunk/src/java/org/apache/myfaces/config/FacesConfigurator.java Wed Aug 31 10:31:44 2005
@@ -71,6 +71,7 @@
         = "org.apache.myfaces.resource".replace('.', '/') + "/standard-faces-config.xml";
     private static final String FACES_CONFIG_RESOURCE = "META-INF/faces-config.xml";
 
+    private static final String META_INF_SERVICES_RESOURCE_PREFIX = "META-INF/services/";
     private static final String META_INF_SERVICES_LOCATION = "/META-INF/services/";
 
     private static final String DEFAULT_RENDER_KIT_CLASS = HtmlRenderKitImpl.class.getName();
@@ -144,57 +145,60 @@
 
     /**
      * This method performs part of the factory search outlined in section 10.2.6.1.
-     * <p/>
-     * FIXME: Should this also search through all the jar files in the WEB-INF/lib
-     * directory?
      */
     protected void feedMetaInfServicesFactories()
     {
-        // keyed on resource names, factory name is the value
-        Map resourceNames = expandFactoryNames(FACTORY_NAMES);
-        //Search for factory files in the jar file
-        Set services = _externalContext.getResourcePaths(META_INF_SERVICES_LOCATION);
-        // retainAll performs the intersection of the factory names that we
-        // are looking for the ones found, only the services found that match
-        // the expected factory names will be retained
-        if (null != services)
+        try
         {
-            services.retainAll(resourceNames.keySet());
-            Iterator itr = services.iterator();
-            while (itr.hasNext())
+            for (Iterator iterator = FACTORY_NAMES.iterator(); iterator.hasNext();)
             {
-                String resourceName = (String) itr.next();
-                InputStream is = _externalContext.getResourceAsStream(resourceName);
-                InputStreamReader isr = new InputStreamReader(is);
-                BufferedReader br = new BufferedReader(isr);
-                String className = null;
-                try
-                {
-                    className = br.readLine();
-                } catch (IOException e)
-                {
-                    throw new FacesException("Unable to read class name from file "
-                                             + resourceName, e);
-                }
-
-                String factoryName = (String) resourceNames.get(resourceName);
-                if (factoryName.equals(FactoryFinder.APPLICATION_FACTORY))
-                {
-                    _dispenser.feedApplicationFactory(className);
-                } else if (factoryName.equals(FactoryFinder.FACES_CONTEXT_FACTORY))
-                {
-                    _dispenser.feedFacesContextFactory(className);
-                } else if (factoryName.equals(FactoryFinder.LIFECYCLE_FACTORY))
-                {
-                    _dispenser.feedLifecycleFactory(className);
-                } else if (factoryName.equals(FactoryFinder.RENDER_KIT_FACTORY))
-                {
-                    _dispenser.feedRenderKitFactory(className);
-                } else
-                {
-                    throw new IllegalStateException("Unexpected factory name " + factoryName);
+                String factoryName = (String)iterator.next();
+                Iterator it = ClassUtils.getResources(META_INF_SERVICES_RESOURCE_PREFIX + factoryName,
+                                                      this);
+                while (it.hasNext())
+                {
+                    URL url = (URL)it.next();
+                    InputStream stream = url.openStream();
+                    InputStreamReader isr = new InputStreamReader(stream);
+                    BufferedReader br = new BufferedReader(isr);
+                    String className = null;
+                    try
+                    {
+                        className = br.readLine();
+                    }
+                    catch (IOException e)
+                    {
+                        throw new FacesException("Unable to read class name from file "
+                                                 + url.toExternalForm(), e);
+                    }
+                    br.close();
+                    isr.close();
+                    stream.close();
+
+                    if (log.isInfoEnabled()) log.info("Found " + factoryName + " factory implementation: " + className);
+
+                    if (factoryName.equals(FactoryFinder.APPLICATION_FACTORY))
+                    {
+                        _dispenser.feedApplicationFactory(className);
+                    } else if (factoryName.equals(FactoryFinder.FACES_CONTEXT_FACTORY))
+                    {
+                        _dispenser.feedFacesContextFactory(className);
+                    } else if (factoryName.equals(FactoryFinder.LIFECYCLE_FACTORY))
+                    {
+                        _dispenser.feedLifecycleFactory(className);
+                    } else if (factoryName.equals(FactoryFinder.RENDER_KIT_FACTORY))
+                    {
+                        _dispenser.feedRenderKitFactory(className);
+                    } else
+                    {
+                        throw new IllegalStateException("Unexpected factory name " + factoryName);
+                    }
                 }
             }
+        }
+        catch (Exception e)
+        {
+            throw new FacesException(e);
         }
     }