camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1061262 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/language/simple/ main/java/org/apache/camel/model/language/ test/java/org/apache/camel/language/
Date Thu, 20 Jan 2011 12:09:28 GMT
Author: davsclaus
Date: Thu Jan 20 12:09:27 2011
New Revision: 1061262

URL: http://svn.apache.org/viewvc?rev=1061262&view=rev
Log:
CAMEL-3564: Added ref function to simple langauge.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ConstantExpression.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=1061262&r1=1061261&r2=1061262&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Thu
Jan 20 12:09:27 2011
@@ -389,6 +389,24 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns an expression for lookup a bean in the {@link org.apache.camel.spi.Registry}
+     *
+     * @return an expression object which will return the bean
+     */
+    public static Expression refExpression(final String ref) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return exchange.getContext().getRegistry().lookup(ref);
+            }
+
+            @Override
+            public String toString() {
+                return "ref(" + ref + ")";
+            }
+        };
+    }
+
+    /**
      * Returns an expression for the {@link org.apache.camel.CamelContext}
      *
      * @return an expression object which will return the camel context

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java?rev=1061262&r1=1061261&r2=1061262&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
Thu Jan 20 12:09:27 2011
@@ -304,6 +304,12 @@ public class SimpleLanguage extends Simp
             return ExpressionBuilder.propertiesComponentExpression(key, locations);
         }
 
+        // ref: prefix
+        remainder = ifStartsWithReturnRemainder("ref:", expression);
+        if (remainder != null) {
+            return ExpressionBuilder.refExpression(remainder);
+        }
+
         if (strict) {
             throw new ExpressionIllegalSyntaxException(expression);
         } else {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ConstantExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ConstantExpression.java?rev=1061262&r1=1061261&r2=1061262&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ConstantExpression.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ConstantExpression.java
Thu Jan 20 12:09:27 2011
@@ -20,10 +20,10 @@ import javax.xml.bind.annotation.XmlRoot
 
 /**
  * For expressions and predicates using a constant
- *
  */
 @XmlRootElement(name = "constant")
 public class ConstantExpression extends ExpressionDefinition {
+
     public ConstantExpression() {
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java?rev=1061262&r1=1061261&r2=1061262&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java Thu Jan
20 12:09:27 2011
@@ -31,6 +31,7 @@ import org.apache.camel.ExpressionIllega
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.LanguageTestSupport;
 import org.apache.camel.component.bean.MethodNotFoundException;
+import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.language.bean.RuntimeBeanExpressionException;
 import org.apache.camel.language.simple.SimpleLanguage;
 
@@ -39,6 +40,22 @@ import org.apache.camel.language.simple.
  */
 public class SimpleTest extends LanguageTestSupport {
 
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myAnimal", new Animal("Donkey", 17));
+        return jndi;
+    }
+
+    public void testRefExpression() throws Exception {
+        assertExpression("ref:myAnimal", "Donkey");
+        assertExpression("${ref:myAnimal}", "Donkey");
+        assertExpression("ref:unknown", null);
+        assertExpression("${ref:unknown}", null);
+        assertExpression("Hello ${ref:myAnimal}", "Hello Donkey");
+        assertExpression("Hello ${ref:unknown}", "Hello ");
+    }
+
     public void testConstantExpression() throws Exception {
         assertExpression("Hello World", "Hello World");
     }



Mime
View raw message