@Override
public void start(StartContext context) throws StartException {
XBundle bundle = injectedBundle.getValue();
Deployment deployment = depUnit.getAttachment(OSGiConstants.DEPLOYMENT_KEY);
BundleManager bundleManager = depUnit.getAttachment(OSGiConstants.BUNDLE_MANAGER_KEY);
Component activatorComponent = injectedComponent.getOptionalValue();
if (activatorComponent != null && deployment.getAttachment(BundleActivator.class) == null) {
ComponentInstance componentInstance = activatorComponent.createInstance();
BundleActivator instance = (BundleActivator) componentInstance.getInstance();
deployment.addAttachment(BundleActivator.class, instance);
}
OperationAssociation.INSTANCE.setAssociation(new ModelNode("deploy"));
try {
bundleManager.startBundle(bundle, Bundle.START_ACTIVATION_POLICY);
depUnit.putAttachment(Attachments.BUNDLE_STATE_KEY, BundleState.ACTIVE);
} catch (BundleException ex) {
throw MESSAGES.cannotStartBundle(ex, bundle);
} finally {
OperationAssociation.INSTANCE.removeAssociation();