activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r521399 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-spring/src/main/java/org/apache/camel/spring/ camel-spring/src/test/java/org/apache/camel/spring/ camel-spring/src/test/resources/org/apache/camel/...
Date Thu, 22 Mar 2007 18:33:56 GMT
Author: chirino
Date: Thu Mar 22 11:33:54 2007
New Revision: 521399

URL: http://svn.apache.org/viewvc?view=rev&rev=521399
Log:
Added needed support for the wire tap impl.. It can now inject array values into builders.

Removed:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringXMLExtensionTest.java
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_xml_extension_test.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ChoiceBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanDefinitionParser.java
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringRouteBuilderTest.java
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_route_builder_test.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ChoiceBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ChoiceBuilder.java?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ChoiceBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ChoiceBuilder.java
Thu Mar 22 11:33:54 2007
@@ -44,12 +44,16 @@
      *
      * @return a builder for creating a when predicate clause and action
      */
-    public WhenBuilder<E> when(Predicate<E> predicate) {
+    @Fluent(nestedActions=true)
+    public WhenBuilder<E> when(
+    		@FluentArg(value="predicate",element=true) 
+    		Predicate<E> predicate) {
         WhenBuilder<E> answer = new WhenBuilder<E>(this, predicate);
         predicateBuilders.add(answer);
         return answer;
     }
 
+    @Fluent(nestedActions=true)
     public FromBuilder<E> otherwise() {
         this.otherwise = new FromBuilder<E>(parent);
         return otherwise;

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
Thu Mar 22 11:33:54 2007
@@ -73,7 +73,9 @@
      * Sends the exchange to a list of endpoints using the {@link MulticastProcessor} pattern
      */
     @Fluent
-    public ProcessorFactory<E> to(@FluentArg("uris") String... uris) {
+    public ProcessorFactory<E> to(
+    		@FluentArg(value="uri", attribute=false, element=true) 
+    		String... uris) {
         return to(endpoints(uris));
     }
 
@@ -81,7 +83,9 @@
      * Sends the exchange to a list of endpoints using the {@link MulticastProcessor} pattern
      */
     @Fluent
-    public ProcessorFactory<E> to(@FluentArg("endpoints") Endpoint<E>... endpoints)
{
+    public ProcessorFactory<E> to(
+    		@FluentArg(value="endpoint", attribute=false, element=true) 
+    		Endpoint<E>... endpoints) {
         return to(endpoints(endpoints));
     }
 
@@ -150,7 +154,7 @@
      *
      * @return the builder for a choice expression
      */
-    @Fluent
+    @Fluent(nestedActions=true)
     public ChoiceBuilder<E> choice() {
         ChoiceBuilder<E> answer = new ChoiceBuilder<E>(this);
         addProcessBuilder(answer);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
Thu Mar 22 11:33:54 2007
@@ -33,13 +33,15 @@
     }
 
     @Override
-    public ChoiceBuilder<E> to(Endpoint<E> endpoint) {
+    @Fluent
+    public ChoiceBuilder<E> to(@FluentArg("endpoint") Endpoint<E> endpoint) {
         super.to(endpoint);
         return parent;
     }
 
     @Override
-    public ChoiceBuilder<E> to(String uri) {
+    @Fluent
+    public ChoiceBuilder<E> to(@FluentArg("uri")  String uri) {
         super.to(uri);
         return parent;
     }

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanDefinitionParser.java?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanDefinitionParser.java
(original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanDefinitionParser.java
Thu Mar 22 11:33:54 2007
@@ -1,6 +1,7 @@
 package org.apache.camel.spring;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -14,6 +15,7 @@
 import org.apache.camel.builder.Fluent;
 import org.apache.camel.builder.FluentArg;
 import org.apache.camel.builder.RouteBuilder;
+import org.springframework.beans.SimpleTypeConverter;
 import org.springframework.beans.factory.config.RuntimeBeanReference;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -74,11 +76,8 @@
 					currentBuilder = parseBuilderElement((Element) node, currentBuilder, actions);
 				} else {
 					// Make sure the there are no child elements.
-					NodeList nl = node.getChildNodes();
-					for (int j = 0; j < nl.getLength(); ++j) {
-						if( nl.item(j).getNodeType() == Node.ELEMENT_NODE ) {
-							throw new IllegalArgumentException("The element "+node.getLocalName()+" should not
have any child elements.");
-						}
+					if( hasChildElements(node) ) {
+						throw new IllegalArgumentException("The element "+node.getLocalName()+" should not
have any child elements.");
 					}
 				}
 				
@@ -106,6 +105,16 @@
 		return currentBuilder;
 	}
 
+	private boolean hasChildElements(Node node) {
+		NodeList nl = node.getChildNodes();
+		for (int j = 0; j < nl.getLength(); ++j) {
+			if( nl.item(j).getNodeType() == Node.ELEMENT_NODE ) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	private Class parseAction(Class currentBuilder, ArrayList<BuilderAction> actions,
Element element, Element previousElement) {
 
 		String actionName = element.getLocalName();
@@ -157,8 +166,14 @@
 	private Object convertTo(ArrayList<Element> elements, Class clazz) {
 
 		if( clazz.isArray() || elements.size() > 1 ) {
-			// TODO: we could support arrays one day soon.
-			throw new IllegalStateException("We don't support injecting array values.");
+			Object array = Array.newInstance(clazz.getComponentType(), elements.size());
+			for( int i=0; i < elements.size(); i ++ ) {
+				ArrayList<Element> e = new ArrayList<Element>(1);
+				e.add(elements.get(i));
+				Object value = convertTo(e, clazz.getComponentType());
+				Array.set(array, i, value);
+			}
+			return array;
 		} else {
 			
 			Element element = elements.get(0);
@@ -167,17 +182,25 @@
 				return new RuntimeBeanReference(ref);
 			}
 			
-			ArrayList<BuilderAction> actions = new ArrayList<BuilderAction>();
-			Class type = parseBuilderElement(element, RouteBuilder.class, actions);
-			BuilderStatement statement = new BuilderStatement();
-			statement.setReturnType(type);
-			statement.setActions(actions);
-			
-			if( !clazz.isAssignableFrom( statement.getReturnType() ) ) {
-				throw new IllegalStateException("Builder does not produce object of expected type: "+clazz.getName());
+			// Use a builder to create the value..
+			if( hasChildElements(element) ) {
+				
+				ArrayList<BuilderAction> actions = new ArrayList<BuilderAction>();
+				Class type = parseBuilderElement(element, RouteBuilder.class, actions);
+				BuilderStatement statement = new BuilderStatement();
+				statement.setReturnType(type);
+				statement.setActions(actions);
+				
+				if( !clazz.isAssignableFrom( statement.getReturnType() ) ) {
+					throw new IllegalStateException("Builder does not produce object of expected type: "+clazz.getName());
+				}
+				
+				return statement;
+			} else {
+				// Just use the text in the element as the value.
+				SimpleTypeConverter converter = new SimpleTypeConverter();
+				return converter.convertIfNecessary(element.getTextContent(), clazz);
 			}
-			
-			return statement;
 		}
 	}
 

Modified: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringRouteBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringRouteBuilderTest.java?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringRouteBuilderTest.java
(original)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringRouteBuilderTest.java
Thu Mar 22 11:33:54 2007
@@ -78,20 +78,24 @@
 	}
 	
 	@Override
-	protected RouteBuilder<Exchange> buildSimpleRouteWithChoice() {
-		// TODO Auto-generated method stub
-		return super.buildSimpleRouteWithChoice();
+	protected RouteBuilder<Exchange> buildSimpleRouteWithHeaderPredicate() {
+		RouteBuilder<Exchange> builder = (RouteBuilder<Exchange>) ctx.getBean("buildSimpleRouteWithHeaderPredicate");
+		assertNotNull(builder);
+		return builder;
 	}
-	
+
 	@Override
-	protected RouteBuilder<Exchange> buildSimpleRouteWithHeaderPredicate() {
-		// TODO Auto-generated method stub
-		return super.buildSimpleRouteWithHeaderPredicate();
+	protected RouteBuilder<Exchange> buildSimpleRouteWithChoice() {
+		RouteBuilder<Exchange> builder = (RouteBuilder<Exchange>) ctx.getBean("buildSimpleRouteWithChoice");
+		assertNotNull(builder);
+		return builder;
 	}
 	
+	
 	@Override
 	protected RouteBuilder<Exchange> buildWireTap() {
-		// TODO Auto-generated method stub
-		return super.buildWireTap();
+		RouteBuilder<Exchange> builder = (RouteBuilder<Exchange>) ctx.getBean("buildWireTap");
+		assertNotNull(builder);
+		return builder;
 	}
 }

Modified: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_route_builder_test.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_route_builder_test.xml?view=diff&rev=521399&r1=521398&r2=521399
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_route_builder_test.xml
(original)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/spring_route_builder_test.xml
Thu Mar 22 11:33:54 2007
@@ -86,22 +86,20 @@
                 .otherwise().to("queue:d");
      -->
     <routeBuilder id="buildSimpleRouteWithChoice" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
-       <!-- 
        <route>
          <from uri="queue:a"/>
          <choice>
              <when>
                  <predicate>
                     <header name="foo"/>
-                    <equalTo value="bar"/>
+                    <isEqualTo value="bar"/>
                  </predicate>
                  <to uri="queue:b"/>
              </when>
-             
              <when>
                  <predicate>
                     <header name="foo"/>
-                    <equalTo value="cheese"/>
+                    <isEqualTo value="cheese"/>
                  </predicate>
                  <to uri="queue:c"/>
              </when>
@@ -110,40 +108,35 @@
              </otherwise>
          </choice>
        </route>
-        -->
     </routeBuilder>
 
     <!-- 
-        from("queue:a").filter(headerEquals("foo", "bar")).to("queue:b");
+        from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b");
      -->
     <routeBuilder id="buildSimpleRouteWithHeaderPredicate" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
-    <!-- 
        <route>
          <from uri="queue:a"/>
          <filter>
              <predicate>
                 <header name="foo"/>
-                <equalTo value="bar"/>
+                <isEqualTo value="bar"/>
              </predicate>
          </filter>
          <to uri="queue:b"/>
        </route>
-     -->
     </routeBuilder>
 
     <!-- 
         from("queue:a").to("queue:tap", "queue:b");
      -->
     <routeBuilder id="buildWireTap" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
-    <!-- 
        <route>
          <from uri="queue:a"/>
          <to>
             <uri>queue:tap</uri>
-            <uri>queue:a</uri>
+            <uri>queue:b</uri>
          </to>
        </route>
-     -->
     </routeBuilder>
 
 </beans>



Mime
View raw message