cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r534945 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/configuration/spring/ rt/core/src/main/java/org/apache/cxf/configuration/spring/ rt/core/src/test/java/org/apache/cxf/configuration/spring/ systests/src/test/java...
Date Thu, 03 May 2007 17:47:23 GMT
Author: andreasmyth
Date: Thu May  3 10:47:22 2007
New Revision: 534945

URL: http://svn.apache.org/viewvc?view=rev&rev=534945
Log:
[JIRA CXF-623] Applied Gary's patch.

Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
      - copied, changed from r534554, incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
Removed:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/test-beans.xml
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/cxf.xml

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java?view=diff&rev=534945&r1=534944&r2=534945
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
Thu May  3 10:47:22 2007
@@ -20,6 +20,8 @@
 package org.apache.cxf.configuration.spring;
 
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -29,6 +31,9 @@
 import org.apache.cxf.configuration.Configurer;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.wiring.BeanConfigurerSupport;
 import org.springframework.beans.factory.wiring.BeanWiringInfo;
 import org.springframework.beans.factory.wiring.BeanWiringInfoResolver;
@@ -41,6 +46,7 @@
     private static final String DEFAULT_USER_CFG_FILE = "cxf.xml";
 
     private ApplicationContext appContext;
+    private final Map<String, String> wildCardBeanDefinitions = new HashMap<String,
String>();
     
     public ConfigurerImpl() {
         this(DEFAULT_USER_CFG_FILE);
@@ -66,11 +72,36 @@
             LogUtils.log(LOG, Level.INFO, "USER_CFG_FILE_NOT_FOUND_MSG", cfgFile);
         }
     }
-    
+
     public ConfigurerImpl(ApplicationContext ac) {
         setApplicationContext(ac);
     }
     
+    private void initWildcardDefinitionMap() {
+        if (null != appContext) {
+            for (String n : appContext.getBeanDefinitionNames()) {
+                if (isWildcardBeanName(n)) {
+                    AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory();
+                    BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf;
+                    BeanDefinition bd = bdr.getBeanDefinition(n);
+                    String className = bd.getBeanClassName();
+                    if (null != className) {
+                        if (!wildCardBeanDefinitions.containsKey(className)) {
+                            wildCardBeanDefinitions.put(className, n);
+                        } else {
+                            LogUtils.log(LOG, Level.WARNING, "ONE_WILDCARD_BEAN_ID_PER_CLASS_MSG",

+                                         new String[]{wildCardBeanDefinitions.get(className),
+                                                      className,
+                                                      n});   
+                        }
+                    } else {
+                        LogUtils.log(LOG, Level.WARNING, "WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG",
n); 
+                    }
+                }
+            }
+        }
+    }
+
     public void configureBean(Object beanInstance) {
         configureBean(null, beanInstance);
     }
@@ -89,6 +120,8 @@
             return;
         }
         
