final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// we only process top level deployment units
if (deploymentUnit.getParent() != null) {
return;
}
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
if (ejbClientDescriptorMetaData == null) {
logger.debug("Deployment unit " + deploymentUnit + " doesn't have any EJB client descriptor metadata associated. " +
"Falling back on the default " + DefaultEjbClientContextService.DEFAULT_SERVICE_NAME + " EJB client context service");
// no client descriptor, so fallback to default EJB client context service
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME, DefaultEjbClientContextService.DEFAULT_SERVICE_NAME);
return;
}
// install the descriptor based EJB client context service
final ServiceName ejbClientContextServiceName = DescriptorBasedEJBClientContextService.BASE_SERVICE_NAME.append(deploymentUnit.getName());
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
// create the service
final DescriptorBasedEJBClientContextService service = new DescriptorBasedEJBClientContextService();
// add the service
final ServiceBuilder serviceBuilder = serviceTarget.addService(ejbClientContextServiceName, service);
// add the remoting connection reference dependencies
for (final String connectionRef : ejbClientDescriptorMetaData.getRemotingReceiverConnectionRefs()) {
final ServiceName connectionDependencyService = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef);
service.addRemotingConnectionDependency(serviceBuilder, connectionDependencyService);
}
// if the local receiver is enabled for this context, then add a dependency on the appropriate LocalEjbReceiver
// service
if (!ejbClientDescriptorMetaData.isLocalReceiverExcluded()) {
if (ejbClientDescriptorMetaData.isLocalReceiverPassByValue()) {
serviceBuilder.addDependency(LocalEjbReceiver.BY_VALUE_SERVICE_NAME, LocalEjbReceiver.class, service.getLocalEjbReceiverInjector());
} else {
serviceBuilder.addDependency(LocalEjbReceiver.BY_REFERENCE_SERVICE_NAME, LocalEjbReceiver.class, service.getLocalEjbReceiverInjector());
}
}