}
else if ( !injectionJavaType.equals("") ) {
// injectionTarget
InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
qualifiedClass.setStringValue( injectionClass );
javaType.setStringValue( injectionJavaType );
injectionTarget.setInjectionTargetClass( qualifiedClass );
injectionTarget.setInjectionTargetName( javaType );
int arraySize = resourceRef.sizeOfInjectionTargetArray();
resourceRef.insertNewInjectionTarget( arraySize );
resourceRef.setInjectionTargetArray( arraySize, injectionTarget );
}
//------------------------------------------------------------------------------
// <resource-ref> optional elements:
//------------------------------------------------------------------------------
// description
String descriptionAnnotation = annotation.description();
if ( descriptionAnnotation.length() > 0 ) {
DescriptionType description = DescriptionType.Factory.newInstance();
description.setStringValue( descriptionAnnotation );
int arraySize = resourceRef.sizeOfDescriptionArray();
resourceRef.insertNewDescription( arraySize );
resourceRef.setDescriptionArray( arraySize,description );
}
// authentication
ResAuthType resAuth = ResAuthType.Factory.newInstance();
if ( annotation.authenticationType() == Resource.AuthenticationType.CONTAINER ) {
resAuth.setStringValue( "Container" );
}
else if ( annotation.authenticationType() == Resource.AuthenticationType.APPLICATION ) {
resAuth.setStringValue( "Application" );
}
resourceRef.setResAuth( resAuth );
// sharing scope
ResSharingScopeType resScope = ResSharingScopeType.Factory.newInstance();
resScope.setStringValue( annotation.shareable() ? "Shareable" : "Unshareable" );
resourceRef.setResSharingScope( resScope );
// mappedName
String mappdedNameAnnotation = annotation.mappedName();
if ( mappdedNameAnnotation.length() > 0 ) {
XsdStringType mappedName = XsdStringType.Factory.newInstance();
mappedName.setStringValue( mappdedNameAnnotation );
resourceRef.setMappedName( mappedName );
}
}
catch ( Exception anyException ) {
log.debug( "ResourceAnnotationHelper: Exception caught while processing <resource-ref>" );
anyException.printStackTrace();
}
}
}
//------------------------------------------------------------------------------------------
// 4. <message-destination-ref>
//------------------------------------------------------------------------------------------
else if ( resourceType.equals("javax.jms.Queue") ||
resourceType.equals("javax.jms.Topic") ) {
log.debug( "addResource(): <message-destination-ref> found");
boolean exists = false;
MessageDestinationRefType[] messageDestinationRefs = webApp.getMessageDestinationRefArray();
for ( MessageDestinationRefType messageDestinationRef : messageDestinationRefs ) {
if ( messageDestinationRef.getMessageDestinationRefName().getStringValue().equals(resourceName) ) {
exists = true;
break;
}
}
if ( !exists ) {
try {
// Doesn't exist in deployment descriptor -- add new
MessageDestinationRefType messageDestinationRef = webApp.addNewMessageDestinationRef();
//------------------------------------------------------------------------------
// <message-destination-ref> required elements:
//------------------------------------------------------------------------------
// message-destination-ref-name
JndiNameType messageDestinationRefName = JndiNameType.Factory.newInstance();
messageDestinationRefName.setStringValue( resourceName );
messageDestinationRef.setMessageDestinationRefName( messageDestinationRefName );
if ( !resourceType.equals("") ) {
// message-destination-ref-type
MessageDestinationTypeType msgDestType = MessageDestinationTypeType.Factory.newInstance();
msgDestType.setStringValue( resourceType );
messageDestinationRef.setMessageDestinationType( msgDestType );
}
else if ( !injectionJavaType.equals("") ) {
// injectionTarget
InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
qualifiedClass.setStringValue( injectionClass );
javaType.setStringValue( injectionJavaType );
injectionTarget.setInjectionTargetClass( qualifiedClass );
injectionTarget.setInjectionTargetName( javaType );
int arraySize = messageDestinationRef.sizeOfInjectionTargetArray();
messageDestinationRef.insertNewInjectionTarget( arraySize );
messageDestinationRef.setInjectionTargetArray( arraySize, injectionTarget );
}
//------------------------------------------------------------------------------
// <message-destination-ref> optional elements:
//------------------------------------------------------------------------------
// description
String descriptionAnnotation = annotation.description();
if ( descriptionAnnotation.length() > 0 ) {
DescriptionType description = DescriptionType.Factory.newInstance();
description.setStringValue( descriptionAnnotation );
int arraySize = messageDestinationRef.sizeOfDescriptionArray();
messageDestinationRef.insertNewDescription( arraySize );
messageDestinationRef.setDescriptionArray( arraySize,description );
}
// mappedName
String mappdedNameAnnotation = annotation.mappedName();
if ( mappdedNameAnnotation.length() > 0 ) {
XsdStringType mappedName = XsdStringType.Factory.newInstance();
mappedName.setStringValue( mappdedNameAnnotation );
messageDestinationRef.setMappedName( mappedName );
}
}
catch ( Exception anyException ) {
log.debug( "ResourceAnnotationHelper: Exception caught while processing <message-destination-ref>" );
anyException.printStackTrace();
}
}
}
//------------------------------------------------------------------------------------------
// 5. Everything else must be a <resource-env-ref>
//------------------------------------------------------------------------------------------
else if ( annotation.type().getCanonicalName().equals("javax.resource.cci.InteractionSpec") ||
annotation.type().getCanonicalName().equals("javax.transaction.UserTransaction") || true ) {
log.debug( "addResource(): <resource-env-ref> found");
boolean exists = false;
ResourceEnvRefType[] resourceEnvRefs = webApp.getResourceEnvRefArray();
for ( ResourceEnvRefType resourceEnvRef : resourceEnvRefs ) {
if ( resourceEnvRef.getResourceEnvRefName().getStringValue().equals(resourceName) ) {
exists = true;
break;
}
}
if ( !exists ) {
try {
// Doesn't exist in deployment descriptor -- add new
ResourceEnvRefType resourceEnvRef = webApp.addNewResourceEnvRef();
//------------------------------------------------------------------------------
// <resource-env-ref> required elements:
//------------------------------------------------------------------------------
// resource-env-ref-name
JndiNameType resourceEnvRefName = JndiNameType.Factory.newInstance();
resourceEnvRefName.setStringValue( resourceName );
resourceEnvRef.setResourceEnvRefName( resourceEnvRefName );
if ( !resourceType.equals("") ) {
// resource-env-ref-type
FullyQualifiedClassType classType = FullyQualifiedClassType.Factory.newInstance();
classType.setStringValue( resourceType );
resourceEnvRef.setResourceEnvRefType( classType );
}
else if ( !injectionJavaType.equals("") ) {
// injectionTarget
InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
qualifiedClass.setStringValue( injectionClass );
javaType.setStringValue( injectionJavaType );
injectionTarget.setInjectionTargetClass( qualifiedClass );
injectionTarget.setInjectionTargetName( javaType );
int arraySize = resourceEnvRef.sizeOfInjectionTargetArray();
resourceEnvRef.insertNewInjectionTarget( arraySize );
resourceEnvRef.setInjectionTargetArray( arraySize, injectionTarget );