+        configureWithWildCard(bn, beanInstance);
+        
         final String beanName = bn;
         setBeanWiringInfoResolver(new BeanWiringInfoResolver() {
             public BeanWiringInfo resolveWiringInfo(Object instance) {
@@ -114,6 +147,26 @@
         }
     }
     
+    private void configureWithWildCard(String bn, Object beanInstance) {
+        if (!wildCardBeanDefinitions.isEmpty() && !isWildcardBeanName(bn)) {
+            String className = beanInstance.getClass().getSimpleName();
+            if (wildCardBeanDefinitions.containsKey(className)) {
+                String wildCardBeanId = wildCardBeanDefinitions.get(className);
+                if (bn.endsWith(stripStar(wildCardBeanId))) {
+                    configureBean(wildCardBeanId, beanInstance);
+                }       
+            }
+        }
+    }
+
+    private boolean isWildcardBeanName(String bn) {
+        return bn.charAt(0) == '*';
+    }
+
+    private String stripStar(String wildCardBeanId) {
+        return wildCardBeanId.substring(1);
+    }
+
     protected String getBeanName(Object beanInstance) {
         if (beanInstance instanceof Configurable) {
             return ((Configurable)beanInstance).getBeanName();
@@ -139,5 +192,6 @@
     private void setApplicationContext(ApplicationContext ac) {
         appContext = ac;
         setBeanFactory(appContext.getAutowireCapableBeanFactory());
+        initWildcardDefinitionMap();
     }
 }

Copied: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
(from r534554, incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/Messages.properties)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties?view=diff&rev=534945&p1=incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/Messages.properties&r1=534554&p2=incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties&r2=534945
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties
Thu May  3 10:47:22 2007
@@ -24,3 +24,5 @@
 USER_CFG_FILE_NOT_FOUND_MSG = Could not find the configuration file {0} on the classpath.
 JAXB_PROPERTY_EDITOR_EXC = Property editor failed to bind element {0}.
 APP_CONTEXT_CREATION_FAILED_MSG = Failed to create application context.
+WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG = Configuration bean with id {0} that uses a '*' or wildcard
must have a class attribute.
+ONE_WILDCARD_BEAN_ID_PER_CLASS_MSG = A wildcard configuration bean with id {0} already exists
for class {1}. The wildcard bean with id {2} will be ignored.  

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java?view=diff&rev=534945&r1=534944&r2=534945
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
Thu May  3 10:47:22 2007
@@ -153,6 +153,20 @@
     }
     
     @Test
+    public void testConfigureSimpleMatchingStarBeanId() {
+        SimpleBean sb = new SimpleBean("simple2");
+        ConfigurerImpl configurer =
+            new ConfigurerImpl("/org/apache/cxf/configuration/spring/test-beans.xml");
+        configurer.configureBean(sb);
+        assertTrue("Unexpected value for attribute booleanAttr", 
+                   !sb.getBooleanAttr());
+        assertEquals("Unexpected value for attribute integerAttr", 
+                     BigInteger.TEN, sb.getIntegerAttr());
+        assertEquals("Unexpected value for attribute stringAttr", 
+                     "StarHallo", sb.getStringAttr());
+    }
+    
+    @Test
     public void testGetBeanName() {
         ConfigurerImpl configurer = new ConfigurerImpl((String)null);
         Object beanInstance = new Configurable() {

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/test-beans.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/test-beans.xml?view=diff&rev=534945&r1=534944&r2=534945
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/test-beans.xml
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/test-beans.xml
Thu May  3 10:47:22 2007
@@ -21,7 +21,27 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
- 
+
+  <bean id="*2" abstract="true" class="SimpleBean">
+      <property name="stringAttr" value="StarHallo"/>
+  </bean>
+
+  <!-- additional wildcards for class SimpleBean will be ignored with a warning -->
+  <bean id="*duplicateWildcardForClassWillBeIgnored" abstract="true" class="SimpleBean">
+      <property name="stringAttr" value="duplicateWildcardForClassWillBeIgnored"/>
+  </bean>
+  
+  <!--  wildcards bean with no class will be ignored with a warning -->
+  <bean id="*willBeIgnoredBecausOfNoClass" abstract="true" >
+      <property name="stringAttr" value="willBeIgnoredBecausOfNoClass"/>
+  </bean>
+  
+  
+  <bean id="simple2" lazy-init="true">
+      <property name="booleanAttr" value="false"/>
+      <property name="integerAttr" value="10"/>
+  </bean>
+    
   <bean id="simple" lazy-init="true">
       <property name="stringAttr" value="hallo"/>
       <property name="booleanAttr" value="false"/>
@@ -44,4 +64,4 @@
       <property name="unsignedByteAttr" value="21"/>
   </bean>
  
-</beans>
\ No newline at end of file
+</beans>

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/cxf.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/cxf.xml?view=diff&rev=534945&r1=534944&r2=534945
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/cxf.xml
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/factory_pattern/cxf.xml
Thu May  3 10:47:22 2007
@@ -24,6 +24,9 @@
 http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schema/transports/http.xsd
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
     <bean name="{http://cxf.apache.org/factory_pattern}NumberPort.http-destination" abstract="true">
+      <!--  applying with wildcard to all JettyHTTPDestinations instead of this verbose
method -->
+    </bean>
+    <bean name="*" abstract="true" class="JettyHTTPDestination">
       <property name="multiplexWithAddress" value="true"/>
     </bean>
 </beans>



Mime
View raw message