activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r520375 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/pojo/ camel-core/src...
Date Tue, 20 Mar 2007 12:39:36 GMT
Author: jstrachan
Date: Tue Mar 20 05:39:34 2007
New Revision: 520375

URL: http://svn.apache.org/viewvc?view=rev&rev=520375
Log:
added support for RecipientList pattern

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java   (with
props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoComponent.java
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpointResolver.java
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpointResolver.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoInvocation.java
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoInvocation.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/package.html
      - copied, changed from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/package.html
Removed:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoComponent.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpoint.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpointResolver.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoExchange.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoInvocation.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/package.html
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExchangeSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpointResolver.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsEndpoint.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/MessageListenerProcessor.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Tue Mar 20
05:39:34 2007
@@ -90,4 +90,11 @@
      */
     void setException(Exception e);
 
+    /**
+     * Returns the container so that a processor can resolve endpoints from URIs
+     *
+     * @return the container which owns this exchange
+     */
+    CamelContainer<Exchange> getContainer();
+
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Expressions.java Tue Mar
20 05:39:34 2007
@@ -32,6 +32,11 @@
             public Object evaluate(E exchange) {
                 return exchange.getHeader(headerName);
             }
+
+            @Override
+            public String toString() {
+                return "header(" + headerName + ")";
+            }
         };
     }
     /**
@@ -44,6 +49,11 @@
         return new Expression<E>() {
             public Object evaluate(E exchange) {
                 return value;
+            }
+
+            @Override
+            public String toString() {
+                return "" + value;
             }
         };
     }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java?view=auto&rev=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
Tue Mar 20 05:39:34 2007
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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;
+
+/**
+ * A runtime exception thrown if a routing processor such as a {@link RecipientList} is unable
to resolve
+ * an {@link Endpoint} from a URI.
+ *
+ * @version $Revision$
+ */
+public class NoSuchEndpointException extends RuntimeCamelException {
+    private final String uri;
+
+    public NoSuchEndpointException(String uri) {
+        super("No endpoint could be found for: " + uri);
+        this.uri = uri;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java?view=auto&rev=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java Tue
Mar 20 05:39:34 2007
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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;
+
+import org.apache.camel.util.ObjectHelper;
+import static org.apache.camel.util.ObjectHelper.notNull;
+
+import java.util.Iterator;
+
+/**
+ * Implements a dynamic <a href="http://activemq.apache.org/camel/recipient-list.html">Recipient
List</a> pattern
+ * where the list of actual endpoints to send a message exchange to are dependent on some
dynamic expression.
+ *
+ * @version $Revision$
+ */
+public class RecipientList<E extends Exchange> implements Processor<E> {
+    private final Expression<E> expression;
+
+    public RecipientList(Expression<E> expression) {
+        notNull(expression, "expression");
+        this.expression = expression;
+    }
+
+    @Override
+    public String toString() {
+        return "RecipientList[" + expression + "]";
+    }
+
+    public void onExchange(E exchange) {
+        Object receipientList = expression.evaluate(exchange);
+        Iterator iter = ObjectHelper.createIterator(receipientList);
+        while (iter.hasNext()) {
+            Object recipient = iter.next();
+            Endpoint<E> endpoint = resolveEndpoint(exchange, recipient);
+            endpoint.onExchange(exchange);
+        }
+    }
+
+    @SuppressWarnings({"unchecked"})
+    protected Endpoint<E> resolveEndpoint(E exchange, Object recipient) {
+        Endpoint<E> endpoint;
+        if (recipient instanceof Endpoint) {
+            endpoint = (Endpoint<E>) recipient;
+        }
+        else {
+            String uri = recipient.toString();
+            endpoint = exchange.getContainer().endpoint(uri);
+            if (endpoint == null) {
+                throw new NoSuchEndpointException(uri);
+            }
+        }
+        return endpoint;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RecipientList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
Tue Mar 20 05:39:34 2007
@@ -127,6 +127,20 @@
         return answer;
     }
 
+    /**
+     * Creates a dynamic <a href="http://activemq.apache.org/camel/recipient-list.html">Recipient
List</a> pattern.
+     * 
+     * @param valueBuilder
+     */
+    public RecipientListBuilder<E> recipientList(ValueBuilder<E> valueBuilder)
{
+        RecipientListBuilder<E> answer = new RecipientListBuilder<E>(this, valueBuilder);
+        addProcessBuilder(answer);
+        return answer;
+    }
+
+
+    // Properties
+    //-------------------------------------------------------------------------
     public RouteBuilder<E> getBuilder() {
         return builder;
     }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java?view=auto&rev=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
Tue Mar 20 05:39:34 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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.builder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Expression;
+import org.apache.camel.RecipientList;
+
+/**
+ * Creates a dynamic <a href="http://activemq.apache.org/camel/recipient-list.html">Recipient
List</a> pattern.
+ *
+ * @version $Revision$
+ */
+public class RecipientListBuilder<E extends Exchange> extends BuilderSupport<E>
implements ProcessorBuilder<E> {
+    private final ValueBuilder<E> valueBuilder;
+
+    public RecipientListBuilder(DestinationBuilder<E> destinationBuilder, ValueBuilder<E>
valueBuilder) {
+        super();
+        this.valueBuilder = valueBuilder;
+    }
+
+    public Processor<E> createProcessor() {
+        Expression<E> expression = valueBuilder.getExpression();
+        return new RecipientList<E>(expression);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RecipientListBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
Tue Mar 20 05:39:34 2007
@@ -16,18 +16,23 @@
  */
 package org.apache.camel.impl;
 
+import org.apache.camel.CamelContainer;
 import org.apache.camel.Exchange;
 
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * A default implementation of {@link Exchange}
  *
  * @version $Revision$
  */
-public class DefaultExchange<M,R,F> extends ExchangeSupport<M,R,F> {
-    private Map<String,Object> headers;
+public class DefaultExchange<M, R, F> extends ExchangeSupport<M, R, F> {
+    private Map<String, Object> headers;
+
+    public DefaultExchange(CamelContainer container) {
+        super(container);
+    }
 
     public Object getHeader(String name) {
         if (headers != null) {
@@ -50,5 +55,4 @@
     public void setHeaders(Map<String, Object> headers) {
         this.headers = headers;
     }
-
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExchangeSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExchangeSupport.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExchangeSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExchangeSupport.java
Tue Mar 20 05:39:34 2007
@@ -17,6 +17,7 @@
 package org.apache.camel.impl;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.CamelContainer;
 
 /**
  * A base class useful for implementing other typesafe exchanges
@@ -29,6 +30,11 @@
     private F fault;
     private Exception exception;
     private String exchangeId;
+    protected final CamelContainer container;
+
+    public ExchangeSupport(CamelContainer container) {
+        this.container = container;
+    }
 
     public Exception getException() {
         return exception;
@@ -72,4 +78,7 @@
         this.exchangeId=id;
     }
 
+    public CamelContainer getContainer() {
+        return container;
+    }
 }

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoComponent.java
(from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoComponent.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoComponent.java?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoComponent.java&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoComponent.java&r2=520375
==============================================================================
    (empty)

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
(from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpoint.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpoint.java&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpoint.java
Tue Mar 20 05:39:34 2007
@@ -59,7 +59,7 @@
     }
 
     public PojoExchange createExchange() {
-        return new PojoExchange();
+        return new PojoExchange(getContainer());
     }
 
     @Override
@@ -87,7 +87,7 @@
 			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 				if( !activated.get() ) {
 					PojoInvocation invocation = new PojoInvocation(proxy, method, args);
-					PojoExchange exchange = new PojoExchange();
+					PojoExchange exchange = createExchange();
 					exchange.setRequest(invocation);
 					endpoint.getInboundProcessor().onExchange(exchange);
 					Throwable fault = exchange.getFault();

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpointResolver.java
(from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpointResolver.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpointResolver.java?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoEndpointResolver.java&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoEndpointResolver.java&r2=520375
==============================================================================
    (empty)

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
(from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoExchange.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoExchange.java&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoExchange.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoExchange.java
Tue Mar 20 05:39:34 2007
@@ -20,29 +20,15 @@
 import java.util.Map;
 
 import org.apache.camel.impl.ExchangeSupport;
-
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.CamelContainer;
 
 /**
  * @version $Revision: 519901 $
  */
-public class PojoExchange extends ExchangeSupport<PojoInvocation, Object, Throwable>
{
-	
-	Map<String, Object> headers;
-	
-	public Object getHeader(String name) {
-		if( headers == null )
-			return null;
-		return headers.get(name);
-	}
-
-	public Map<String, Object> getHeaders() {
-		if( headers == null )
-			headers = new HashMap<String, Object>();
-		return headers;
-	}
-	
-	public void setHeader(String name, Object value) {
-		getHeaders().put(name, value);
-	}
+public class PojoExchange extends DefaultExchange<PojoInvocation, Object, Throwable>
{
 
+    public PojoExchange(CamelContainer container) {
+        super(container);
+    }
 }

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoInvocation.java
(from r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoInvocation.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoInvocation.java?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoInvocation.java&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/PojoInvocation.java&r2=520375
==============================================================================
    (empty)

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/package.html (from
r520367, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/package.html)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/package.html?view=diff&rev=520375&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/package.html&r1=520367&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/pojo/package.html&r2=520375
==============================================================================
    (empty)

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpoint.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpoint.java
Tue Mar 20 05:39:34 2007
@@ -23,6 +23,7 @@
 
 import org.apache.camel.CamelContainer;
 import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultExchange;
 
@@ -33,7 +34,7 @@
  * @org.apache.xbean.XBean
  * @version $Revision: 519973 $
  */
-public class QueueEndpoint<E> extends DefaultEndpoint<E> {
+public class QueueEndpoint<E extends Exchange> extends DefaultEndpoint<E> {
     private BlockingQueue<E> queue;
 	private org.apache.camel.queue.QueueEndpoint.Activation activation;
 
@@ -54,7 +55,7 @@
     public E createExchange() {
     	// How can we create a specific Exchange if we are generic??
     	// perhaps it would be better if we did not implement this. 
-        return (E) new DefaultExchange();
+        return (E) new DefaultExchange(getContainer());
     }
 
     public Queue<E> getQueue() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpointResolver.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpointResolver.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/queue/QueueEndpointResolver.java
Tue Mar 20 05:39:34 2007
@@ -23,6 +23,7 @@
 import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointResolver;
+import org.apache.camel.Exchange;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -37,7 +38,7 @@
  * 
  * @version $Revision: 519901 $
  */
-public class QueueEndpointResolver<E> implements EndpointResolver<E> {
+public class QueueEndpointResolver<E extends Exchange> implements EndpointResolver<E>
{
 	
 	public static final String DEFAULT_COMPONENT_NAME = QueueComponent.class.getName();
 	

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Tue Mar 20 05:39:34 2007
@@ -16,6 +16,12 @@
  */
 package org.apache.camel.util;
 
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.Arrays;
+import java.util.Collections;
+import java.lang.reflect.Array;
+
 /**
  * @version $Revision$
  */
@@ -80,4 +86,23 @@
     	return rc;
 	}
 
+    /**
+     * Creates an iterator over the value if the value is a collection, an Object[] or a
primitive type array; otherwise
+     * to simplify the caller's code, we just create a singleton collection iterator over
a single value
+     */
+    public static Iterator createIterator(Object value) {
+        if (value == null) {
+            return Collections.EMPTY_LIST.iterator();
+        }
+        else if (value instanceof Collection) {
+            Collection collection = (Collection) value;
+            return collection.iterator();
+        }
+        else if (value.getClass().isArray()) {
+            return Arrays.asList(value).iterator();
+        }
+        else {
+            return Collections.singletonList(value).iterator();
+        }
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java Tue
Mar 20 05:39:34 2007
@@ -326,6 +326,47 @@
         }
     }
 
+    protected RouteBuilder<Exchange> buildStaticReceipentList() {
+        // START SNIPPET: e8
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("queue:a").to("queue:b", "queue:c", "queue:d");
+            }
+        };
+        // END SNIPPET: e8
+        return builder;
+    }
+
+    protected RouteBuilder<Exchange> buildDynamicReceipentList() {
+        // START SNIPPET: e8
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("queue:a").recipientList(header("foo"));
+            }
+        };
+        // END SNIPPET: e8
+        return builder;
+    }
+
+    public void testRouteDynamicReceipentList() throws Exception {
+
+        RouteBuilder<Exchange> builder = buildDynamicReceipentList();
+
+        Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
+        System.out.println("Created map: " + routeMap);
+
+        Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
+        assertEquals("Number routes created", 1, routes.size());
+        for (Map.Entry<Endpoint<Exchange>, Processor<Exchange>> route :
routes) {
+            Endpoint<Exchange> key = route.getKey();
+            assertEquals("From endpoint", "queue:a", key.getEndpointUri());
+            Processor processor = route.getValue();
+
+            assertTrue("Processor should be a RecipientList but was: " + processor + " with
type: " + processor.getClass().getName(), processor instanceof RecipientList);
+            RecipientList<Exchange> p1 = (RecipientList<Exchange>) processor;
+        }
+    }
+
     protected void assertSendTo(Processor processor, String uri) {
         assertTrue("Processor should be a SendProcessor but was: " + processor + " with type:
" + processor.getClass().getName(), processor instanceof SendProcessor);
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoRouteTest.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/pojo/PojoRouteTest.java
Tue Mar 20 05:39:34 2007
@@ -31,9 +31,6 @@
  */
 public class PojoRouteTest extends TestCase {
 	
-	static class StringExchange extends DefaultExchange<String, String, String> {		
-	}
-	
     public void testJmsRoute() throws Exception {
 
         CamelContainer container = new CamelContainer();

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/queue/QueueRouteTest.java
Tue Mar 20 05:39:34 2007
@@ -33,8 +33,11 @@
  */
 public class QueueRouteTest extends TestCase {
 	
-	static class StringExchange extends DefaultExchange<String, String, String> {		
-	}
+	static class StringExchange extends DefaultExchange<String, String, String> {
+        public StringExchange(CamelContainer container) {
+            super(container);
+        }
+    }
 	
     public void testJmsRoute() throws Exception {
         final CountDownLatch latch = new CountDownLatch(1);
@@ -59,7 +62,7 @@
         
         // now lets fire in a message
         Endpoint<StringExchange> endpoint = container.endpoint("queue:test.a");
-        StringExchange exchange = new StringExchange();
+        StringExchange exchange = new StringExchange(container);
         exchange.setHeader("cheese", 123);
         endpoint.onExchange(exchange);
 

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/DefaultJmsExchange.java
Tue Mar 20 05:39:34 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.jms;
 
+import org.apache.camel.CamelContainer;
 import org.apache.camel.InvalidHeaderTypeException;
 import org.apache.camel.impl.ExchangeSupport;
 
@@ -29,13 +30,15 @@
 /**
  * @version $Revision$
  */
-public class DefaultJmsExchange extends ExchangeSupport<Message,Message,Message> implements
JmsExchange {
+public class DefaultJmsExchange extends ExchangeSupport<Message, Message, Message>
implements JmsExchange {
     private Map<String, Object> lazyHeaders;
 
-    public DefaultJmsExchange() {
+    public DefaultJmsExchange(CamelContainer container) {
+        super(container);
     }
 
-    public DefaultJmsExchange(Message message) {
+    public DefaultJmsExchange(CamelContainer container, Message message) {
+        super(container);
         setRequest(message);
     }
 
@@ -104,7 +107,6 @@
         }
     }
 
-
     public Message createMessage(Session session) throws JMSException {
         Message request = getRequest();
         if (request == null) {
@@ -119,5 +121,4 @@
         }
         return request;
     }
-
 }

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsEndpoint.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsEndpoint.java (original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/JmsEndpoint.java Tue
Mar 20 05:39:34 2007
@@ -81,17 +81,12 @@
     }
 
     public JmsExchange createExchange() {
-        return new DefaultJmsExchange();
+        return new DefaultJmsExchange(getContainer());
     }
 
 
     public JmsExchange createExchange(Message message) {
-        return new DefaultJmsExchange(message);
-    }
-
-
-    protected MessageListener createMessageListener(Processor<Exchange> processor)
{
-        return new MessageListenerProcessor(processor);
+        return new DefaultJmsExchange(getContainer(), message);
     }
 
 

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/MessageListenerProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/MessageListenerProcessor.java?view=diff&rev=520375&r1=520374&r2=520375
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/MessageListenerProcessor.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/jms/MessageListenerProcessor.java
Tue Mar 20 05:39:34 2007
@@ -19,26 +19,28 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.Endpoint;
 
 import javax.jms.MessageListener;
 import javax.jms.Message;
 
 /**
+ * Represents a JMS {@link MessageListener} which can be used directly with any JMS client
+ * or derived from to create an MDB for processing messages using a {@link Processor}
+ *  
  * @version $Revision$
  */
 public class MessageListenerProcessor implements MessageListener {
-    private Processor<Exchange> processor;
+    private final JmsEndpoint endpoint;
+    private final Processor<Exchange> processor;
     
-    public MessageListenerProcessor(Processor<Exchange> processor) {
+    public MessageListenerProcessor(JmsEndpoint endpoint, Processor<Exchange> processor)
{
+        this.endpoint = endpoint;
         this.processor = processor;
     }
 
     public void onMessage(Message message) {
-        Exchange exchange = createMessageExchange(message);
+        Exchange exchange = endpoint.createExchange(message);
         processor.onExchange(exchange);
-    }
-
-    protected DefaultJmsExchange createMessageExchange(Message message) {
-        return new DefaultJmsExchange(message);
     }
 }



Mime
View raw message