You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/03/20 03:31:24 UTC
svn commit: r756313 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/ExpressionBuilder.java
test/java/org/apache/camel/builder/ExpressionBuilderTest.java
Author: ningjiang
Date: Fri Mar 20 02:31:24 2009
New Revision: 756313
URL: http://svn.apache.org/viewvc?rev=756313&view=rev
Log:
CAMEL-1468 added the expression builder for camel context properties
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.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=756313&r1=756312&r2=756313&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 Fri Mar 20 02:31:24 2009
@@ -204,7 +204,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
@@ -223,9 +223,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
@@ -242,6 +241,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 Expression camelContextPropertiesExpression() {
+ return new ExpressionAdapter() {
+ public Object evaluate(Exchange 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 Expression camelContextPropertyExpression(final String propertyName) {
+ return new ExpressionAdapter() {
+ public Object evaluate(Exchange 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/trunk/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java?rev=756313&r1=756312&r2=756313&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java Fri Mar 20 02:31:24 2009
@@ -19,7 +19,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Map;
+import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
@@ -34,8 +36,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 expression = regexTokenizeExpression(headerExpression("location"), ",");
ArrayList expected = new ArrayList(Arrays.asList(new String[] {"Islington", "London", "UK"}));
@@ -89,6 +92,15 @@
ArrayList expected = new ArrayList(Arrays.asList(new String[] {"Claus", "Hadrian", "James", "Jonathan"}));
assertExpression(expression, exchange, expected);
}
+
+ public void testCamelContextPropertiesExpression() throws Exception {
+ camelContext.getProperties().put("CamelTestKey", "CamelTestValue");
+ Expression 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 {