// the base ServiceName which will be used to create the ServiceName(s) for each of the view bindings
final StringBuilder jndiBindingsLogMessage = new StringBuilder();
jndiBindingsLogMessage.append("JNDI bindings for session bean named " + sessionBean.getEJBName() + " in deployment unit " + deploymentUnit + " are as follows:\n\n");
// now create the bindings for each view under the java:global, java:app and java:module namespaces
EJBViewDescription ejbViewDescription = null;
for (ViewDescription viewDescription : views) {
ejbViewDescription = (EJBViewDescription) viewDescription;
if (!ejbViewDescription.hasJNDIBindings()) continue;
final String viewClassName = ejbViewDescription.getViewClassName();
// java:global bindings
final String globalJNDIName = globalJNDIBaseName + "!" + viewClassName;
registerBinding(viewDescription, globalJNDIName);
logBinding(jndiBindingsLogMessage, globalJNDIName);
// java:app bindings
final String appJNDIName = appJNDIBaseName + "!" + viewClassName;
registerBinding(viewDescription, appJNDIName);
logBinding(jndiBindingsLogMessage, appJNDIName);
// java:module bindings
final String moduleJNDIName = moduleJNDIBaseName + "!" + viewClassName;
registerBinding(viewDescription, moduleJNDIName);
logBinding(jndiBindingsLogMessage, moduleJNDIName);
}
// EJB3.1 spec, section 4.4.1 Global JNDI Access states:
// In addition to the previous requirements, if the bean exposes only one of the
// applicable client interfaces(or alternatively has only a no-interface view), the container
// registers an entry for that view with the following syntax :
//
// java:global[/<app-name>]/<module-name>/<bean-name>
//
// Note that this also applies to java:app and java:module bindings
// as can be seen by the examples in 4.4.2.1
if (views.size() == 1) {
final EJBViewDescription viewDescription = (EJBViewDescription) views.iterator().next();
if (ejbViewDescription.hasJNDIBindings()) {
// java:global binding
registerBinding(viewDescription, globalJNDIBaseName);
logBinding(jndiBindingsLogMessage, globalJNDIBaseName);