int unresolvedRefSize = resourceRefsUntyped.size();
for (ResourceRefType resourceRef : resourceRefsUntyped) {
String name = resourceRef.getResRefName().getStringValue().trim();
addInjections(name, resourceRef.getInjectionTargetArray(), componentContext);
String type = resourceRef.getResType().getStringValue().trim();
GerResourceRefType gerResourceRef = (GerResourceRefType) refMap.get(name);
refMap.remove(name);
Class iface;
try {
iface = cl.loadClass(type);
} catch (ClassNotFoundException e) {
throw new DeploymentException("could not load class " + type, e);
}
if (iface == URL.class) {
if (gerResourceRef == null || !gerResourceRef.isSetUrl()) {
throw new DeploymentException("No url supplied to resolve: " + name);
}
String url = gerResourceRef.getUrl().trim();
//TODO expose jsr-77 objects for these guys
try {
//check for malformed URL
new URL(url);
} catch (MalformedURLException e) {
throw new DeploymentException("Could not convert " + url + " to URL", e);
}
getJndiContextMap(componentContext).put(ENV + name, new URLReference(url));
} else if (ORB.class.isAssignableFrom(iface)) {
CorbaGBeanNameSource corbaGBeanNameSource = (CorbaGBeanNameSource) corbaGBeanNameSourceCollection.getElement();
if (corbaGBeanNameSource == null) {
throw new DeploymentException("No orb setup but there is a orb reference");
}
AbstractNameQuery corbaName = corbaGBeanNameSource.getCorbaGBeanName();
if (corbaName != null) {
Artifact[] moduleId = module.getConfigId();
Map context = getJndiContextMap(componentContext);
context.put(ENV + name, new ORBReference(moduleId, corbaName));
EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), corbaEnvironment);
}
} else {
//determine jsr-77 type from interface
String j2eeType;
if (JAVAX_MAIL_SESSION_CLASS.equals(type)) {
j2eeType = NameFactory.JAVA_MAIL_RESOURCE;
} else if (JAXR_CONNECTION_FACTORY_CLASS.equals(type)) {
j2eeType = NameFactory.JAXR_CONNECTION_FACTORY;
} else {
j2eeType = NameFactory.JCA_MANAGED_CONNECTION_FACTORY;
}
try {
AbstractNameQuery containerId = getResourceContainerId(name, j2eeType, null, gerResourceRef);
module.getEarContext().findGBean(containerId);
Object ref = new ResourceReferenceFactory<ResourceException>(module.getConfigId(), containerId, iface);
getJndiContextMap(componentContext).put(ENV + name, ref);
} catch (GBeanNotFoundException e) {
StringBuffer errorMessage = new StringBuffer("Unable to resolve resource reference '");
errorMessage.append(name);
errorMessage.append("' (");
if (e.hasMatches()) {
errorMessage.append("Found multiple matching resources. Try being more specific in a resource-ref mapping in your Geronimo deployment plan.\n");
for (AbstractName match : e.getMatches()) {
errorMessage.append(match).append("\n");
}
} else if (gerResourceRef == null) {
errorMessage.append("Could not auto-map to resource. Try adding a resource-ref mapping to your Geronimo deployment plan.");
} else if (gerResourceRef.isSetResourceLink()) {
errorMessage.append("Could not find resource '");
errorMessage.append(gerResourceRef.getResourceLink());
errorMessage.append("'. Perhaps it has not yet been configured, or your application does not have a dependency declared for that resource module?");
} else {
errorMessage.append("Could not find the resource specified in your Geronimo deployment plan:");
errorMessage.append(gerResourceRef.getPattern());
}
errorMessage.append("\nSearch conducted in current module and dependencies:\n");
for (Dependency dependency : module.getEnvironment().getDependencies()) {
errorMessage.append(dependency).append("\n");
}