public boolean processResource(AnnotatedApp annotatedApp,
Resource annotation,
Class cls,
Method method,
Field field) {
log.debug("processResource( [annotatedApp] " + annotatedApp.toString() + "," + '\n' +
"[annotation] " + annotation.toString() + "," + '\n' +
"[cls] " + (cls != null ? cls.getName() : null) + "," + '\n' +
"[method] " + (method != null ? method.getName() : null) + "," + '\n' +
"[field] " + (field != null ? field.getName() : null) + " ): Entry");
String resourceName = getResourceName(annotation, method, field);
String resourceType = getResourceType(annotation, method, field);
if (resourceType.equals("javax.sql.DataSource") ||
resourceType.equals("javax.mail.Session") ||
resourceType.equals("java.net.URL") ||
resourceType.equals("org.omg.CORBA.ORB") ||
resourceType.equals("org.omg.CORBA_2_3.ORB") ||
resourceType.equals("org.omg.CORBA_2_4.ORB") ||
resourceType.endsWith("ConnectionFactory")) {
log.debug("processResource(): < resource-ref > found");
boolean exists = false;
ResourceRefType[] resourceRefs = annotatedApp.getResourceRefArray();
for (ResourceRefType resourceRef : resourceRefs) {
if (resourceRef.getResRefName().getStringValue().trim().equals(resourceName)) {
if (method != null || field != null) {
InjectionTargetType[] targets = resourceRef.getInjectionTargetArray();
if (!hasTarget(method, field, targets)) {
configureInjectionTarget(resourceRef.addNewInjectionTarget(), method, field);
}
}
exists = true;
break;
}
}
if (!exists) {
try {
log.debug("processResource(): Does not exist in DD: " + resourceName);
// Doesn't exist in deployment descriptor -- add new
ResourceRefType resourceRef = annotatedApp.addNewResourceRef();
//------------------------------------------------------------------------------
// < resource-ref > required elements:
//------------------------------------------------------------------------------
// resource-ref-name
JndiNameType resourceRefName = resourceRef.addNewResRefName();
resourceRefName.setStringValue(resourceName);
if (!resourceType.equals("")) {
// resource-ref-type
FullyQualifiedClassType qualifiedClass = resourceRef.addNewResType();
qualifiedClass.setStringValue(resourceType);
}
if (method != null || field != null) {
// injectionTarget
InjectionTargetType injectionTarget = resourceRef.addNewInjectionTarget();
configureInjectionTarget(injectionTarget, method, field);
}
//------------------------------------------------------------------------------
// < resource-ref > optional elements:
//------------------------------------------------------------------------------
// description
String descriptionAnnotation = annotation.description();
if (!descriptionAnnotation.equals("")) {
DescriptionType description = resourceRef.addNewDescription();
description.setStringValue(descriptionAnnotation);
}
// authentication
if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) {
ResAuthType resAuth = resourceRef.addNewResAuth();
resAuth.setStringValue("Container");
resourceRef.setResAuth(resAuth);
} else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
ResAuthType resAuth = resourceRef.addNewResAuth();
resAuth.setStringValue("Application");
resourceRef.setResAuth(resAuth);
}
// sharing scope
ResSharingScopeType resScope = resourceRef.addNewResSharingScope();
resScope.setStringValue(annotation.shareable() ? "Shareable" : "Unshareable");
resourceRef.setResSharingScope(resScope);
// mappedName
String mappdedNameAnnotation = annotation.mappedName();
if (!mappdedNameAnnotation.equals("")) {
XsdStringType mappedName = resourceRef.addNewMappedName();
mappedName.setStringValue(mappdedNameAnnotation);
resourceRef.setMappedName(mappedName);
}
}
catch (Exception anyException) {
log.debug("ResourceRefBuilder: Exception caught while processing < resource-ref >");
}
}
return true;
}
return false;
}
|