svn commit: r756318 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java

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

svn commit: r756318 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java

ningjiang
Author: ningjiang
Date: Fri Mar 20 03:14:31 2009
New Revision: 756318

URL: http://svn.apache.org/viewvc?rev=756318&view=rev
Log:
Merged revisions 756313 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk

........
  r756313 | ningjiang | 2009-03-20 10:31:24 +0800 (Fri, 20 Mar 2009) | 1 line
 
  CAMEL-1468 added the expression builder for camel context properties
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 20 03:14:31 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=756318&r1=756317&r2=756318&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Fri Mar 20 03:14:31 2009
@@ -137,7 +137,7 @@
     }
 
     /**
-     * Returns an expression for the property value with the given name
+     * Returns an expression for the property value of exchange with the given name
      *
      * @see Exchange#getProperty(String)
      * @param propertyName the name of the property the expression will return
@@ -156,9 +156,8 @@
         };
     }
 
-
     /**
-     * Returns an expression for the property value with the given name
+     * Returns an expression for the properties of exchange with the given name
      *
      * @see Exchange#getProperties()
      * @return an expression object which will return the properties
@@ -175,6 +174,45 @@
             }
         };
     }
+    
+    /**
+     * Returns an expression for the properties of exchange with the given name
+     *
+     * @see Exchange#getProperties()
+     * @return an expression object which will return the properties
+     */
+    public static <E extends Exchange> Expression<E> camelContextPropertiesExpression() {
+        return new Expression<E>() {
+            public Object evaluate(E exchange) {
+                return exchange.getContext().getProperties();
+            }
+
+            @Override
+            public String toString() {
+                return "camelContextProperties";
+            }
+        };
+    }
+    
+    /**
+     * Returns an expression for the property value of the camel context with the given name
+     *
+     * @see Exchange#getProperty(String)
+     * @param propertyName the name of the property the expression will return
+     * @return an expression object which will return the property value
+     */
+    public static <E extends Exchange> Expression<E> camelContextPropertyExpression(final String propertyName) {
+        return new Expression<E>() {
+            public Object evaluate(E exchange) {
+                return exchange.getContext().getProperties().get(propertyName);
+            }
+
+            @Override
+            public String toString() {
+                return "camelContextProperty(" + propertyName + ")";
+            }
+        };
+    }
 
     /**
      * Returns an expression for a system property value with the given name

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java?rev=756318&r1=756317&r2=756318&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java Fri Mar 20 03:14:31 2009
@@ -18,7 +18,9 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Map;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Message;
@@ -28,6 +30,8 @@
 import org.apache.camel.impl.DefaultExchange;
 
 import static org.apache.camel.builder.ExpressionBuilder.bodyExpression;
+import static org.apache.camel.builder.ExpressionBuilder.camelContextPropertiesExpression;
+import static org.apache.camel.builder.ExpressionBuilder.camelContextPropertyExpression;
 import static org.apache.camel.builder.ExpressionBuilder.constantExpression;
 import static org.apache.camel.builder.ExpressionBuilder.headerExpression;
 import static org.apache.camel.builder.ExpressionBuilder.regexReplaceAll;
@@ -39,8 +43,9 @@
  * @version $Revision$
  */
 public class ExpressionBuilderTest extends TestSupport {
-    protected Exchange exchange = new DefaultExchange(new DefaultCamelContext());
-
+    protected CamelContext camelContext = new DefaultCamelContext();
+    protected Exchange exchange = new DefaultExchange(camelContext);
+    
     public void testRegexTokenize() throws Exception {
         Expression<Exchange> expression = regexTokenize(headerExpression("location"), ",");
         ArrayList expected = new ArrayList(Arrays.asList(new String[] {"Islington", "London", "UK"}));
@@ -87,6 +92,16 @@
         assertExpression(expression, exchange, expected);
     }
 
+    
+    public void testCamelContextPropertiesExpression() throws Exception {
+        camelContext.getProperties().put("CamelTestKey", "CamelTestValue");        
+        Expression<Exchange> expression = camelContextPropertyExpression("CamelTestKey");
+        assertExpression(expression, exchange, "CamelTestValue");        
+        expression = camelContextPropertiesExpression();
+        Map<String, String> properties = (Map<String, String>)expression.evaluate(exchange);
+        assertEquals("Get a wrong properties size", properties.size(), 1);
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();