Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ExchangeHelper |
|
| 0.0;0 |
1 | /** |
|
2 | * |
|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | * contributor license agreements. See the NOTICE file distributed with |
|
5 | * this work for additional information regarding copyright ownership. |
|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | * (the "License"); you may not use this file except in compliance with |
|
8 | * the License. You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | package org.apache.camel.util; |
|
19 | ||
20 | import org.apache.camel.Endpoint; |
|
21 | import org.apache.camel.Exchange; |
|
22 | import org.apache.camel.NoSuchEndpointException; |
|
23 | ||
24 | /** |
|
25 | * Some helper methods for working with {@link Exchange} objects |
|
26 | * |
|
27 | * @version $Revision: 532790 $ |
|
28 | */ |
|
29 | 0 | public class ExchangeHelper { |
30 | ||
31 | /** |
|
32 | * Attempts to resolve the endpoint for the given value |
|
33 | * |
|
34 | * @param exchange the message exchange being processed |
|
35 | * @param value the value which can be an {@link Endpoint} or an object which provides a String representation |
|
36 | * of an endpoint via {@link #toString()} |
|
37 | * |
|
38 | * @return the endpoint |
|
39 | * @throws NoSuchEndpointException if the endpoint cannot be resolved |
|
40 | */ |
|
41 | @SuppressWarnings({"unchecked"}) |
|
42 | public static <E extends Exchange> Endpoint<E> resolveEndpoint(E exchange, Object value) throws NoSuchEndpointException { |
|
43 | Endpoint<E> endpoint; |
|
44 | 3 | if (value instanceof Endpoint) { |
45 | 0 | endpoint = (Endpoint<E>) value; |
46 | 0 | } |
47 | else { |
|
48 | 3 | String uri = value.toString(); |
49 | 3 | endpoint = (Endpoint<E>) exchange.getContext().getEndpoint(uri); |
50 | 3 | if (endpoint == null) { |
51 | 0 | throw new NoSuchEndpointException(uri); |
52 | } |
|
53 | } |
|
54 | 3 | return endpoint; |
55 | } |
|
56 | } |