1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.jbi; |
19 |
|
|
20 |
|
import org.apache.camel.Endpoint; |
21 |
|
import org.apache.camel.spring.SpringCamelContext; |
22 |
|
import org.apache.servicemix.common.xbean.AbstractXBeanDeployer; |
23 |
|
import org.apache.servicemix.common.ServiceUnit; |
24 |
|
import org.apache.xbean.kernel.Kernel; |
25 |
|
import org.apache.xbean.server.spring.loader.PureSpringLoader; |
26 |
|
import org.apache.xbean.server.spring.loader.SpringLoader; |
27 |
|
import org.springframework.context.ApplicationContext; |
28 |
|
import org.springframework.context.support.AbstractXmlApplicationContext; |
29 |
|
import org.springframework.context.support.FileSystemXmlApplicationContext; |
30 |
|
import org.springframework.context.support.GenericApplicationContext; |
31 |
|
|
32 |
|
import javax.jbi.management.DeploymentException; |
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.Collection; |
35 |
|
import java.util.List; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public class CamelSpringDeployer extends AbstractXBeanDeployer { |
43 |
|
private final CamelJbiComponent component; |
44 |
0 |
private PureSpringLoader springLoader = new PureSpringLoader() { |
45 |
|
@Override |
46 |
0 |
protected AbstractXmlApplicationContext createXmlApplicationContext(String configLocation) { |
47 |
0 |
return new FileSystemXmlApplicationContext(new String[]{configLocation}, false, createParentApplicationContext()); |
48 |
|
} |
49 |
|
}; |
50 |
0 |
private List<CamelJbiEndpoint> activatedEndpoints = new ArrayList<CamelJbiEndpoint>(); |
51 |
|
|
52 |
|
public CamelSpringDeployer(CamelJbiComponent component) { |
53 |
0 |
super(component); |
54 |
0 |
this.component = component; |
55 |
0 |
} |
56 |
|
|
57 |
|
protected String getXBeanFile() { |
58 |
0 |
return "camel-context"; |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Override |
65 |
|
public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException { |
66 |
|
|
67 |
0 |
component.deployer = this; |
68 |
0 |
ServiceUnit serviceUnit = super.deploy(serviceUnitName, serviceUnitRootPath); |
69 |
0 |
return serviceUnit; |
70 |
|
} |
71 |
|
|
72 |
|
public void addService(CamelJbiEndpoint endpoint) { |
73 |
0 |
activatedEndpoints.add(endpoint); |
74 |
0 |
} |
75 |
|
|
76 |
|
protected List getServices(Kernel kernel) { |
77 |
|
try { |
78 |
0 |
List<CamelJbiEndpoint> services = new ArrayList<CamelJbiEndpoint>(activatedEndpoints); |
79 |
0 |
activatedEndpoints.clear(); |
80 |
|
|
81 |
0 |
ApplicationContext applicationContext = springLoader.getApplicationContext(); |
82 |
0 |
SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext); |
83 |
|
|
84 |
|
|
85 |
0 |
Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints(); |
86 |
0 |
for (Endpoint endpoint : endpoints) { |
87 |
0 |
if (component.isEndpointExposedOnNmr(endpoint)) { |
88 |
0 |
services.add(component.createJbiEndpointFromCamel(endpoint)); |
89 |
|
} |
90 |
|
} |
91 |
0 |
return services; |
92 |
|
} |
93 |
0 |
catch (Exception e) { |
94 |
0 |
throw new RuntimeException(e); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
|
@Override |
99 |
|
protected SpringLoader createSpringLoader() { |
100 |
0 |
return springLoader; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
protected ApplicationContext createParentApplicationContext() { |
108 |
0 |
GenericApplicationContext answer = new GenericApplicationContext(); |
109 |
0 |
answer.getBeanFactory().registerSingleton("jbi", component); |
110 |
0 |
answer.start(); |
111 |
0 |
answer.refresh(); |
112 |
0 |
return answer; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
} |