geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1028188 - in /geronimo/server/trunk/plugins/myfaces: ./ geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/ geronimo-myfaces-builder/src/test/java/org/apache/geronimo/myfaces/deployment/ geronimo-myfaces/ geronim...
Date Thu, 28 Oct 2010 05:28:04 GMT
Author: xuhaihong
Date: Thu Oct 28 05:28:03 2010
New Revision: 1028188

URL: http://svn.apache.org/viewvc?rev=1028188&view=rev
Log:
GERONIMO-5561 First step changes, use a MyFacesWebAppContext GBean holds all the meta data, including faces configuration URLs and anntations. Once update to 2.0.3, some hack codes could be removed, and we might even store the final info data, as MyFaces would provide some more SPI.

Added:
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java   (with props)
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java   (with props)
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java   (with props)
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java   (with props)
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java   (with props)
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java   (with props)
Removed:
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/test/java/org/apache/geronimo/myfaces/deployment/BasicTest.java
Modified:
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/pom.xml
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/test/java/org/apache/geronimo/myfaces/BasicTest.java
    geronimo/server/trunk/plugins/myfaces/myfaces/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/myfaces/pom.xml

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java Thu Oct 28 05:28:03 2010
@@ -21,24 +21,35 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.LinkedHashSet;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+import javax.faces.bean.ManagedBean;
+import javax.faces.component.FacesComponent;
+import javax.faces.component.behavior.FacesBehavior;
+import javax.faces.convert.FacesConverter;
+import javax.faces.event.NamedEvent;
+import javax.faces.render.FacesBehaviorRenderer;
+import javax.faces.render.FacesRenderer;
+import javax.faces.validator.FacesValidator;
 import javax.faces.webapp.FacesServlet;
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.deployment.Deployable;
 import org.apache.geronimo.deployment.ModuleIDBuilder;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
 import org.apache.geronimo.gbean.AbstractName;
@@ -59,18 +70,26 @@ import org.apache.geronimo.kernel.Naming
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.geronimo.kernel.util.JarUtils;
 import org.apache.geronimo.myfaces.LifecycleProviderGBean;
+import org.apache.geronimo.myfaces.config.resource.ConfigurationResource;
+import org.apache.geronimo.myfaces.webapp.GeronimoStartupServletContextListener;
+import org.apache.geronimo.myfaces.webapp.MyFacesWebAppContext;
 import org.apache.geronimo.web.info.WebAppInfo;
-import org.apache.myfaces.webapp.StartupServletContextListener;
 import org.apache.openejb.jee.FacesConfig;
 import org.apache.openejb.jee.FacesManagedBean;
 import org.apache.openejb.jee.JaxbJavaee;
 import org.apache.openejb.jee.ParamValue;
 import org.apache.openejb.jee.Servlet;
 import org.apache.openejb.jee.WebApp;
+import org.apache.xbean.finder.BundleAnnotationFinder;
 import org.apache.xbean.finder.ClassFinder;
+import org.apache.xbean.osgi.bundle.util.DiscoveryRange;
+import org.apache.xbean.osgi.bundle.util.ResourceDiscoveryFilter;
 import org.apache.xmlbeans.XmlObject;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -90,21 +109,21 @@ public class MyFacesModuleBuilderExtensi
 
     private final NamingBuilder namingBuilders;
 
-    private static final String CONTEXT_LISTENER_NAME = StartupServletContextListener.class.getName();
+    private static final String CONTEXT_LISTENER_NAME = GeronimoStartupServletContextListener.class.getName();
 
     private static final String FACES_SERVLET_NAME = FacesServlet.class.getName();
 
-    private static final String SCHEMA_LOCATION_URL = "http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd";
+    public static final EARContext.Key<Set<ConfigurationResource>> JSF_META_INF_CONFIGURATION_RESOURCES = new EARContext.Key<Set<ConfigurationResource>>() {
 
-    private static final String VERSION = "2.0";
-
-    private static final String JAVAX_FACES_CONFIG_FILES = "javax.faces.CONFIG_FILES";
-
-    private static final String JAVAX_FACES_CONFIG_FILES_SEPARATOR = ",";
+        @Override
+        public Set<ConfigurationResource> get(Map<EARContext.Key, Object> context) {
+            return (Set<ConfigurationResource>) context.get(this);
+        }
+    };
 
     public MyFacesModuleBuilderExtension(@ParamAttribute(name = "defaultEnvironment") Environment defaultEnvironment,
-                                         @ParamAttribute(name = "providerFactoryNameQuery") AbstractNameQuery providerFactoryNameQuery,
-                                         @ParamReference(name = "NamingBuilders", namingType = NameFactory.MODULE_BUILDER) NamingBuilder namingBuilders) {
+            @ParamAttribute(name = "providerFactoryNameQuery") AbstractNameQuery providerFactoryNameQuery,
+            @ParamReference(name = "NamingBuilders", namingType = NameFactory.MODULE_BUILDER) NamingBuilder namingBuilders) {
         this.defaultEnvironment = defaultEnvironment;
         this.providerFactoryNameQuery = providerFactoryNameQuery;
         this.namingBuilders = namingBuilders;
@@ -115,7 +134,7 @@ public class MyFacesModuleBuilderExtensi
     }
 
     public void createModule(Module module, Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, Environment environment, Object moduleContextInfo, AbstractName earName, Naming naming,
-                             ModuleIDBuilder idBuilder) throws DeploymentException {
+            ModuleIDBuilder idBuilder) throws DeploymentException {
         mergeEnvironment(module);
     }
 
