use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class OpenEJBContextConfig method adjustDataSourceNameIfNecessary.
private void adjustDataSourceNameIfNecessary() {
if (context == null || "false".equalsIgnoreCase(ADJUST_DATASOURCE_JNDI_NAMES)) {
return;
}
final NamingResourcesImpl resources = context.getNamingResources();
if (resources == null) {
return;
}
final ContextResource[] foundResources = resources.findResources();
String[] ids = null;
if (foundResources != null) {
for (final ContextResource resource : foundResources) {
if ("javax.sql.DataSource".equals(resource.getType()) && !ResourceFactory.class.getName().equals(resource.getProperty(Constants.FACTORY))) {
String jndiName = (String) resource.getProperty("mappedName");
if (jndiName == null) {
jndiName = resource.getName();
}
if (jndiName == null) {
continue;
}
if (ids == null) {
final Properties props = new Properties();
final OpenEjbConfiguration runningConfig = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
final List<String> resourceIds = new ArrayList<String>();
if (runningConfig != null) {
for (final ResourceInfo resourceInfo : runningConfig.facilities.resources) {
if (ConfigurationFactory.isResourceType(resourceInfo.service, resourceInfo.types, "javax.sql.DataSource") && ServiceUtils.implies(props, resourceInfo.properties)) {
resourceIds.add(resourceInfo.id);
}
}
}
ids = resourceIds.toArray(new String[resourceIds.size()]);
}
String mostMatchingId = null;
for (final String id : ids) {
if (id.equals(jndiName)) {
mostMatchingId = jndiName;
break;
} else if (jndiName.endsWith("/" + id) && mostMatchingId == null) {
mostMatchingId = id;
} else if (id.endsWith("/" + jndiName) && mostMatchingId == null) {
mostMatchingId = "openejb/Resource/" + id;
}
}
if (mostMatchingId != null) {
resource.setProperty("mappedName", "java:" + mostMatchingId);
resource.setProperty(NamingUtil.RESOURCE_ID, "java:" + mostMatchingId);
resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
}
}
}
}
}
Aggregations