cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r500912 - in /incubator/cxf/trunk/common/common/src: main/java/org/apache/cxf/configuration/spring/ test/java/org/apache/cxf/configuration/spring/
Date Mon, 29 Jan 2007 00:19:19 GMT
Author: dandiep
Date: Sun Jan 28 16:19:18 2007
New Revision: 500912

URL: http://svn.apache.org/viewvc?view=rev&rev=500912
Log:
Support lazy loading of bindings/transports/etc via SpringBeanMap. Now we read the BeanDefininition
for the IDs/namespaces if they're there. If they aren't there, we resort to loading the bean
and accessing them via getFooIds() (or getActivationNamespaces as it is in the Binding/Transport
cases).

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/SpringBeanMap.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/PersonImpl.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/SpringBeanMapTest.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/beanMap.xml

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/SpringBeanMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/SpringBeanMap.java?view=diff&rev=500912&r1=500911&r2=500912
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/SpringBeanMap.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/SpringBeanMap.java
Sun Jan 28 16:19:18 2007
@@ -32,6 +32,8 @@
 import org.apache.cxf.helpers.CastUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeansException;
+import org.springframework.beans.Mergeable;
+import org.springframework.beans.PropertyValue;
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.beans.factory.BeanIsAbstractException;
 import org.springframework.beans.factory.InitializingBean;
@@ -61,7 +63,7 @@
             return;
         }
 
-        String[] beanNames = beanFactory.getBeanDefinitionNames();
+        String[] beanNames = beanFactory.getBeanNamesForType(type);
 
         ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)beanFactory;
 
@@ -73,19 +75,34 @@
                 continue;
             }
 
-            Class beanType = ctxt.getType(beanNames[i]);
-            if (beanType == null || !type.isAssignableFrom(beanType)) {
-                continue;
-            }
-
             try {
-                Collection<String> ids = getIds(ctxt.getBean(beanNames[i]));
+                Collection<?> ids = null;
+                PropertyValue pv = def.getPropertyValues().getPropertyValue(idsProperty);
+                
+                if (pv != null) {
+                    Object value = pv.getValue();
+                    if (!(value instanceof Collection)) {
+                        throw new RuntimeException("The property " + idsProperty + " must
be a collection!");
+                    }
+
+                    if (value instanceof Mergeable) {
+                        if (!((Mergeable)value).isMergeEnabled()) {
+                            ids = (Collection<?>)value;
+                        }
+                    } else {
+                        ids = (Collection<?>)value;
+                    }
+                } 
+                
                 if (ids == null) {
-                    continue;
+                    ids = getIds(ctxt.getBean(beanNames[i]));
+                    if (ids == null) {
+                        continue;
+                    }
                 }
                 
-                for (String id : ids) {
-                    idToBeanName.put(id, beanNames[i]);
+                for (Object id : ids) {
+                    idToBeanName.put(id.toString(), beanNames[i]);
                 }
             } catch (BeanIsAbstractException e) {
                 // The bean is abstract, we won't be doing anything with it.

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/PersonImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/PersonImpl.java?view=diff&rev=500912&r1=500911&r2=500912
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/PersonImpl.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/PersonImpl.java
Sun Jan 28 16:19:18 2007
@@ -20,12 +20,26 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 public class PersonImpl implements Person {
-    public Collection<String> getIds() {
-        List<String> ids = new ArrayList<String>();
+    private static int loadCount;
+    private Collection<String> ids;
+    
+    public PersonImpl() {
+        ids = new ArrayList<String>();
         ids.add("dan");
+        loadCount++;
+    }
+    
+    public Collection<String> getIds() {
         return ids;
+    }
+
+    public void setIds(Collection<String> ids) {
+        this.ids = ids;
+    }
+
+    public static int getLoadCount() {
+        return loadCount;
     }
 }

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/SpringBeanMapTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/SpringBeanMapTest.java?view=diff&rev=500912&r1=500911&r2=500912
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/SpringBeanMapTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/SpringBeanMapTest.java
Sun Jan 28 16:19:18 2007
@@ -36,21 +36,22 @@
         Map<String, Person> beans = (Map<String, Person>)context.getBean("mapOfPersons");
         assertNotNull(beans);
 
-        assertEquals(1, beans.size());
+        assertEquals(2, beans.size());
 
         Person p = (Person)beans.get("dan");
         assertNotNull(p);
+ 
+        assertEquals(1, PersonImpl.getLoadCount());
         
-        Collection<Person> values = beans.values();
-        assertEquals(1, values.size());
-        Person p2 = values.iterator().next();
-        assertNotNull(p2);
-        assertEquals(p, p2);
+        Person jane = (Person)beans.get("jane");
+        assertNotNull(jane);
+        assertEquals(2, PersonImpl.getLoadCount());
         
+        Collection<Person> values = beans.values();
+        assertEquals(2, values.size());
+
         Set<Entry<String, Person>> entries = beans.entrySet();
-        Entry<String, Person> e = entries.iterator().next();
-        assertEquals("dan", e.getKey());
-        assertEquals(p, e.getValue());
+        assertEquals(2, entries.size());
         
         Person p3 = new PersonImpl();
         beans.put("foo", p3);
@@ -59,6 +60,5 @@
         
         beans.put("dan", p3);
         assertEquals(p3, beans.get("dan"));
-        
     }
 }

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/beanMap.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/beanMap.xml?view=diff&rev=500912&r1=500911&r2=500912
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/beanMap.xml
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/configuration/spring/beanMap.xml
Sun Jan 28 16:19:18 2007
@@ -29,4 +29,12 @@
     
     <bean id="dan" class="org.apache.cxf.configuration.spring.PersonImpl"/>
 
+    <bean id="jane" class="org.apache.cxf.configuration.spring.PersonImpl" lazy-init="true">
+      <property name="ids">
+        <list>
+          <value>jane</value>
+        </list>
+      </property>
+    </bean>
+
 </beans>



Mime
View raw message