You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2010/07/08 08:43:57 UTC
svn commit: r961595 - in
/servicemix/components/shared-libraries/trunk/servicemix-common: ./
src/main/java/org/apache/servicemix/common/xbean/
src/test/java/org/apache/servicemix/common/xbean/
src/test/resources/org/apache/servicemix/common/packaging/c...
Author: gnodet
Date: Thu Jul 8 06:43:57 2010
New Revision: 961595
URL: http://svn.apache.org/viewvc?rev=961595&view=rev
Log:
SMXCOMP-771: Upgrade to spring 3.x
Added:
servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/SimpleBeanFactoryTest.java
Modified:
servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml
servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
servicemix/components/shared-libraries/trunk/servicemix-common/src/test/resources/org/apache/servicemix/common/packaging/consumes/xbean.xml
Modified: servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml?rev=961595&r1=961594&r2=961595&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml Thu Jul 8 06:43:57 2010
@@ -92,12 +92,12 @@
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
- <version>3.4.3</version>
+ <version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-classloader</artifactId>
- <version>3.4.3</version>
+ <version>3.4.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java?rev=961595&r1=961594&r2=961595&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java Thu Jul 8 06:43:57 2010
@@ -84,6 +84,7 @@ public class AbstractXBeanDeployer exten
applicationContext.addBeanFactoryPostProcessor(processor);
}
+ applicationContext.setValidating(false);
applicationContext.refresh();
su.setApplicationContext(applicationContext);
// Use SU classloader
Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java?rev=961595&r1=961594&r2=961595&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java Thu Jul 8 06:43:57 2010
@@ -50,6 +50,21 @@ public class SimpleBeanFactory implement
public Object getBean(String name) throws BeansException {
return getBean(name, (Class) null);
}
+ public <T> T getBean(Class<T> type) throws BeansException {
+ T result = null;
+ for (Object bean : beans.values()) {
+ if (type.isAssignableFrom(bean.getClass())) {
+ if (result != null) {
+ throw new NoSuchBeanDefinitionException(type, "Found multiple beans matching type " + type);
+ }
+ result = (T) bean;
+ }
+ }
+ if (result == null) {
+ throw new NoSuchBeanDefinitionException(type, "No bean found matching type " + type);
+ }
+ return result;
+ }
public Object getBean(String name, Class requiredType) throws BeansException {
Object bean = beans.get(name);
if (bean == null) {
Added: servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/SimpleBeanFactoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/SimpleBeanFactoryTest.java?rev=961595&view=auto
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/SimpleBeanFactoryTest.java (added)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/SimpleBeanFactoryTest.java Thu Jul 8 06:43:57 2010
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.common.xbean;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.common.Container;
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.ServiceMixComponent;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.xbean.classloader.JarFileClassLoader;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Currency;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test cases for {@link org.apache.servicemix.common.xbean.SimpleBeanFactory}
+ */
+public class SimpleBeanFactoryTest extends TestCase {
+
+ private static final String BEAN1_NAME = "bean1";
+ private static final String BEAN2_NAME = "bean2";
+ private static final String BEAN3_NAME = "bean3";
+
+ private static final String BEAN1 = "A simple bean object";
+ private static final String BEAN2 = "Another bean object";
+ private static final Integer BEAN3 = 100;
+
+ private BeanFactory factory;
+
+ protected void setUp() throws Exception {
+ Map<String, Object> beans = new HashMap<String, Object>();
+ beans.put(BEAN1_NAME, BEAN1);
+ beans.put(BEAN2_NAME, BEAN2);
+ beans.put(BEAN3_NAME, BEAN3);
+
+ factory = new SimpleBeanFactory(beans);
+ }
+
+ public void testGetBeanByType() throws Exception {
+ assertEquals(BEAN3, factory.getBean(Integer.class));
+
+ try {
+ factory.getBean(String.class);
+ fail("Should have thrown NoSuchBeanDefinitionException: two beans of matching type available");
+ } catch (NoSuchBeanDefinitionException e) {
+ // this is OK
+ }
+
+ try {
+ factory.getBean(Currency.class);
+ fail("Should have thrown NoSuchBeanDefinitionException: no bean of matching type available");
+ } catch (NoSuchBeanDefinitionException e) {
+ // this is OK
+ }
+ }
+}
Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/test/resources/org/apache/servicemix/common/packaging/consumes/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/test/resources/org/apache/servicemix/common/packaging/consumes/xbean.xml?rev=961595&r1=961594&r2=961595&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/test/resources/org/apache/servicemix/common/packaging/consumes/xbean.xml (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/test/resources/org/apache/servicemix/common/packaging/consumes/xbean.xml Thu Jul 8 06:43:57 2010
@@ -18,7 +18,10 @@
-->
-<beans>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ 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-3.0.xsd">
<bean id="consumerBean" class="org.apache.servicemix.common.packaging.ConsumerBeanEndpoint">
<property name="service" value="serviceConsumer"/>