cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1212725 - in /cxf/trunk: rt/core/src/main/java/org/apache/cxf/bus/spring/ rt/core/src/main/java/org/apache/cxf/buslifecycle/ rt/core/src/test/java/org/apache/cxf/bus/spring/ systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/
Date Sat, 10 Dec 2011 03:22:28 GMT
Author: dkulp
Date: Sat Dec 10 03:22:27 2011
New Revision: 1212725

URL: http://svn.apache.org/viewvc?rev=1212725&view=rev
Log:
Simplify spring Bus parsing by parsing directly to the Bus object when
posible
make sure the BusLifeCycleListeners are loaded and registered prior to
initComplete called.

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/LifeCycleListenerTester.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java Sat
Dec 10 03:22:27 2011
@@ -37,6 +37,8 @@ import org.apache.cxf.interceptor.Abstra
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.message.Message;
 import org.springframework.beans.BeansException;
+import org.springframework.beans.PropertyValue;
+import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.xml.ParserContext;
@@ -50,6 +52,7 @@ public class BusDefinitionParser extends
         super();
         setBeanClass(BusConfig.class);
     }
+
     protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean)
{
         String bus = element.getAttribute("bus");        
         if (StringUtils.isEmpty(bus)) {
@@ -60,21 +63,46 @@ public class BusDefinitionParser extends
         }
         element.removeAttribute("name");
         if (StringUtils.isEmpty(bus)) {
-            addBusWiringAttribute(bean, BusWiringType.PROPERTY, null, ctx);
-        } else {
-            addBusWiringAttribute(bean, BusWiringType.PROPERTY, bus, ctx);
-            bean.getRawBeanDefinition().setAttribute(WIRE_BUS_CREATE, Boolean.TRUE);
+            bus = "cxf";
         }
         String id = element.getAttribute("id");
         if (!StringUtils.isEmpty(id)) {
             bean.addPropertyValue("id", id);
         }
 
-        bean.addConstructorArgValue(bus);
-        bean.setLazyInit(false);
+        String tmp = element.getAttribute("bus");
+        element.removeAttribute("bus");
         super.doParse(element, ctx, bean);
+        if (StringUtils.isEmpty(tmp)) {
+            element.setAttribute("bus", tmp);
+        }
+        
+        if (ctx.getRegistry().containsBeanDefinition(bus)) {
+            BeanDefinition def = ctx.getRegistry().getBeanDefinition(bus);
+            copyProps(bean, def);
+            bean.addConstructorArgValue(bus);
+        } else if (!"cxf".equals(bus)) {
+            bean.getRawBeanDefinition().setBeanClass(SpringBus.class);
+            bean.getRawBeanDefinition().getPropertyValues().removePropertyValue("bus");
+            element.setUserData("ID", bus, null);
+        } else {
+            addBusWiringAttribute(bean, BusWiringType.PROPERTY, bus, ctx);
+            bean.getRawBeanDefinition().setAttribute(WIRE_BUS_CREATE, 
+                                                     resolveId(element, null, ctx));
+            bean.addConstructorArgValue(bus);
+        }
     }
     
