/* (non-Javadoc)
* @see org.apache.servicemix.common.Deployer#deploy(java.lang.String, java.lang.String)
*/
public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
Kernel kernel = KernelFactory.newInstance().createKernel(component.getComponentName() + "/" + serviceUnitName);
try {
// Create service unit
XBeanServiceUnit su = new XBeanServiceUnit();
su.setKernel(kernel);
su.setComponent(component);
su.setName(serviceUnitName);
su.setRootPath(serviceUnitRootPath);
// Load configuration
ClassLoader classLoader = component.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
SpringLoader springLoader = createSpringLoader();
springLoader.setKernel(kernel);
springLoader.setBaseDir(new File(serviceUnitRootPath));
springLoader.setXmlPreprocessors(getXmlPreProcessors(serviceUnitRootPath));
springLoader.setBeanFactoryPostProcessors(getBeanFactoryPostProcessors(serviceUnitRootPath));
ServiceName configurationName = springLoader.load(getXBeanFile());
kernel.startService(configurationName);
su.setConfiguration(configurationName);
// Use SU classloader
Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
// Retrieve endpoints
List services = getServices(kernel);
if (services == null || services.size() == 0) {
throw failure("deploy", "No endpoints found", null);
}
for (Iterator iter = services.iterator(); iter.hasNext();) {
Endpoint endpoint = (Endpoint) iter.next();
endpoint.setServiceUnit(su);
validate(endpoint);
su.addEndpoint(endpoint);
}
if (su.getEndpoints().size() == 0) {
throw failure("deploy", "No endpoint found", null);
}
return su;
} catch (Throwable e) {
// There is a chance the thread context classloader has been changed by the xbean kernel,
// so put back a good one
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
kernel.destroy();
if (e instanceof DeploymentException) {
throw ((DeploymentException) e);
} else {
throw failure("deploy", "Could not deploy xbean service unit", e);
}