1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.component.bean; |
18 |
|
|
19 |
|
import java.util.Map; |
20 |
|
|
21 |
|
import org.apache.camel.Endpoint; |
22 |
|
import org.apache.camel.impl.DefaultComponent; |
23 |
|
import org.apache.camel.impl.ProcessorEndpoint; |
24 |
|
import org.apache.camel.spi.Registry; |
25 |
|
import org.apache.camel.util.IntrospectionSupport; |
26 |
|
import org.apache.commons.logging.Log; |
27 |
|
import org.apache.commons.logging.LogFactory; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
public class BeanComponent extends DefaultComponent { |
37 |
3 |
private static final Log LOG = LogFactory.getLog(BeanComponent.class); |
38 |
|
private ParameterMappingStrategy parameterMappingStrategy; |
39 |
|
|
40 |
9 |
public BeanComponent() { |
41 |
9 |
} |
42 |
|
|
43 |
|
public ParameterMappingStrategy getParameterMappingStrategy() { |
44 |
6 |
if (parameterMappingStrategy == null) { |
45 |
6 |
parameterMappingStrategy = createParameterMappingStrategy(); |
46 |
|
} |
47 |
6 |
return parameterMappingStrategy; |
48 |
|
} |
49 |
|
|
50 |
|
public void setParameterMappingStrategy(ParameterMappingStrategy parameterMappingStrategy) { |
51 |
0 |
this.parameterMappingStrategy = parameterMappingStrategy; |
52 |
0 |
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { |
58 |
6 |
Object bean = getBean(remaining); |
59 |
6 |
BeanProcessor processor = new BeanProcessor(bean, getParameterMappingStrategy()); |
60 |
6 |
IntrospectionSupport.setProperties(processor, parameters); |
61 |
6 |
return new ProcessorEndpoint(uri, this, processor); |
62 |
|
} |
63 |
|
|
64 |
|
public Object getBean(String remaining) throws NoBeanAvailableException { |
65 |
6 |
Registry registry = getCamelContext().getRegistry(); |
66 |
6 |
Object bean = registry.lookup(remaining); |
67 |
6 |
if (bean == null) { |
68 |
0 |
throw new NoBeanAvailableException(remaining); |
69 |
|
} |
70 |
6 |
return bean; |
71 |
|
} |
72 |
|
|
73 |
|
protected ParameterMappingStrategy createParameterMappingStrategy() { |
74 |
6 |
return BeanProcessor.createParameterMappingStrategy(getCamelContext()); |
75 |
|
} |
76 |
|
} |