@@ -138,73 +157,7 @@ public class MyFacesModuleBuilderExtensi
         if (!(module instanceof WebModule)) {
             return;
         }
-        //For MyFaces uses common Jar Strategy to find the config files, while it is impossible in OSGi environment.
-        //Current workaround is to copy all the files in the lib/*.jar files to a temp folder, and add those files to the context parameter in web.xml file
-        WebModule webModule = (WebModule) module;
-        WebApp webApp = webModule.getSpecDD();
-        ParamValue configFilesPV = null;
-        for (ParamValue pv : webApp.getContextParam()) {
-            if (JAVAX_FACES_CONFIG_FILES.equals(pv.getParamName().trim())) {
-                configFilesPV = pv;
-                break;
-            }
-        }
-        StringBuilder configFiles = new StringBuilder(configFilesPV != null && configFilesPV.getParamValue() != null ? configFilesPV.getParamValue() : "");
-        File libDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "lib");
-        if (!libDirectory.exists()) {
-            return;
-        }
-        for (File jarFile : libDirectory.listFiles()) {
-            if (!jarFile.getName().endsWith(".jar")) {
-                continue;
-            }
-
-            JarFile zipFile;
-            try {
-                zipFile = new JarFile(jarFile);
-            } catch (IOException e) {
-                //Just ignore
-                continue;
-            }
-
-            ZipInputStream in = null;
-            try {
-                in = new ZipInputStream(new FileInputStream(jarFile));
-                ZipEntry zipEntry;
-
-                while ((zipEntry = in.getNextEntry()) != null) {
-                    String name = zipEntry.getName();
-
-                    // Scan config files named as faces-config.xml or *.faces-config.xml under META-INF
-                    if (name.equals("META-INF/faces-cofig.xml") || (name.startsWith("META-INF/") && name.endsWith(".faces-config.xml"))) {
-
-                        // copy config file
-                        String destination = "temp/" + jarFile.getName() + ".tempdir" + "/" + name;
-                        earContext.addFile(module.resolve(destination), zipFile, zipEntry);
-
-                        // add new location of config file name to configFiles
-                        if (configFiles.length() > 0) {
-                            configFiles.append(JAVAX_FACES_CONFIG_FILES_SEPARATOR);
-                        }
-                        configFiles.append("/").append(destination);
-                    }
-                }
-            } catch (Exception e) {
-                throw new DeploymentException("Can not preprocess myfaces application configuration resources", e);
-            } finally {
-                IOUtils.close(in);
-            }
-        }
-
-        // write configFiles back to web.xml
-        if (configFilesPV == null && configFiles.length() > 0) {
-            configFilesPV = new ParamValue();
-            configFilesPV.setParamName(JAVAX_FACES_CONFIG_FILES);
-            webApp.getContextParam().add(configFilesPV);
-        }
-        if (configFilesPV != null && configFiles.length() > 0) {
-            configFilesPV.setParamValue(configFiles.toString());
-        }
+        module.getEarContext().getGeneralData().put(JSF_META_INF_CONFIGURATION_RESOURCES, findMetaInfConfigurationResources(earContext, module));
     }
 
     public void initContext(EARContext earContext, Module module, Bundle bundle) throws DeploymentException {
@@ -235,6 +188,7 @@ public class MyFacesModuleBuilderExtensi
                 ((Collection<String>) value).add(CONTEXT_LISTENER_NAME);
             }
         }
+
         AbstractName moduleName = moduleContext.getModuleName();
         Map<EARContext.Key, Object> buildingContext = new HashMap<EARContext.Key, Object>();
         buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, moduleName);
@@ -245,7 +199,38 @@ public class MyFacesModuleBuilderExtensi
 
         XmlObject jettyWebApp = webModule.getVendorDD();
 
-        ClassFinder classFinder = createMyFacesClassFinder(webApp, webModule);
+        FacesConfig defaultWebAppFacesConfig = getDefaultWebAppFacesConfig(webModule);
+        Set<ConfigurationResource> metaInfConfigurationResources = JSF_META_INF_CONFIGURATION_RESOURCES.get(earContext.getGeneralData());
+        Map<Class<? extends Annotation>, Set<Class>> annotationClassSetMap = null;
+        if (!defaultWebAppFacesConfig.isMetadataComplete()) {
+            annotationClassSetMap = scanJSFAnnotations(earContext, webModule, bundle, metaInfConfigurationResources);
+        }
+
+
+        AbstractName myFacesWebAppContextName = moduleContext.getNaming().createChildName(moduleName, "myFacesWebAppContext", "MyFacesWebAppContext");
+        GBeanData myFacesWebAppContextData = new GBeanData(myFacesWebAppContextName, MyFacesWebAppContext.class);
+        myFacesWebAppContextData.setAttribute("annotationClassSetMap", annotationClassSetMap);
+        myFacesWebAppContextData.setAttribute("metaInfConfigurationResources", metaInfConfigurationResources);
+
+        List<FacesConfig> facesConfigs = new ArrayList<FacesConfig>();
+        facesConfigs.add(defaultWebAppFacesConfig);
+        facesConfigs.addAll(getContextFacesConfigs(webApp, webModule));
+        for (ConfigurationResource configurationResource : metaInfConfigurationResources) {
+            URL url;
+            try {
+                url = configurationResource.getConfigurationResourceURL(bundle);
+            } catch (MalformedURLException e) {
+                throw new DeploymentException("Fail to read the faces Configuration file " + configurationResource.getConfigurationResourcePath()
+                        + (configurationResource.getJarFilePath() == null ? "" : " from jar file " + configurationResource.getJarFilePath()), e);
+            }
+            if (url == null) {
+                throw new DeploymentException("Fail to read the faces Configuration file " + configurationResource.getConfigurationResourcePath()
+                        + (configurationResource.getJarFilePath() == null ? "" : " from jar file " + configurationResource.getJarFilePath()));
+            }
+            facesConfigs.add(parseConfigFile(url, bundle));
+        }
+
+        ClassFinder classFinder = createMyFacesClassFinder(facesConfigs, annotationClassSetMap != null ? annotationClassSetMap.get(ManagedBean.class) : null, bundle);
         webModule.setClassFinder(classFinder);
 
         namingBuilders.buildNaming(webApp, jettyWebApp, webModule, buildingContext);
