// Bind Local EJB references
{
Iterator i = beanMetaData.getEjbLocalReferences();
while (i.hasNext())
{
EjbLocalRefMetaData ref = (EjbLocalRefMetaData)i.next();
String refName = ref.getName();
log.debug("Binding an EJBLocalReference " + ref.getName());
if (ref.getLink() != null)
{
// Internal link
log.debug("Binding " + refName + " to bean source: " + ref.getLink());
String jndiName = ref.getJndiName();
Util.bind(envCtx, ref.getName(), new LinkRef(jndiName));
}
else
{
// Bind the bean level ejb-local-ref/local-jndi-name
if (ref.getJndiName() == null)
{
throw new DeploymentException("ejb-local-ref " + ref.getName() + ", expected either ejb-link in ejb-jar.xml " + "or local-jndi-name in jboss.xml");
}
Util.bind(envCtx, ref.getName(), new LinkRef(ref.getJndiName()));
}
}
}
// Bind service references
{
ClassLoader loader = unit.getClassLoader();
UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(unit.getRoot());
Iterator<ServiceReferenceMetaData> serviceReferences = beanMetaData.getServiceReferences();
if (serviceReferences != null)
{
while (serviceReferences.hasNext())
{
ServiceReferenceMetaData sref = serviceReferences.next();
String refName = sref.getServiceRefName();
new ServiceReferenceHandler().bindServiceRef(envCtx, refName, vfsRoot, loader, sref);
}
}
}
// Bind resource references
{
Iterator i = beanMetaData.getResourceReferences();
// let's play guess the cast game ;) New metadata should fix this.
ApplicationMetaData application = beanMetaData.getApplicationMetaData();
while (i.hasNext())
{
ResourceRefMetaData ref = (ResourceRefMetaData)i.next();
String resourceName = ref.getResourceName();
String finalName = application.getResourceByName(resourceName);
String resType = ref.getType();
// If there was no resource-manager specified then an immeadiate
// jndi-name or res-url name should have been given
if (finalName == null)
finalName = ref.getJndiName();
if (finalName == null && resType.equals("java.net.URL") == false)
{
// the application assembler did not provide a resource manager
// if the type is javax.sql.Datasoure use the default one
if (ref.getType().equals("javax.sql.DataSource"))
{
// Go through JNDI and look for DataSource - use the first one
Context dsCtx = new InitialContext();
try
{
// Check if it is available in JNDI
dsCtx.lookup("java:/DefaultDS");
finalName = "java:/DefaultDS";
}
catch (Exception e)
{
log.debug("failed to lookup DefaultDS; ignoring", e);
}
finally
{
dsCtx.close();
}
}
// Default failed? Warn user and move on
// POTENTIALLY DANGEROUS: should this be a critical error?
if (finalName == null)
{
log.warn("No resource manager found for " + ref.getResourceName());
continue;
}
}
if (resType.equals("java.net.URL"))
{
// URL bindings
if (ref.getResURL() != null)
{
// The URL string was given by the res-url
log.debug("Binding URL: " + ref.getRefName() + " to JDNI ENC as: " + ref.getResURL());
URL resURL = new URL(ref.getResURL());
Util.bind(envCtx, ref.getRefName(), resURL);
}
else
{
log.debug("Binding URL: " + ref.getRefName() + " to: " + finalName);
Object bind = null;
if (ref.getJndiName() != null)
{
// Was the url given as a jndi-name reference to link to it
bind = new LinkRef(finalName);
}
else
{
// The url string was given via a resource-name mapping
bind = new URL(finalName);
}
Util.bind(envCtx, ref.getRefName(), bind);
}
}
else
{
// Resource Manager bindings, should validate the type...
log.debug("Binding resource manager: " + ref.getRefName() + " to JDNI ENC as: " + finalName);
Util.bind(envCtx, ref.getRefName(), new LinkRef(finalName));
}
}
}
// Bind resource env references
{
Iterator i = beanMetaData.getResourceEnvReferences();
while (i.hasNext())
{
ResourceEnvRefMetaData resRef = (ResourceEnvRefMetaData)i.next();
String encName = resRef.getRefName();
String jndiName = resRef.getJndiName();
// Should validate the type...
log.debug("Binding env resource: " + encName + " to JDNI ENC as: " + jndiName);
Util.bind(envCtx, encName, new LinkRef(jndiName));
}
}
// Bind message destination references
{
Iterator i = beanMetaData.getMessageDestinationReferences();
while (i.hasNext())
{
MessageDestinationRefMetaData ref = (MessageDestinationRefMetaData)i.next();
String refName = ref.getRefName();
String jndiName = ref.getJNDIName();
String link = ref.getLink();
if (link != null)
{
if (jndiName == null)
{
MessageDestinationMetaData messageDestination = getMessageDestination(link);