activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r533658 - in /activemq/camel/trunk/camel-spring/src: main/java/org/apache/camel/spring/ main/java/org/apache/camel/spring/xml/ main/resources/org/apache/camel/spring/ test/java/org/apache/camel/spring/ test/resources/org/apache/camel/spring/
Date Mon, 30 Apr 2007 10:05:44 GMT
Author: jstrachan
Date: Mon Apr 30 03:05:43 2007
New Revision: 533658

URL: http://svn.apache.org/viewvc?view=rev&rev=533658
Log:
added a test case to show the creation of a Spring CamelContext using the spring XML namespaces
approach

Added:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java
  (with props)
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
  (with props)
Modified:
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/xml/CamelNamespaceHandler.java
    activemq/camel/trunk/camel-spring/src/main/resources/org/apache/camel/spring/camel-1.0.xsd
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?view=diff&rev=533658&r1=533657&r2=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Mon Apr 30 03:05:43 2007
@@ -19,7 +19,6 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
@@ -84,13 +83,19 @@
         this.context = context;
     }
 
-	public RouteBuilder getRouteBuilder() {
-		return routeBuilder;
-	}
-
-	public void setRouteBuilder(RouteBuilder routeBuilder) {
-		this.routeBuilder = routeBuilder;
-	}
+    public RouteBuilder getRouteBuilder() {
+        return routeBuilder;
+    }
+
+    public void setRouteBuilder(RouteBuilder routeBuilder) {
+        this.routeBuilder = routeBuilder;
+    }
+
+    public void setRouteBuilders(RouteBuilder[] builders) {
+        for (RouteBuilder builder : builders) {
+            additionalBuilders.add(builder);
+        }
+    }
 
     public ApplicationContext getApplicationContext() {
         return applicationContext;
@@ -108,7 +113,6 @@
         this.packages = packages;
     }
 
-
     // Implementation methods
     //-------------------------------------------------------------------------
 
@@ -119,8 +123,9 @@
         for (RouteBuilder routeBuilder : additionalBuilders) {
             getContext().addRoutes(routeBuilder);
         }