+    private void copyProps(BeanDefinitionBuilder src, BeanDefinition def) {
+        for (PropertyValue v : src.getBeanDefinition().getPropertyValues().getPropertyValues())
{
+            if (!"bus".equals(v.getName())) {
+                def.getPropertyValues().add(v.getName(), v.getValue());
+            }
+            src.getBeanDefinition().getPropertyValues().removePropertyValue(v);
+        }
+        
+    }
+
     @Override
     protected void mapElement(ParserContext ctx, 
                               BeanDefinitionBuilder bean, 
@@ -93,14 +121,18 @@ public class BusDefinitionParser extends
     @Override
     protected String resolveId(Element element, AbstractBeanDefinition definition, 
                                ParserContext ctx) {
-        String bus = element.getAttribute("bus");        
-        if (StringUtils.isEmpty(bus)) {
-            bus = element.getAttribute("name");
-        }
-        if (StringUtils.isEmpty(bus)) {
-            bus = Bus.DEFAULT_BUS_ID + ".config" + counter.getAndIncrement();
-        } else {
-            bus = bus + ".config";
+        String bus = (String)element.getUserData("ID");
+        if (bus == null) {
+            bus = element.getAttribute("bus");        
+            if (StringUtils.isEmpty(bus)) {
+                bus = element.getAttribute("name");
+            }
+            if (StringUtils.isEmpty(bus)) {
+                bus = Bus.DEFAULT_BUS_ID + ".config" + counter.getAndIncrement();
+            } else {
+                bus = bus + ".config";
+            }
+            element.setUserData("ID", bus, null);
         }
         return bus;
     }
@@ -120,6 +152,9 @@ public class BusDefinitionParser extends
         }
         
         public void setBus(Bus bb) {
+            if (bus == bb) {
+                return;
+            }
             CXFBusImpl b = (CXFBusImpl)bb;
             if (properties != null) {
                 b.setProperties(properties);
@@ -151,11 +186,10 @@ public class BusDefinitionParser extends
             if (bus != null) {
                 return;
             }
-            if (busName == null) {
-                setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(applicationContext));
-            } else {
-                setBus(BusWiringBeanFactoryPostProcessor.addBus(applicationContext, busName));
               
-            }
+            /*
+            bus = (CXFBusImpl)BusWiringBeanFactoryPostProcessor
+                    .addBus(applicationContext, busName);
+                    */                
         }
         
         public List<Interceptor<? extends Message>> getOutFaultInterceptors()
{
@@ -188,7 +222,7 @@ public class BusDefinitionParser extends
 
         public void setInInterceptors(List<Interceptor<? extends Message>> interceptors)
{
             if (bus != null) {
-                bus.setInInterceptors(interceptors);
+                bus.getInInterceptors().addAll(interceptors);
             } else {
                 super.setInInterceptors(interceptors);
             }
@@ -196,7 +230,7 @@ public class BusDefinitionParser extends
 
         public void setInFaultInterceptors(List<Interceptor<? extends Message>>
interceptors) {
             if (bus != null) {
-                bus.setInFaultInterceptors(interceptors);
+                bus.getInFaultInterceptors().addAll(interceptors);
             } else {
                 super.setInFaultInterceptors(interceptors);
             }
@@ -204,7 +238,7 @@ public class BusDefinitionParser extends
 
         public void setOutInterceptors(List<Interceptor<? extends Message>> interceptors)
{
             if (bus != null) {
-                bus.setOutInterceptors(interceptors);
+                bus.getOutInterceptors().addAll(interceptors);
             } else {
                 super.setOutInterceptors(interceptors);
             }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
Sat Dec 10 03:22:27 2011
@@ -78,11 +78,18 @@ public class BusWiringBeanFactoryPostPro
     }
     private Object getBusForName(String name,
                                  ConfigurableListableBeanFactory factory,
-                                 boolean create) {
+                                 boolean create,
+                                 String cn) {
         if (!factory.containsBeanDefinition(name) && (create || Bus.DEFAULT_BUS_ID.equals(name)))
{
             DefaultListableBeanFactory df = (DefaultListableBeanFactory)factory;
-            df.registerBeanDefinition(name, 
-                                      new RootBeanDefinition(SpringBus.class));
+            RootBeanDefinition rbd = new RootBeanDefinition(SpringBus.class);
+            if (cn != null) {
+                rbd.setAttribute("busConfig", new RuntimeBeanReference(cn));
+            }
+            df.registerBeanDefinition(name, rbd);
+        } else if (cn != null) {
+            BeanDefinition bd = factory.getBeanDefinition(name);
+            bd.getPropertyValues().add("busConfig", new RuntimeBeanReference(cn));
         }
         return new RuntimeBeanReference(name);        
     }
@@ -90,7 +97,7 @@ public class BusWiringBeanFactoryPostPro
     public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException
{
         Object inject = bus;
         if (inject == null) {
-            inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true);
+            inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true, null);
         } else {
             if (!factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID)
                 && !factory.containsSingleton(Bus.DEFAULT_BUS_ID)) {
@@ -105,24 +112,26 @@ public class BusWiringBeanFactoryPostPro
                 continue;
             }
             String busname = (String)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
-            Boolean create = (Boolean)beanDefinition
+            String create = (String)beanDefinition
                 .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
             Object inj = inject;
             if (busname != null) {
                 if (bus != null) {
                     continue;
                 }
-                inj = getBusForName(busname, factory, create == null ? false : create);
+                inj = getBusForName(busname, factory, create != null, create);
             }
             beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
             beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
             beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
-            if (BusWiringType.PROPERTY == type) {
-                beanDefinition.getPropertyValues()
-                    .addPropertyValue("bus", inj);
-            } else if (BusWiringType.CONSTRUCTOR == type) {
-                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
-                insertConstructorArg(constructorArgs, inj);
+            if (create == null) {
+                if (BusWiringType.PROPERTY == type) {
+                    beanDefinition.getPropertyValues()
+                        .addPropertyValue("bus", inj);
+                } else if (BusWiringType.CONSTRUCTOR == type) {
+                    ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
+                    insertConstructorArg(constructorArgs, inj);
+                }
             }
         }
     }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java Sat Dec 10 03:22:27
2011
@@ -52,6 +52,10 @@ public class SpringBus extends Extension
     public SpringBus() {
     }
     
+    public void setBusConfig(BusDefinitionParser.BusConfig bc) {
+        bc.setBus(this);
+    }
+    
     public void loadAdditionalFeatures() {
         super.loadAdditionalFeatures();
         ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
Sat Dec 10 03:22:27 2011
@@ -25,12 +25,14 @@ import javax.annotation.Resource;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
 
 @NoJSR250Annotations(unlessNull = "bus")
 public class CXFBusLifeCycleManager implements BusLifeCycleManager {
 
     private final CopyOnWriteArrayList<BusLifeCycleListener> listeners;
     private Bus bus;
+    private boolean initCalled;
     private boolean preShutdownCalled;
     private boolean postShutdownCalled;
     
@@ -54,8 +56,11 @@ public class CXFBusLifeCycleManager impl
      * @see org.apache.cxf.buslifecycle.BusLifeCycleManager#registerLifeCycleListener(
      * org.apache.cxf.buslifecycle.BusLifeCycleListener)
      */
-    public void registerLifeCycleListener(BusLifeCycleListener listener) {
+    public final void registerLifeCycleListener(BusLifeCycleListener listener) {
         listeners.addIfAbsent(listener);
+        if (initCalled) {
+            listener.initComplete();
+        }
         
     }
 
@@ -67,9 +72,15 @@ public class CXFBusLifeCycleManager impl
         listeners.remove(listener);      
     }
     
+    
     public void initComplete() {
+        if (bus != null) {
+            bus.getExtension(ConfiguredBeanLocator.class)
+                .getBeansOfType(BusLifeCycleListener.class);
+        }
         preShutdownCalled = false;
         postShutdownCalled = false;
+        initCalled = true;
         for (BusLifeCycleListener listener : listeners) {
             listener.initComplete();
         }

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java Sat
Dec 10 03:22:27 2011
@@ -136,7 +136,7 @@ public class SpringBusFactoryTest extend
         Bus bus = new SpringBusFactory().createBus();
         BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
         lifeCycleManager.registerLifeCycleListener(bl);
-        
+        EasyMock.reset(bl);
         bl.preShutdown();
         EasyMock.expectLastCall();
         bl.postShutdown();

Modified: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/LifeCycleListenerTester.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/LifeCycleListenerTester.java?rev=1212725&r1=1212724&r2=1212725&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/LifeCycleListenerTester.java
(original)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/wsdl/LifeCycleListenerTester.java
Sat Dec 10 03:22:27 2011
@@ -21,6 +21,7 @@ package org.apache.cxf.systest.wsdl;
 
 import javax.annotation.Resource;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.buslifecycle.BusLifeCycleListener;
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 
@@ -34,9 +35,9 @@ public class LifeCycleListenerTester imp
     public LifeCycleListenerTester() {
     }
     
-    @Resource(name = "org.apache.cxf.buslifecycle.BusLifeCycleManager")
-    public void setBusLifeCycleManager(BusLifeCycleManager mgr) {
-        mgr.registerLifeCycleListener(this);
+    @Resource(name = "cxf")
+    public void setBus(Bus b) {
+        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
     }
     
     public static int getInitCount() {



Mime
View raw message