@@ -257,6 +242,7 @@ public class MyFacesModuleBuilderExtensi
         providerData.setReferencePattern("LifecycleProviderFactory", providerFactoryNameQuery);
         try {
             moduleContext.addGBean(providerData);
+            moduleContext.addGBean(myFacesWebAppContextData);
         } catch (GBeanAlreadyExistsException e) {
             throw new DeploymentException("Duplicate jsf config gbean in web module", e);
         }
@@ -266,130 +252,211 @@ public class MyFacesModuleBuilderExtensi
 
     }
 
-    private boolean hasFacesServlet(WebApp webApp) {
-        for (Servlet servlet : webApp.getServlet()) {
-            if (servlet.getServletClass() != null && FACES_SERVLET_NAME.equals(servlet.getServletClass().trim())) {
-                return true;
+    protected Map<Class<? extends Annotation>, Set<Class>> scanJSFAnnotations(EARContext earContext, Module module, Bundle bundle, Set<ConfigurationResource> metaInfConfigurationResources) throws DeploymentException {
+        ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
+        try {
+            PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
+            final Set<String> requiredJarFiles = new HashSet<String>();
+            for (ConfigurationResource configurationResource : metaInfConfigurationResources) {
+                if (configurationResource.getJarFilePath() != null) {
+                    requiredJarFiles.add(configurationResource.getJarFilePath());
+                }
             }
-        }
-        return false;
-    }
+            Map<Class<? extends Annotation>, Set<Class>> annotationClassSetMap = new HashMap<Class<? extends Annotation>, Set<Class>>();
+            BundleAnnotationFinder bundleAnnotationFinder = new BundleAnnotationFinder(packageAdmin, bundle, new ResourceDiscoveryFilter() {
 
-    protected ClassFinder createMyFacesClassFinder(WebApp webApp, WebModule webModule) throws DeploymentException {
+                @Override
+                public boolean directoryDiscoveryRequired(String directory) {
+                    //TODO WEB-INF/classes ???
+                    return true;
+                }
 
-        LinkedHashSet<Class> classes = getFacesClasses(webApp, webModule);
-        return new ClassFinder(new ArrayList<Class>(classes));
-    }
+                @Override
+                public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange) {
+                    return discoveryRange.equals(DiscoveryRange.BUNDLE_CLASSPATH);
+                }
 
-    /**
-     * getFacesConfigFileURL()
-     * <p/>
-     * <p>Locations to search for the MyFaces configuration file(s):
-     * <ol>
-     * <li>META-INF/faces-config.xml
-     * <li>WEB-INF/faces-config.xml
-     * <li>javax.faces.CONFIG_FILES -- Context initialization param of Comma separated
-     * list of URIs of (additional) faces config files
-     * </ol>
-     * <p/>
-     * <p><strong>Notes:</strong>
-     * <ul>
-     * </ul>
-     *
-     * @param webApp    spec DD for module
-     * @param webModule module being deployed
-     * @return list of all managed bean classes from all faces-config xml files.
-     * @throws org.apache.geronimo.common.DeploymentException
-     *          if a faces-config.xml file is located but cannot be parsed.
-     */
-    private LinkedHashSet<Class> getFacesClasses(WebApp webApp, WebModule webModule) throws DeploymentException {
-        log.debug("getFacesClasses( " + webApp.toString() + "," + '\n' + (webModule != null ? webModule.getName() : null) + " ): Entry");
-
-        Deployable deployable = webModule.getDeployable();
-        Bundle bundle = webModule.getEarContext().getDeploymentBundle();
-
-        // 1. META-INF/faces-config.xml
-        LinkedHashSet<Class> classes = new LinkedHashSet<Class>();
-        URL url = deployable.getResource("META-INF/faces-config.xml");
-        if (url != null) {
-            parseConfigFile(url, bundle, classes);
+                @Override
+                public boolean zipFileDiscoveryRequired(String jarFile) {
+                    return requiredJarFiles.contains(jarFile);
+                }
+
+            });
+            annotationClassSetMap.put(FacesComponent.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesComponent.class)));
+            annotationClassSetMap.put(FacesConverter.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesConverter.class)));
+            annotationClassSetMap.put(FacesValidator.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesValidator.class)));
+            annotationClassSetMap.put(FacesRenderer.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesRenderer.class)));
+            annotationClassSetMap.put(ManagedBean.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(ManagedBean.class)));
+            annotationClassSetMap.put(NamedEvent.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(NamedEvent.class)));
+            annotationClassSetMap.put(FacesBehavior.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesBehavior.class)));
+            annotationClassSetMap.put(FacesBehaviorRenderer.class, new HashSet<Class>(bundleAnnotationFinder.findAnnotatedClasses(FacesBehaviorRenderer.class)));
+            return annotationClassSetMap;
+        } catch (Exception e) {
+            throw new DeploymentException("Fail to scan JSF annotations", e);
+        } finally {
+            bundle.getBundleContext().ungetService(reference);
         }
