for (int i = 0; i < resourceRefsUntyped.length; i++) {
ResourceRefType resourceRef = (ResourceRefType) resourceRefsUntyped[i];
String name = resourceRef.getResRefName().getStringValue().trim();
String type = resourceRef.getResType().getStringValue().trim();
GerResourceRefType gerResourceRef = (GerResourceRefType) refMap.get(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);
}
try {
//TODO expose jsr-77 objects for these guys
getJndiContextMap(componentContext).put(ENV + name, new URL(gerResourceRef.getUrl()));
} catch (MalformedURLException e) {
throw new DeploymentException("Could not convert " + gerResourceRef.getUrl() + " to URL", e);
}
} 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);
try {
localConfiguration.findGBean(containerId);
} catch (GBeanNotFoundException e) {
throw new UnresolvedReferenceException("Resource", false, containerId.toString(), localConfiguration.getId().toString());
}
Reference ref = new ResourceReference(localConfiguration.getId(), containerId, iface);
getJndiContextMap(componentContext).put(ENV + name, ref);
} catch (UnresolvedReferenceException e) {
StringBuffer errorMessage = new StringBuffer("Unable to resolve resource reference '");
errorMessage.append(name);
errorMessage.append("' (");
if (e.isMultiple()) {
errorMessage.append("Found multiple matching resources. Try being more specific in a resource-ref mapping in your Geronimo deployment plan.");
} 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(")");
throw new DeploymentException(errorMessage.toString());
}