cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: Added CXF Feature detection support into CDI extension
Date Mon, 18 May 2015 18:28:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 7e82d2f10 -> 4e60f32c9


Added CXF Feature detection support into CDI extension


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4e60f32c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4e60f32c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4e60f32c

Branch: refs/heads/master
Commit: 4e60f32c9c370b99d9574fa54d546badf647db53
Parents: 7e82d2f
Author: reta <drreta@gmail.com>
Authored: Mon May 18 14:28:21 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Mon May 18 14:28:21 2015 -0400

----------------------------------------------------------------------
 .../cxf/cdi/JAXRSCdiResourceExtension.java      | 36 +++++++++++++++++---
 1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4e60f32c/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 2218281..b5d88c6 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -58,7 +58,9 @@ public class JAXRSCdiResourceExtension implements Extension {
     private final List< Bean< ? > > applicationBeans = new ArrayList< Bean<
? > >();
     private final List< Bean< ? > > serviceBeans = new ArrayList< Bean<
? > >();
     private final List< Bean< ? > > providerBeans = new ArrayList< Bean<
? > >();
+    private final List< Bean< ? extends Feature > > featureBeans = new ArrayList<
Bean< ? extends Feature > >();
         
+    @SuppressWarnings("unchecked")
     public <T> void collect(@Observes final ProcessBean< T > event) {
         if (event.getAnnotated().isAnnotationPresent(ApplicationPath.class)) {
             applicationBeans.add(event.getBean());
@@ -66,9 +68,11 @@ public class JAXRSCdiResourceExtension implements Extension {
             serviceBeans.add(event.getBean());
         } else if (event.getAnnotated().isAnnotationPresent(Provider.class)) {
             providerBeans.add(event.getBean());
+        } else if (event.getBean().getTypes().contains(Feature.class)) {
+            featureBeans.add((Bean< ? extends Feature >)event.getBean());
         } else if (CdiBusBean.CXF.equals(event.getBean().getName()) 
                 && Bus.class.isAssignableFrom(event.getBean().getBeanClass())) {
-            busBean = event.getBean();  
+            busBean = event.getBean();
         }
     }
     
@@ -88,9 +92,9 @@ public class JAXRSCdiResourceExtension implements Extension {
             
             // If there is an application without any singletons and classes defined, we
will
             // create a server factory bean with all services and providers discovered. 
-            if (instance.getSingletons().isEmpty() && instance.getClasses().isEmpty())
{                            
-                final JAXRSServerFactoryBean factory = createFactoryInstance(instance,  
      
-                    loadServices(beanManager), loadProviders(beanManager));
+            if (instance.getSingletons().isEmpty() && instance.getClasses().isEmpty())
{
+                final JAXRSServerFactoryBean factory = createFactoryInstance(instance,
+                    loadServices(beanManager), loadProviders(beanManager), loadFeatures(beanManager));
                 factory.init();   
             } else {
                 // If there is an application with any singletons or classes defined, we
will
@@ -122,12 +126,13 @@ public class JAXRSCdiResourceExtension implements Extension {
      * @return JAXRSServerFactoryBean instance
      */
     private JAXRSServerFactoryBean createFactoryInstance(final Application application, final
List< ? > services,
-            final List< ? > providers) {        
+            final List< ? > providers, final List< ? extends Feature > features)
{
         
         final JAXRSServerFactoryBean instance = ResourceUtils.createApplication(application,
false, false);          
         instance.setServiceBeans(new ArrayList< Object >(services));
         instance.setProviders(providers);
         instance.setProviders(loadExternalProviders());
+        instance.setFeatures(features);
         instance.setBus(bus);                  
         
         return instance; 
@@ -240,4 +245,25 @@ public class JAXRSCdiResourceExtension implements Extension {
         
         return services;
     }
+    
+    /**
+     * Gets the references for all discovered CXF-specific features
+     * @param beanManager bean manager instance
+     * @return the references for all discovered CXF-specific features
+     */
+    private List< Feature > loadFeatures(final BeanManager beanManager) {
+        final List< Feature > services = new ArrayList<>();
+        
+        for (final Bean< ? extends Feature > bean: featureBeans) {
+            services.add(
+                (Feature)beanManager.getReference(
+                    bean, 
+                    bean.getBeanClass(), 
+                    beanManager.createCreationalContext(bean) 
+                )
+            );    
+        }
+        
+        return services;
+    }
 }


Mime
View raw message