1 23 24 package com.sun.enterprise.deployment.annotation.handlers; 25 26 import java.util.Set ; 27 import java.util.StringTokenizer ; 28 29 import java.lang.reflect.AnnotatedElement ; 30 import java.lang.annotation.Annotation ; 31 32 import javax.enterprise.deploy.shared.ModuleType ; 33 34 import com.sun.enterprise.deployment.annotation.AnnotationHandler; 35 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 36 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler; 37 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 38 import com.sun.enterprise.deployment.annotation.ProcessingContext; 39 import com.sun.enterprise.deployment.annotation.ResultType; 40 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 41 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 42 43 import com.sun.enterprise.deployment.annotation.impl.AnnotationUtils; 44 import com.sun.enterprise.deployment.annotation.impl.HandlerProcessingResultImpl; 45 46 import com.sun.enterprise.deployment.annotation.context.AnnotationContext; 47 import com.sun.enterprise.deployment.annotation.context.WebBundleContext; 48 import com.sun.enterprise.deployment.annotation.context.EjbContext; 49 50 import com.sun.enterprise.deployment.WebBundleDescriptor; 51 import com.sun.enterprise.deployment.EjbBundleDescriptor; 52 import com.sun.enterprise.deployment.BundleDescriptor; 53 import com.sun.enterprise.deployment.WebServicesDescriptor; 54 import com.sun.enterprise.deployment.WebService; 55 import com.sun.enterprise.deployment.WebServiceEndpoint; 56 import com.sun.enterprise.deployment.EjbDescriptor; 57 import com.sun.enterprise.deployment.WebComponentDescriptor; 58 59 import javax.xml.namespace.QName ; 60 61 67 68 public class WebServiceProviderHandler implements AnnotationHandler { 69 70 71 public WebServiceProviderHandler() { 72 } 73 74 public Class <? extends Annotation > getAnnotationType() { 75 return javax.xml.ws.WebServiceProvider.class; 76 } 77 78 83 public Class <? extends Annotation >[] getTypeDependencies() { 84 Class dependencies[] = { javax.ejb.Stateless .class }; 85 return dependencies; 86 } 87 88 public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) 89 throws AnnotationProcessorException 90 { 91 AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler(); 92 AnnotatedElement annElem = annInfo.getAnnotatedElement(); 93 94 if (!(annElem instanceof Class )) { 96 AnnotationProcessorException ape = new AnnotationProcessorException( 97 "@WebServiceProvider can only be specified on TYPE", annInfo); 98 annInfo.getProcessingContext().getErrorHandler().error(ape); 99 return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED); 100 } 101 if (!javax.xml.ws.Provider.class.isAssignableFrom((Class ) annElem)) { 103 AnnotationProcessorException ape = new AnnotationProcessorException( 104 annElem.toString() + "does not implement the javax.xml.ws.Provider interface", annInfo); 105 annInfo.getProcessingContext().getErrorHandler().error(ape); 106 return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.FAILED); 107 } 108 109 javax.xml.ws.WebServiceProvider ann = (javax.xml.ws.WebServiceProvider) annInfo.getAnnotation(); 111 112 BundleDescriptor bundleDesc; 113 114 if (annElem.getAnnotation(javax.ejb.Stateless .class)!=null) { 116 EjbContext ctx = (EjbContext) annCtx; 118 bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); 119 bundleDesc.setSpecVersion("3.0"); 120 } else { 121 WebBundleContext ctx = (WebBundleContext)annCtx; 123 bundleDesc = ctx.getDescriptor(); 124 bundleDesc.setSpecVersion("2.5"); 125 } 126 127 String portComponentName = ((Class ) annElem).getName(); 129 130 String svcName = ann.serviceName(); 133 if(svcName == null) { 134 svcName = ""; 135 } 136 137 String userSpecifiedBinding = null; 139 javax.xml.ws.BindingType bindingAnn = (javax.xml.ws.BindingType) 140 ((Class )annElem).getAnnotation(javax.xml.ws.BindingType.class); 141 if(bindingAnn != null) { 142 userSpecifiedBinding = bindingAnn.value(); 143 } 144 145 String targetNameSpace = ann.targetNamespace(); 150 if(targetNameSpace == null) { 151 targetNameSpace = ""; 152 } 153 154 String portName = ann.portName(); 155 if(portName == null) { 156 portName = ""; 157 } 158 159 WebServicesDescriptor wsDesc = bundleDesc.getWebServices(); 161 WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName); 162 WebService newWS; 163 if(endpoint == null) { 164 if (svcName.length()!=0) { 167 newWS = wsDesc.getWebServiceByName(svcName); 168 } else { 169 newWS = wsDesc.getWebServiceByName(((Class )annElem).getSimpleName()+"Service"); 170 } 171 if(newWS==null) { 172 newWS = new WebService(); 173 if (svcName.length()!=0) { 175 newWS.setName(svcName); 176 } else { 177 newWS.setName(((Class )annElem).getSimpleName()+"Service"); 178 } 179 wsDesc.addWebService(newWS); 180 } 181 endpoint = new WebServiceEndpoint(); 182 endpoint.setEndpointName(portComponentName); 184 newWS.addEndpoint(endpoint); 185 wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION); 186 } else { 187 newWS = endpoint.getWebService(); 188 } 189 190 if(endpoint.getWsdlService() != null) { 195 if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) && 196 (!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) { 197 throw new AnnotationProcessorException( 198 "Target Namespace inwsdl-service element does not match @WebService.targetNamespace", 199 annInfo); 200 } 201 targetNameSpace = endpoint.getWsdlService().getNamespaceURI(); 202 } 203 204 if((!endpoint.hasUserSpecifiedProtocolBinding()) && 206 (userSpecifiedBinding != null) && 207 (userSpecifiedBinding.length() != 0)){ 208 endpoint.setProtocolBinding(userSpecifiedBinding); 209 } 210 211 if(newWS.getWsdlFileUri() == null) { 213 if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) { 215 newWS.setWsdlFileUri(ann.wsdlLocation()); 216 } 217 } 218 219 annElem = annInfo.getAnnotatedElement(); 220 221 Class clz = (Class ) annElem; 223 Class serviceEndpointIntf = null; 224 for (Class intf : clz.getInterfaces()) { 225 if (javax.xml.ws.Provider.class.isAssignableFrom(intf)) { 226 serviceEndpointIntf = intf; 227 break; 228 } 229 } 230 if (serviceEndpointIntf==null) { 231 endpoint.setServiceEndpointInterface("javax.xml.ws.Provider"); 232 } else { 233 endpoint.setServiceEndpointInterface(serviceEndpointIntf.getName()); 234 } 235 236 if (ModuleType.WAR.equals(bundleDesc.getModuleType())) { 237 if(endpoint.getServletImplClass() == null) { 238 endpoint.setServletImplClass(((Class )annElem).getName()); 240 } 241 242 WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc; 244 if(endpoint.getWebComponentLink() == null) { 245 endpoint.setWebComponentLink(portComponentName); 246 } 247 if(endpoint.getWebComponentImpl() == null) { 248 WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle. 249 getWebComponentByCanonicalName(endpoint.getWebComponentLink()); 250 251 if (webComponent == null) { 253 webComponent = new WebComponentDescriptor(); 254 webComponent.setServlet(true); 255 webComponent.setWebComponentImplementation(((Class ) annElem).getCanonicalName()); 256 webComponent.setName(endpoint.getEndpointName()); 257 webComponent.addUrlPattern("/"+newWS.getName()); 258 webBundle.addWebComponentDescriptor(webComponent); 259 } 260 endpoint.setWebComponentImpl(webComponent); 261 } 262 } else { 263 if(endpoint.getEjbLink() == null) { 264 EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class )annElem).getName()); 265 if(ejbDescs.length != 1) { 266 throw new AnnotationProcessorException( 267 "Unable to find matching descriptor for EJB endpoint", 268 annInfo); 269 } 270 endpoint.setEjbComponentImpl(ejbDescs[0]); 271 ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface()); 272 endpoint.setEjbLink(ejbDescs[0].getName()); 273 } 274 } 275 276 if(endpoint.getWsdlPort() == null) { 277 endpoint.setWsdlPort(new QName (targetNameSpace, portName, "ns1")); 278 } 279 280 if(endpoint.getWsdlService() == null) { 281 endpoint.setWsdlService(new QName (targetNameSpace, svcName)); 282 } 283 284 return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED); 285 } 286 } 287 | Popular Tags |