src/share/jaxws_classes/com/sun/tools/internal/ws/processor/modeler/annotation/WebServiceVisitor.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.internal.ws.processor.modeler.annotation;
aoqi@0 27
aoqi@0 28 import com.sun.tools.internal.ws.processor.model.Port;
aoqi@0 29 import com.sun.tools.internal.ws.resources.WebserviceapMessages;
aoqi@0 30 import com.sun.tools.internal.ws.util.ClassNameInfo;
aoqi@0 31 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
aoqi@0 32 import com.sun.xml.internal.ws.model.RuntimeModeler;
aoqi@0 33
aoqi@0 34 import javax.annotation.processing.ProcessingEnvironment;
aoqi@0 35 import javax.jws.Oneway;
aoqi@0 36 import javax.jws.WebMethod;
aoqi@0 37 import javax.jws.WebParam;
aoqi@0 38 import javax.jws.WebResult;
aoqi@0 39 import javax.jws.WebService;
aoqi@0 40 import javax.jws.soap.SOAPBinding;
aoqi@0 41 import javax.jws.soap.SOAPBinding.ParameterStyle;
aoqi@0 42 import javax.lang.model.element.Element;
aoqi@0 43 import javax.lang.model.element.ElementKind;
aoqi@0 44 import javax.lang.model.element.ExecutableElement;
aoqi@0 45 import javax.lang.model.element.Modifier;
aoqi@0 46 import javax.lang.model.element.Name;
aoqi@0 47 import javax.lang.model.element.PackageElement;
aoqi@0 48 import javax.lang.model.element.TypeElement;
aoqi@0 49 import javax.lang.model.element.VariableElement;
aoqi@0 50 import javax.lang.model.type.DeclaredType;
aoqi@0 51 import javax.lang.model.type.NoType;
aoqi@0 52 import javax.lang.model.type.TypeKind;
aoqi@0 53 import javax.lang.model.type.TypeMirror;
aoqi@0 54 import javax.lang.model.util.ElementFilter;
aoqi@0 55 import javax.lang.model.util.SimpleElementVisitor6;
aoqi@0 56 import javax.lang.model.util.SimpleTypeVisitor6;
aoqi@0 57 import javax.lang.model.util.Types;
aoqi@0 58 import java.lang.annotation.Annotation;
aoqi@0 59 import java.util.Collection;
aoqi@0 60 import java.util.HashSet;
aoqi@0 61 import java.util.List;
aoqi@0 62 import java.util.Set;
aoqi@0 63 import java.util.Stack;
aoqi@0 64
aoqi@0 65 /**
aoqi@0 66 * @author WS Development Team
aoqi@0 67 */
aoqi@0 68 public abstract class WebServiceVisitor extends SimpleElementVisitor6<Void, Object> {
aoqi@0 69
aoqi@0 70 protected ModelBuilder builder;
aoqi@0 71 protected String wsdlNamespace;
aoqi@0 72 protected String typeNamespace;
aoqi@0 73 protected Stack<SOAPBinding> soapBindingStack;
aoqi@0 74 protected SOAPBinding typeElementSoapBinding;
aoqi@0 75 protected SOAPStyle soapStyle = SOAPStyle.DOCUMENT;
aoqi@0 76 protected boolean wrapped = true;
aoqi@0 77 protected Port port;
aoqi@0 78 protected Name serviceImplName;
aoqi@0 79 protected Name endpointInterfaceName;
aoqi@0 80 protected AnnotationProcessorContext context;
aoqi@0 81 protected AnnotationProcessorContext.SeiContext seiContext;
aoqi@0 82 protected boolean processingSei = false;
aoqi@0 83 protected String serviceName;
aoqi@0 84 protected Name packageName;
aoqi@0 85 protected String portName;
aoqi@0 86 protected boolean endpointReferencesInterface = false;
aoqi@0 87 protected boolean hasWebMethods = false;
aoqi@0 88 protected TypeElement typeElement;
aoqi@0 89 protected Set<String> processedMethods;
aoqi@0 90 protected boolean pushedSoapBinding = false;
aoqi@0 91
aoqi@0 92 private static final NoTypeVisitor NO_TYPE_VISITOR = new NoTypeVisitor();
aoqi@0 93
aoqi@0 94 public WebServiceVisitor(ModelBuilder builder, AnnotationProcessorContext context) {
aoqi@0 95 this.builder = builder;
aoqi@0 96 this.context = context;
aoqi@0 97 soapBindingStack = new Stack<SOAPBinding>();
aoqi@0 98 processedMethods = new HashSet<String>();
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 @Override
aoqi@0 102 public Void visitType(TypeElement e, Object o) {
aoqi@0 103 WebService webService = e.getAnnotation(WebService.class);
aoqi@0 104 if (!shouldProcessWebService(webService, e))
aoqi@0 105 return null;
aoqi@0 106 if (builder.checkAndSetProcessed(e))
aoqi@0 107 return null;
aoqi@0 108 typeElement = e;
aoqi@0 109
aoqi@0 110 switch (e.getKind()) {
aoqi@0 111 case INTERFACE: {
aoqi@0 112 if (endpointInterfaceName != null && !endpointInterfaceName.equals(e.getQualifiedName())) {
aoqi@0 113 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTERFACES_DO_NOT_MATCH(endpointInterfaceName, e.getQualifiedName()), e);
aoqi@0 114 }
aoqi@0 115 verifySeiAnnotations(webService, e);
aoqi@0 116 endpointInterfaceName = e.getQualifiedName();
aoqi@0 117 processingSei = true;
aoqi@0 118 preProcessWebService(webService, e);
aoqi@0 119 processWebService(webService, e);
aoqi@0 120 postProcessWebService(webService, e);
aoqi@0 121 break;
aoqi@0 122 }
aoqi@0 123 case CLASS: {
aoqi@0 124 typeElementSoapBinding = e.getAnnotation(SOAPBinding.class);
aoqi@0 125 if (serviceImplName == null)
aoqi@0 126 serviceImplName = e.getQualifiedName();
aoqi@0 127 String endpointInterfaceName = webService != null ? webService.endpointInterface() : null;
aoqi@0 128 if (endpointInterfaceName != null && endpointInterfaceName.length() > 0) {
aoqi@0 129 checkForInvalidImplAnnotation(e, SOAPBinding.class);
aoqi@0 130 if (webService.name().length() > 0)
aoqi@0 131 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTEFACE_PLUS_ELEMENT("name"), e);
aoqi@0 132 endpointReferencesInterface = true;
aoqi@0 133 verifyImplAnnotations(e);
aoqi@0 134 inspectEndpointInterface(endpointInterfaceName, e);
aoqi@0 135 serviceImplName = null;
aoqi@0 136 return null;
aoqi@0 137 }
aoqi@0 138 processingSei = false;
aoqi@0 139 preProcessWebService(webService, e);
aoqi@0 140 processWebService(webService, e);
aoqi@0 141 serviceImplName = null;
aoqi@0 142 postProcessWebService(webService, e);
aoqi@0 143 serviceImplName = null;
aoqi@0 144 break;
aoqi@0 145 }
aoqi@0 146 default:
aoqi@0 147 break;
aoqi@0 148 }
aoqi@0 149 return null;
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 protected void verifySeiAnnotations(WebService webService, TypeElement d) {
aoqi@0 153 if (webService.endpointInterface().length() > 0) {
aoqi@0 154 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTERFACE_ON_INTERFACE(
aoqi@0 155 d.getQualifiedName(), webService.endpointInterface()), d);
aoqi@0 156 }
aoqi@0 157 if (webService.serviceName().length() > 0) {
aoqi@0 158 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SEI_ANNOTATION_ELEMENT(
aoqi@0 159 "serviceName", d.getQualifiedName()), d);
aoqi@0 160 }
aoqi@0 161 if (webService.portName().length() > 0) {
aoqi@0 162 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SEI_ANNOTATION_ELEMENT(
aoqi@0 163 "portName", d.getQualifiedName()), d);
aoqi@0 164 }
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 protected void verifyImplAnnotations(TypeElement d) {
aoqi@0 168 for (ExecutableElement method : ElementFilter.methodsIn(d.getEnclosedElements())) {
aoqi@0 169 checkForInvalidImplAnnotation(method, WebMethod.class);
aoqi@0 170 checkForInvalidImplAnnotation(method, Oneway.class);
aoqi@0 171 checkForInvalidImplAnnotation(method, WebResult.class);
aoqi@0 172 for (VariableElement param : method.getParameters()) {
aoqi@0 173 checkForInvalidImplAnnotation(param, WebParam.class);
aoqi@0 174 }
aoqi@0 175 }
aoqi@0 176 }
aoqi@0 177
aoqi@0 178 protected void checkForInvalidSeiAnnotation(TypeElement element, Class annotationClass) {
aoqi@0 179 Object annotation = element.getAnnotation(annotationClass);
aoqi@0 180 if (annotation != null) {
aoqi@0 181 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SEI_ANNOTATION(
aoqi@0 182 annotationClass.getName(), element.getQualifiedName()), element);
aoqi@0 183 }
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 protected void checkForInvalidImplAnnotation(Element element, Class annotationClass) {
aoqi@0 187 Object annotation = element.getAnnotation(annotationClass);
aoqi@0 188 if (annotation != null) {
aoqi@0 189 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTEFACE_PLUS_ANNOTATION(annotationClass.getName()), element);
aoqi@0 190 }
aoqi@0 191 }
aoqi@0 192
aoqi@0 193 protected void preProcessWebService(WebService webService, TypeElement element) {
aoqi@0 194 processedMethods = new HashSet<String>();
aoqi@0 195 seiContext = context.getSeiContext(element);
aoqi@0 196 String targetNamespace = null;
aoqi@0 197 if (webService != null)
aoqi@0 198 targetNamespace = webService.targetNamespace();
aoqi@0 199 PackageElement packageElement = builder.getProcessingEnvironment().getElementUtils().getPackageOf(element);
aoqi@0 200 if (targetNamespace == null || targetNamespace.length() == 0) {
aoqi@0 201 String packageName = packageElement.getQualifiedName().toString();
aoqi@0 202 if (packageName == null || packageName.length() == 0) {
aoqi@0 203 builder.processError(WebserviceapMessages.WEBSERVICEAP_NO_PACKAGE_CLASS_MUST_HAVE_TARGETNAMESPACE(
aoqi@0 204 element.getQualifiedName()), element);
aoqi@0 205 }
aoqi@0 206 targetNamespace = RuntimeModeler.getNamespace(packageName);
aoqi@0 207 }
aoqi@0 208 seiContext.setNamespaceUri(targetNamespace);
aoqi@0 209 if (serviceImplName == null)
aoqi@0 210 serviceImplName = seiContext.getSeiImplName();
aoqi@0 211 if (serviceImplName != null) {
aoqi@0 212 seiContext.setSeiImplName(serviceImplName);
aoqi@0 213 context.addSeiContext(serviceImplName, seiContext);
aoqi@0 214 }
aoqi@0 215 portName = ClassNameInfo.getName(element.getSimpleName().toString().replace('$', '_'));
aoqi@0 216 packageName = packageElement.getQualifiedName();
aoqi@0 217 portName = webService != null && webService.name() != null && webService.name().length() > 0 ?
aoqi@0 218 webService.name() : portName;
aoqi@0 219 serviceName = ClassNameInfo.getName(element.getQualifiedName().toString()) + WebServiceConstants.SERVICE.getValue();
aoqi@0 220 serviceName = webService != null && webService.serviceName() != null && webService.serviceName().length() > 0 ?
aoqi@0 221 webService.serviceName() : serviceName;
aoqi@0 222 wsdlNamespace = seiContext.getNamespaceUri();
aoqi@0 223 typeNamespace = wsdlNamespace;
aoqi@0 224
aoqi@0 225 SOAPBinding soapBinding = element.getAnnotation(SOAPBinding.class);
aoqi@0 226 if (soapBinding != null) {
aoqi@0 227 pushedSoapBinding = pushSoapBinding(soapBinding, element, element);
aoqi@0 228 } else if (element.equals(typeElement)) {
aoqi@0 229 pushedSoapBinding = pushSoapBinding(new MySoapBinding(), element, element);
aoqi@0 230 }
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 public static boolean sameStyle(SOAPBinding.Style style, SOAPStyle soapStyle) {
aoqi@0 234 return style.equals(SOAPBinding.Style.DOCUMENT)
aoqi@0 235 && soapStyle.equals(SOAPStyle.DOCUMENT)
aoqi@0 236 || style.equals(SOAPBinding.Style.RPC)
aoqi@0 237 && soapStyle.equals(SOAPStyle.RPC);
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 protected boolean pushSoapBinding(SOAPBinding soapBinding, Element bindingElement, TypeElement classElement) {
aoqi@0 241 boolean changed = false;
aoqi@0 242 if (!sameStyle(soapBinding.style(), soapStyle)) {
aoqi@0 243 changed = true;
aoqi@0 244 if (pushedSoapBinding)
aoqi@0 245 builder.processError(WebserviceapMessages.WEBSERVICEAP_MIXED_BINDING_STYLE(
aoqi@0 246 classElement.getQualifiedName()), bindingElement);
aoqi@0 247 }
aoqi@0 248 if (soapBinding.style().equals(SOAPBinding.Style.RPC)) {
aoqi@0 249 soapStyle = SOAPStyle.RPC;
aoqi@0 250 wrapped = true;
aoqi@0 251 if (soapBinding.parameterStyle().equals(ParameterStyle.BARE)) {
aoqi@0 252 builder.processError(WebserviceapMessages.WEBSERVICEAP_RPC_LITERAL_MUST_NOT_BE_BARE(
aoqi@0 253 classElement.getQualifiedName()), bindingElement);
aoqi@0 254 }
aoqi@0 255 } else {
aoqi@0 256 soapStyle = SOAPStyle.DOCUMENT;
aoqi@0 257 if (wrapped != soapBinding.parameterStyle().equals(ParameterStyle.WRAPPED)) {
aoqi@0 258 wrapped = soapBinding.parameterStyle().equals(ParameterStyle.WRAPPED);
aoqi@0 259 changed = true;
aoqi@0 260 }
aoqi@0 261 }
aoqi@0 262 if (soapBinding.use().equals(SOAPBinding.Use.ENCODED)) {
aoqi@0 263 String style = "rpc";
aoqi@0 264 if (soapBinding.style().equals(SOAPBinding.Style.DOCUMENT))
aoqi@0 265 style = "document";
aoqi@0 266 builder.processError(WebserviceapMessages.WEBSERVICE_ENCODED_NOT_SUPPORTED(
aoqi@0 267 classElement.getQualifiedName(), style), bindingElement);
aoqi@0 268 }
aoqi@0 269 if (changed || soapBindingStack.empty()) {
aoqi@0 270 soapBindingStack.push(soapBinding);
aoqi@0 271 pushedSoapBinding = true;
aoqi@0 272 }
aoqi@0 273 return changed;
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 protected SOAPBinding popSoapBinding() {
aoqi@0 277 if (pushedSoapBinding)
aoqi@0 278 soapBindingStack.pop();
aoqi@0 279 SOAPBinding soapBinding = null;
aoqi@0 280 if (!soapBindingStack.empty()) {
aoqi@0 281 soapBinding = soapBindingStack.peek();
aoqi@0 282 if (soapBinding.style().equals(SOAPBinding.Style.RPC)) {
aoqi@0 283 soapStyle = SOAPStyle.RPC;
aoqi@0 284 wrapped = true;
aoqi@0 285 } else {
aoqi@0 286 soapStyle = SOAPStyle.DOCUMENT;
aoqi@0 287 wrapped = soapBinding.parameterStyle().equals(ParameterStyle.WRAPPED);
aoqi@0 288 }
aoqi@0 289 } else {
aoqi@0 290 pushedSoapBinding = false;
aoqi@0 291 }
aoqi@0 292 return soapBinding;
aoqi@0 293 }
aoqi@0 294
aoqi@0 295 protected String getNamespace(PackageElement packageElement) {
aoqi@0 296 return RuntimeModeler.getNamespace(packageElement.getQualifiedName().toString());
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 protected boolean shouldProcessWebService(WebService webService, TypeElement element) {
aoqi@0 300 switch (element.getKind()) {
aoqi@0 301 case INTERFACE: {
aoqi@0 302 hasWebMethods = false;
aoqi@0 303 if (webService == null)
aoqi@0 304 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTERFACE_HAS_NO_WEBSERVICE_ANNOTATION(
aoqi@0 305 element.getQualifiedName()), element);
aoqi@0 306
aoqi@0 307 SOAPBinding soapBinding = element.getAnnotation(SOAPBinding.class);
aoqi@0 308 if (soapBinding != null
aoqi@0 309 && soapBinding.style() == SOAPBinding.Style.RPC
aoqi@0 310 && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
aoqi@0 311 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SOAPBINDING_PARAMETERSTYLE(
aoqi@0 312 soapBinding, element), element);
aoqi@0 313 return false;
aoqi@0 314 }
aoqi@0 315 return isLegalSei(element);
aoqi@0 316 }
aoqi@0 317 case CLASS: {
aoqi@0 318 if (webService == null)
aoqi@0 319 return false;
aoqi@0 320 hasWebMethods = hasWebMethods(element);
aoqi@0 321 SOAPBinding soapBinding = element.getAnnotation(SOAPBinding.class);
aoqi@0 322 if (soapBinding != null
aoqi@0 323 && soapBinding.style() == SOAPBinding.Style.RPC
aoqi@0 324 && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
aoqi@0 325 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SOAPBINDING_PARAMETERSTYLE(
aoqi@0 326 soapBinding, element), element);
aoqi@0 327 return false;
aoqi@0 328 }
aoqi@0 329 return isLegalImplementation(webService, element);
aoqi@0 330 }
aoqi@0 331 default: {
aoqi@0 332 throw new IllegalArgumentException("Class or Interface was expecting. But element: " + element);
aoqi@0 333 }
aoqi@0 334 }
aoqi@0 335 }
aoqi@0 336
aoqi@0 337 abstract protected void processWebService(WebService webService, TypeElement element);
aoqi@0 338
aoqi@0 339 protected void postProcessWebService(WebService webService, TypeElement element) {
aoqi@0 340 processMethods(element);
aoqi@0 341 popSoapBinding();
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 protected boolean hasWebMethods(TypeElement element) {
aoqi@0 345 if (element.getQualifiedName().toString().equals(Object.class.getName()))
aoqi@0 346 return false;
aoqi@0 347 WebMethod webMethod;
aoqi@0 348 for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
aoqi@0 349 webMethod = method.getAnnotation(WebMethod.class);
aoqi@0 350 if (webMethod != null) {
aoqi@0 351 if (webMethod.exclude()) {
aoqi@0 352 if (webMethod.operationName().length() > 0)
aoqi@0 353 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE(
aoqi@0 354 "operationName", element.getQualifiedName(), method.toString()), method);
aoqi@0 355 if (webMethod.action().length() > 0)
aoqi@0 356 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_WEBMETHOD_ELEMENT_WITH_EXCLUDE(
aoqi@0 357 "action", element.getQualifiedName(), method.toString()), method);
aoqi@0 358 } else {
aoqi@0 359 return true;
aoqi@0 360 }
aoqi@0 361 }
aoqi@0 362 }
aoqi@0 363 return false;//hasWebMethods(d.getSuperclass().getDeclaration());
aoqi@0 364 }
aoqi@0 365
aoqi@0 366 protected void processMethods(TypeElement element) {
aoqi@0 367 switch (element.getKind()) {
aoqi@0 368 case INTERFACE: {
aoqi@0 369 builder.log("ProcessedMethods Interface: " + element);
aoqi@0 370 hasWebMethods = false;
aoqi@0 371 for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
aoqi@0 372 method.accept(this, null);
aoqi@0 373 }
aoqi@0 374 for (TypeMirror superType : element.getInterfaces())
aoqi@0 375 processMethods((TypeElement) ((DeclaredType) superType).asElement());
aoqi@0 376 break;
aoqi@0 377 }
aoqi@0 378 case CLASS: {
aoqi@0 379 builder.log("ProcessedMethods Class: " + element);
aoqi@0 380 hasWebMethods = hasWebMethods(element);
aoqi@0 381 if (element.getQualifiedName().toString().equals(Object.class.getName()))
aoqi@0 382 return;
aoqi@0 383 if (element.getAnnotation(WebService.class) != null) {
aoqi@0 384 // Super classes must have @WebService annotations to pick up their methods
aoqi@0 385 for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
aoqi@0 386 method.accept(this, null);
aoqi@0 387 }
aoqi@0 388 }
aoqi@0 389 TypeMirror superclass = element.getSuperclass();
aoqi@0 390 if (!superclass.getKind().equals(TypeKind.NONE)) {
aoqi@0 391 processMethods((TypeElement) ((DeclaredType) superclass).asElement());
aoqi@0 392 }
aoqi@0 393 break;
aoqi@0 394 }
aoqi@0 395 default:
aoqi@0 396 break;
aoqi@0 397 }
aoqi@0 398 }
aoqi@0 399
aoqi@0 400 private TypeElement getEndpointInterfaceElement(String endpointInterfaceName, TypeElement element) {
aoqi@0 401 TypeElement intTypeElement = null;
aoqi@0 402 for (TypeMirror interfaceType : element.getInterfaces()) {
aoqi@0 403 if (endpointInterfaceName.equals(interfaceType.toString())) {
aoqi@0 404 intTypeElement = (TypeElement) ((DeclaredType) interfaceType).asElement();
aoqi@0 405 seiContext = context.getSeiContext(intTypeElement.getQualifiedName());
aoqi@0 406 assert (seiContext != null);
aoqi@0 407 seiContext.setImplementsSei(true);
aoqi@0 408 break;
aoqi@0 409 }
aoqi@0 410 }
aoqi@0 411 if (intTypeElement == null) {
aoqi@0 412 intTypeElement = builder.getProcessingEnvironment().getElementUtils().getTypeElement(endpointInterfaceName);
aoqi@0 413 }
aoqi@0 414 if (intTypeElement == null)
aoqi@0 415 builder.processError(WebserviceapMessages.WEBSERVICEAP_ENDPOINTINTERFACE_CLASS_NOT_FOUND(endpointInterfaceName));
aoqi@0 416 return intTypeElement;
aoqi@0 417 }
aoqi@0 418
aoqi@0 419 private void inspectEndpointInterface(String endpointInterfaceName, TypeElement d) {
aoqi@0 420 TypeElement intTypeElement = getEndpointInterfaceElement(endpointInterfaceName, d);
aoqi@0 421 if (intTypeElement != null)
aoqi@0 422 intTypeElement.accept(this, null);
aoqi@0 423 }
aoqi@0 424
aoqi@0 425 @Override
aoqi@0 426 public Void visitExecutable(ExecutableElement method, Object o) {
aoqi@0 427 // Methods must be public
aoqi@0 428 if (!method.getModifiers().contains(Modifier.PUBLIC))
aoqi@0 429 return null;
aoqi@0 430 if (processedMethod(method))
aoqi@0 431 return null;
aoqi@0 432 WebMethod webMethod = method.getAnnotation(WebMethod.class);
aoqi@0 433 if (webMethod != null && webMethod.exclude())
aoqi@0 434 return null;
aoqi@0 435 SOAPBinding soapBinding = method.getAnnotation(SOAPBinding.class);
aoqi@0 436 if (soapBinding == null && !method.getEnclosingElement().equals(typeElement)) {
aoqi@0 437 if (method.getEnclosingElement().getKind().equals(ElementKind.CLASS)) {
aoqi@0 438 soapBinding = method.getEnclosingElement().getAnnotation(SOAPBinding.class);
aoqi@0 439 if (soapBinding != null)
aoqi@0 440 builder.log("using " + method.getEnclosingElement() + "'s SOAPBinding.");
aoqi@0 441 else {
aoqi@0 442 soapBinding = new MySoapBinding();
aoqi@0 443 }
aoqi@0 444 }
aoqi@0 445 }
aoqi@0 446 boolean newBinding = false;
aoqi@0 447 if (soapBinding != null) {
aoqi@0 448 newBinding = pushSoapBinding(soapBinding, method, typeElement);
aoqi@0 449 }
aoqi@0 450 try {
aoqi@0 451 if (shouldProcessMethod(method, webMethod)) {
aoqi@0 452 processMethod(method, webMethod);
aoqi@0 453 }
aoqi@0 454 } finally {
aoqi@0 455 if (newBinding) {
aoqi@0 456 popSoapBinding();
aoqi@0 457 }
aoqi@0 458 }
aoqi@0 459 return null;
aoqi@0 460 }
aoqi@0 461
aoqi@0 462 protected boolean processedMethod(ExecutableElement method) {
aoqi@0 463 String id = method.toString();
aoqi@0 464 if (processedMethods.contains(id))
aoqi@0 465 return true;
aoqi@0 466 processedMethods.add(id);
aoqi@0 467 return false;
aoqi@0 468 }
aoqi@0 469
aoqi@0 470 protected boolean shouldProcessMethod(ExecutableElement method, WebMethod webMethod) {
aoqi@0 471 builder.log("should process method: " + method.getSimpleName() + " hasWebMethods: " + hasWebMethods + " ");
aoqi@0 472 /*
aoqi@0 473 Fix for https://jax-ws.dev.java.net/issues/show_bug.cgi?id=577
aoqi@0 474 if (hasWebMethods && webMethod == null) {
aoqi@0 475 builder.log("webMethod == null");
aoqi@0 476 return false;
aoqi@0 477 }
aoqi@0 478 */
aoqi@0 479 Collection<Modifier> modifiers = method.getModifiers();
aoqi@0 480 boolean staticFinal = modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.FINAL);
aoqi@0 481 if (staticFinal) {
aoqi@0 482 if (webMethod != null) {
aoqi@0 483 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_METHOD_IS_STATIC_OR_FINAL(method.getEnclosingElement(),
aoqi@0 484 method), method);
aoqi@0 485 }
aoqi@0 486 return false;
aoqi@0 487 }
aoqi@0 488 boolean result = (endpointReferencesInterface ||
aoqi@0 489 method.getEnclosingElement().equals(typeElement) ||
aoqi@0 490 (method.getEnclosingElement().getAnnotation(WebService.class) != null));
aoqi@0 491 builder.log("endpointReferencesInterface: " + endpointReferencesInterface);
aoqi@0 492 builder.log("declaring class has WebService: " + (method.getEnclosingElement().getAnnotation(WebService.class) != null));
aoqi@0 493 builder.log("returning: " + result);
aoqi@0 494 return result;
aoqi@0 495 }
aoqi@0 496
aoqi@0 497 abstract protected void processMethod(ExecutableElement method, WebMethod webMethod);
aoqi@0 498
aoqi@0 499 protected boolean isLegalImplementation(WebService webService, TypeElement classElement) {
aoqi@0 500 boolean isStateful = isStateful(classElement);
aoqi@0 501
aoqi@0 502 Collection<Modifier> modifiers = classElement.getModifiers();
aoqi@0 503 if (!modifiers.contains(Modifier.PUBLIC)) {
aoqi@0 504 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_NOT_PUBLIC(classElement.getQualifiedName()), classElement);
aoqi@0 505 return false;
aoqi@0 506 }
aoqi@0 507 if (modifiers.contains(Modifier.FINAL) && !isStateful) {
aoqi@0 508 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_FINAL(classElement.getQualifiedName()), classElement);
aoqi@0 509 return false;
aoqi@0 510 }
aoqi@0 511 if (modifiers.contains(Modifier.ABSTRACT) && !isStateful) {
aoqi@0 512 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_ABSTRACT(classElement.getQualifiedName()), classElement);
aoqi@0 513 return false;
aoqi@0 514 }
aoqi@0 515 boolean hasDefaultConstructor = false;
aoqi@0 516 for (ExecutableElement constructor : ElementFilter.constructorsIn(classElement.getEnclosedElements())) {
aoqi@0 517 if (constructor.getModifiers().contains(Modifier.PUBLIC) &&
aoqi@0 518 constructor.getParameters().isEmpty()) {
aoqi@0 519 hasDefaultConstructor = true;
aoqi@0 520 break;
aoqi@0 521 }
aoqi@0 522 }
aoqi@0 523 if (!hasDefaultConstructor && !isStateful) {
aoqi@0 524 if (classElement.getEnclosingElement() != null && !modifiers.contains(Modifier.STATIC)) {
aoqi@0 525 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_INNERCLASS_NOT_STATIC(
aoqi@0 526 classElement.getQualifiedName()), classElement);
aoqi@0 527 return false;
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_NO_DEFAULT_CONSTRUCTOR(
aoqi@0 531 classElement.getQualifiedName()), classElement);
aoqi@0 532 return false;
aoqi@0 533 }
aoqi@0 534 if (webService.endpointInterface().isEmpty()) {
aoqi@0 535 if (!methodsAreLegal(classElement))
aoqi@0 536 return false;
aoqi@0 537 } else {
aoqi@0 538 TypeElement interfaceElement = getEndpointInterfaceElement(webService.endpointInterface(), classElement);
aoqi@0 539 if (!classImplementsSei(classElement, interfaceElement))
aoqi@0 540 return false;
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 return true;
aoqi@0 544 }
aoqi@0 545
aoqi@0 546 private boolean isStateful(TypeElement classElement) {
aoqi@0 547 try {
aoqi@0 548 // We don't want dependency on rt-ha module as its not integrated in JDK
aoqi@0 549 return classElement.getAnnotation((Class<? extends Annotation>) Class.forName("com.sun.xml.internal.ws.developer.Stateful")) != null;
aoqi@0 550 } catch (ClassNotFoundException e) {
aoqi@0 551 //ignore
aoqi@0 552 }
aoqi@0 553 return false;
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 protected boolean classImplementsSei(TypeElement classElement, TypeElement interfaceElement) {
aoqi@0 557 for (TypeMirror interfaceType : classElement.getInterfaces()) {
aoqi@0 558 if (((DeclaredType) interfaceType).asElement().equals(interfaceElement))
aoqi@0 559 return true;
aoqi@0 560 }
aoqi@0 561 List<ExecutableElement> classMethods = getClassMethods(classElement);
aoqi@0 562 boolean implementsMethod;
aoqi@0 563 for (ExecutableElement interfaceMethod : ElementFilter.methodsIn(interfaceElement.getEnclosedElements())) {
aoqi@0 564 implementsMethod = false;
aoqi@0 565 for (ExecutableElement classMethod : classMethods) {
aoqi@0 566 if (sameMethod(interfaceMethod, classMethod)) {
aoqi@0 567 implementsMethod = true;
aoqi@0 568 classMethods.remove(classMethod);
aoqi@0 569 break;
aoqi@0 570 }
aoqi@0 571 }
aoqi@0 572 if (!implementsMethod) {
aoqi@0 573 builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_NOT_IMPLEMENTED(interfaceElement.getSimpleName(), classElement.getSimpleName(), interfaceMethod), interfaceMethod);
aoqi@0 574 return false;
aoqi@0 575 }
aoqi@0 576 }
aoqi@0 577 return true;
aoqi@0 578 }
aoqi@0 579
aoqi@0 580 private static List<ExecutableElement> getClassMethods(TypeElement classElement) {
aoqi@0 581 if (classElement.getQualifiedName().toString().equals(Object.class.getName())) // we don't need Object's methods
aoqi@0 582 return null;
aoqi@0 583 TypeElement superclassElement = (TypeElement) ((DeclaredType) classElement.getSuperclass()).asElement();
aoqi@0 584 List<ExecutableElement> superclassesMethods = getClassMethods(superclassElement);
aoqi@0 585 List<ExecutableElement> classMethods = ElementFilter.methodsIn(classElement.getEnclosedElements());
aoqi@0 586 if (superclassesMethods == null)
aoqi@0 587 return classMethods;
aoqi@0 588 else
aoqi@0 589 superclassesMethods.addAll(classMethods);
aoqi@0 590 return superclassesMethods;
aoqi@0 591 }
aoqi@0 592
aoqi@0 593 protected boolean sameMethod(ExecutableElement method1, ExecutableElement method2) {
aoqi@0 594 if (!method1.getSimpleName().equals(method2.getSimpleName()))
aoqi@0 595 return false;
aoqi@0 596 Types typeUtils = builder.getProcessingEnvironment().getTypeUtils();
aoqi@0 597 if(!typeUtils.isSameType(method1.getReturnType(), method2.getReturnType())
aoqi@0 598 && !typeUtils.isSubtype(method2.getReturnType(), method1.getReturnType()))
aoqi@0 599 return false;
aoqi@0 600 List<? extends VariableElement> parameters1 = method1.getParameters();
aoqi@0 601 List<? extends VariableElement> parameters2 = method2.getParameters();
aoqi@0 602 if (parameters1.size() != parameters2.size())
aoqi@0 603 return false;
aoqi@0 604 for (int i = 0; i < parameters1.size(); i++) {
aoqi@0 605 if (!typeUtils.isSameType(parameters1.get(i).asType(), parameters2.get(i).asType()))
aoqi@0 606 return false;
aoqi@0 607 }
aoqi@0 608 return true;
aoqi@0 609 }
aoqi@0 610
aoqi@0 611 protected boolean isLegalSei(TypeElement interfaceElement) {
aoqi@0 612 for (VariableElement field : ElementFilter.fieldsIn(interfaceElement.getEnclosedElements()))
aoqi@0 613 if (field.getConstantValue() != null) {
aoqi@0 614 builder.processError(WebserviceapMessages.WEBSERVICEAP_SEI_CANNOT_CONTAIN_CONSTANT_VALUES(
aoqi@0 615 interfaceElement.getQualifiedName(), field.getSimpleName()));
aoqi@0 616 return false;
aoqi@0 617 }
aoqi@0 618 return methodsAreLegal(interfaceElement);
aoqi@0 619 }
aoqi@0 620
aoqi@0 621 protected boolean methodsAreLegal(TypeElement element) {
aoqi@0 622 switch (element.getKind()) {
aoqi@0 623 case INTERFACE: {
aoqi@0 624 hasWebMethods = false;
aoqi@0 625 for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
aoqi@0 626 if (!isLegalMethod(method, element))
aoqi@0 627 return false;
aoqi@0 628 }
aoqi@0 629 for (TypeMirror superInterface : element.getInterfaces()) {
aoqi@0 630 if (!methodsAreLegal((TypeElement) ((DeclaredType) superInterface).asElement()))
aoqi@0 631 return false;
aoqi@0 632 }
aoqi@0 633 return true;
aoqi@0 634 }
aoqi@0 635 case CLASS: {
aoqi@0 636 hasWebMethods = hasWebMethods(element);
aoqi@0 637 for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
aoqi@0 638 if (!method.getModifiers().contains(Modifier.PUBLIC))
aoqi@0 639 continue; // let's validate only public methods
aoqi@0 640 if (!isLegalMethod(method, element))
aoqi@0 641 return false;
aoqi@0 642 }
aoqi@0 643 DeclaredType superClass = (DeclaredType) element.getSuperclass();
aoqi@0 644
aoqi@0 645 TypeElement tE = (TypeElement) superClass.asElement();
aoqi@0 646 return tE.getQualifiedName().toString().equals(Object.class.getName())
aoqi@0 647 || methodsAreLegal(tE);
aoqi@0 648 }
aoqi@0 649 default: {
aoqi@0 650 throw new IllegalArgumentException("Class or interface was expecting. But element: " + element);
aoqi@0 651 }
aoqi@0 652 }
aoqi@0 653 }
aoqi@0 654
aoqi@0 655 protected boolean isLegalMethod(ExecutableElement method, TypeElement typeElement) {
aoqi@0 656 WebMethod webMethod = method.getAnnotation(WebMethod.class);
aoqi@0 657 //SEI cannot have methods with @WebMethod(exclude=true)
aoqi@0 658 if (typeElement.getKind().equals(ElementKind.INTERFACE) && webMethod != null && webMethod.exclude())
aoqi@0 659 builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SEI_ANNOTATION_ELEMENT_EXCLUDE("exclude=true", typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 660 // With https://jax-ws.dev.java.net/issues/show_bug.cgi?id=577, hasWebMethods has no effect
aoqi@0 661 if (hasWebMethods && webMethod == null) // backwards compatibility (for legacyWebMethod computation)
aoqi@0 662 return true;
aoqi@0 663
aoqi@0 664 if ((webMethod != null) && webMethod.exclude()) {
aoqi@0 665 return true;
aoqi@0 666 }
aoqi@0 667 /*
aoqi@0 668 This check is not needed as Impl class is already checked that it is not abstract.
aoqi@0 669 if (typeElement instanceof TypeElement && method.getModifiers().contains(Modifier.ABSTRACT)) { // use Kind.equals instead of instanceOf
aoqi@0 670 builder.processError(method.getPosition(), WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_METHOD_IS_ABSTRACT(typeElement.getQualifiedName(), method.getSimpleName()));
aoqi@0 671 return false;
aoqi@0 672 }
aoqi@0 673 */
aoqi@0 674 TypeMirror returnType = method.getReturnType();
aoqi@0 675 if (!isLegalType(returnType)) {
aoqi@0 676 builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_RETURN_TYPE_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(),
aoqi@0 677 method.getSimpleName(),
aoqi@0 678 returnType), method);
aoqi@0 679 }
aoqi@0 680 boolean isOneWay = method.getAnnotation(Oneway.class) != null;
aoqi@0 681 if (isOneWay && !isValidOneWayMethod(method, typeElement))
aoqi@0 682 return false;
aoqi@0 683
aoqi@0 684 SOAPBinding soapBinding = method.getAnnotation(SOAPBinding.class);
aoqi@0 685 if (soapBinding != null) {
aoqi@0 686 if (soapBinding.style().equals(SOAPBinding.Style.RPC)) {
aoqi@0 687 builder.processError(WebserviceapMessages.WEBSERVICEAP_RPC_SOAPBINDING_NOT_ALLOWED_ON_METHOD(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 688 }
aoqi@0 689 }
aoqi@0 690
aoqi@0 691 int paramIndex = 0;
aoqi@0 692 for (VariableElement parameter : method.getParameters()) {
aoqi@0 693 if (!isLegalParameter(parameter, method, typeElement, paramIndex++))
aoqi@0 694 return false;
aoqi@0 695 }
aoqi@0 696
aoqi@0 697 if (!isDocLitWrapped() && soapStyle.equals(SOAPStyle.DOCUMENT)) {
aoqi@0 698 VariableElement outParam = getOutParameter(method);
aoqi@0 699 int inParams = getModeParameterCount(method, WebParam.Mode.IN);
aoqi@0 700 int outParams = getModeParameterCount(method, WebParam.Mode.OUT);
aoqi@0 701 if (inParams != 1) {
aoqi@0 702 builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_AND_NO_ONE_IN(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 703 }
aoqi@0 704 if (returnType.accept(NO_TYPE_VISITOR, null)) {
aoqi@0 705 if (outParam == null && !isOneWay) {
aoqi@0 706 builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_NO_OUT(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 707 }
aoqi@0 708 if (outParams != 1) {
aoqi@0 709 if (!isOneWay && outParams != 0)
aoqi@0 710 builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_NO_RETURN_AND_NO_OUT(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 711 }
aoqi@0 712 } else {
aoqi@0 713 if (outParams > 0) {
aoqi@0 714 builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_RETURN_AND_OUT(typeElement.getQualifiedName(), method.toString()), outParam);
aoqi@0 715 }
aoqi@0 716 }
aoqi@0 717 }
aoqi@0 718 return true;
aoqi@0 719 }
aoqi@0 720
aoqi@0 721 protected boolean isLegalParameter(VariableElement param,
aoqi@0 722 ExecutableElement method,
aoqi@0 723 TypeElement typeElement,
aoqi@0 724 int paramIndex) {
aoqi@0 725 if (!isLegalType(param.asType())) {
aoqi@0 726 builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_PARAMETER_TYPES_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(),
aoqi@0 727 method.getSimpleName(),
aoqi@0 728 param.getSimpleName(),
aoqi@0 729 param.asType().toString()), param);
aoqi@0 730 return false;
aoqi@0 731 }
aoqi@0 732 TypeMirror holderType;
aoqi@0 733 holderType = builder.getHolderValueType(param.asType());
aoqi@0 734 WebParam webParam = param.getAnnotation(WebParam.class);
aoqi@0 735 WebParam.Mode mode = null;
aoqi@0 736 if (webParam != null)
aoqi@0 737 mode = webParam.mode();
aoqi@0 738
aoqi@0 739 if (holderType != null) {
aoqi@0 740 if (mode != null && mode == WebParam.Mode.IN)
aoqi@0 741 builder.processError(WebserviceapMessages.WEBSERVICEAP_HOLDER_PARAMETERS_MUST_NOT_BE_IN_ONLY(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
aoqi@0 742 } else if (mode != null && mode != WebParam.Mode.IN) {
aoqi@0 743 builder.processError(WebserviceapMessages.WEBSERVICEAP_NON_IN_PARAMETERS_MUST_BE_HOLDER(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
aoqi@0 744 }
aoqi@0 745
aoqi@0 746 return true;
aoqi@0 747 }
aoqi@0 748
aoqi@0 749 protected boolean isDocLitWrapped() {
aoqi@0 750 return soapStyle.equals(SOAPStyle.DOCUMENT) && wrapped;
aoqi@0 751 }
aoqi@0 752
aoqi@0 753 private static final class NoTypeVisitor extends SimpleTypeVisitor6<Boolean, Void> {
aoqi@0 754
aoqi@0 755 @Override
aoqi@0 756 public Boolean visitNoType(NoType t, Void o) {
aoqi@0 757 return true;
aoqi@0 758 }
aoqi@0 759
aoqi@0 760 @Override
aoqi@0 761 protected Boolean defaultAction(TypeMirror e, Void aVoid) {
aoqi@0 762 return false;
aoqi@0 763 }
aoqi@0 764 }
aoqi@0 765
aoqi@0 766 protected boolean isValidOneWayMethod(ExecutableElement method, TypeElement typeElement) {
aoqi@0 767 boolean valid = true;
aoqi@0 768 if (!(method.getReturnType().accept(NO_TYPE_VISITOR, null))) {
aoqi@0 769 // this is an error, cannot be OneWay and have a return type
aoqi@0 770 builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_HAVE_RETURN_TYPE(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 771 valid = false;
aoqi@0 772 }
aoqi@0 773 VariableElement outParam = getOutParameter(method);
aoqi@0 774 if (outParam != null) {
aoqi@0 775 builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_OUT(typeElement.getQualifiedName(), method.toString()), outParam);
aoqi@0 776 valid = false;
aoqi@0 777 }
aoqi@0 778 if (!isDocLitWrapped() && soapStyle.equals(SOAPStyle.DOCUMENT)) {
aoqi@0 779 int inCnt = getModeParameterCount(method, WebParam.Mode.IN);
aoqi@0 780 if (inCnt != 1) {
aoqi@0 781 builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_NOT_ONE_IN(typeElement.getQualifiedName(), method.toString()), method);
aoqi@0 782 valid = false;
aoqi@0 783 }
aoqi@0 784 }
aoqi@0 785 for (TypeMirror thrownType : method.getThrownTypes()) {
aoqi@0 786 TypeElement thrownElement = (TypeElement) ((DeclaredType) thrownType).asElement();
aoqi@0 787 if (builder.isServiceException(thrownType)) {
aoqi@0 788 builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_DECLARE_EXCEPTIONS(
aoqi@0 789 typeElement.getQualifiedName(), method.toString(), thrownElement.getQualifiedName()), method);
aoqi@0 790 valid = false;
aoqi@0 791 }
aoqi@0 792 }
aoqi@0 793 return valid;
aoqi@0 794 }
aoqi@0 795
aoqi@0 796 protected int getModeParameterCount(ExecutableElement method, WebParam.Mode mode) {
aoqi@0 797 WebParam webParam;
aoqi@0 798 int cnt = 0;
aoqi@0 799 for (VariableElement param : method.getParameters()) {
aoqi@0 800 webParam = param.getAnnotation(WebParam.class);
aoqi@0 801 if (webParam != null) {
aoqi@0 802 if (webParam.header())
aoqi@0 803 continue;
aoqi@0 804 if (isEquivalentModes(mode, webParam.mode()))
aoqi@0 805 cnt++;
aoqi@0 806 } else {
aoqi@0 807 if (isEquivalentModes(mode, WebParam.Mode.IN)) {
aoqi@0 808 cnt++;
aoqi@0 809 }
aoqi@0 810 }
aoqi@0 811 }
aoqi@0 812 return cnt;
aoqi@0 813 }
aoqi@0 814
aoqi@0 815 protected boolean isEquivalentModes(WebParam.Mode mode1, WebParam.Mode mode2) {
aoqi@0 816 if (mode1.equals(mode2))
aoqi@0 817 return true;
aoqi@0 818 assert mode1 == WebParam.Mode.IN || mode1 == WebParam.Mode.OUT;
aoqi@0 819 return (mode1 == WebParam.Mode.IN && mode2 != WebParam.Mode.OUT) || (mode1 == WebParam.Mode.OUT && mode2 != WebParam.Mode.IN);
aoqi@0 820 }
aoqi@0 821
aoqi@0 822 protected boolean isHolder(VariableElement param) {
aoqi@0 823 return builder.getHolderValueType(param.asType()) != null;
aoqi@0 824 }
aoqi@0 825
aoqi@0 826 protected boolean isLegalType(TypeMirror type) {
aoqi@0 827 if (!(type != null && type.getKind().equals(TypeKind.DECLARED)))
aoqi@0 828 return true;
aoqi@0 829 TypeElement tE = (TypeElement) ((DeclaredType) type).asElement();
aoqi@0 830 if (tE == null) {
aoqi@0 831 // can be null, if this type's declaration is unknown. This may be the result of a processing error, such as a missing class file.
aoqi@0 832 builder.processError(WebserviceapMessages.WEBSERVICEAP_COULD_NOT_FIND_TYPEDECL(type.toString(), context.getRound()));
aoqi@0 833 }
aoqi@0 834 return !builder.isRemote(tE);
aoqi@0 835 }
aoqi@0 836
aoqi@0 837 protected VariableElement getOutParameter(ExecutableElement method) {
aoqi@0 838 WebParam webParam;
aoqi@0 839 for (VariableElement param : method.getParameters()) {
aoqi@0 840 webParam = param.getAnnotation(WebParam.class);
aoqi@0 841 if (webParam != null && webParam.mode() != WebParam.Mode.IN) {
aoqi@0 842 return param;
aoqi@0 843 }
aoqi@0 844 }
aoqi@0 845 return null;
aoqi@0 846 }
aoqi@0 847
aoqi@0 848 protected static class MySoapBinding implements SOAPBinding {
aoqi@0 849
aoqi@0 850 @Override
aoqi@0 851 public Style style() {
aoqi@0 852 return SOAPBinding.Style.DOCUMENT;
aoqi@0 853 }
aoqi@0 854
aoqi@0 855 @Override
aoqi@0 856 public Use use() {
aoqi@0 857 return SOAPBinding.Use.LITERAL;
aoqi@0 858 }
aoqi@0 859
aoqi@0 860 @Override
aoqi@0 861 public ParameterStyle parameterStyle() {
aoqi@0 862 return SOAPBinding.ParameterStyle.WRAPPED;
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 @Override
aoqi@0 866 public Class<? extends java.lang.annotation.Annotation> annotationType() {
aoqi@0 867 return SOAPBinding.class;
aoqi@0 868 }
aoqi@0 869 }
aoqi@0 870 }

mercurial