private void addDataSourceGBean(Module module, Map<EARContext.Key, Object> sharedContext, DataSource ds)
throws DeploymentException {
String jndiName = ds.getKey();
if (lookupJndiContextMap(module, jndiName) != null) {
return;
}
String name = jndiName;
if (name.startsWith("java:")) {
name = name.substring(5);
}
EARContext earContext = module.getEarContext();
AbstractName dataSourceAbstractName = earContext.getNaming().createChildName(module.getModuleName(), name, "GBean");
DataSourceDescription dsDescription = createDataSourceDescription(ds);
String osgiJndiName = null;
if (dsDescription.getProperties() != null) {
osgiJndiName = dsDescription.getProperties().get(ConnectorModuleBuilder.OSGI_JNDI_SERVICE_NAME);
}
if (osgiJndiName == null) {
osgiJndiName = module.getEarContext().getNaming().toOsgiJndiName(dataSourceAbstractName);
}
dsDescription.setOsgiServiceName(osgiJndiName);
try {
Object ref = DataSourceService.buildReference(dsDescription);
put(jndiName, ref, ReferenceType.DATA_SOURCE, module.getJndiContext(), Collections.<InjectionTarget>emptySet(), sharedContext);
} catch (IOException e) {
throw new DeploymentException("Could not construct Reference for datasource " + dsDescription, e);
}
}