EB> I will be sending out another changebundle to share the diffs for
EB> three sets of changes to other parts of the source tree that need
to
EB> be made along with this change in the same commit as this change.
JY> Changes look fine. Thanks.
Great, I'll commit it, but, for the record, here is the other
changebundle. Sahoo, Shing-Wai, Rajiv, Siva, and maybe Jerome, may be
interested in this.
When running Mojarra in GlassFish 3.1, leverage annotation scanning
facility
http://java.net/jira/browse/JAVASERVERFACES-1835
SECTION: Changes to the web/web-core and web/web-glue to enable
web/jsf-connector to get a reference to the DeploymentContext
Reviewed and approved by Shing-Wai on 29 November 2010.
http://java.net/projects/glassfish/lists/dev/archive/2010-11/message/12
M
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContext.
java
- add getStandardContext() method.
M
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextF
acade.java
- add getApplicationContext() method.
M
web/web-glue/src/main/java/com/sun/enterprise/web/ServerConfigLookup.ja
va
- With Rajiv's guidance, implement this method.
+ public DeploymentContext getDeploymentContext(ServletContext ctx)
{
+ org.apache.catalina.core.ApplicationContext applicationContext
=
+
((org.apache.catalina.core.ApplicationContextFacade)ctx).getApplication
Context();
+ DeploymentContext dc =
((WebModule)applicationContext.getStandardContext()).getWebModuleConfig
().getDeploymentContext();
+ return dc;
+ }
SECTION: Changes to jsf-connector to implement the behavior required by
Mojarra 2.1.0-b09 to allow GlassFish to perform the annotation
scanning.
Also, include API changes to conform to fix for
<
http://java.net/jira/browse/GLASSFISH-14430>.
M
web/jsf-connector/src/main/java/org/glassfish/faces/integration/GlassFi
shInjectionProvider.java
- in ctor, get reference to serverConfigLookup.
- make this class implement the new Mojarra spi interface,
AnnotationScanner, with this method.
+ public Map<String, List<ScannedAnnotation>>
getAnnotatedClassesInCurrentModule(ServletContext servletContext)
+ throws InjectionProviderException {
- This method uses Jerome's Type system to get scanned class metadata
so
Mojarra doesn't have to.
M web/jsf-connector/pom.xml
- New dependency on web-glue so I can get DeploymentContext.
SECTION: Changes to weld-integration to implement API changes from
issue
<
http://java.net/jira/browse/GLASSFISH-14430>.
M
web/weld-integration/src/main/java/org/glassfish/weld/jsf/WeldFacesConf
igProvider.java
- Per Sahoo's issue GLASSFISH-14430, use URI instead of URL where
possible.
SECTION: Changes to osgi-javaee/osgi-web-container to implement API
changes from issue
<
http://java.net/jira/browse/GLASSFISH-14430>.
M
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesAnnotationScanner.java
M
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
WebModuleDecorator.java
M
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesConfigResourceProvider.java
M
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FaceletConfigResourceProvider.java
- Per Sahoo's issue GLASSFISH-14430, use URI instead of URL where
possible.
SECTION: Diffs
Index:
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContext.
java
===================================================================
---
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContext.
java (revision 43680)
+++
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContext.
java (working copy)
@@ -104,7 +104,11 @@
Boolean.valueOf(context.isUseMyFaces()));
}
+ public StandardContext getStandardContext() {
+ return context;
+ }
+
// ----------------------------------------------------- Class
Variables
// START PWC 1.2
Index:
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextF
acade.java
===================================================================
---
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextF
acade.java (revision 43680)
+++
web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextF
acade.java (working copy)
@@ -170,7 +170,11 @@
return (theContext);
}
+ public ApplicationContext getApplicationContext() {
+ return context;
+ }
+
public int getMajorVersion() {
return context.getMajorVersion();
}
Index:
web/web-glue/src/main/java/com/sun/enterprise/web/ServerConfigLookup.ja
va
===================================================================
---
web/web-glue/src/main/java/com/sun/enterprise/web/ServerConfigLookup.ja
va (revision 43680)
+++
web/web-glue/src/main/java/com/sun/enterprise/web/ServerConfigLookup.ja
va (working copy)
@@ -57,6 +57,7 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.ServletContext;
@Service
@Scoped(PerLookup.class)
@@ -345,6 +346,13 @@
return asyncReplication;
}
+ public DeploymentContext getDeploymentContext(ServletContext ctx)
{
+ org.apache.catalina.core.ApplicationContext applicationContext
=
+
((org.apache.catalina.core.ApplicationContextFacade)ctx).getApplication
Context();
+ DeploymentContext dc =
((WebModule)applicationContext.getStandardContext()).getWebModuleConfig
().getDeploymentContext();
+ return dc;
+ }
+
public PersistenceType getPersistenceTypeFromConfig() {
String persistenceTypeString = null;
PersistenceType persistenceType = null;
Index:
web/jsf-connector/src/main/java/org/glassfish/faces/integration/GlassFi
shInjectionProvider.java
===================================================================
---
web/jsf-connector/src/main/java/org/glassfish/faces/integration/GlassFi
shInjectionProvider.java (revision 43680)
+++
web/jsf-connector/src/main/java/org/glassfish/faces/integration/GlassFi
shInjectionProvider.java (working copy)
@@ -44,12 +44,16 @@
import
com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import
com.sun.enterprise.container.common.spi.util.InjectionException;
import com.sun.enterprise.container.common.spi.util.InjectionManager;
+import com.sun.enterprise.web.ServerConfigLookup;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.InjectionInfo;
import com.sun.enterprise.deployment.JndiNameEnvironment;
import com.sun.faces.spi.DiscoverableInjectionProvider;
+import com.sun.faces.spi.AnnotationScanner;
+import com.sun.faces.spi.AnnotationScanner.ScannedAnnotation;
import com.sun.faces.spi.InjectionProviderException;
import com.sun.faces.util.FacesLogger;
+import java.net.URI;
import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
import org.jvnet.hk2.component.Habitat;
@@ -57,15 +61,24 @@
import javax.servlet.ServletContext;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.glassfish.api.deployment.DeploymentContext;
+import org.glassfish.hk2.classmodel.reflect.AnnotationModel;
+import org.glassfish.hk2.classmodel.reflect.Type;
+import org.glassfish.hk2.classmodel.reflect.Types;
/**
* <p>This <code>InjectionProvider</code> is specific to the
* GlassFish/SJSAS 9.x PE/EE application servers.</p>
*/
-public class GlassFishInjectionProvider extends
DiscoverableInjectionProvider {
+public class GlassFishInjectionProvider extends
DiscoverableInjectionProvider implements AnnotationScanner {
private static final Logger LOGGER =
FacesLogger.APPLICATION.getLogger();
private static final String HABITAT_ATTRIBUTE =
@@ -74,6 +87,7 @@
private InjectionManager injectionManager;
private InvocationManager invokeMgr;
private JCDIService jcdiService;
+ private ServerConfigLookup serverConfigLookup;
/**
* <p>Constructs a new <code>GlassFishInjectionProvider</code>
instance.</p>
@@ -86,8 +100,73 @@
compEnvManager =
defaultHabitat.getByContract(ComponentEnvManager.class);
invokeMgr =
defaultHabitat.getByContract(InvocationManager.class);
injectionManager =
defaultHabitat.getByContract(InjectionManager.class);
- jcdiService = defaultHabitat.getByContract(JCDIService.class);
+ jcdiService = defaultHabitat.getByContract(JCDIService.class);
+ serverConfigLookup =
defaultHabitat.getComponent(ServerConfigLookup.class);
+
}
+
+ @Override
+ public Map<String, List<ScannedAnnotation>>
getAnnotatedClassesInCurrentModule(ServletContext servletContext)
+ throws InjectionProviderException {
+
+ DeploymentContext dc =
serverConfigLookup.getDeploymentContext(servletContext);
+ Types types = dc.getModuleMetaData(Types.class);
+ Collection<Type> allTypes = types.getAllTypes();
+ Collection<AnnotationModel> annotations = null;
+ Map<String, List<ScannedAnnotation>> classesByAnnotation =
+ new HashMap<String, List<ScannedAnnotation>>();
+ List<ScannedAnnotation> classesWithThisAnnotation = null;
+ for (final Type cur : allTypes) {
+ annotations = cur.getAnnotations();
+ ScannedAnnotation toAdd = null;
+ for (AnnotationModel curAnnotation : annotations) {
+ String curAnnotationName =
curAnnotation.getType().getName();
+ if (null == (classesWithThisAnnotation =
classesByAnnotation.get(curAnnotationName))) {
+ classesWithThisAnnotation = new
ArrayList<ScannedAnnotation>();
+ classesByAnnotation.put(curAnnotationName,
classesWithThisAnnotation);
+ }
+ toAdd = new ScannedAnnotation() {
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj instanceof ScannedAnnotation) {
+ String otherName =
((ScannedAnnotation)obj).getFullyQualifiedClassName();
+ if (null != otherName) {
+ result =
cur.getName().equals(otherName);
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ String str = getFullyQualifiedClassName();
+ Collection<URI> obj = getDefiningURIs();
+ int result = str != null ? str.hashCode() : 0;
+ result = 31 * result + (obj != null ?
obj.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String getFullyQualifiedClassName() {
+ return cur.getName();
+ }
+
+ @Override
+ public Collection<URI> getDefiningURIs() {
+ return cur.getDefiningURIs();
+ }
+
+ };
+ if (!classesWithThisAnnotation.contains(toAdd)) {
+ classesWithThisAnnotation.add(toAdd);
+ }
+ }
+ }
+ return classesByAnnotation;
+ }
/**
* <p>The implementation of this method must perform the following
Index: web/jsf-connector/pom.xml
===================================================================
--- web/jsf-connector/pom.xml (revision 43680)
+++ web/jsf-connector/pom.xml (working copy)
@@ -78,7 +78,13 @@
<dependency>
<groupId>com.sun.enterprise</groupId>
<artifactId>hk2</artifactId>
+ <version>${hk2.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.web</groupId>
+ <artifactId>web-glue</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
Index:
web/weld-integration/src/main/java/org/glassfish/weld/jsf/WeldFacesConf
igProvider.java
===================================================================
---
web/weld-integration/src/main/java/org/glassfish/weld/jsf/WeldFacesConf
igProvider.java (revision 43680)
+++
web/weld-integration/src/main/java/org/glassfish/weld/jsf/WeldFacesConf
igProvider.java (working copy)
@@ -40,18 +40,24 @@
package org.glassfish.weld.jsf;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.servlet.ServletContext;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.web.WebModule;
import com.sun.faces.spi.FacesConfigResourceProvider;
+import com.sun.logging.LogDomains;
+import java.net.URI;
import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
+import org.glassfish.weld.WeldApplicationContainer;
import org.glassfish.weld.WeldDeployer;
import org.jvnet.hk2.component.Habitat;
@@ -65,9 +71,11 @@
"org.glassfish.servlet.habitat";
private InvocationManager invokeMgr;
+ private Logger _logger =
LogDomains.getLogger(WeldApplicationContainer.class,
LogDomains.CORE_LOGGER);
+
private static final String SERVICES_FACES_CONFIG =
"META-INF/services/faces-config.xml";
- public Collection<URL> getResources(ServletContext context) {
+ public Collection<URI> getResources(ServletContext context) {
Habitat defaultHabitat = (Habitat)context.getAttribute(
HABITAT_ATTRIBUTE);
@@ -76,7 +84,7 @@
WebModule webModule = (WebModule)inv.getContainer();
WebBundleDescriptor wdesc =
webModule.getWebBundleDescriptor();
- List<URL> list = new ArrayList<URL>(1);
+ List<URI> list = new ArrayList<URI>(1);
if (!wdesc.hasExtensionProperty(WeldDeployer.WELD_EXTENSION))
{
return list;
@@ -86,7 +94,22 @@
// be available from the same classloader that loaded this
instance.
// Doing so allows us to be more OSGi friendly.
ClassLoader loader = this.getClass().getClassLoader();
- list.add(loader.getResource(SERVICES_FACES_CONFIG));
+ URL resource = loader.getResource(SERVICES_FACES_CONFIG);
+ if (null != resource) {
+ URI toAdd = null;
+ try {
+ toAdd = new URI(resource.toExternalForm());
+ } catch (URISyntaxException ex) {
+ if (_logger.isLoggable(Level.SEVERE)) {
+ String message = "Unable to create URI for URL " +
+ resource.toExternalForm();
+ _logger.log(Level.SEVERE, message, ex);
+ }
+ }
+ if (null != toAdd) {
+ list.add(toAdd);
+ }
+ }
return list;
}
Index:
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesAnnotationScanner.java
===================================================================
---
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesAnnotationScanner.java (revision 43680)
+++
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesAnnotationScanner.java (working copy)
@@ -55,7 +55,6 @@
import javax.servlet.ServletContext;
import java.lang.annotation.Annotation;
import java.net.URI;
-import java.net.URL;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -79,7 +78,7 @@
}
@Override
- public Map<Class<? extends Annotation>, Set<Class<?>>>
getAnnotatedClasses(Set<URL> urls) {
+ public Map<Class<? extends Annotation>, Set<Class<?>>>
getAnnotatedClasses(Set<URI> uris) {
Map<Class<? extends Annotation>, Set<Class<?>>> result =
(Map<Class<? extends Annotation>, Set<Class<?>>>)
sc.getAttribute(Constants.FACES_ANNOTATED_CLASSES);
sc.setAttribute(Constants.FACES_ANNOTATED_CLASSES, null); //
clear it
Index:
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
WebModuleDecorator.java
===================================================================
---
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
WebModuleDecorator.java (revision 43680)
+++
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
WebModuleDecorator.java (working copy)
@@ -56,7 +56,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.net.MalformedURLException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -111,8 +110,8 @@
}
private void populateFacesInformation(WebModule module,
BundleContext bctx, ServletContext sc) {
- Collection<URL> facesConfigs = new ArrayList<URL>();
- Collection<URL> faceletConfigs = new ArrayList<URL>();
+ Collection<URI> facesConfigs = new ArrayList<URI>();
+ Collection<URI> faceletConfigs = new ArrayList<URI>();
discoverJSFConfigs(bctx.getBundle(), facesConfigs,
faceletConfigs);
sc.setAttribute(Constants.FACES_CONFIG_ATTR, facesConfigs);
sc.setAttribute(Constants.FACELET_CONFIG_ATTR,
faceletConfigs);
@@ -154,20 +153,16 @@
* reported in
https://glassfish.dev.java.net/issues/show_bug.cgi?id=12914, we only
find faces config resources
* that ends with .faces-config.xml.
*/
- private void discoverJSFConfigs(Bundle b, Collection<URL>
facesConfigs, Collection<URL> faceletConfigs) {
+ private void discoverJSFConfigs(Bundle b, Collection<URI>
facesConfigs, Collection<URI> faceletConfigs) {
OSGiBundleArchive archive = new OSGiBundleArchive(b);
for (BundleResource r : archive) {
final String path = r.getPath();
if (path.startsWith("META-INF/")) {
- try {
- final URL url = r.getUri().toURL();
- if (path.endsWith(".taglib.xml")) {
- faceletConfigs.add(url);
- } else if (path.endsWith(".faces-config.xml")) {
// this check automatically excludes META-INF/faces-config.xml
- facesConfigs.add(url);
- }
- } catch (MalformedURLException e) {
- e.printStackTrace(); // ignore and continue
+ final URI url = r.getUri();
+ if (path.endsWith(".taglib.xml")) {
+ faceletConfigs.add(url);
+ } else if (path.endsWith(".faces-config.xml")) { //
this check automatically excludes META-INF/faces-config.xml
+ facesConfigs.add(url);
}
}
}
Index:
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesConfigResourceProvider.java
===================================================================
---
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesConfigResourceProvider.java (revision 43680)
+++
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FacesConfigResourceProvider.java (working copy)
@@ -41,12 +41,9 @@
package org.glassfish.osgiweb;
import javax.servlet.ServletContext;
-import java.net.URL;
import java.net.URI;
-import java.net.MalformedURLException;
import java.util.Collection;
import java.util.Collections;
-import java.util.ArrayList;
import java.util.logging.Logger;
/**
@@ -61,10 +58,10 @@
*/
public class OSGiFacesConfigResourceProvider implements
com.sun.faces.spi.FacesConfigResourceProvider,
com.sun.faces.spi.ConfigurationResourceProvider {
private static Logger logger =
Logger.getLogger(OSGiFacesConfigResourceProvider.class.getPackage().get
Name());
- public Collection<URL> getResources(ServletContext context) {
- Collection<URL> urls = (Collection<URL>)
context.getAttribute(Constants.FACES_CONFIG_ATTR);
- if (urls == null) return Collections.EMPTY_LIST;
- logger.info("Faces Config urls excluding the ones named as
faces-config.xml = " + urls); // TODO(Sahoo): change to finer
- return urls;
+ public Collection<URI> getResources(ServletContext context) {
+ Collection<URI> uris = (Collection<URI>)
context.getAttribute(Constants.FACES_CONFIG_ATTR);
+ if (uris == null) return Collections.EMPTY_LIST;
+ logger.info("Faces Config urls excluding the ones named as
faces-config.xml = " + uris); // TODO(Sahoo): change to finer
+ return uris;
}
}
Index:
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FaceletConfigResourceProvider.java
===================================================================
---
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FaceletConfigResourceProvider.java (revision 43680)
+++
osgi-javaee/osgi-web-container/src/main/java/org/glassfish/osgiweb/OSGi
FaceletConfigResourceProvider.java (working copy)
@@ -60,10 +60,10 @@
*/
public class OSGiFaceletConfigResourceProvider implements
com.sun.faces.spi.FaceletConfigResourceProvider,
com.sun.faces.spi.ConfigurationResourceProvider {
private static Logger logger =
Logger.getLogger(OSGiFaceletConfigResourceProvider.class.getPackage().g
etName());
- public Collection<URL> getResources(ServletContext context) {
- Collection<URL> urls = (Collection<URL>)
context.getAttribute(Constants.FACELET_CONFIG_ATTR);
- if (urls == null) return Collections.EMPTY_LIST;
- logger.info("Facelet Config urls = " + urls); // TODO(Sahoo):
change to debug level statement
- return urls;
+ public Collection<URI> getResources(ServletContext context) {
+ Collection<URI> uris = (Collection<URI>)
context.getAttribute(Constants.FACELET_CONFIG_ATTR);
+ if (uris == null) return Collections.EMPTY_LIST;
+ logger.info("Facelet Config urls = " + uris); // TODO(Sahoo):
change to debug level statement
+ return uris;
}
}