-        if( routeBuilder!=null )
-        	getContext().addRoutes(routeBuilder);
+        if (routeBuilder != null) {
+            getContext().addRoutes(routeBuilder);
+        }
     }
 
     /**

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/xml/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/xml/CamelNamespaceHandler.java?view=diff&rev=533658&r1=533657&r2=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/xml/CamelNamespaceHandler.java
(original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/xml/CamelNamespaceHandler.java
Mon Apr 30 03:05:43 2007
@@ -1,12 +1,44 @@
 package org.apache.camel.spring.xml;
 
-import org.apache.camel.spring.xml.CamelBeanDefinitionParser;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.spring.CamelContextFactoryBean;
+import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 public class CamelNamespaceHandler extends NamespaceHandlerSupport {
+    protected CamelBeanDefinitionParser camelBeanDefinitionParser = new CamelBeanDefinitionParser();
 
-	public void init() {
-		 registerBeanDefinitionParser("routeBuilder", new CamelBeanDefinitionParser());    
-	}
+    public void init() {
+        registerBeanDefinitionParser("routes", camelBeanDefinitionParser);
+        registerBeanDefinitionParser("routeBuilder", camelBeanDefinitionParser);
+        
+        registerBeanDefinitionParser("camelContext", new AbstractSimpleBeanDefinitionParser()
{
+            protected Class getBeanClass(Element element) {
+                return CamelContextFactoryBean.class;
+            }
 
+            @Override
+            protected boolean isEligibleAttribute(String attributeName) {
+                return super.isEligibleAttribute(attributeName) && !attributeName.equals("xmlns");
+            }
+
+            @Override
+            protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder
builder) {
+                super.doParse(element, parserContext, builder);
+
+                NodeList list = element.getElementsByTagName("routes");
+                for (int size = list.getLength(), i = 0; i < size; i++) {
+                    Element node = (Element) list.item(i);
+                    BeanDefinition definition = camelBeanDefinitionParser.parseInternal(node,
parserContext);
+                    builder.addPropertyValue("routeBuilder", definition);
+                }
+            }
+        });
+    }
 }

Modified: activemq/camel/trunk/camel-spring/src/main/resources/org/apache/camel/spring/camel-1.0.xsd
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/resources/org/apache/camel/spring/camel-1.0.xsd?view=diff&rev=533658&r1=533657&r2=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/resources/org/apache/camel/spring/camel-1.0.xsd
(original)
+++ activemq/camel/trunk/camel-spring/src/main/resources/org/apache/camel/spring/camel-1.0.xsd
Mon Apr 30 03:05:43 2007
@@ -1,26 +1,48 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xs:schema 
-  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
-  elementFormDefault="qualified" 
-  attributeFormDefault="unqualified"
-  targetNamespace="http://activemq.apache.org/camel/schema/camel-1.0.xsd" 
-  xmlns:c="http://activemq.apache.org/camel/schema/camel-1.0.xsd"
-  xmlns:s="http://www.springframework.org/schema/beans"
-  >
- 
+<xs:schema
+        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+        elementFormDefault="qualified"
+        attributeFormDefault="unqualified"
+        targetNamespace="http://activemq.apache.org/camel/schema/camel-1.0.xsd"
+        xmlns:c="http://activemq.apache.org/camel/schema/camel-1.0.xsd"
+        xmlns:s="http://www.springframework.org/schema/beans"
+        >
+
   <xs:import namespace="http://www.springframework.org/schema/beans"/>
+
+  <xs:element name="camelContext">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="s:identifiedType">
+          <xs:sequence>
+            <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:routes"/>
+          </xs:sequence>
+          <xs:attribute name="packages" type="xs:NMTOKEN"/>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+
+  <xs:element name="routes">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:route"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+
   <xs:element name="routeBuilder">
     <xs:complexType>
       <xs:complexContent>
         <xs:extension base="s:identifiedType">
-		  <xs:sequence>
-		    <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:route"/>
-		  </xs:sequence>
-	    </xs:extension>
-  	  </xs:complexContent>
+          <xs:sequence>
+            <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:route"/>
+          </xs:sequence>
+        </xs:extension>
+      </xs:complexContent>
     </xs:complexType>
   </xs:element>
-  
+
   <xs:element name="route">
     <xs:complexType>
       <xs:sequence>

Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java?view=auto&rev=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java
(added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java
Mon Apr 30 03:05:43 2007
@@ -0,0 +1,31 @@
+/**
+ *
+ * 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.camel.spring;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class RoutingUsingCamelContextFactoryAndNamespacesTest extends RoutingUsingCamelContextFactoryTest
{
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml");
+    }
+
+}

Propchange: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryAndNamespacesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java?view=diff&rev=533658&r1=533657&r2=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java
(original)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java
Mon Apr 30 03:05:43 2007
@@ -17,18 +17,18 @@
  */
 package org.apache.camel.spring;
 
-import org.apache.camel.TestSupport;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Processor;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.TestSupport;
+import org.apache.camel.Route;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.util.CamelClient;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.List;
 
 /**
  * @version $Revision: 521586 $
@@ -38,10 +38,10 @@
     protected AbstractXmlApplicationContext applicationContext;
 
     public void testXMLRouteLoading() throws Exception {
-        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/routingUsingCamelContextFactoryTest.xml");
+        applicationContext = createApplicationContext();
 
-        CamelContext context = (CamelContext) applicationContext.getBean("camel");
-        assertNotNull("No context found!", context);
+        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean("camel");
+        assertValidContext(context);
 
         MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
         resultEndpoint.expectedBodiesReceived(body);
@@ -55,14 +55,27 @@
                 in.setBody(body);
             }
         });
-        
 
         resultEndpoint.assertIsSatisfied();
     }
 
+    protected void assertValidContext(SpringCamelContext context) {
+        assertNotNull("No context found!", context);
+
+        List<Route> routes = context.getRoutes();
+        assertNotNull("Should have some routes defined", routes);
+        assertEquals("Number of routes defined", 1, routes.size());
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/routingUsingCamelContextFactoryTest.xml");
+    }
+
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();
-        applicationContext.destroy();
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
     }
 }

Added: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml?view=auto&rev=533658
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
(added)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
Mon Apr 30 03:05:43 2007
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<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-2.0.xsd
+       http://activemq.apache.org/camel/schema/camel-1.0.xsd http://activemq.apache.org/camel/schema/camel-1.0.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
+    <routes>
+      <route>
+        <from uri="queue:start"/>
+        <to uri="mock:result"/>
+      </route>
+    </routes>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>

Propchange: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message