+    }
 
-        // 2. WEB-INF/faces-config.xml
-        url = deployable.getResource("WEB-INF/faces-config.xml");
+    protected FacesConfig getDefaultWebAppFacesConfig(WebModule webModule) throws DeploymentException {
+        URL url = webModule.getDeployable().getResource("WEB-INF/faces-config.xml");
         if (url != null) {
-            parseConfigFile(url, bundle, classes);
+            Bundle bundle = webModule.getEarContext().getDeploymentBundle();
+            return parseConfigFile(url, bundle);
+        } else {
+            return new FacesConfig();
         }
+    }
 
-        // 3. javax.faces.CONFIG_FILES
-        List<ParamValue> paramValues = webApp.getContextParam();
-        for (ParamValue paramValue : paramValues) {
-            if (paramValue.getParamName().trim().equals("javax.faces.CONFIG_FILES")) {
+    protected List<FacesConfig> getContextFacesConfigs(WebApp webApp, WebModule webModule) throws DeploymentException {
+        for (ParamValue paramValue : webApp.getContextParam()) {
+            if (paramValue.getParamName().trim().equals(FacesServlet.CONFIG_FILES_ATTR)) {
+                List<FacesConfig> contextFacesConfigs = new ArrayList<FacesConfig>();
                 String configFiles = paramValue.getParamValue().trim();
                 StringTokenizer st = new StringTokenizer(configFiles, ",", false);
+                Bundle bundle = webModule.getEarContext().getDeploymentBundle();
                 while (st.hasMoreTokens()) {
                     String configfile = st.nextToken().trim();
                     if (!configfile.equals("")) {
                         if (configfile.startsWith("/")) {
                             configfile = configfile.substring(1);
                         }
-                        url = webModule.getEarContext().getTargetURL(webModule.resolve(configfile));
+                        URL url = webModule.getEarContext().getTargetURL(webModule.resolve(configfile));
                         if (url == null) {
-                            throw new DeploymentException("Could not locate config file " + configfile);
+                            throw new DeploymentException("Could not locate config file " + configfile + " configured with " + FacesServlet.CONFIG_FILES_ATTR + " in the web.xml");
                         } else {
-                            parseConfigFile(url, bundle, classes);
+                            contextFacesConfigs.add(parseConfigFile(url, bundle));
                         }
                     }
                 }
-                break;
+                return contextFacesConfigs;
             }
         }
-
-        log.debug("getFacesClasses() Exit: " + classes.size() + " " + classes.toString());
-        return classes;
+        return Collections.<FacesConfig> emptyList();
     }
 
-    private void parseConfigFile(URL url, Bundle bundle, LinkedHashSet<Class> classes) throws DeploymentException {
-        log.debug("parseConfigFile( " + url.toString() + " ): Entry");
-
-        try {
-            InputStream in = url.openStream();
-            FacesConfig facesConfig = null;
-            try {
-                facesConfig = (FacesConfig) JaxbJavaee.unmarshalJavaee(FacesConfig.class, in);
-            } finally {
-                in.close();
-            }
-
-            // Get all the managed beans from the faces configuration file
-            List<FacesManagedBean> managedBeans = facesConfig.getManagedBean();
-            for (FacesManagedBean managedBean : managedBeans) {
+    protected ClassFinder createMyFacesClassFinder(List<FacesConfig> facesConfigs, Set<Class> annotatedManagedBeanClasses, Bundle bundle) throws DeploymentException {
+        List<Class> managedBeanClasses = new ArrayList<Class>();
+        for (FacesConfig facesConfig : facesConfigs) {
+            for (FacesManagedBean managedBean : facesConfig.getManagedBean()) {
                 String className = managedBean.getManagedBeanClass().trim();
                 Class<?> clas;
                 try {
                     clas = bundle.loadClass(className);
                     while (clas != null) {
-                        classes.add(clas);
+                        managedBeanClasses.add(clas);
                         clas = clas.getSuperclass();
                     }
                 } catch (ClassNotFoundException e) {
-                    log.warn("MyFacesModuleBuilderExtension: Could not load managed bean class: " + className + " mentioned in faces-config.xml file at " + url.toString());
+                    log.warn("MyFacesModuleBuilderExtension: Could not load managed bean class: " + className);
+                }
+            }
+        }
+        if (annotatedManagedBeanClasses != null) {
+            for (Class<?> clas : annotatedManagedBeanClasses) {
+                while (clas != null) {
+                    managedBeanClasses.add(clas);
+                    clas = clas.getSuperclass();
+                }
+            }
+        }
+        return new ClassFinder(managedBeanClasses);
+    }
+
+    protected Set<ConfigurationResource> findMetaInfConfigurationResources(EARContext earContext, Module module) throws DeploymentException {
+        Set<ConfigurationResource> metaInfConfigurationResources = new HashSet<ConfigurationResource>();
+        //1. jar files in the WEB-INF/lib folder
+        File libDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "lib");
+        if (libDirectory.exists()) {
+            for (File file : libDirectory.listFiles()) {
+                if (!file.getName().endsWith(".jar")) {
+                    continue;
+                }
+                try {
+                    if (!JarUtils.isJarFile(file)) {
+                        continue;
+                    }
+                } catch (IOException e) {
+                    continue;
+                }
+                ZipInputStream in = null;
+                JarFile jarFile = null;
+                try {
+                    jarFile = new JarFile(file);
+                    in = new ZipInputStream(new FileInputStream(file));
+                    ZipEntry zipEntry;
+
+                    while ((zipEntry = in.getNextEntry()) != null) {
+                        String name = zipEntry.getName();
+                        // Scan config files named as faces-config.xml or *.faces-config.xml under META-INF
+                        if (name.equals("META-INF/faces-cofig.xml") || (name.startsWith("META-INF/") && name.endsWith(".faces-config.xml"))) {
+                            //TODO Double check the relative jar file path once EAR is really supported
+                            //TODO Should find a way to avoid the file copying
+                            String destination = "META-INF/WEB-INF_lib_" + file.getName() + "/" + name;
+                            earContext.addFile(module.resolve(destination), jarFile, zipEntry);
+                            metaInfConfigurationResources.add(new ConfigurationResource("WEB-INF/lib/" + file.getName(), name, destination));
+                        }
+                    }
+                } catch (Exception e) {
+                    throw new DeploymentException("Can not preprocess myfaces application configuration resources", e);
+                } finally {
+                    IOUtils.close(in);
+                    JarUtils.close(jarFile);
                 }
             }
+        }
+        //2. WEB-INF/classes/META-INF folder
+        File webInfClassesDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "META-INF");
+        if (webInfClassesDirectory.exists() && webInfClassesDirectory.isDirectory()) {
+            for (File file : webInfClassesDirectory.listFiles()) {
+                String fileName = file.getName();
+                if (fileName.equals("META-INF/faces-cofig.xml") || (fileName.startsWith("META-INF/") && fileName.endsWith(".faces-config.xml"))) {
+                    //TODO Double check the relative jar file path once EAR is really supported
+                    String filePath = "WEB-INF/classes/META-INF/" + fileName;
+                    metaInfConfigurationResources.add(new ConfigurationResource(null, filePath, filePath));
+                }
+            }
+        }
+        //3. META-INF folder
+        File baseDirectory = new File(earContext.getBaseDir() + File.separator + "META-INF");
+        if (baseDirectory.exists() && baseDirectory.isDirectory()) {
+            for (File file : baseDirectory.listFiles()) {
+                String fileName = file.getName();
+                if (fileName.equals("META-INF/faces-cofig.xml") || (fileName.startsWith("META-INF/") && fileName.endsWith(".faces-config.xml"))) {
+                    //TODO Double check the relative jar file path once EAR is really supported
+                    String filePath = "META-INF/" + fileName;
+                    metaInfConfigurationResources.add(new ConfigurationResource(null, filePath, filePath));
+                }
+            }
+        }
+        return metaInfConfigurationResources;
+    }
+
+    private boolean hasFacesServlet(WebApp webApp) {
+        for (Servlet servlet : webApp.getServlet()) {
+            if (servlet.getServletClass() != null && FACES_SERVLET_NAME.equals(servlet.getServletClass().trim())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private FacesConfig parseConfigFile(URL url, Bundle bundle) throws DeploymentException {
+        log.debug("parseConfigFile( " + url.toString() + " ): Entry");
+        InputStream in = null;
+        try {
+            in = url.openStream();
+            return (FacesConfig) JaxbJavaee.unmarshalJavaee(FacesConfig.class, in);
         } catch (ParserConfigurationException e) {
             throw new DeploymentException("Could not parse alleged faces-config.xml at " + url.toString(), e);
-
         } catch (SAXException e) {
             throw new DeploymentException("Could not parse alleged faces-config.xml at " + url.toString(), e);
-
         } catch (JAXBException e) {
             throw new DeploymentException("Could not parse alleged faces-config.xml at " + url.toString(), e);
-
         } catch (IOException ioe) {
             throw new DeploymentException("Error reading jsf configuration file " + url, ioe);
+        } finally {
+            IOUtils.close(in);
         }
-
-        log.debug("parseConfigFile(): Exit");
     }
-
 }

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/pom.xml?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/pom.xml (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/pom.xml Thu Oct 28 05:28:03 2010
@@ -41,6 +41,18 @@
         </dependency>
         
         <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-web</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-wab</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
+        <dependency>
             <groupId>org.apache.geronimo.framework</groupId>
             <artifactId>geronimo-naming</artifactId>
             <version>${project.version}</version>

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java Thu Oct 28 05:28:03 2010
@@ -43,13 +43,13 @@ import org.osgi.framework.Bundle;
  */
 @GBean
 public class LifecycleProviderGBean implements LifecycleProvider, GBeanLifecycle {
-    
+
     private final Holder holder;
     private final Context context;
     private final ApplicationIndexedLifecycleProviderFactory factory;
     private final ClassLoader classLoader;
     private final Bundle bundle;
-    
+
     public LifecycleProviderGBean(@ParamAttribute(name="holder") Holder holder,
                                   @ParamReference(name="ContextSource", namingType = "Context") ContextSource contextSource,
                                   @ParamReference(name="LifecycleProviderFactory") LifecycleProviderFactorySource factory,
@@ -71,7 +71,7 @@ public class LifecycleProviderGBean impl
     }
 
     public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException {
-        Class clazz = o.getClass();
+        Class<?> clazz = o.getClass();
         if (holder != null) {
             Map<String, LifecycleMethod> preDestroy = holder.getPreDestroy();
             if (preDestroy != null) {

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,59 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.config.annotation;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.spi.AnnotationProvider;
+import org.apache.myfaces.spi.AnnotationProviderFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoAnnotationProviderFactory extends AnnotationProviderFactory {
+
+    private AnnotationProvider defaultAnnotationProvider;
+
+    public GeronimoAnnotationProviderFactory(final Map<Class<? extends Annotation>, Set<Class<?>>> annotationClassSetMap) {
+        this.defaultAnnotationProvider = new AnnotationProvider() {
+
+            @Override
+            public Map<Class<? extends Annotation>, Set<Class<?>>> getAnnotatedClasses(ExternalContext arg0) {
+                return annotationClassSetMap;
+            }
+
+            @Override
+            public Set<URL> getBaseUrls() throws IOException {
+                return null;
+            }
+
+        };
+    }
+
+    @Override
+    public AnnotationProvider createAnnotationProvider(ExternalContext externalContext) {
+
+        return defaultAnnotationProvider;
+    }
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/annotation/GeronimoAnnotationProviderFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,98 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.config.resource;
+
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationResource implements Serializable {
+
+    private String configurationResourcePath;
+
+    private String jarFilePath;
+
+    private String tempPath;
+
+    public ConfigurationResource(String jarFilePath, String configurationResourcePath, String tempPath) {
+        this.jarFilePath = jarFilePath;
+        this.configurationResourcePath = configurationResourcePath;
+        this.tempPath = tempPath;
+    }
+
+    public String getConfigurationResourcePath() {
+        return configurationResourcePath;
+    }
+
+    public String getJarFilePath() {
+        return jarFilePath;
+    }
+
+    public void setJarFilePath(String jarFilePath) {
+        this.jarFilePath = jarFilePath;
+    }
+
+    public void setConfigurationResourcePath(String configurationResourcePath) {
+        this.configurationResourcePath = configurationResourcePath;
+    }
+
+    public URL getConfigurationResourceURL(Bundle bundle) throws MalformedURLException {
+        return bundle.getEntry(tempPath);
+    }
+
+    @Override
+    public String toString() {
+        return "ConfigurationResource [configurationResourcePath=" + configurationResourcePath + ", jarFilePath=" + jarFilePath + "]";
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((configurationResourcePath == null) ? 0 : configurationResourcePath.hashCode());
+        result = prime * result + ((jarFilePath == null) ? 0 : jarFilePath.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ConfigurationResource other = (ConfigurationResource) obj;
+        if (configurationResourcePath == null) {
+            if (other.configurationResourcePath != null)
+                return false;
+        } else if (!configurationResourcePath.equals(other.configurationResourcePath))
+            return false;
+        if (jarFilePath == null) {
+            if (other.jarFilePath != null)
+                return false;
+        } else if (!jarFilePath.equals(other.jarFilePath))
+            return false;
+        return true;
+    }
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,55 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.config.resource;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.spi.FacesConfigResourceProvider;
+import org.apache.myfaces.spi.FacesConfigResourceProviderFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoFacesConfigResourceProviderFactory extends FacesConfigResourceProviderFactory {
+
+    public static final String GERONIMO_FACES_CONFIG_RESOURCE_PROVIDER = "GERONIMO_FACES_CONFIG_RESOURCE_PROVIDER";
+
+    private FacesConfigResourceProvider defaultFacesConfigResourceProvider;
+
+    public GeronimoFacesConfigResourceProviderFactory(final Collection<URL> metaInfConfigurationResources) {
+        this.defaultFacesConfigResourceProvider = new FacesConfigResourceProvider() {
+
+            @Override
+            public Collection<URL> getMetaInfConfigurationResources(ExternalContext arg0) throws IOException {
+                return metaInfConfigurationResources;
+            }
+
+        };
+    }
+
+    @Override
+    public FacesConfigResourceProvider createFacesConfigResourceProvider(ExternalContext externalContext) {
+
+        return defaultFacesConfigResourceProvider;
+    }
+
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/GeronimoFacesConfigResourceProviderFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,46 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+import org.apache.geronimo.osgi.web.WebApplicationConstants;
+import org.apache.geronimo.web.WebAttributeName;
+import org.apache.geronimo.web.info.WebAppInfo;
+import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+import org.apache.myfaces.webapp.StartupServletContextListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoStartupServletContextListener extends StartupServletContextListener {
+
+    @Override
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+        ServletContext servletContext = servletContextEvent.getServletContext();
+        WebAppInfo webAppInfo = (WebAppInfo) servletContext.getAttribute(WebAttributeName.WEB_APP_INFO.name());
+        Bundle bundle = ((BundleContext) servletContext.getAttribute(WebApplicationConstants.BUNDLE_CONTEXT_ATTRIBUTE)).getBundle();
+        //TODO remove the delegateFacesServlet constructor patameter once upgrading to MyFaces 2.0.3
+        GeronimoWebXml webXml = new GeronimoWebXml(bundle, webAppInfo, servletContext.getInitParameter("org.apache.myfaces.DELEGATE_FACES_SERVLET"));
+        servletContext.setAttribute(WebXml.class.getName(), webXml);
+        super.contextInitialized(servletContextEvent);
+    }
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,110 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.webapp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.webapp.FacesServlet;
+
+import org.apache.geronimo.web.info.FilterInfo;
+import org.apache.geronimo.web.info.FilterMappingInfo;
+import org.apache.geronimo.web.info.ServletInfo;
+import org.apache.geronimo.web.info.WebAppInfo;
+import org.apache.myfaces.shared_impl.webapp.webxml.DelegatedFacesServlet;
+import org.apache.myfaces.shared_impl.webapp.webxml.FilterMapping;
+import org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping;
+import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoWebXml extends WebXml {
+
+    private List<ServletMapping> facesServletMappings;
+
+    private List<FilterMapping> facesExtensionsFilterMapppings;
+
+    private boolean errorPagePresent;
+    
+    //TODO remove once upgrade to MyFaces 2.0.3
+    private String delegateFacesServlet;
+
+    public GeronimoWebXml(Bundle bundle, WebAppInfo webAppInfo, String delegateFacesServlet) {
+        errorPagePresent = webAppInfo.errorPages != null && webAppInfo.errorPages.size() > 0;
+        this.delegateFacesServlet = delegateFacesServlet;
+        facesServletMappings = new ArrayList<ServletMapping>();
+        for (ServletInfo servletInfo : webAppInfo.servlets) {
+            if (servletInfo.servletClass == null) {
+                continue;
+            }
+            Class<?> servletClass;
+            try {
+                servletClass = bundle.loadClass(servletInfo.servletClass);
+            } catch (ClassNotFoundException e) {
+                throw new IllegalArgumentException("Could not load the servlet class " + servletInfo.servletClass, e);
+            }
+            if (isFacesServlet(servletClass)) {
+                for (String urlPattern : servletInfo.servletMappings)
+                    facesServletMappings.add(new ServletMapping(servletInfo.servletName, servletClass, urlPattern));
+            }
+        }
+        facesExtensionsFilterMapppings = new ArrayList<FilterMapping>();
+        for (FilterInfo filterInfo : webAppInfo.filters) {
+            Class<?> filterClass;
+            try {
+                filterClass = bundle.loadClass(filterInfo.filterClass);
+            } catch (ClassNotFoundException e) {
+                throw new IllegalArgumentException("Could not load the filter class " + filterInfo.filterClass, e);
+            }
+            if (!isFacesExtensionsFilter(filterClass)) {
+                continue;
+            }
+            for (FilterMappingInfo filterMappingInfo : filterInfo.urlMappings) {
+                for (String urlPattern : filterMappingInfo.mapping) {
+                    facesExtensionsFilterMapppings.add(new FilterMapping(filterInfo.filterName, filterClass, urlPattern));
+                }
+            }
+        }
+    }
+
+    @Override
+    public List<ServletMapping> getFacesServletMappings() {
+        return facesServletMappings;
+    }
+
+    @Override
+    public List<FilterMapping> getFacesExtensionsFilterMappings() {
+        return facesExtensionsFilterMapppings;
+    }
+
+    @Override
+    public boolean isErrorPagePresent() {
+        return errorPagePresent;
+    }    
+    
+    //TODO remove once upgrade to MyFaces 2.0.3
+    protected boolean isFacesServlet(Class<?> servletClass) {
+        return FacesServlet.class.isAssignableFrom(servletClass) || DelegatedFacesServlet.class.isAssignableFrom(servletClass) || servletClass.getName().equals(delegateFacesServlet);
+    }
+
+    protected boolean isFacesExtensionsFilter(Class<?> filterClass) {
+        return "org.apache.myfaces.component.html.util.ExtensionsFilter".equals(filterClass.getName()) || "org.apache.myfaces.webapp.filter.ExtensionsFilter".equals(filterClass.getName());
+    }
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoWebXml.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java?rev=1028188&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java Thu Oct 28 05:28:03 2010
@@ -0,0 +1,118 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.webapp;
+
+import java.lang.annotation.Annotation;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.discovery.tools.EnvironmentCache;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.apache.geronimo.myfaces.config.resource.ConfigurationResource;
+import org.apache.geronimo.myfaces.config.resource.GeronimoFacesConfigResourceProviderFactory;
+import org.apache.myfaces.spi.AnnotationProviderFactory;
+import org.apache.myfaces.spi.FacesConfigResourceProviderFactory;
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@GBean(name = "MyFaces WebApplication Context", j2eeType = "MyFacesWebAppContext")
+public class MyFacesWebAppContext implements GBeanLifecycle {
+
+    private static final Map<Bundle, MyFacesWebAppContext> myFacesWebAppContexts = new ConcurrentHashMap<Bundle, MyFacesWebAppContext>();
+
+    private Map<Class<? extends Annotation>, Set<Class<?>>> annotationClassSetMap;
+
+    private Set<URL> metaInfConfigurationResources;
+
+    private Bundle bundle;
+
+    private ClassLoader classLoader;
+
+    public MyFacesWebAppContext(@ParamAttribute(name = "annotationClassSetMap") Map<Class<? extends Annotation>, Set<Class<?>>> annotationClassSetMap,
+            @ParamAttribute(name = "metaInfConfigurationResources") Set<ConfigurationResource> metaInfConfigurationResources, @ParamSpecial(type = SpecialAttributeType.bundle) Bundle bundle,
+            @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) {
+        this.annotationClassSetMap = annotationClassSetMap;
+        this.bundle = bundle;
+        this.classLoader = classLoader;
+        this.metaInfConfigurationResources = new HashSet<URL>();
+        try {
+            for (ConfigurationResource metaInfConfigurationResource : metaInfConfigurationResources) {
+                this.metaInfConfigurationResources.add(metaInfConfigurationResource.getConfigurationResourceURL(bundle));
+            }
+        } catch (MalformedURLException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    public Map<Class<? extends Annotation>, Set<Class<?>>> getAnnotationClassSetMap() {
+        return annotationClassSetMap;
+    }
+
+    public Set<URL> getMetaInfConfigurationResources() {
+        return metaInfConfigurationResources;
+    }
+
+    @Override
+    public void doFail() {
+        try {
+            doStop();
+        } catch (Exception e) {
+        }
+    }
+
+    @Override
+    public void doStart() throws Exception {
+        myFacesWebAppContexts.put(bundle, this);
+        //Set AnnotationProviderFactory/FacesConfigResourceProviderFactory in the commons-discovery cache
+        Map<String, Object> cache = (Map<String, Object>) EnvironmentCache.get(classLoader);
+        if (cache == null) {
+            cache = new HashMap<String, Object>(EnvironmentCache.smallHashSize);
+            EnvironmentCache.put(classLoader, cache);
+        }
+        //cache.put(AnnotationProviderFactory.class.getName(), new GeronimoAnnotationProviderFactory(annotationClassSetMap));
+        cache.put(FacesConfigResourceProviderFactory.class.getName(), new GeronimoFacesConfigResourceProviderFactory(metaInfConfigurationResources));
+    }
+
+    @Override
+    public void doStop() throws Exception {
+        myFacesWebAppContexts.remove(bundle);
+        //Clear the cache
+        Map<String, Object> cache = (Map<String, Object>) EnvironmentCache.get(classLoader);
+        if (cache != null) {
+            cache.remove(AnnotationProviderFactory.class.getName());
+            cache.remove(FacesConfigResourceProviderFactory.class.getName());
+        }
+
+    }
+
+    public static MyFacesWebAppContext getMyFacesWebAppContext(Bundle bundle) {
+        return myFacesWebAppContexts.get(bundle);
+    }
+
+}

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/test/java/org/apache/geronimo/myfaces/BasicTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/test/java/org/apache/geronimo/myfaces/BasicTest.java?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/test/java/org/apache/geronimo/myfaces/BasicTest.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/test/java/org/apache/geronimo/myfaces/BasicTest.java Thu Oct 28 05:28:03 2010
@@ -21,9 +21,6 @@
 package org.apache.geronimo.myfaces;
 
 import junit.framework.TestCase;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoFactory;
 
 /**
  * @version $Rev$ $Date$
@@ -31,14 +28,8 @@ import org.apache.geronimo.gbean.annotat
 public class BasicTest extends TestCase {
 
     public void testLifecycleProviderFactory() throws Exception {
-        GBeanInfo gbeanInfo = new AnnotationGBeanInfoFactory().getGBeanInfo(LifecycleProviderFactoryGBean.class);
         LifecycleProviderFactoryGBean factory = new LifecycleProviderFactoryGBean();
         ApplicationIndexedLifecycleProviderFactory providerFactory = factory.getLifecycleProviderFactory();
         assertNotNull(providerFactory);
     }
-
-    public void testLifecycleProvider() throws Exception {
-        GBeanData gBeanInfo = new GBeanData(LifecycleProviderGBean.class);
-        
-    }
 }

Modified: geronimo/server/trunk/plugins/myfaces/myfaces/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/myfaces/src/main/history/dependencies.xml?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/myfaces/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/myfaces/myfaces/src/main/history/dependencies.xml Thu Oct 28 05:28:03 2010
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<plugin-artifact xmlns:ns2="http://geronimo.apache.org/xml/ns/attributes-1.2" xmlns="http://geronimo.apache.org/xml/ns/plugins-1.3">
+<plugin-artifact xmlns="http://geronimo.apache.org/xml/ns/plugins-1.3" xmlns:ns2="http://geronimo.apache.org/xml/ns/attributes-1.2">
     <module-id>
         <groupId>org.apache.geronimo.configs</groupId>
         <artifactId>myfaces</artifactId>
@@ -7,6 +7,16 @@
         <type>car</type>
     </module-id>
     <dependency>
+        <groupId>commons-beanutils</groupId>
+        <artifactId>commons-beanutils</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>commons-collections</groupId>
+        <artifactId>commons-collections</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.apache.geronimo.bundles</groupId>
         <artifactId>commons-digester</artifactId>
         <type>jar</type>
@@ -33,12 +43,22 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-j2ee-schema</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
         <artifactId>geronimo-myfaces</artifactId>
         <type>jar</type>
     </dependency>
     <dependency>
-        <groupId>org.apache.geronimo.specs</groupId>
-        <artifactId>geronimo-annotation_1.1_spec</artifactId>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-wab</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-web</artifactId>
         <type>jar</type>
     </dependency>
     <dependency>
@@ -52,6 +72,11 @@
         <type>jar</type>
     </dependency>
     <dependency>
+        <groupId>org.apache.openejb</groupId>
+        <artifactId>openejb-jee</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
         <groupId>org.apache.servicemix.bundles</groupId>
         <artifactId>org.apache.servicemix.bundles.commons-codec</artifactId>
         <type>jar</type>

Modified: geronimo/server/trunk/plugins/myfaces/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/pom.xml?rev=1028188&r1=1028187&r2=1028188&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/pom.xml (original)
+++ geronimo/server/trunk/plugins/myfaces/pom.xml Thu Oct 28 05:28:03 2010
@@ -33,6 +33,10 @@
         MyFaces plugin
     </description>
 
+    <properties>
+        <myfacesVersion>2.0.2</myfacesVersion>
+    </properties>
+    
     <modules>
         <module>geronimo-myfaces</module>
         <module>geronimo-myfaces-builder</module>
@@ -60,11 +64,10 @@
 
     <dependencyManagement>
         <dependencies>
-            <!--JSF 1.2 JARs from Apache MyFaces -->
             <dependency>
                 <groupId>org.apache.myfaces.core</groupId>
                 <artifactId>myfaces-api</artifactId>
-                <version>2.0.2</version>
+                <version>${myfacesVersion}</version>
                 <exclusions>
                     <exclusion>
                         <groupId>commons-logging</groupId>
@@ -84,7 +87,7 @@
             <dependency>
                 <groupId>org.apache.myfaces.core</groupId>
                 <artifactId>myfaces-impl</artifactId>
-                <version>2.0.2</version>
+                <version>${myfacesVersion}</version>
                 <exclusions>
                     <exclusion>
                         <groupId>commons-logging</groupId>



Mime
View raw message