Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
ExpressionHelper |
|
| 0.0;0 |
1 | /** |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.camel.util; |
|
18 | ||
19 | import org.apache.camel.Exchange; |
|
20 | import org.apache.camel.Expression; |
|
21 | ||
22 | /** |
|
23 | * A collection of helper methods for working with expressions. |
|
24 | * |
|
25 | * @version $Revision: 1.1 $ |
|
26 | */ |
|
27 | public class ExpressionHelper { |
|
28 | ||
29 | /** |
|
30 | * Utility classes should not have a public constructor. |
|
31 | */ |
|
32 | 0 | private ExpressionHelper() { |
33 | 0 | } |
34 | ||
35 | /** |
|
36 | * Evaluates the given expression on the exchange as a String value |
|
37 | * |
|
38 | * @param expression the expression to evaluate |
|
39 | * @param exchange the exchange to use to evaluate the expression |
|
40 | * @return the result of the evaluation as a string. |
|
41 | */ |
|
42 | public static <E extends Exchange> String evaluateAsString(Expression<E> expression, E exchange) { |
|
43 | 18 | return evaluateAsType(expression, exchange, String.class); |
44 | } |
|
45 | ||
46 | /** |
|
47 | * Evaluates the given expression on the exchange, converting the result to |
|
48 | * the given type |
|
49 | * |
|
50 | * @param expression the expression to evaluate |
|
51 | * @param exchange the exchange to use to evaluate the expression |
|
52 | * @param resultType the type of the result that is required |
|
53 | * @return the result of the evaluation as the specified type. |
|
54 | */ |
|
55 | public static <T, E extends Exchange> T evaluateAsType(Expression<E> expression, E exchange, |
|
56 | Class<T> resultType) { |
|
57 | 21 | Object value = expression.evaluate(exchange); |
58 | 21 | return exchange.getContext().getTypeConverter().convertTo(resultType, value); |
59 | } |
|
60 | } |