//------------------------------------------------------------------------------------------
// 1. <service-ref>
//------------------------------------------------------------------------------------------
ServiceRefType serviceRef = null;
ServiceRefType[] serviceRefs = annotatedApp.getServiceRefArray();
for (ServiceRefType currServiceRef : serviceRefs) {
if (currServiceRef.getServiceRefName().getStringValue().trim().equals(webServiceRefName)) {
serviceRef = currServiceRef;
break;
}
}
if (serviceRef == null) {
// Doesn't exist in deployment descriptor -- add new
serviceRef = annotatedApp.addNewServiceRef();
// ------------------------------------------------------------------------------
// <service-ref> required elements:
// ------------------------------------------------------------------------------
// service-ref-name
JndiNameType serviceRefName = serviceRef.addNewServiceRefName();
serviceRefName.setStringValue(webServiceRefName);
serviceRef.setServiceRefName(serviceRefName);
// service-ref-interface
if (!webServiceRefValue.equals(Object.class)) {
FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
qualifiedClass.setStringValue(webServiceRefValue.getName());
serviceRef.setServiceInterface(qualifiedClass);
} else {
FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
qualifiedClass.setStringValue(webServiceRefType.getName());
serviceRef.setServiceInterface(qualifiedClass);
}
}
//------------------------------------------------------------------------------
// <service-ref> optional elements:
//------------------------------------------------------------------------------
// service-ref-type
if (!serviceRef.isSetServiceRefType() && !webServiceRefType.equals(Object.class)) {
FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceRefType();
qualifiedClass.setStringValue(webServiceRefType.getName());
serviceRef.setServiceRefType(qualifiedClass);
}
// mapped-name
if (!serviceRef.isSetMappedName() && annotation.mappedName().trim().length() > 0) {
XsdStringType mappedName = serviceRef.addNewMappedName();
mappedName.setStringValue(annotation.mappedName().trim());
serviceRef.setMappedName(mappedName);
}
// WSDL document location
if (!serviceRef.isSetWsdlFile()) {
String wsdlLocation = annotation.wsdlLocation();
if (wsdlLocation == null || wsdlLocation.trim().length() == 0) {
WebServiceClient wsClient = null;
if (Object.class.equals(webServiceRefValue)) {
wsClient = (WebServiceClient) webServiceRefType.getAnnotation(WebServiceClient.class);
} else {
wsClient = (WebServiceClient) webServiceRefValue.getAnnotation(WebServiceClient.class);
}
if (wsClient == null) {
wsdlLocation = null;
} else {
wsdlLocation = wsClient.wsdlLocation();
}
}
if (wsdlLocation != null && wsdlLocation.trim().length() > 0) {
XsdAnyURIType wsdlFile = serviceRef.addNewWsdlFile();
wsdlFile.setStringValue(wsdlLocation);
serviceRef.setWsdlFile(wsdlFile);
}
}
// handler-chains
if (!serviceRef.isSetHandlerChains()) {
HandlerChain handlerChain = null;
Class annotatedClass = null;
if (method != null) {
handlerChain = method.getAnnotation(HandlerChain.class);
annotatedClass = method.getDeclaringClass();
} else if (field != null) {
handlerChain = field.getAnnotation(HandlerChain.class);
annotatedClass = field.getDeclaringClass();
}
// if not specified on method or field, try to get it from Service class
if (handlerChain == null) {
if (Object.class.equals(webServiceRefValue)) {
handlerChain = (HandlerChain) webServiceRefType.getAnnotation(HandlerChain.class);
annotatedClass = webServiceRefType;
} else {
handlerChain = (HandlerChain) webServiceRefValue.getAnnotation(HandlerChain.class);
annotatedClass = webServiceRefValue;
}
}
if (handlerChain != null) {
HandlerChainAnnotationHelper.insertHandlers(serviceRef, handlerChain, annotatedClass);
}
}
if (method != null || field != null) {
configureInjectionTarget(serviceRef.addNewInjectionTarget(), method, field);
}
}