Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ProxyHelper |
|
| 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.component.bean; |
|
18 | ||
19 | import java.lang.reflect.Proxy; |
|
20 | ||
21 | import org.apache.camel.Endpoint; |
|
22 | import org.apache.camel.Producer; |
|
23 | ||
24 | /** |
|
25 | * A helper class for creating proxies which delegate to Camel |
|
26 | * |
|
27 | * @version $Revision: 519973 $ |
|
28 | */ |
|
29 | public class ProxyHelper { |
|
30 | ||
31 | /** |
|
32 | * Utility classes should not have a public constructor. |
|
33 | */ |
|
34 | 0 | private ProxyHelper() { |
35 | 0 | } |
36 | ||
37 | /** |
|
38 | * Creates a Proxy which sends PojoExchange to the endpoint. |
|
39 | * |
|
40 | * @throws Exception |
|
41 | */ |
|
42 | public static Object createProxy(final Endpoint endpoint, ClassLoader cl, Class interfaces[]) |
|
43 | throws Exception { |
|
44 | 3 | final Producer producer = endpoint.createProducer(); |
45 | 3 | return Proxy.newProxyInstance(cl, interfaces, new CamelInvocationHandler(endpoint, producer)); |
46 | } |
|
47 | ||
48 | /** |
|
49 | * Creates a Proxy which sends PojoExchange to the endpoint. |
|
50 | * |
|
51 | * @throws Exception |
|
52 | */ |
|
53 | public static Object createProxy(Endpoint endpoint, Class interfaces[]) throws Exception { |
|
54 | 3 | if (interfaces.length < 1) { |
55 | 0 | throw new IllegalArgumentException("You must provide at least 1 interface class."); |
56 | } |
|
57 | 3 | return createProxy(endpoint, interfaces[0].getClassLoader(), interfaces); |
58 | } |
|
59 | ||
60 | /** |
|
61 | * Creates a Proxy which sends PojoExchange to the endpoint. |
|
62 | * |
|
63 | * @throws Exception |
|
64 | */ |
|
65 | @SuppressWarnings("unchecked") |
|
66 | public static <T> T createProxy(Endpoint endpoint, ClassLoader cl, Class<T> interfaceClass) |
|
67 | throws Exception { |
|
68 | 0 | return (T)createProxy(endpoint, cl, new Class[] {interfaceClass}); |
69 | } |
|
70 | ||
71 | /** |
|
72 | * Creates a Proxy which sends PojoExchange to the endpoint. |
|
73 | * |
|
74 | * @throws Exception |
|
75 | */ |
|
76 | @SuppressWarnings("unchecked") |
|
77 | public static <T> T createProxy(Endpoint endpoint, Class<T> interfaceClass) throws Exception { |
|
78 | 3 | return (T)createProxy(endpoint, new Class[] {interfaceClass}); |
79 | } |
|
80 | ||
81 | } |