camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r712133 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/test/resources/org/apache/camel/spring/processor/
Date Fri, 07 Nov 2008 14:23:48 GMT
Author: janstey
Date: Fri Nov  7 06:23:26 2008
New Revision: 712133

URL: http://svn.apache.org/viewvc?rev=712133&view=rev
Log:
CAMEL-1038 - Made the expression bit optional in aggregator as you don't need it with an aggregation
collection. Won't be moving this to 1.x.

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-strategy.xml
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
Fri Nov  7 06:23:26 2008
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.model;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
@@ -31,9 +34,12 @@
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.builder.xml.DefaultNamespaceContext;
 import org.apache.camel.model.language.ExpressionType;
 import org.apache.camel.processor.Aggregator;
+import org.apache.camel.processor.FilterProcessor;
 import org.apache.camel.processor.aggregate.AggregationCollection;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
@@ -46,7 +52,13 @@
  */
 @XmlRootElement(name = "aggregator")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class AggregatorType extends ExpressionNode {
+public class AggregatorType extends ProcessorType<ProcessorType> {
+    @XmlElement(name = "correlationExpression", required = false)
+    private ExpressionSubElementType correlationExpression;
+    @XmlTransient
+    private ExpressionType expression;
+    @XmlElementRef
+    private List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
     @XmlTransient
     private AggregationStrategy aggregationStrategy;
     @XmlTransient
@@ -67,22 +79,31 @@
     public AggregatorType() {
     }
 
+    public AggregatorType(Predicate predicate) {
+        if (predicate != null) {
+            setExpression(new ExpressionType(predicate));
+        }
+    }    
+    
     public AggregatorType(Expression correlationExpression) {
-        super(correlationExpression);
+        if (correlationExpression != null) {
+            setExpression(new ExpressionType(correlationExpression));
+        }
     }
 
     public AggregatorType(ExpressionType correlationExpression) {
-        super(correlationExpression);
+        this.expression = correlationExpression;
     }
 
     public AggregatorType(Expression correlationExpression, AggregationStrategy aggregationStrategy)
{
-        super(correlationExpression);
+        this(correlationExpression);
         this.aggregationStrategy = aggregationStrategy;
     }
 
     @Override
     public String toString() {
-        return "Aggregator[" + getExpression() + " -> " + getOutputs() + "]";
+        String expressionString = (getExpression() != null) ? getExpression().getLabel()
: "";     
+        return "Aggregator[" + expressionString + " -> " + getOutputs() + "]";
     }
 
     @Override
@@ -90,6 +111,7 @@
         return "aggregator";
     }
 
+    
     @SuppressWarnings("unchecked")
     @Override
     public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws
Exception {
@@ -118,6 +140,12 @@
         return aggregator;
     }
 
+    public ExpressionClause<AggregatorType> createAndSetExpression() {
+        ExpressionClause<AggregatorType> clause = new ExpressionClause<AggregatorType>(this);
+        this.setExpression(clause);
+        return clause;
+    }
+    
     protected Aggregator createAggregator(RouteContext routeContext) throws Exception {
         Endpoint from = routeContext.getEndpoint();
         final Processor processor = routeContext.createProcessor(this);
@@ -143,7 +171,12 @@
             // create the aggregator using a default collection
             AggregationStrategy strategy = createAggregationStrategy(routeContext);
 
-            Expression aggregateExpression = getExpression().createExpression(routeContext);
+            if (getExpression() == null) {
+                throw new RuntimeCamelException("You need to specify an expression or aggregation
collection " +
+                                                "for the aggregator.");
+            }
+            
+            Expression aggregateExpression = getExpression().createExpression(routeContext);
          
 
             Predicate predicate = null;
             if (getCompletedPredicate() != null) {
@@ -305,4 +338,48 @@
             throw new IllegalArgumentException("There is already a completedPredicate defined
for this aggregator: " + this);
         }
     }
+
+    public void setCorrelationExpression(ExpressionSubElementType correlationExpression)
{
+        this.correlationExpression = correlationExpression;
+    }
+
+    public ExpressionSubElementType getCorrelationExpression() {
+        return correlationExpression;
+    }
+
+    // Section - Methods from ExpressionNode
+    // Needed to copy methods from ExpressionNode here so that I could specify the
+    // correlation expression as optional in JAXB
+    
+    public ExpressionType getExpression() {
+        if (expression == null && correlationExpression != null) {
+            expression = correlationExpression.getExpressionType();            
+        }
+        return expression;
+    }
+
+    public void setExpression(ExpressionType expression) {
+        this.expression = expression;
+    }
+
+    public List<ProcessorType<?>> getOutputs() {
+        return outputs;
+    }
+
+    public void setOutputs(List<ProcessorType<?>> outputs) {
+        this.outputs = outputs;
+    }    
+
+    protected FilterProcessor createFilterProcessor(RouteContext routeContext) throws Exception
{
+        Processor childProcessor = routeContext.createProcessor(this);
+        return new FilterProcessor(getExpression().createPredicate(routeContext), childProcessor);
+    }
+    
+    @Override
+    protected void configureChild(ProcessorType output) {
+        super.configureChild(output);
+        if (isInheritErrorHandler()) {
+            output.setErrorHandlerBuilder(getErrorHandlerBuilder());
+        }
+    }    
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
Fri Nov  7 06:23:26 2008
@@ -754,7 +754,7 @@
         }
         AggregatorType answer = new AggregatorType();
         addOutput(answer);
-        return ExpressionClause.createAndSetExpression(answer);
+        return answer.createAndSetExpression();
     }
 
     /**
@@ -781,14 +781,14 @@
         AggregatorType answer = new AggregatorType();
         answer.setAggregationStrategy(aggregationStrategy);
         addOutput(answer);
-        return ExpressionClause.createAndSetExpression(answer);
+        return answer.createAndSetExpression();
     }
 
     /**
      * Creates an <a
      * href="http://activemq.apache.org/camel/aggregator.html">Aggregator</a>
      * pattern using a custom aggregation collection implementation. The aggregation collection
must
-     * be configued with the strategy and correlation expression that this aggregator should
use.
+     * be configured with the strategy and correlation expression that this aggregator should
use.
      * This avoids duplicating this configuration on both the collection and the aggregator
itself.
      *
      * @param aggregationCollection the collection used to perform the aggregation

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
Fri Nov  7 06:23:26 2008
@@ -27,7 +27,6 @@
     <route>
       <from uri="direct:start"/>
       <aggregator batchTimeout="500" collectionRef="aggregatorCollection">
-        <expression/>
         <to uri="mock:result"/>
       </aggregator>
     </route>

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-strategy.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-strategy.xml?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-strategy.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-strategy.xml
Fri Nov  7 06:23:26 2008
@@ -27,7 +27,9 @@
     <route>
       <from uri="direct:start"/>
       <aggregator strategyRef="aggregatorStrategy">
-        <simple>header.cheese</simple>
+        <correlationExpression>
+          <simple>header.cheese</simple>
+        </correlationExpression>
         <to uri="mock:result"/>
       </aggregator>
     </route>

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml
Fri Nov  7 06:23:26 2008
@@ -27,7 +27,9 @@
     <route>
       <from uri="direct:start"/>
       <aggregator>
-        <simple>header.cheese</simple>
+        <correlationExpression>
+          <simple>header.cheese</simple>
+        </correlationExpression>
         <to uri="mock:result"/>
       </aggregator>
     </route>
@@ -41,7 +43,9 @@
     <route>
       <from uri="direct:temp"/>
       <aggregator>
-        <simple>header.cheese</simple>
+        <correlationExpression>      
+          <simple>header.cheese</simple>
+        </correlationExpression>
         <to uri="mock:result"/>
       </aggregator>
     </route>
@@ -49,7 +53,9 @@
     <route>
       <from uri="direct:predicate"/>
       <aggregator strategyRef="myAggregatorStrategy">
-        <simple>header.cheese</simple>
+        <correlationExpression>
+          <simple>header.cheese</simple>
+        </correlationExpression>
         <to uri="mock:result"/>
         <completedPredicate>
           <method bean="myAggregatorStrategy" method="isCompleted"/>

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml?rev=712133&r1=712132&r2=712133&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml
Fri Nov  7 06:23:26 2008
@@ -61,7 +61,9 @@
     <route>
        <from uri="direct:aggregater"/>
        <aggregator strategyRef="bodyInAggregatorStrategy">
-        <simple>header.cheese</simple>
+        <correlationExpression>
+          <simple>header.cheese</simple>
+        </correlationExpression>
         <to uri="mock:result"/>
         <completedPredicate>
           <method bean="bodyInAggregatorStrategy" method="isCompleted"/>



Mime
View raw message