}
// let's get the main annotation of interest.
javax.xml.ws.WebServiceProvider ann = (javax.xml.ws.WebServiceProvider) annInfo.getAnnotation();
BundleDescriptor bundleDesc = null;
try {
// let's see the type of web service we are dealing with...
if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null && (annCtx instanceof EjbContext)) {
// this is an ejb !
EjbContext ctx = (EjbContext) annCtx;
bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
bundleDesc.setSpecVersion("3.0");
} else {
if (annCtx instanceof WebComponentContext) {
bundleDesc = ((WebComponentContext) annCtx).getDescriptor().getWebBundleDescriptor();
} else if (!(annCtx instanceof WebBundleContext)) {
return getInvalidAnnotatedElementHandlerResult(
annInfo.getProcessingContext().getHandler(), annInfo);
}
bundleDesc = ((WebBundleContext) annCtx).getDescriptor();
bundleDesc.setSpecVersion("2.5");
}
} catch (Exception e) {
throw new AnnotationProcessorException(rb.getString("webservice.annotation.exception") + e.getMessage());
}
// For WSProvider, portComponentName is the fully qualified class name
String portComponentName = ((Class) annElem).getName();
// As per JSR181, the serviceName is either specified in the deployment descriptor
// or in @WebSErvice annotation in impl class; if neither service name implclass+Service
String svcName = ann.serviceName();
if(svcName == null) {
svcName = "";
}
// Store binding type specified in Impl class
String userSpecifiedBinding = null;
javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType)
((Class)annElem).getAnnotation(javax.xml.ws.BindingType.class);
if(bindingAnn != null) {
userSpecifiedBinding = bindingAnn.value();
}
// In case user gives targetNameSpace in the Impl class, that has to be used as
// the namespace for service, port; typically user will do this in cases where
// port_types reside in a different namespace than that of server/port.
// Store the targetNameSpace, if any, in the impl class for later use
String targetNameSpace = ann.targetNamespace();
if(targetNameSpace == null) {
targetNameSpace = "";
}
String portName = ann.portName();
if(portName == null) {
portName = "";
}
// Check if the same endpoint is already defined in webservices.xml
WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
WebService newWS;
if(endpoint == null) {
// Check if a service with the same name is already present
// If so, add this endpoint to the existing service
if (svcName.length()!=0) {
newWS = wsDesc.getWebServiceByName(svcName);
} else {
newWS = wsDesc.getWebServiceByName(((Class)annElem).getSimpleName());
}
if(newWS==null) {
newWS = new WebService();
// service name from annotation
if (svcName.length()!=0) {
newWS.setName(svcName);
} else {
newWS.setName(((Class)annElem).getSimpleName());
}
wsDesc.addWebService(newWS);
}
endpoint = new WebServiceEndpoint();
// port-component-name is fully qualified class name
endpoint.setEndpointName(portComponentName);
newWS.addEndpoint(endpoint);
wsDesc.setSpecVersion(WebServicesDescriptorNode.SPEC_VERSION);
} else {
newWS = endpoint.getWebService();
}
// If wsdl-service is specified in the descriptor, then the targetnamespace
// in wsdl-service should match the @WebService.targetNameSpace, if any.
// make that assertion here - and the targetnamespace in wsdl-service, if
// present overrides everything else
if(endpoint.getWsdlService() != null) {
if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
(!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
throw new AnnotationProcessorException(
"Target Namespace inwsdl-service element does not match @WebService.targetNamespace",
annInfo);
}
targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
}
// Set binding id id @BindingType is specified by the user in the impl class
if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
(userSpecifiedBinding != null) &&
(userSpecifiedBinding.length() != 0)){
endpoint.setProtocolBinding(userSpecifiedBinding);
}
// Use annotated values only if the deployment descriptor equivalent has not been specified
if(newWS.getWsdlFileUri() == null) {
// take wsdl location from annotation
if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
newWS.setWsdlFileUri(ann.wsdlLocation());
}
}
annElem = annInfo.getAnnotatedElement();
// we checked that the endpoint implements the provider interface above
Class clz = (Class) annElem;
Class serviceEndpointIntf = null;
for (Class intf : clz.getInterfaces()) {
if (javax.xml.ws.Provider.class.isAssignableFrom(intf)) {
serviceEndpointIntf = intf;
break;
}
}
if (serviceEndpointIntf==null) {
endpoint.setServiceEndpointInterface("javax.xml.ws.Provider");
} else {
endpoint.setServiceEndpointInterface(serviceEndpointIntf.getName());
}
if (DOLUtils.warType().equals(bundleDesc.getModuleType())) {
if(endpoint.getServletImplClass() == null) {
// Set servlet impl class here
endpoint.setServletImplClass(((Class)annElem).getName());
}