svn commit: r595654 - 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/component/bean/ camel-core/src/main/java/org/apache/camel/language/b...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r595654 - 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/component/bean/ camel-core/src/main/java/org/apache/camel/language/b...

jstrachan-2
Author: jstrachan
Date: Fri Nov 16 05:22:28 2007
New Revision: 595654

URL: http://svn.apache.org/viewvc?rev=595654&view=rev
Log:
added support for bean method calls as expressions/predicates for https://issues.apache.org/activemq/browse/CAMEL-226 which makes adding custom predicates/beans really easy without clever expression languages. Also fixed up the failing Aggregator test

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
      - copied, changed from r594497, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
      - copied, changed from r594497, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java   (with props)
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/bean
      - copied, changed from r594497, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/simple
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/BeanTest.java
      - copied, changed from r594497, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SimpleExpression.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SqlExpression.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator.xml

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java (from r594497, 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/NoSuchBeanException.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java&r1=594497&r2=595654&rev=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchEndpointException.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java Fri Nov 16 05:22:28 2007
@@ -16,23 +16,23 @@
  */
 package org.apache.camel;
 
+import org.apache.camel.spi.Registry;
 
 /**
- * A runtime exception thrown if a routing processor such as a
- * {@link RecipientList} is unable to resolve an {@link Endpoint} from a URI.
- *
+ * A runtime exception if a given bean could not be found in the {@link Registry}
+ *
  * @version $Revision$
  */
-public class NoSuchEndpointException extends RuntimeCamelException {
+public class NoSuchBeanException extends RuntimeCamelException {
     private static final long serialVersionUID = -8721487431101572630L;
-    private final String uri;
+    private final String name;
 
-    public NoSuchEndpointException(String uri) {
-        super("No endpoint could be found for: " + uri);
-        this.uri = uri;
+    public NoSuchBeanException(String name) {
+        super("No bean could be found in the registry for: " + name);
+        this.name = name;
     }
 
-    public String getUri() {
-        return uri;
+    public String getName() {
+        return name;
     }
-}
+}
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java Fri Nov 16 05:22:28 2007
@@ -21,6 +21,7 @@
 
 import org.apache.camel.builder.xml.Namespaces;
 import org.apache.camel.model.ExpressionNode;
+import org.apache.camel.model.language.MethodCall;
 import org.apache.camel.model.language.ExpressionType;
 import org.apache.camel.model.language.XPathExpression;
 import org.apache.camel.model.language.XQueryExpression;
@@ -47,6 +48,35 @@
 
     // Fluent API
     //-------------------------------------------------------------------------
+
+    /**
+     * Evaluates an expression using the
+     * <a href="http://activemq.apache.org/camel/bean-language.html>bean language</a>
+     * which basically means the bean is invoked to determine the expression value.
+     *
+     * @param bean the name of the bean looked up the registry
+     * @return the builder to continue processing the DSL
+     */
+    public T bean(String bean) {
+        MethodCall expression = new MethodCall(bean);
+        setExpressionType(expression);
+        return result;
+    }
+
+    /**
+     * Evaluates an expression using the
+     * <a href="http://activemq.apache.org/camel/bean-language.html>bean language</a>
+     * which basically means the bean is invoked to determine the expression value.
+     *
+     * @param bean the name of the bean looked up the registry
+     * @param method the name of the method to invoke on the bean
+     * @return the builder to continue processing the DSL
+     */
+    public T bean(String bean, String method) {
+        MethodCall expression = new MethodCall(bean, method);
+        setExpressionType(expression);
+        return result;
+    }
 
     /**
      * Evaluates the  <a href="http://activemq.apache.org/camel/el.html">EL Language from JSP and JSF</a>

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Fri Nov 16 05:22:28 2007
@@ -139,7 +139,12 @@
                 hasCustomAnnotation |= ObjectHelper.hasAnnotation(parameterAnnotations, Body.class);
                 if (bodyParameters.isEmpty()) {
                     // lets assume its the body
-                    expression = ExpressionBuilder.bodyExpression(parameterType);
+                    if (Exchange.class.isAssignableFrom(parameterType)) {
+                        expression = ExpressionBuilder.exchangeExpression();
+                    }
+                    else {
+                        expression = ExpressionBuilder.bodyExpression(parameterType);
+                    }
                     parameterInfo.setExpression(expression);
                     bodyParameters.add(parameterInfo);
                 } else {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java?rev=595654&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java Fri Nov 16 05:22:28 2007
@@ -0,0 +1,63 @@
+/**
+ *
+ * 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.language.bean;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.impl.ExpressionSupport;
+import org.apache.camel.util.ExchangeHelper;
+
+/**
+ * Evaluates an expression using a bean method invocation
+ *
+ * @version $Revision: 1.1 $
+ */
+public class BeanExpression<E extends Exchange> extends ExpressionSupport<E> {
+    private String beanName;
+    private String method;
+
+    public BeanExpression(String beanName, String method) {
+        this.beanName = beanName;
+        this.method = method;
+    }
+
+    @Override
+    public String toString() {
+        return "BeanExpression[bean: " + beanName + " method: " + method + "]";
+    }
+
+    protected String assertionFailureMessage(E exchange) {
+        return "bean: " + beanName + " method: " + method;
+    }
+
+    public Object evaluate(E exchange) {
+        Object bean = ExchangeHelper.lookupMandatoryBean(exchange, beanName);
+        BeanProcessor processor = new BeanProcessor(bean, exchange.getContext());
+        if (method != null) {
+            processor.setMethod(method);
+        }
+        try {
+            Exchange newExchange = exchange.copy();
+            processor.process(newExchange);
+            return newExchange.getOut(true).getBody();
+        }
+        catch (Exception e) {
+            throw new RuntimeBeanExpressionException(exchange, bean, method, e);
+        }
+    }
+}

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

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java (from r594497, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java&r1=594497&r2=595654&rev=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java Fri Nov 16 05:22:28 2007
@@ -14,140 +14,42 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.language.simple;
-
-import java.util.ArrayList;
-import java.util.List;
+package org.apache.camel.language.bean;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
-import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.builder.PredicateBuilder;
-import org.apache.camel.language.IllegalSyntaxException;
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.ObjectHelper;
 
 /**
- * A <a href="http://activemq.apache.org/camel/simple.html>simple language</a>
- * which maps simple property style notations to acces headers and bodies.
- * Examples of supported expressions are <p/>
- * <ul>
- * <li>in.header.foo or header.foo to access an inbound header called 'foo'</li>
- * <li>in.body or body to access the inbound body</li>
- * <li>out.header.foo to access an outbound header called 'foo'</li>
- * <li>out.body to access the inbound body</li>
- * <li>property.foo to access the exchange property called 'foo'</li>
- * <li>sys.foo to access the system property called 'foo'</li>
- * </ul>
+ * A <a href="http://activemq.apache.org/camel/bean-language.html>bean language</a>
+ * which uses a simple text notation to invoke methods on beans to evaluate predicates or expressions<p/>
+ * <p/>
+ * The notation is essentially <code>beanName.methodName</code> which is then invoked using the
+ * beanName to lookup in the <a href="http://activemq.apache.org/camel/registry.html>registry</a>
+ * then the method is invoked to evaluate the expression using the
+ * <a href="http://activemq.apache.org/camel/bean-integration.html>bean integration</a> to bind the
+ * {@link Exchange} to the method arguments.
  *
  * @version $Revision: $
  */
-public class SimpleLanguage implements Language {
-
-    public static Expression simple(String expression) {
-        SimpleLanguage language = new SimpleLanguage();
-        return language.createExpression(expression);
-    }
-    
+public class BeanLanguage implements Language {
     public Predicate<Exchange> createPredicate(String expression) {
         return PredicateBuilder.toPredicate(createExpression(expression));
     }
 
     public Expression<Exchange> createExpression(String expression) {
-        if (expression.indexOf("${") >= 0) {
-            return createComplexExpression(expression);
-        }
-        return createSimpleExpression(expression);
-    }
-
-    protected Expression<Exchange> createComplexExpression(String expression) {
-        List<Expression> results = new ArrayList<Expression>();
-
-        int pivot = 0;
-        int size = expression.length();
-        while (pivot < size) {
-            int idx = expression.indexOf("${", pivot);
-            if (idx < 0) {
-                results.add(createConstantExpression(expression, pivot, size));
-                break;
-            }
-            else {
-                if (pivot < idx) {
-                    results.add(createConstantExpression(expression, pivot, idx));
-                }
-                pivot = idx + 2;
-                int endIdx = expression.indexOf("}", pivot);
-                if (endIdx < 0) {
-                    throw new IllegalArgumentException("Expecting } but found end of string for simple expression: " + expression);
-                }
-                String simpleText = expression.substring(pivot, endIdx);
-
-                Expression simpleExpression = createSimpleExpression(simpleText);
-                results.add(simpleExpression);
-                pivot = endIdx + 1;
-            }
-        }
-        return ExpressionBuilder.concatExpression(results, expression);
-    }
-
-    protected Expression createConstantExpression(String expression, int start, int end) {
-        return ExpressionBuilder.constantExpression(expression.substring(start, end));
-    }
-
-    protected Expression<Exchange> createSimpleExpression(String expression) {
-        if (ObjectHelper.isEqualToAny(expression, "body", "in.body")) {
-            return ExpressionBuilder.bodyExpression();
-        }
-        else if (ObjectHelper.equal(expression, "out.body")) {
-            return ExpressionBuilder.outBodyExpression();
-        }
-
-        // in header expression
-        String remainder = ifStartsWithReturnRemainder("in.header.", expression);
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("header.", expression);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("headers.", expression);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("in.headers.", expression);
-        }
-        if (remainder != null) {
-            return ExpressionBuilder.headerExpression(remainder);
-        }
-
-        // out header expression
-        remainder = ifStartsWithReturnRemainder("out.header.", expression);
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("out.headers.", expression);
-        }
-        if (remainder != null) {
-            return ExpressionBuilder.outHeaderExpression(remainder);
-        }
-
-        // property
-        remainder = ifStartsWithReturnRemainder("property.", expression);
-        if (remainder != null) {
-            return ExpressionBuilder.propertyExpression(remainder);
-        }
-
-        // system property
-        remainder = ifStartsWithReturnRemainder("sys.", expression);
-        if (remainder != null) {
-            return ExpressionBuilder.propertyExpression(remainder);
-        }
-        throw new IllegalSyntaxException(this, expression);
-    }
+        ObjectHelper.notNull(expression, "expression");
 
-    protected String ifStartsWithReturnRemainder(String prefix, String text) {
-        if (text.startsWith(prefix)) {
-            String remainder = text.substring(prefix.length());
-            if (remainder.length() > 0) {
-                return remainder;
-            }
+        int idx = expression.lastIndexOf('.');
+        String beanName = expression;
+        String method = null;
+        if (idx > 0) {
+            beanName = expression.substring(0, idx);
+            method = expression.substring(idx + 1);
         }
-        return null;
+        return new BeanExpression(beanName, method);
     }
-}
+}
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java?rev=595654&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java Fri Nov 16 05:22:28 2007
@@ -0,0 +1,49 @@
+/**
+ *
+ * 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.language.bean;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeExpressionException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class RuntimeBeanExpressionException extends RuntimeExpressionException {
+    private Exchange exchange;
+    private Object bean;
+    private String method;
+
+    public RuntimeBeanExpressionException(Exchange exchange, Object bean, String method, Throwable e) {
+        super("Failed to invoke method: " + method + " on " + bean + " due to: " + e, e);
+        this.exchange = exchange;
+        this.bean = bean;
+        this.method = method;
+    }
+
+    public Object getBean() {
+        return bean;
+    }
+
+    public Exchange getExchange() {
+        return exchange;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+}

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

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java?rev=595654&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java Fri Nov 16 05:22:28 2007
@@ -0,0 +1,81 @@
+/**
+ * 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.model.language;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.impl.RouteContext;
+import org.apache.camel.language.bean.BeanExpression;
+
+/**
+ * For expresions and predicates using the
+ * <a href="http://activemq.apache.org/camel/bean-language.html>bean language</a>
+ *
+ * @version $Revision: 1.1 $
+ */
+@XmlRootElement(name = "methodCall")
+public class MethodCall extends ExpressionType {
+    @XmlAttribute(required = false)
+    private String bean;
+    @XmlAttribute(required = false)
+    private String method;
+
+    public MethodCall() {
+    }
+
+    public MethodCall(String beanName) {
+        super(beanName);
+    }
+
+    public MethodCall(String beanName, String method) {
+        super(beanName);
+        this.method = method;
+    }
+
+    public String getLanguage() {
+        return "bean";
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    @Override
+    public Expression createExpression(RouteContext routeContext) {
+        return new BeanExpression(beanName(), getMethod());
+    }
+
+    @Override
+    public Predicate<Exchange> createPredicate(RouteContext routeContext) {
+        return new BeanExpression<Exchange>(beanName(), getMethod());
+    }
+
+    protected String beanName() {
+        if (bean != null) {
+            return bean;
+        }
+        return getExpression();
+    }
+}
\ No newline at end of file

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SimpleExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SimpleExpression.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SimpleExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SimpleExpression.java Fri Nov 16 05:22:28 2007
@@ -19,7 +19,8 @@
 import javax.xml.bind.annotation.XmlRootElement;
 
 /**
- * For Groovy expresions and predicates
+ * For expresions and predicates using the
+ * <a href="http://activemq.apache.org/camel/simple.html>simple language</a>
  *
  * @version $Revision: 1.1 $
  */

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SqlExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SqlExpression.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SqlExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/SqlExpression.java Fri Nov 16 05:22:28 2007
@@ -19,7 +19,7 @@
 import javax.xml.bind.annotation.XmlRootElement;
 
 /**
- * For SQ: expresions and predicates
+ * For SQL expresions and predicates
  *
  * @version $Revision: 1.1 $
  */

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java Fri Nov 16 05:22:28 2007
@@ -116,4 +116,5 @@
         }
         return expression;
     }
+
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Nov 16 05:22:28 2007
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.util;
 
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -25,9 +25,9 @@
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.InvalidTypeException;
 import org.apache.camel.Message;
+import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.NoSuchPropertyException;
-import org.apache.camel.CamelContext;
 
 /**
  * Some helper methods for working with {@link Exchange} objects
@@ -266,5 +266,41 @@
      */
     public static String getContentType(Exchange exchange) {
        return exchange.getIn().getHeader("Content-Type", String.class);
+    }
+
+    /**
+     * Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
+     */
+    public static Object lookupMandatoryBean(Exchange exchange, String name) {
+        Object value = lookupBean(exchange, name);
+        if (value == null) {
+            throw new NoSuchBeanException(name);
+        }
+        return value;
+    }
+
+    /**
+     * Performs a lookup in the registry of the mandatory bean name and throws an exception if it could not be found
+     */
+    public static <T> T lookupMandatoryBean(Exchange exchange, String name, Class<T> type) {
+        T value = lookupBean(exchange, name, type);
+        if (value == null) {
+            throw new NoSuchBeanException(name);
+        }
+        return value;
+    }
+
+    /**
+     * Performs a lookup in the registry of the bean name
+     */
+    public static Object lookupBean(Exchange exchange, String name) {
+        return exchange.getContext().getRegistry().lookup(name);
+    }
+
+    /**
+     * Performs a lookup in the registry of the bean name and type
+     */
+    public static <T> T lookupBean(Exchange exchange, String name, Class<T> type) {
+        return exchange.getContext().getRegistry().lookup(name, type);
     }
 }

Copied: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/bean (from r594497, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/simple)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/bean?p2=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/bean&p1=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/simple&r1=594497&r2=595654&rev=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/simple (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/language/bean Fri Nov 16 05:22:28 2007
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.language.simple.SimpleLanguage
+class=org.apache.camel.language.bean.BeanLanguage

Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index Fri Nov 16 05:22:28 2007
@@ -20,6 +20,7 @@
 HeaderExpression
 JavaScriptExpression
 LanguageExpression
+MethodCall
 OgnlExpression
 PhpExpression
 PythonExpression

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/BeanTest.java (from r594497, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/BeanTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/BeanTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java&r1=594497&r2=595654&rev=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/BeanTest.java Fri Nov 16 05:22:28 2007
@@ -16,48 +16,44 @@
  */
 package org.apache.camel.language;
 
+import javax.naming.Context;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Header;
 import org.apache.camel.LanguageTestSupport;
+import org.apache.camel.Message;
 
 /**
  * @version $Revision: $
  */
-public class SimpleTest extends LanguageTestSupport {
-
+public class BeanTest extends LanguageTestSupport {
     public void testSimpleExpressions() throws Exception {
-        assertExpression("body", "<hello id='m123'>world!</hello>");
-        assertExpression("in.body", "<hello id='m123'>world!</hello>");
-        assertExpression("in.header.foo", "abc");
-        assertExpression("header.foo", "abc");
+        assertExpression("foo.cheese", "abc");
     }
 
-    public void testComplexExpressions() throws Exception {
-        assertExpression("hey ${in.header.foo}", "hey abc");
-        assertExpression("hey ${in.header.foo}!", "hey abc!");
-        assertExpression("hey ${in.header.foo}-${in.header.foo}!", "hey abc-abc!");
-        assertExpression("hey ${in.header.foo}${in.header.foo}", "hey abcabc");
-        assertExpression("${in.header.foo}${in.header.foo}", "abcabc");
-        assertExpression("${in.header.foo}", "abc");
-        assertExpression("${in.header.foo}!", "abc!");
+    public void testPredicates() throws Exception {
+        assertPredicate("foo.isFooHeaderAbc");
     }
 
-
-    public void testInvalidComplexExpression() throws Exception {
-        try {
-            assertExpression("hey ${foo", "bad expression!");
-            fail("Should have thrown an exception!");
-        }
-        catch (IllegalArgumentException e) {
-            log.debug("Caught expected exception: " + e, e);
-        }
+    protected String getLanguageName() {
+        return "bean";
     }
 
-    public void testPredicates() throws Exception {
-        assertPredicate("body");
-        assertPredicate("header.foo");
-        assertPredicate("header.madeUpHeader", false);
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        context.bind("foo", new MyBean());
+        return context;
     }
 
-    protected String getLanguageName() {
-        return "simple";
+    public static class MyBean {
+        public Object cheese(Exchange exchange) {
+            Message in = exchange.getIn();
+            return in.getHeader("foo");
+        }
+
+        public boolean isFooHeaderAbc(@Header(name = "foo")String foo) {
+            return "abc".equals(foo);
+        }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java?rev=595654&r1=595653&r2=595654&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java Fri Nov 16 05:22:28 2007
@@ -17,10 +17,8 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
 
 /**
  * @version $Revision: 1.1 $
@@ -52,31 +50,17 @@
             template.sendBodyAndHeader("direct:predicate", body, "cheese", 123);
         }
 
-        resultEndpoint.assertIsSatisfied();        
+        resultEndpoint.assertIsSatisfied();
     }
-    
+
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
                 // START SNIPPET: ex
                 from("direct:start").aggregator(header("cheese")).to("mock:result");
-                
-                from("direct:predicate").aggregator(header("cheese"), new UseLatestAggregationStrategy() {
-                
-                    @Override
-                    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
-                        Exchange result = super.aggregate(oldExchange, newExchange);
-                        Integer old = (Integer) oldExchange.getProperty("aggregated");
-                        if (old == null) {
-                            old = 1;
-                        }
-                        result.setProperty("aggregated", old + 1);
-                        return result;
-                    }
-                
-                }).
-                    completedPredicate(header("aggregated").
-                    isEqualTo(5)).to("mock:result");
+
+                from("direct:predicate").aggregator(header("cheese"), new MyAggregationStrategy()).
+                        completedPredicate(header("aggregated").isEqualTo(5)).to("mock:result");
                 // END SNIPPET: ex
             }
         };

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java?rev=595654&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java Fri Nov 16 05:22:28 2007
@@ -0,0 +1,48 @@
+/**
+ *
+ * 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.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Header;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+
+/**
+ * @version $Revision: 1.1 $
+*/
+public class MyAggregationStrategy extends UseLatestAggregationStrategy {
+    @Override
+    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        Exchange result = super.aggregate(oldExchange, newExchange);
+        Integer old = (Integer) oldExchange.getProperty("aggregated");
+        if (old == null) {
+            old = 1;
+        }
+        result.setProperty("aggregated", old + 1);
+        return result;
+    }
+
+    /**
+     * An expression used to determine if the aggreagation is complete
+     */
+    public boolean isCompleted(@Header(name="aggregated") Integer aggregated) {
+        if (aggregated == null) {
+            return false;
+        }
+        return aggregated == 5;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyAggregationStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=595654&r1=595653&r2=595654&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 16 05:22:28 2007
@@ -31,7 +31,19 @@
         <to uri="mock:result"/>
       </aggregator>
     </route>
+
+    <route>
+      <from uri="direct:predicate"/>
+      <aggregator strategyRef="myAggregatorStrategy">
+        <simple>header.cheese</simple>
+        <to uri="mock:result"/>
+        <completedPredicate>
+          <methodCall method="isCompleted">myAggregatorStrategy</methodCall>
+        </completedPredicate>
+      </aggregator>
+    </route>
   </camelContext>
   <!-- END SNIPPET: example -->
 
+  <bean id="myAggregatorStrategy" class="org.apache.camel.processor.MyAggregationStrategy"/>
 </beans>