myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sless...@apache.org
Subject svn commit: r697249 - in /myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config: FacesConfigDispenser.java FacesConfigurator.java RuntimeConfig.java
Date Fri, 19 Sep 2008 21:24:15 GMT
Author: slessard
Date: Fri Sep 19 14:24:15 2008
New Revision: 697249

URL: http://svn.apache.org/viewvc?rev=697249&view=rev
Log:
Cleanup and added some Java 5 generics.

Modified:
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigDispenser.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigDispenser.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigDispenser.java?rev=697249&r1=697248&r2=697249&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigDispenser.java
(original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigDispenser.java
Fri Sep 19 14:24:15 2008
@@ -98,10 +98,10 @@
     public Iterator<String> getViewHandlerIterator();
 
     /** @return Iterator over StateManager class names*/
-    public Iterator getStateManagerIterator();
+    public Iterator<String> getStateManagerIterator();
     
     /** @return Iterator over ResourceHandler class names*/
-    public Iterator getResourceHandlerIterator();
+    public Iterator<String> getResourceHandlerIterator();
 
     /** @return Iterator over PropertyResolver class names */
     public Iterator<String> getPropertyResolverIterator();

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=697249&r1=697248&r2=697249&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
(original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Fri Sep 19 14:24:15 2008
@@ -28,7 +28,6 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -70,6 +69,7 @@
 import org.apache.myfaces.config.element.Renderer;
 import org.apache.myfaces.config.impl.digester.DigesterFacesConfigDispenserImpl;
 import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
+import org.apache.myfaces.config.impl.digester.elements.FacesConfig;
 import org.apache.myfaces.config.impl.digester.elements.ResourceBundle;
 import org.apache.myfaces.context.FacesContextFactoryImpl;
 import org.apache.myfaces.el.DefaultPropertyResolver;
@@ -118,13 +118,10 @@
     }
 
     private final ExternalContext _externalContext;
-    private FacesConfigUnmarshaller _unmarshaller;
-    private FacesConfigDispenser _dispenser;
+    private FacesConfigUnmarshaller<? extends FacesConfig> _unmarshaller;
+    private FacesConfigDispenser<FacesConfig> _dispenser;
 
     private RuntimeConfig _runtimeConfig;
-    private static final String JAR_EXTENSION = ".jar";
-    private static final String META_INF_MANIFEST_SUFFIX = "!/META-INF/MANIFEST.MF";
-    private static final String JAR_PREFIX = "jar:";
 
     private static long lastUpdate;
 
@@ -135,24 +132,24 @@
     public static final String MYFACES_TOMAHAWK_SANDBOX15_PACKAGE_NAME = "tomahawk-sandbox15";
     public static final String COMMONS_EL_PACKAGE_NAME = "commons-el";
     public static final String JSP_API_PACKAGE_NAME = "jsp-api";
-    
+
     /**
-     * Regular expression used to extract the jar information from the 
-     * files present in the classpath.
-     * <p>The groups found with the regular expression are:</p>
+     * Regular expression used to extract the jar information from the files present in the
classpath.
+     * <p>
+     * The groups found with the regular expression are:
+     * </p>
      * <ul>
-     *   <li>Group 1: file path (required)</li>
-     *   <li>Group 2: artifact id (required)</li>
-     *   <li>Group 3: major version (required)</li>
-     *   <li>Group 5: minor version (optional)</li>
-     *   <li>Group 7: maintenance version (optional)</li>
-     *   <li>Group 9: extra version (optional)</li>
-     *   <li>Group 10: SNAPSHOT marker (optional)</li>
+     * <li>Group 1: file path (required)</li>
+     * <li>Group 2: artifact id (required)</li>
+     * <li>Group 3: major version (required)</li>
+     * <li>Group 5: minor version (optional)</li>
+     * <li>Group 7: maintenance version (optional)</li>
+     * <li>Group 9: extra version (optional)</li>
+     * <li>Group 10: SNAPSHOT marker (optional)</li>
      * </ul>
      */
-    public static final String REGEX_LIBRARY = "jar:(file:.*/(.+)-" +
-            "(\\d+)(\\.(\\d+)(\\.(\\d+)(\\.(\\d+))?)?)?(-SNAPSHOT)?" +
-            "\\.jar)!/META-INF/MANIFEST.MF";
+    public static final String REGEX_LIBRARY = "jar:(file:.*/(.+)-"
+            + "(\\d+)(\\.(\\d+)(\\.(\\d+)(\\.(\\d+))?)?)?(-SNAPSHOT)?" + "\\.jar)!/META-INF/MANIFEST.MF";
 
     public FacesConfigurator(ExternalContext externalContext)
     {
@@ -168,7 +165,7 @@
      * @param unmarshaller
      *            the unmarshaller to set
      */
-    public void setUnmarshaller(FacesConfigUnmarshaller unmarshaller)
+    public void setUnmarshaller(FacesConfigUnmarshaller<? extends FacesConfig> unmarshaller)
     {
         _unmarshaller = unmarshaller;
     }
@@ -176,12 +173,13 @@
     /**
      * @return the unmarshaller
      */
-    protected FacesConfigUnmarshaller getUnmarshaller()
+    protected FacesConfigUnmarshaller<? extends FacesConfig> getUnmarshaller()
     {
         if (_unmarshaller == null)
         {
             _unmarshaller = new DigesterFacesConfigUnmarshallerImpl(_externalContext);
         }
+
         return _unmarshaller;
     }
 
@@ -189,7 +187,7 @@
      * @param dispenser
      *            the dispenser to set
      */
-    public void setDispenser(FacesConfigDispenser dispenser)
+    public void setDispenser(FacesConfigDispenser<FacesConfig> dispenser)
     {
         _dispenser = dispenser;
     }
@@ -197,28 +195,33 @@
     /**
      * @return the dispenser
      */
-    protected FacesConfigDispenser getDispenser()
+    protected FacesConfigDispenser<FacesConfig> getDispenser()
     {
         if (_dispenser == null)
         {
             _dispenser = new DigesterFacesConfigDispenserImpl();
         }
+
         return _dispenser;
     }
 
     private long getResourceLastModified(String resource)
     {
-        try {
-            URL url =  _externalContext.getResource(resource);
-            if (url != null) {
+        try
+        {
+            URL url = _externalContext.getResource(resource);
+            if (url != null)
+            {
                 return url.openConnection().getLastModified();
             }
-        } catch (IOException e) {
+        }
+        catch (IOException e)
+        {
             log.error("Could not read resource " + resource, e);
         }
         return 0;
     }
-    
+
     private long getLastModifiedTime()
     {
         long lastModified = 0;
@@ -228,16 +231,13 @@
         if (resModified > lastModified)
             lastModified = resModified;
 
-
-        List configFilesList = getConfigFilesList();
-
-        for (int i = 0; i < configFilesList.size(); i++) {
-            String systemId = (String) configFilesList.get(i);
-
+        for (String systemId : getConfigFilesList())
+        {
             resModified = getResourceLastModified(systemId);
-                if (resModified > lastModified)
-                    lastModified = resModified;
-
+            if (resModified > lastModified)
+            {
+                lastModified = resModified;
+            }
         }
 
         return lastModified;
@@ -245,19 +245,28 @@
 
     public void update()
     {
-        long refreshPeriod = (MyfacesConfig.getCurrentInstance(_externalContext).getConfigRefreshPeriod())*1000;
+        long refreshPeriod = (MyfacesConfig.getCurrentInstance(_externalContext).getConfigRefreshPeriod())
* 1000;
 
-        if (refreshPeriod > 0){
+        if (refreshPeriod > 0)
+        {
             long ttl = lastUpdate + refreshPeriod;
-            if ((System.currentTimeMillis() > ttl) && (getLastModifiedTime() >
ttl)) {
-                try {
+            if ((System.currentTimeMillis() > ttl) && (getLastModifiedTime() >
ttl))
+            {
+                try
+                {
                     purgeConfiguration();
-                } catch (NoSuchMethodException e) {
+                }
+                catch (NoSuchMethodException e)
+                {
                     log.error("Configuration objects do not support clean-up. Update aborted");
                     return;
-                } catch (IllegalAccessException e) {
+                }
+                catch (IllegalAccessException e)
+                {
                     log.fatal("Error during configuration clean-up" + e.getMessage());
-                } catch (InvocationTargetException e) {
+                }
+                catch (InvocationTargetException e)
+                {
                     log.fatal("Error during configuration clean-up" + e.getMessage());
                 }
                 configure();
@@ -268,26 +277,24 @@
     private void purgeConfiguration() throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException
     {
         Method purgeMethod;
-        Class[] emptyParameterList = new Class[]{};
-
+        
         ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
-        purgeMethod = applicationFactory.getClass().getMethod("purgeApplication", emptyParameterList);
-        purgeMethod.invoke(applicationFactory, emptyParameterList);
+        purgeMethod = applicationFactory.getClass().getMethod("purgeApplication", (Class<?>[])null);
+        purgeMethod.invoke(applicationFactory, (Object[])null);
 
         RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-        purgeMethod = renderKitFactory.getClass().getMethod("purgeRenderKit", emptyParameterList);
-        purgeMethod.invoke(renderKitFactory, emptyParameterList);
+        purgeMethod = renderKitFactory.getClass().getMethod("purgeRenderKit", (Class<?>[])null);
+        purgeMethod.invoke(renderKitFactory, (Object[])null);
 
         RuntimeConfig.getCurrentInstance(_externalContext).purge();
 
         LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
-        purgeMethod = lifecycleFactory.getClass().getMethod("purgeLifecycle", emptyParameterList);
-        purgeMethod.invoke(lifecycleFactory, emptyParameterList);
+        purgeMethod = lifecycleFactory.getClass().getMethod("purgeLifecycle", (Class<?>[])null);
+        purgeMethod.invoke(lifecycleFactory, (Object[])null);
 
         // factories and serial factory need not be purged...
     }
 
-
     public void configure() throws FacesException
     {
         try
@@ -319,7 +326,7 @@
         configureLifecycle();
         handleSerialFactory();
 
-        //record the time of update
+        // record the time of update
         lastUpdate = System.currentTimeMillis();
     }
 
@@ -337,15 +344,14 @@
     /**
      * This method performs part of the factory search outlined in section 10.2.6.1.
      */
-    @SuppressWarnings("unchecked")
     protected void logMetaInf()
     {
         try
         {
             Map<String, List<JarInfo>> libs = new HashMap<String, List<JarInfo>>(30);
-            
+
             Pattern pattern = Pattern.compile(REGEX_LIBRARY);
-            
+
             Iterator<URL> it = ClassUtils.getResources("META-INF/MANIFEST.MF", this);
             while (it.hasNext())
             {
@@ -361,12 +367,11 @@
                         versions = new ArrayList<JarInfo>(2);
                         libs.put(artifactId, versions);
                     }
-                    
+
                     String path = matcher.group(1);
-                    
-                    Version version = new Version(matcher.group(3), matcher.group(5), 
-                                                  matcher.group(7), matcher.group(9),
-                                                  matcher.group(10));
+
+                    Version version = new Version(matcher.group(3), matcher.group(5), matcher.group(7),
+                                                  matcher.group(9), matcher.group(10));
 
                     JarInfo newInfo = new JarInfo(path, version);
                     if (!versions.contains(newInfo))
@@ -375,13 +380,13 @@
                     }
                 }
             }
-            
+
             if (log.isInfoEnabled())
             {
-                String[] artifactIds = {MYFACES_API_PACKAGE_NAME, MYFACES_IMPL_PACKAGE_NAME,
MYFACES_TOMAHAWK_PACKAGE_NAME, 
-                                        MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME, MYFACES_TOMAHAWK_SANDBOX15_PACKAGE_NAME,

-                                        COMMONS_EL_PACKAGE_NAME, JSP_API_PACKAGE_NAME};
-                
+                String[] artifactIds = { MYFACES_API_PACKAGE_NAME, MYFACES_IMPL_PACKAGE_NAME,
+                        MYFACES_TOMAHAWK_PACKAGE_NAME, MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME,
+                        MYFACES_TOMAHAWK_SANDBOX15_PACKAGE_NAME, COMMONS_EL_PACKAGE_NAME,
JSP_API_PACKAGE_NAME };
+
                 if (log.isWarnEnabled())
                 {
                     for (String artifactId : artifactIds)
@@ -397,7 +402,7 @@
                             builder.append(" loaded from: ");
                             builder.append(versions.get(0).getUrl());
                             builder.append(", but also found the following versions: ");
-                            
+
                             boolean needComma = false;
                             for (int i = 1; i < versions.size(); i++)
                             {
@@ -406,19 +411,19 @@
                                 {
                                     builder.append(", ");
                                 }
-                                
+
                                 builder.append(info.getVersion());
                                 builder.append(" loaded from: ");
                                 builder.append(info.getUrl());
-                                
+
                                 needComma = true;
                             }
-                            
+
                             log.warn(builder);
                         }
                     }
                 }
-                
+
                 for (String artifactId : artifactIds)
                 {
                     startLib(artifactId, libs);
@@ -441,10 +446,10 @@
             for (Iterator<String> iterator = FACTORY_NAMES.iterator(); iterator.hasNext();)
             {
                 String factoryName = iterator.next();
-                Iterator it = ClassUtils.getResources(META_INF_SERVICES_RESOURCE_PREFIX +
factoryName, this);
+                Iterator<URL> it = ClassUtils.getResources(META_INF_SERVICES_RESOURCE_PREFIX
+ factoryName, this);
                 while (it.hasNext())
                 {
-                    URL url = (URL) it.next();
+                    URL url = it.next();
                     InputStream stream = openStreamWithoutCache(url);
                     InputStreamReader isr = new InputStreamReader(stream);
                     BufferedReader br = new BufferedReader(isr);
@@ -507,29 +512,37 @@
     {
         try
         {
-            Map<String,URL> facesConfigs = new TreeMap<String,URL>();
-            Iterator it = ClassUtils.getResources(FACES_CONFIG_RESOURCE, this);
+            Map<String, URL> facesConfigs = new TreeMap<String, URL>();
+            Iterator<URL> it = ClassUtils.getResources(FACES_CONFIG_RESOURCE, this);
             while (it.hasNext())
             {
-                URL url = (URL) it.next();
+                URL url = it.next();
                 String systemId = url.toExternalForm();
-                facesConfigs.put(systemId,url);
+                facesConfigs.put(systemId, url);
             }
 
-            Iterator<Map.Entry<String,URL>> facesConfigIt=facesConfigs.entrySet().iterator();
+            Iterator<Map.Entry<String, URL>> facesConfigIt = facesConfigs.entrySet().iterator();
 
-            while(facesConfigIt.hasNext()) {
-                Map.Entry<String,URL> entry = facesConfigIt.next();
+            while (facesConfigIt.hasNext())
+            {
+                Map.Entry<String, URL> entry = facesConfigIt.next();
                 InputStream stream = null;
-                try {
+                try
+                {
                     openStreamWithoutCache(entry.getValue());
                     if (log.isInfoEnabled())
+                    {
                         log.info("Reading config : " + entry.getKey());
+                    }
+
                     getDispenser().feed(getUnmarshaller().getFacesConfig(stream, entry.getKey()));
                 }
-                finally {
-                    if(stream!=null)
+                finally
+                {
+                    if (stream != null)
+                    {
                         stream.close();
+                    }
                 }
             }
         }
@@ -539,12 +552,10 @@
         }
     }
 
-
     private void feedContextSpecifiedConfig() throws IOException, SAXException
     {
-        List configFilesList = getConfigFilesList();
-        for (int i = 0; i < configFilesList.size(); i++) {
-            String systemId = (String) configFilesList.get(i);
+        for (String systemId : getConfigFilesList())
+        {
             InputStream stream = _externalContext.getResourceAsStream(systemId);
             if (stream == null)
             {
@@ -552,15 +563,20 @@
                 continue;
             }
 
-            if (log.isInfoEnabled()) log.info("Reading config " + systemId);
+            if (log.isInfoEnabled())
+            {
+                log.info("Reading config " + systemId);
+            }
+
             getDispenser().feed(getUnmarshaller().getFacesConfig(stream, systemId));
             stream.close();
         }
     }
 
-    private List getConfigFilesList() {
+    private List<String> getConfigFilesList()
+    {
         String configFiles = _externalContext.getInitParameter(FacesServlet.CONFIG_FILES_ATTR);
-        List configFilesList = new ArrayList();
+        List<String> configFilesList = new ArrayList<String>();
         if (configFiles != null)
         {
             StringTokenizer st = new StringTokenizer(configFiles, ",", false);
@@ -570,14 +586,18 @@
 
                 if (DEFAULT_FACES_CONFIG.equals(systemId))
                 {
-                    if(log.isWarnEnabled())
-                        log.warn(DEFAULT_FACES_CONFIG + " has been specified in the " +
-                                FacesServlet.CONFIG_FILES_ATTR + " context parameter of "
+
-                                "the deployment descriptor. This will automatically be removed,
" +
-                                "if we wouldn't do this, it would be loaded twice.  See JSF
spec 1.1, 10.3.2");
+                    if (log.isWarnEnabled())
+                    {
+                        log.warn(DEFAULT_FACES_CONFIG + " has been specified in the " + FacesServlet.CONFIG_FILES_ATTR
+                                + " context parameter of "
+                                + "the deployment descriptor. This will automatically be
removed, "
+                                + "if we wouldn't do this, it would be loaded twice.  See
JSF spec 1.1, 10.3.2");
+                    }
                 }
                 else
+                {
                     configFilesList.add(systemId);
+                }
             }
         }
         return configFilesList;
@@ -598,28 +618,30 @@
 
     private void configureFactories()
     {
-        FacesConfigDispenser dispenser = getDispenser();
+        FacesConfigDispenser<FacesConfig> dispenser = getDispenser();
         setFactories(FactoryFinder.APPLICATION_FACTORY, dispenser.getApplicationFactoryIterator(),
-                DEFAULT_APPLICATION_FACTORY);
+                     DEFAULT_APPLICATION_FACTORY);
         setFactories(FactoryFinder.FACES_CONTEXT_FACTORY, dispenser.getFacesContextFactoryIterator(),
-                DEFAULT_FACES_CONTEXT_FACTORY);
+                     DEFAULT_FACES_CONTEXT_FACTORY);
         setFactories(FactoryFinder.LIFECYCLE_FACTORY, dispenser.getLifecycleFactoryIterator(),
-                DEFAULT_LIFECYCLE_FACTORY);
+                     DEFAULT_LIFECYCLE_FACTORY);
         setFactories(FactoryFinder.RENDER_KIT_FACTORY, dispenser.getRenderKitFactoryIterator(),
-                DEFAULT_RENDER_KIT_FACTORY);
+                     DEFAULT_RENDER_KIT_FACTORY);
     }
 
-    private void setFactories(String factoryName, Iterator factories, String defaultFactory)
+    private void setFactories(String factoryName, Iterator<String> factories, String
defaultFactory)
     {
         FactoryFinder.setFactory(factoryName, defaultFactory);
         while (factories.hasNext())
         {
-            String factory = (String) factories.next();
+            String factory = factories.next();
             if (!factory.equals(defaultFactory))
+            {
                 FactoryFinder.setFactory(factoryName, factory);
+            }
         }
     }
-    
+
     private void startLib(String artifactId, Map<String, List<JarInfo>> libs)
     {
         List<JarInfo> versions = libs.get(artifactId);
@@ -630,19 +652,18 @@
         else
         {
             JarInfo info = versions.get(0);
-            log.info("Starting up MyFaces-package : " + artifactId + " in version : "
-                     + info.getVersion() + " from path : " + info.getUrl());
+            log.info("Starting up MyFaces-package : " + artifactId + " in version : " + info.getVersion()
+                    + " from path : " + info.getUrl());
         }
     }
 
     private void configureApplication()
     {
-        Application application = 
-            ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
-        
-        FacesConfigDispenser dispenser = getDispenser();
-        application.setActionListener((ActionListener) getApplicationObject(ActionListener.class,

-                dispenser.getActionListenerIterator(), null));
+        Application application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+
+        FacesConfigDispenser<FacesConfig> dispenser = getDispenser();
+        application.setActionListener((ActionListener)getApplicationObject(ActionListener.class,
+                                                                           dispenser.getActionListenerIterator(),
null));
 
         if (dispenser.getDefaultLocale() != null)
         {
@@ -659,45 +680,49 @@
             application.setMessageBundle(dispenser.getMessageBundle());
         }
 
-        application.setNavigationHandler((NavigationHandler) getApplicationObject(NavigationHandler.class,

-                dispenser.getNavigationHandlerIterator(), application.getNavigationHandler()));
-        
-        application.setStateManager((StateManager) getApplicationObject(StateManager.class,

-                dispenser.getStateManagerIterator(), application.getStateManager()));
-        
-        application.setResourceHandler((ResourceHandler) getApplicationObject(ResourceHandler.class,

-                dispenser.getResourceHandlerIterator(), application.getResourceHandler()));
-                                                                
+        application.setNavigationHandler((NavigationHandler)getApplicationObject(NavigationHandler.class,
+                                                                                 dispenser.getNavigationHandlerIterator(),
+                                                                                 application.getNavigationHandler()));
+
+        application.setStateManager((StateManager)getApplicationObject(StateManager.class,
+                                                                       dispenser.getStateManagerIterator(),
+                                                                       application.getStateManager()));
+
+        application.setResourceHandler((ResourceHandler)getApplicationObject(ResourceHandler.class,
+                                                                             dispenser.getResourceHandlerIterator(),
+                                                                             application.getResourceHandler()));
+
         List<Locale> locales = new ArrayList<Locale>();
-        for (Iterator it = dispenser.getSupportedLocalesIterator(); it.hasNext();)
+        for (Iterator<String> it = dispenser.getSupportedLocalesIterator(); it.hasNext();)
         {
             locales.add(LocaleUtils.toLocale((String) it.next()));
         }
-        
+
         application.setSupportedLocales(locales);
 
         application.setViewHandler((ViewHandler) getApplicationObject(ViewHandler.class,
-                dispenser.getViewHandlerIterator(), application.getViewHandler()));
+                                                                      dispenser.getViewHandlerIterator(),
+                                                                      application.getViewHandler()));
 
-        for (Iterator it = dispenser.getComponentTypes(); it.hasNext();)
+        for (Iterator<String> it = dispenser.getComponentTypes(); it.hasNext();)
         {
-            String componentType = (String) it.next();
+            String componentType = it.next();
             application.addComponent(componentType, dispenser.getComponentClass(componentType));
         }
 
-        for (Iterator it = dispenser.getConverterIds(); it.hasNext();)
+        for (Iterator<String> it = dispenser.getConverterIds(); it.hasNext();)
         {
-            String converterId = (String) it.next();
+            String converterId = it.next();
             application.addConverter(converterId, dispenser.getConverterClassById(converterId));
         }
 
-        for (Iterator it = dispenser.getConverterClasses(); it.hasNext();)
+        for (Iterator<String> it = dispenser.getConverterClasses(); it.hasNext();)
         {
-            String converterClass = (String) it.next();
+            String converterClass = it.next();
             try
             {
-                application.addConverter(ClassUtils.simpleClassForName(converterClass), 
-                    dispenser.getConverterClassByClass(converterClass));
+                application.addConverter(ClassUtils.simpleClassForName(converterClass),
+                                         dispenser.getConverterClassByClass(converterClass));
             }
             catch (Exception ex)
             {
@@ -707,28 +732,30 @@
 
         if (application instanceof ApplicationImpl)
         {
-            for (Iterator it = dispenser.getConverterConfigurationByClassName(); it.hasNext();)
+            for (Iterator<String> it = dispenser.getConverterConfigurationByClassName();
it.hasNext();)
             {
-                String converterClassName = (String) it.next();
+                String converterClassName = it.next();
 
-                ((ApplicationImpl) application).addConverterConfiguration(converterClassName,

-                     dispenser.getConverterConfiguration(converterClassName));
+                ((ApplicationImpl)application).addConverterConfiguration(converterClassName,
+                                                                         dispenser.getConverterConfiguration(converterClassName));
             }
         }
 
-        for (Iterator it = dispenser.getValidatorIds(); it.hasNext();)
+        for (Iterator<String> it = dispenser.getValidatorIds(); it.hasNext();)
         {
-            String validatorId = (String) it.next();
+            String validatorId = it.next();
             application.addValidator(validatorId, dispenser.getValidatorClass(validatorId));
         }
 
         RuntimeConfig runtimeConfig = getRuntimeConfig();
-        
-        runtimeConfig.setPropertyResolverChainHead((PropertyResolver) getApplicationObject(PropertyResolver.class,

-                dispenser.getPropertyResolverIterator(), new DefaultPropertyResolver()));
-        
-        runtimeConfig.setVariableResolverChainHead((VariableResolver) getApplicationObject(VariableResolver.class,

-                dispenser.getVariableResolverIterator(), new VariableResolverImpl()));
+
+        runtimeConfig.setPropertyResolverChainHead((PropertyResolver) getApplicationObject(PropertyResolver.class,
+                                                                                        
  dispenser.getPropertyResolverIterator(),
+                                                                                        
  new DefaultPropertyResolver()));
+
+        runtimeConfig.setVariableResolverChainHead((VariableResolver) getApplicationObject(VariableResolver.class,
+                                                                                        
  dispenser.getVariableResolverIterator(),
+                                                                                        
  new VariableResolverImpl()));
     }
 
     /**
@@ -736,19 +763,18 @@
      */
     protected RuntimeConfig getRuntimeConfig()
     {
-        if(_runtimeConfig == null) 
+        if (_runtimeConfig == null)
         {
             _runtimeConfig = RuntimeConfig.getCurrentInstance(_externalContext);
         }
         return _runtimeConfig;
     }
-    
+
     public void setRuntimeConfig(RuntimeConfig runtimeConfig)
     {
         _runtimeConfig = runtimeConfig;
     }
 
-    @SuppressWarnings("unchecked")
     private <T> T getApplicationObject(Class<T> interfaceClass, Iterator<String>
classNamesIterator, T defaultObject)
     {
         T current = defaultObject;
@@ -774,7 +800,8 @@
                 // let's check if class supports the decorator pattern
                 try
                 {
-                    Constructor<? extends T> delegationConstructor = implClass.getConstructor(new
Class[] { interfaceClass });
+                    Constructor<? extends T> delegationConstructor = implClass
+                                                                              .getConstructor(new
Class[] { interfaceClass });
                     // impl class supports decorator pattern,
                     try
                     {
@@ -812,14 +839,16 @@
     {
         RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(_externalContext);
 
-        FacesConfigDispenser dispenser = getDispenser();
-        for (Iterator iterator = dispenser.getManagedBeans(); iterator.hasNext();)
+        FacesConfigDispenser<FacesConfig> dispenser = getDispenser();
+        for (Iterator<ManagedBean> iterator = dispenser.getManagedBeans(); iterator.hasNext();)
         {
-            ManagedBean bean = (ManagedBean) iterator.next();
+            ManagedBean bean = iterator.next();
 
             if (log.isWarnEnabled() && runtimeConfig.getManagedBean(bean.getManagedBeanName())
!= null)
+            {
                 log.warn("More than one managed bean w/ the name of '" + bean.getManagedBeanName()
                         + "' - only keeping the last ");
+            }
 
             runtimeConfig.addManagedBean(bean.getManagedBeanName(), bean);
 
@@ -827,9 +856,9 @@
 
         removePurgedBeansFromSessionAndApplication(runtimeConfig);
 
-        for (Iterator iterator = dispenser.getNavigationRules(); iterator.hasNext();)
+        for (Iterator<NavigationRule> iterator = dispenser.getNavigationRules(); iterator.hasNext();)
         {
-            NavigationRule rule = (NavigationRule) iterator.next();
+            NavigationRule rule = iterator.next();
             runtimeConfig.addNavigationRule(rule);
 
         }
@@ -838,7 +867,7 @@
         {
             runtimeConfig.addResourceBundle(iter.next());
         }
-        
+
         for (Iterator<String> iter = dispenser.getElResolvers(); iter.hasNext();)
         {
             runtimeConfig.addFacesConfigElResolver((ELResolver) ClassUtils.newInstance(iter.next(),
ELResolver.class));
@@ -848,35 +877,37 @@
 
     private void removePurgedBeansFromSessionAndApplication(RuntimeConfig runtimeConfig)
     {
-        Map oldManagedBeans = runtimeConfig.getManagedBeansNotReaddedAfterPurge();
-        if(oldManagedBeans!=null) {
-            Iterator it=oldManagedBeans.entrySet().iterator();
-            while(it.hasNext()) {
-                Map.Entry entry = (Map.Entry) it.next();
-                ManagedBean bean = (ManagedBean) entry.getValue();
+        Map<String, ManagedBean> oldManagedBeans = runtimeConfig.getManagedBeansNotReaddedAfterPurge();
+        if (oldManagedBeans != null)
+        {
+            for (Map.Entry<String, ManagedBean> entry : oldManagedBeans.entrySet())
+            {
+                ManagedBean bean = (ManagedBean)entry.getValue();
 
                 String scope = bean.getManagedBeanScope();
 
-                if(scope!=null && scope.equalsIgnoreCase("session")) {
+                if (scope != null && scope.equalsIgnoreCase("session"))
+                {
                     _externalContext.getSessionMap().remove(entry.getKey());
                 }
-                else if(scope!=null && scope.equalsIgnoreCase("application")) {
+                else if (scope != null && scope.equalsIgnoreCase("application"))
+                {
                     _externalContext.getApplicationMap().remove(entry.getKey());
                 }
             }
         }
+        
         runtimeConfig.resetManagedBeansNotReaddedAfterPurge();
     }
 
     private void configureRenderKits()
     {
-        RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
-                .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        RenderKitFactory renderKitFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
 
-        FacesConfigDispenser dispenser = getDispenser();
-        for (Iterator iterator = dispenser.getRenderKitIds(); iterator.hasNext();)
+        FacesConfigDispenser<FacesConfig> dispenser = getDispenser();
+        for (Iterator<String> iterator = dispenser.getRenderKitIds(); iterator.hasNext();)
         {
-            String renderKitId = (String) iterator.next();
+            String renderKitId = iterator.next();
             String renderKitClass = dispenser.getRenderKitClass(renderKitId);
 
             if (renderKitClass == null)
@@ -886,9 +917,9 @@
 
             RenderKit renderKit = (RenderKit) ClassUtils.newInstance(renderKitClass);
 
-            for (Iterator renderers = dispenser.getRenderers(renderKitId); renderers.hasNext();)
+            for (Iterator<Renderer> renderers = dispenser.getRenderers(renderKitId);
renderers.hasNext();)
             {
-                Renderer element = (Renderer) renderers.next();
+                Renderer element = renderers.next();
                 javax.faces.render.Renderer renderer;
                 try
                 {
@@ -901,7 +932,7 @@
                     continue;
                 }
 
-               renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(),
renderer);
+                renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(),
renderer);
             }
 
             renderKitFactory.addRenderKit(renderKitId, renderKit);
@@ -911,14 +942,13 @@
     private void configureLifecycle()
     {
         // create the lifecycle used by the app
-        LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
-                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
         Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
 
         // add phase listeners
-        for (Iterator iterator = getDispenser().getLifecyclePhaseListeners(); iterator.hasNext();)
+        for (Iterator<String> iterator = getDispenser().getLifecyclePhaseListeners();
iterator.hasNext();)
         {
-            String listenerClassName = (String) iterator.next();
+            String listenerClassName = iterator.next();
             try
             {
                 lifecycle.addPhaseListener((PhaseListener) ClassUtils.newInstance(listenerClassName));
@@ -941,83 +971,48 @@
 
         return LifecycleFactory.DEFAULT_LIFECYCLE;
     }
-/*
-    public static class VersionInfo
-    {
-        private String artifactId;
-        private List<JarInfo> jarInfos;
-
-        public VersionInfo(String artifactId)
-        {
-            this.artifactId = artifactId;
-        }
-
-        public String getArtifactId()
-        {
-            return packageName;
-        }
-
-        public void addJarInfo(Matcher matcher)
-        {
-            if (jarInfos == null)
-            {
-                jarInfos = new ArrayList<JarInfo>();
-            }
-            
-            String path = matcher.group(1);
-            
-            Version version = new Version(matcher.group(3), matcher.group(5), 
-                                          matcher.group(7), matcher.group(9),
-                                          matcher.group(10));
-
-            jarInfos.add(new JarInfo(path, version));
-        }
-
-        public String getLastVersion()
-        {
-            if (jarInfos == null)
-                return null;
-            if (jarInfos.size() == 0)
-                return null;
-
-return "";
-            //return jarInfos.get(jarInfos.size() - 1).getVersion();
-        }
-
-        /**
-         * Probably, the first encountered version will be used.
-         * 
-         * @return probably used version
-         *
-        public String getUsedVersion()
-        {
-
-            if (jarInfos == null)
-                return null;
-            if (jarInfos.size() == 0)
-                return null;
-return "";
-            //return jarInfos.get(0).getVersion();
-        }
-
-        /**
-         * Probably, the first encountered version will be used.
-         * 
-         * @return probably used classpath
-         *
-        public String getUsedVersionPath()
-        {
-
-            if (jarInfos == null)
-                return null;
-            if (jarInfos.size() == 0)
-                return null;
 
-            return jarInfos.get(0).getUrl();
-
-        }
-    }
-*/
+    /*
+     * public static class VersionInfo { private String artifactId; private List<JarInfo>
jarInfos;
+     * 
+     * public VersionInfo(String artifactId) { this.artifactId = artifactId; }
+     * 
+     * public String getArtifactId() { return packageName; }
+     * 
+     * public void addJarInfo(Matcher matcher) { if (jarInfos == null) { jarInfos = new ArrayList<JarInfo>();
}
+     * 
+     * String path = matcher.group(1);
+     * 
+     * Version version = new Version(matcher.group(3), matcher.group(5), matcher.group(7),
matcher.group(9),
+     * matcher.group(10));
+     * 
+     * jarInfos.add(new JarInfo(path, version)); }
+     * 
+     * public String getLastVersion() { if (jarInfos == null) return null; if (jarInfos.size()
== 0) return null;
+     * 
+     * return ""; //return jarInfos.get(jarInfos.size() - 1).getVersion(); }
+     * 
+     * / Probably, the first encountered version will be used.
+     * 
+     * @return probably used version
+     * 
+     * public String getUsedVersion() {
+     * 
+     * if (jarInfos == null) return null; if (jarInfos.size() == 0) return null; return "";
//return
+     * jarInfos.get(0).getVersion(); }
+     * 
+     * / Probably, the first encountered version will be used.
+     * 
+     * @return probably used classpath
+     * 
+     * public String getUsedVersionPath() {
+     * 
+     * if (jarInfos == null) return null; if (jarInfos.size() == 0) return null;
+     * 
+     * return jarInfos.get(0).getUrl();
+     * 
+     * } }
+     */
     private static class JarInfo implements Comparable<JarInfo>
     {
         private String url;
@@ -1043,7 +1038,7 @@
         {
             return version.compareTo(info.version);
         }
-        
+
         @Override
         public boolean equals(Object o)
         {
@@ -1053,7 +1048,7 @@
             }
             else if (o instanceof JarInfo)
             {
-                JarInfo other = (JarInfo)o;
+                JarInfo other = (JarInfo) o;
                 return version.equals(other.version);
             }
             else
@@ -1061,41 +1056,40 @@
                 return false;
             }
         }
-        
+
         @Override
         public int hashCode()
         {
             return version.hashCode();
         }
     }
-    
+
     private static class Version implements Comparable<Version>
     {
         private Integer[] parts;
-        
+
         private boolean snapshot;
-        
-        public Version(String major, String minor, String maintenance,
-                       String extra, String snapshot)
+
+        public Version(String major, String minor, String maintenance, String extra, String
snapshot)
         {
             parts = new Integer[4];
             parts[0] = Integer.valueOf(major);
-            
+
             if (minor != null)
             {
                 parts[1] = Integer.valueOf(minor);
-                
+
                 if (maintenance != null)
                 {
                     parts[2] = Integer.valueOf(maintenance);
-                    
+
                     if (extra != null)
                     {
                         parts[3] = Integer.valueOf(extra);
                     }
                 }
             }
-            
+
             this.snapshot = snapshot != null;
         }
 
@@ -1132,7 +1126,7 @@
                     }
                 }
             }
-            
+
             if (snapshot)
             {
                 return v.snapshot ? 0 : -1;
@@ -1142,7 +1136,7 @@
                 return v.snapshot ? 1 : 0;
             }
         }
-        
+
         @Override
         public boolean equals(Object o)
         {
@@ -1152,12 +1146,12 @@
             }
             else if (o instanceof Version)
             {
-                Version other = (Version)o;
+                Version other = (Version) o;
                 if (snapshot != other.snapshot)
                 {
                     return false;
                 }
-                
+
                 for (int i = 0; i < parts.length; i++)
                 {
                     Integer thisPart = parts[i];
@@ -1175,7 +1169,7 @@
                 return false;
             }
         }
-        
+
         @Override
         public int hashCode()
         {
@@ -1187,12 +1181,12 @@
                     hash ^= parts[i].hashCode();
                 }
             }
-            
+
             hash ^= Boolean.valueOf(snapshot).hashCode();
-            
+
             return hash;
         }
-        
+
         @Override
         public String toString()
         {
@@ -1206,12 +1200,12 @@
                     builder.append('.').append(val);
                 }
             }
-            
+
             if (snapshot)
             {
                 builder.append("-SNAPSHOT");
             }
-            
+
             return builder.toString();
         }
     }
@@ -1255,29 +1249,4 @@
         log.info("Serialization provider : " + serialFactory.getClass());
         _externalContext.getApplicationMap().put(StateUtils.SERIAL_FACTORY, serialFactory);
     }
-    
-    public static void main(String... args)
-    {
-        Pattern pattern = Pattern.compile(REGEX_LIBRARY);
-        List<Version> l = new ArrayList<Version>();
-        l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-collections-3.jar!/META-INF/MANIFEST.MF"));
-        l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-codec-1.3.jar!/META-INF/MANIFEST.MF"));
-        l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0.jar!/META-INF/MANIFEST.MF"));
-        l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0.6.jar!/META-INF/MANIFEST.MF"));
-        l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
-
-        Collections.sort(l);
-    }
-    
-    private static Version testJar(Pattern pattern, String libName)
-    {
-        Matcher matcher = pattern.matcher(libName);
-        if (matcher.matches())
-        {
-            return new Version(matcher.group(3), matcher.group(5), matcher.group(7), matcher.group(9),

-                               matcher.group(10));
-        }
-        
-        return null;
-    }
 }

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java?rev=697249&r1=697248&r2=697249&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
(original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
Fri Sep 19 14:24:15 2008
@@ -255,7 +255,7 @@
         return _variableResolverChainHead;
     }
 
-    public Map getManagedBeansNotReaddedAfterPurge()
+    public Map<String, ManagedBean> getManagedBeansNotReaddedAfterPurge()
     {
         return _oldManagedBeans;
     }



Mime
View raw message