src/share/jaxws_classes/com/sun/xml/internal/ws/model/RuntimeModeler.java

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 450
b0c2840e2513
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.model;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
alanb@368 29 import com.sun.istack.internal.localization.Localizable;
ohair@286 30 import com.sun.xml.internal.ws.api.BindingID;
ohair@286 31 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 32 import com.sun.xml.internal.ws.api.WSBinding;
ohair@286 33 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
ohair@286 34 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
ohair@286 35 import com.sun.xml.internal.ws.api.model.ExceptionType;
ohair@286 36 import com.sun.xml.internal.ws.api.model.MEP;
ohair@286 37 import com.sun.xml.internal.ws.api.model.Parameter;
ohair@286 38 import com.sun.xml.internal.ws.api.model.ParameterBinding;
ohair@286 39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
ohair@286 40 import com.sun.xml.internal.ws.api.model.wsdl.WSDLInput;
ohair@286 41 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPart;
ohair@286 42 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 43 import com.sun.xml.internal.ws.binding.WebServiceFeatureList;
ohair@286 44 import com.sun.xml.internal.ws.model.soap.SOAPBindingImpl;
ohair@286 45 import com.sun.xml.internal.ws.resources.ModelerMessages;
ohair@286 46 import com.sun.xml.internal.ws.resources.ServerMessages;
ohair@286 47 import com.sun.xml.internal.ws.spi.db.BindingContext;
ohair@286 48 import com.sun.xml.internal.ws.spi.db.TypeInfo;
ohair@286 49 import com.sun.xml.internal.ws.spi.db.WrapperComposite;
alanb@368 50
alanb@368 51 import static com.sun.xml.internal.ws.binding.WebServiceFeatureList.getSoapVersion;
ohair@286 52
ohair@286 53 import javax.jws.*;
ohair@286 54 import javax.jws.WebParam.Mode;
ohair@286 55 import javax.jws.soap.SOAPBinding;
ohair@286 56 import javax.jws.soap.SOAPBinding.Style;
ohair@286 57 import javax.xml.bind.annotation.XmlElement;
ohair@286 58 import javax.xml.bind.annotation.XmlSeeAlso;
ohair@286 59 import javax.xml.namespace.QName;
ohair@286 60 import javax.xml.ws.*;
ohair@286 61 import javax.xml.ws.soap.MTOM;
ohair@286 62 import javax.xml.ws.soap.MTOMFeature;
ohair@286 63 import java.lang.annotation.Annotation;
ohair@286 64 import java.lang.reflect.Method;
ohair@286 65 import java.lang.reflect.Modifier;
ohair@286 66 import java.lang.reflect.ParameterizedType;
ohair@286 67 import java.lang.reflect.Type;
ohair@286 68 import java.rmi.RemoteException;
ohair@286 69 import java.security.AccessController;
ohair@286 70 import java.util.HashSet;
ohair@286 71 import java.util.Map;
ohair@286 72 import java.util.Set;
ohair@286 73 import java.util.StringTokenizer;
ohair@286 74 import java.util.TreeMap;
ohair@286 75 import java.util.concurrent.Future;
ohair@286 76 import java.util.logging.Logger;
ohair@286 77
ohair@286 78 import static javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED;
ohair@286 79
ohair@286 80 /**
ohair@286 81 * Creates a runtime model of a SEI (portClass).
ohair@286 82 *
ohair@286 83 * @author WS Developement Team
ohair@286 84 */
ohair@286 85 public class RuntimeModeler {
ohair@286 86 private final WebServiceFeatureList features;
ohair@286 87 private BindingID bindingId;
ohair@286 88 private WSBinding wsBinding;
ohair@286 89 private final Class portClass;
ohair@286 90 private AbstractSEIModelImpl model;
ohair@286 91 private SOAPBindingImpl defaultBinding;
ohair@286 92 // can be empty but never null
ohair@286 93 private String packageName;
ohair@286 94 private String targetNamespace;
ohair@286 95 private boolean isWrapped = true;
ohair@286 96 private ClassLoader classLoader;
ohair@286 97 private final WSDLPort binding;
ohair@286 98 private QName serviceName;
ohair@286 99 private QName portName;
ohair@286 100 private Set<Class> classUsesWebMethod;
ohair@286 101 private DatabindingConfig config;
ohair@286 102 private MetadataReader metadataReader;
ohair@286 103 /**
ohair@286 104 *
ohair@286 105 */
ohair@286 106 public static final String PD_JAXWS_PACKAGE_PD = ".jaxws.";
ohair@286 107 /**
ohair@286 108 *
ohair@286 109 */
ohair@286 110 public static final String JAXWS_PACKAGE_PD = "jaxws.";
ohair@286 111 public static final String RESPONSE = "Response";
ohair@286 112 public static final String RETURN = "return";
ohair@286 113 public static final String BEAN = "Bean";
ohair@286 114 public static final String SERVICE = "Service";
ohair@286 115 public static final String PORT = "Port";
ohair@286 116 public static final Class HOLDER_CLASS = Holder.class;
ohair@286 117 public static final Class<RemoteException> REMOTE_EXCEPTION_CLASS = RemoteException.class;
ohair@286 118 public static final Class<RuntimeException> RUNTIME_EXCEPTION_CLASS = RuntimeException.class;
ohair@286 119 public static final Class<Exception> EXCEPTION_CLASS = Exception.class;
alanb@368 120 public static final String DecapitalizeExceptionBeanProperties = "com.sun.xml.internal.ws.api.model.DecapitalizeExceptionBeanProperties";
alanb@368 121 public static final String SuppressDocLitWrapperGeneration = "com.sun.xml.internal.ws.api.model.SuppressDocLitWrapperGeneration";
alanb@368 122 public static final String DocWrappeeNamespapceQualified = "com.sun.xml.internal.ws.api.model.DocWrappeeNamespapceQualified";
ohair@286 123
ohair@286 124 /*public RuntimeModeler(@NotNull Class portClass, @NotNull QName serviceName, @NotNull BindingID bindingId, @NotNull WebServiceFeature... features) {
ohair@286 125 this(portClass, serviceName, null, bindingId, features);
ohair@286 126 }*/
ohair@286 127
ohair@286 128 /**
ohair@286 129 *
ohair@286 130 * creates an instance of RunTimeModeler given a <code>sei</code> and <code>binding</code>
ohair@286 131 * @param portClass The SEI class to be modeled.
ohair@286 132 * @param serviceName The ServiceName to use instead of one calculated from the implementation class
ohair@286 133 * @param wsdlPort {@link com.sun.xml.internal.ws.api.model.wsdl.WSDLPort}
ohair@286 134 * @param features web service features
ohair@286 135 */
ohair@286 136 /*public RuntimeModeler(@NotNull Class portClass, @NotNull QName serviceName, @NotNull WSDLPortImpl wsdlPort, @NotNull WebServiceFeature... features){
ohair@286 137 this(portClass, serviceName, wsdlPort, wsdlPort.getBinding().getBindingId(), features);
ohair@286 138 }*/
ohair@286 139
ohair@286 140 /*private RuntimeModeler(@NotNull Class portClass, @NotNull QName serviceName, WSDLPortImpl binding, BindingID bindingId, @NotNull WebServiceFeature... features) {
ohair@286 141 this.portClass = portClass;
ohair@286 142 this.serviceName = serviceName;
ohair@286 143 this.binding = binding;
ohair@286 144 this.bindingId = bindingId;
ohair@286 145 this.features = features;
ohair@286 146 }*/
ohair@286 147
ohair@286 148 public RuntimeModeler(@NotNull DatabindingConfig config){
ohair@286 149 this.portClass = (config.getEndpointClass() != null)? config.getEndpointClass() : config.getContractClass();
ohair@286 150 this.serviceName = config.getMappingInfo().getServiceName();
ohair@286 151 this.binding = config.getWsdlPort();
ohair@286 152 this.classLoader = config.getClassLoader();
ohair@286 153 this.portName = config.getMappingInfo().getPortName();
ohair@286 154 this.config = config;
ohair@286 155 this.wsBinding = config.getWSBinding();
ohair@286 156 metadataReader = config.getMetadataReader();
alanb@368 157 targetNamespace = config.getMappingInfo().getTargetNamespace();
ohair@286 158 if (metadataReader == null) metadataReader = new ReflectAnnotationReader();
ohair@286 159 if (wsBinding != null) {
ohair@286 160 this.bindingId = wsBinding.getBindingId();
ohair@286 161 if (config.getFeatures() != null) wsBinding.getFeatures().mergeFeatures(config.getFeatures(), false);
ohair@286 162 if (binding != null) wsBinding.getFeatures().mergeFeatures(binding.getFeatures(), false);
ohair@286 163 this.features = WebServiceFeatureList.toList(wsBinding.getFeatures());
ohair@286 164 } else {
ohair@286 165 this.bindingId = config.getMappingInfo().getBindingID();
alanb@368 166 this.features = WebServiceFeatureList.toList(config.getFeatures());
ohair@286 167 if (binding != null) bindingId = binding.getBinding().getBindingId();
ohair@286 168 if (bindingId == null) bindingId = getDefaultBindingID();
ohair@286 169 if (!features.contains(MTOMFeature.class)) {
ohair@286 170 MTOM mtomAn = getAnnotation(portClass, MTOM.class);
ohair@286 171 if (mtomAn != null) features.add(WebServiceFeatureList.getFeature(mtomAn));
ohair@286 172 }
alanb@368 173 if (!features.contains(com.oracle.webservices.internal.api.EnvelopeStyleFeature.class)) {
alanb@368 174 com.oracle.webservices.internal.api.EnvelopeStyle es = getAnnotation(portClass, com.oracle.webservices.internal.api.EnvelopeStyle.class);
alanb@368 175 if (es != null) features.add(WebServiceFeatureList.getFeature(es));
alanb@368 176 }
ohair@286 177 this.wsBinding = bindingId.createBinding(features);
ohair@286 178 }
ohair@286 179 }
ohair@286 180
ohair@286 181 private BindingID getDefaultBindingID() {
ohair@286 182 BindingType bt = getAnnotation(portClass, BindingType.class);
alanb@368 183 if (bt != null) return BindingID.parse(bt.value());
alanb@368 184 SOAPVersion ver = getSoapVersion(features);
alanb@368 185 boolean mtomEnabled = features.isEnabled(MTOMFeature.class);
alanb@368 186 if (SOAPVersion.SOAP_12.equals(ver)) {
alanb@368 187 return (mtomEnabled) ? BindingID.SOAP12_HTTP_MTOM : BindingID.SOAP12_HTTP;
alanb@368 188 } else {
alanb@368 189 return (mtomEnabled) ? BindingID.SOAP11_HTTP_MTOM : BindingID.SOAP11_HTTP;
alanb@368 190 }
ohair@286 191 }
ohair@286 192
ohair@286 193 /**
ohair@286 194 * sets the classloader to be used when loading classes by the <code>RuntimeModeler</code>.
ohair@286 195 * @param classLoader ClassLoader used to load classes
ohair@286 196 */
ohair@286 197 public void setClassLoader(ClassLoader classLoader) {
ohair@286 198 this.classLoader = classLoader;
ohair@286 199 }
ohair@286 200
ohair@286 201 /**
ohair@286 202 * sets the PortName to be used by the <code>RuntimeModeler</code>.
ohair@286 203 * @param portName The PortName to be used instead of the PortName
ohair@286 204 * retrieved via annotations
ohair@286 205 */
ohair@286 206 public void setPortName(QName portName) {
ohair@286 207 this.portName = portName;
ohair@286 208 }
ohair@286 209
ohair@286 210 private <T extends Annotation> T getAnnotation(final Class<?> clazz, final Class<T> T) {
ohair@286 211 return metadataReader.getAnnotation(T, clazz);
ohair@286 212 }
ohair@286 213
ohair@286 214 private <T extends Annotation> T getAnnotation(final Method method, final Class<T> T) {
ohair@286 215 return metadataReader.getAnnotation(T, method);
ohair@286 216 }
ohair@286 217
ohair@286 218 private Annotation[] getAnnotations(final Method method) {
ohair@286 219 return metadataReader.getAnnotations(method);
ohair@286 220 }
ohair@286 221
ohair@286 222 private Annotation[] getAnnotations(final Class<?> c) {
ohair@286 223 return metadataReader.getAnnotations(c);
ohair@286 224 }
ohair@286 225 private Annotation[][] getParamAnnotations(final Method method) {
ohair@286 226 return metadataReader.getParameterAnnotations(method);
ohair@286 227 }
ohair@286 228
ohair@286 229 private static final Logger logger =
ohair@286 230 Logger.getLogger(
ohair@286 231 com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".server");
ohair@286 232
ohair@286 233 //currently has many local vars which will be eliminated after debugging issues
ohair@286 234 //first draft
ohair@286 235 /**
ohair@286 236 * builds the runtime model from the <code>portClass</code> using the binding ID <code>bindingId</code>.
ohair@286 237 * @return the runtime model for the <code>portClass</code>.
ohair@286 238 */
ohair@286 239 public AbstractSEIModelImpl buildRuntimeModel() {
ohair@286 240 model = new SOAPSEIModel(features);
ohair@286 241 model.contractClass = config.getContractClass();
ohair@286 242 model.endpointClass = config.getEndpointClass();
ohair@286 243 model.classLoader = this.classLoader;
ohair@286 244 model.wsBinding = wsBinding;
mkos@384 245 model.databindingInfo.setWsdlURL(config.getWsdlURL());
ohair@286 246 model.databindingInfo.properties().putAll(config.properties());
ohair@286 247 if (model.contractClass == null) model.contractClass = portClass;
ohair@286 248 if (model.endpointClass == null && !portClass.isInterface()) model.endpointClass = portClass;
ohair@286 249 Class<?> seiClass = portClass;
ohair@286 250 metadataReader.getProperties(model.databindingInfo.properties(), portClass);
ohair@286 251 WebService webService = getAnnotation(portClass, WebService.class);
ohair@286 252 if (webService == null) {
ohair@286 253 throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation",
ohair@286 254 portClass.getCanonicalName());
ohair@286 255 }
ohair@286 256 Class<?> seiFromConfig = configEndpointInterface();
ohair@286 257 if (webService.endpointInterface().length() > 0 || seiFromConfig != null) {
ohair@286 258 if (seiFromConfig != null) {
ohair@286 259 seiClass = seiFromConfig;
ohair@286 260 } else {
ohair@286 261 seiClass = getClass(webService.endpointInterface(), ModelerMessages.localizableRUNTIME_MODELER_CLASS_NOT_FOUND(webService.endpointInterface()));
ohair@286 262 }
ohair@286 263 model.contractClass = seiClass;
ohair@286 264 model.endpointClass = portClass;
ohair@286 265 WebService seiService = getAnnotation(seiClass, WebService.class);
ohair@286 266 if (seiService == null) {
ohair@286 267 throw new RuntimeModelerException("runtime.modeler.endpoint.interface.no.webservice",
ohair@286 268 webService.endpointInterface());
ohair@286 269 }
ohair@286 270
ohair@286 271 //check if @SOAPBinding is defined on the impl class
ohair@286 272 SOAPBinding sbPortClass = getAnnotation(portClass, SOAPBinding.class);
ohair@286 273 SOAPBinding sbSei = getAnnotation(seiClass, SOAPBinding.class);
ohair@286 274 if(sbPortClass != null){
ohair@286 275 if(sbSei == null || sbSei.style() != sbPortClass.style()|| sbSei.use() != sbPortClass.use()){
ohair@286 276 logger.warning(ServerMessages.RUNTIMEMODELER_INVALIDANNOTATION_ON_IMPL("@SOAPBinding", portClass.getName(), seiClass.getName()));
ohair@286 277 }
ohair@286 278 }
ohair@286 279 }
ohair@286 280 if (serviceName == null)
ohair@286 281 serviceName = getServiceName(portClass, metadataReader);
ohair@286 282 model.setServiceQName(serviceName);
ohair@286 283
ohair@286 284 // String portLocalName = portClass.getSimpleName()+PORT;
ohair@286 285 // if (webService.portName().length() >0) {
ohair@286 286 // portLocalName = webService.portName();
ohair@286 287 // } else if (webService.name().length() >0) {
ohair@286 288 // portLocalName = webService.name()+PORT;
ohair@286 289 // }
ohair@286 290 //
ohair@286 291 // if (portName == null)
ohair@286 292 // portName = new QName(serviceName.getNamespaceURI(), portLocalName);
ohair@286 293 // if (!portName.getNamespaceURI().equals(serviceName.getNamespaceURI())) {
ohair@286 294 // throw new RuntimeModelerException("runtime.modeler.portname.servicename.namespace.mismatch",
ohair@286 295 // serviceName, portName);
ohair@286 296 // }
ohair@286 297
alanb@368 298 if (portName == null) portName = getPortName(portClass, metadataReader, serviceName.getNamespaceURI());
ohair@286 299 model.setPortName(portName);
ohair@286 300
ohair@286 301 // Check if databinding is overridden in annotation.
alanb@368 302 com.oracle.webservices.internal.api.databinding.DatabindingMode dbm2 = getAnnotation(portClass, com.oracle.webservices.internal.api.databinding.DatabindingMode.class);
alanb@368 303 if (dbm2 != null) model.databindingInfo.setDatabindingMode(dbm2.value());
ohair@286 304
ohair@286 305 processClass(seiClass);
ohair@286 306 if (model.getJavaMethods().size() == 0)
ohair@286 307 throw new RuntimeModelerException("runtime.modeler.no.operations",
ohair@286 308 portClass.getName());
ohair@286 309 model.postProcess();
ohair@286 310
ohair@286 311 // Make the configured databinding mode available to the
ohair@286 312 // DatabindingConfig.
ohair@286 313 config.properties().put(BindingContext.class.getName(),
ohair@286 314 model.bindingContext);
ohair@286 315
ohair@286 316 // TODO: this needs to be fixed properly --
ohair@286 317 // when we are building RuntimeModel first before building WSDLModel,
ohair@286 318 // we still need to do this correctly
ohair@286 319 if(binding!=null)
ohair@286 320 model.freeze(binding);
ohair@286 321 return model;
ohair@286 322 }
ohair@286 323
ohair@286 324 private Class configEndpointInterface() {
ohair@286 325 if (config.getEndpointClass() == null ||
ohair@286 326 config.getEndpointClass().isInterface() ) return null; //client proxy Interface
ohair@286 327 return config.getContractClass();
ohair@286 328 }
ohair@286 329
ohair@286 330 /**
ohair@286 331 * utility method to load classes
ohair@286 332 * @param className the name of the class to load
ohair@286 333 * @param errorMessage
ohair@286 334 * Error message to use when the resolution fails.
ohair@286 335 * @return the class specified by <code>className</code>
ohair@286 336 */
ohair@286 337 private Class getClass(String className, Localizable errorMessage) {
ohair@286 338 try {
ohair@286 339 if (classLoader == null)
ohair@286 340 return Thread.currentThread().getContextClassLoader().loadClass(className);
ohair@286 341 else
ohair@286 342 return classLoader.loadClass(className);
ohair@286 343 } catch (ClassNotFoundException e) {
ohair@286 344 throw new RuntimeModelerException(errorMessage);
ohair@286 345 }
ohair@286 346 }
ohair@286 347
alanb@368 348 private boolean noWrapperGen() {
alanb@368 349 Object o = config.properties().get(SuppressDocLitWrapperGeneration);
alanb@368 350 return (o!= null && o instanceof Boolean) ? ((Boolean) o) : false;
alanb@368 351 }
alanb@368 352
ohair@286 353 private Class getRequestWrapperClass(String className, Method method, QName reqElemName) {
ohair@286 354 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
ohair@286 355 try {
ohair@286 356 return loader.loadClass(className);
ohair@286 357 } catch (ClassNotFoundException e) {
alanb@368 358 if (noWrapperGen()) return WrapperComposite.class;
ohair@286 359 logger.fine("Dynamically creating request wrapper Class " + className);
ohair@286 360 return WrapperBeanGenerator.createRequestWrapperBean(className, method, reqElemName, loader);
ohair@286 361 }
ohair@286 362 }
ohair@286 363
ohair@286 364 private Class getResponseWrapperClass(String className, Method method, QName resElemName) {
ohair@286 365 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
ohair@286 366 try {
ohair@286 367 return loader.loadClass(className);
ohair@286 368 } catch (ClassNotFoundException e) {
alanb@368 369 if (noWrapperGen()) return WrapperComposite.class;
ohair@286 370 logger.fine("Dynamically creating response wrapper bean Class " + className);
ohair@286 371 return WrapperBeanGenerator.createResponseWrapperBean(className, method, resElemName, loader);
ohair@286 372 }
ohair@286 373 }
ohair@286 374
ohair@286 375
ohair@286 376 private Class getExceptionBeanClass(String className, Class exception, String name, String namespace) {
alanb@368 377 boolean decapitalizeExceptionBeanProperties = true;
alanb@368 378 Object o = config.properties().get(DecapitalizeExceptionBeanProperties);
alanb@368 379 if (o!= null && o instanceof Boolean) decapitalizeExceptionBeanProperties = (Boolean) o;
ohair@286 380 ClassLoader loader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
ohair@286 381 try {
ohair@286 382 return loader.loadClass(className);
ohair@286 383 } catch (ClassNotFoundException e) {
ohair@286 384 logger.fine("Dynamically creating exception bean Class " + className);
alanb@368 385 return WrapperBeanGenerator.createExceptionBean(className, exception, targetNamespace, name, namespace, loader, decapitalizeExceptionBeanProperties);
ohair@286 386 }
ohair@286 387 }
ohair@286 388
ohair@286 389 protected void determineWebMethodUse(Class clazz) {
ohair@286 390 if (clazz == null)
ohair@286 391 return;
ohair@286 392 if (!clazz.isInterface()) {
ohair@286 393 if (clazz == Object.class)
ohair@286 394 return;
ohair@286 395 WebMethod webMethod;
ohair@286 396 for (Method method : clazz.getMethods()) {
ohair@286 397 if (method.getDeclaringClass()!=clazz)
ohair@286 398 continue;
ohair@286 399 webMethod = getAnnotation(method, WebMethod.class);
ohair@286 400 if (webMethod != null && !webMethod.exclude()) {
ohair@286 401 classUsesWebMethod.add(clazz);
ohair@286 402 break;
ohair@286 403 }
ohair@286 404 }
ohair@286 405 }
ohair@286 406 determineWebMethodUse(clazz.getSuperclass());
ohair@286 407 }
ohair@286 408
ohair@286 409 void processClass(Class clazz) {
ohair@286 410 classUsesWebMethod = new HashSet<Class>();
ohair@286 411 determineWebMethodUse(clazz);
ohair@286 412 WebService webService = getAnnotation(clazz, WebService.class);
ohair@286 413 QName portTypeName = getPortTypeName(clazz, targetNamespace, metadataReader);
ohair@286 414 // String portTypeLocalName = clazz.getSimpleName();
ohair@286 415 // if (webService.name().length() >0)
ohair@286 416 // portTypeLocalName = webService.name();
ohair@286 417 //
ohair@286 418 // targetNamespace = webService.targetNamespace();
ohair@286 419 packageName = "";
ohair@286 420 if (clazz.getPackage() != null)
ohair@286 421 packageName = clazz.getPackage().getName();
ohair@286 422 // if (targetNamespace.length() == 0) {
ohair@286 423 // targetNamespace = getNamespace(packageName);
ohair@286 424 // }
ohair@286 425 // model.setTargetNamespace(targetNamespace);
ohair@286 426 // QName portTypeName = new QName(targetNamespace, portTypeLocalName);
ohair@286 427 targetNamespace = portTypeName.getNamespaceURI();
ohair@286 428 model.setPortTypeName(portTypeName);
ohair@286 429 model.setTargetNamespace(targetNamespace);
alanb@368 430 model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix();
ohair@286 431 model.setWSDLLocation(webService.wsdlLocation());
ohair@286 432
ohair@286 433 SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class);
ohair@286 434 if (soapBinding != null) {
ohair@286 435 if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
ohair@286 436 throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle",
ohair@286 437 soapBinding, clazz);
ohair@286 438
ohair@286 439 }
ohair@286 440 isWrapped = soapBinding.parameterStyle()== WRAPPED;
ohair@286 441 }
ohair@286 442 defaultBinding = createBinding(soapBinding);
ohair@286 443 /*
ohair@286 444 * if clazz != portClass then there is an SEI. If there is an
ohair@286 445 * SEI, then all methods should be processed. However, if there is
ohair@286 446 * no SEI, and the implementation class uses at least one
ohair@286 447 * WebMethod annotation, then only methods with this annotation
ohair@286 448 * will be processed.
ohair@286 449 */
ohair@286 450 /* if (clazz == portClass) {
ohair@286 451 WebMethod webMethod;
ohair@286 452 for (Method method : clazz.getMethods()) {
ohair@286 453 webMethod = getPrivMethodAnnotation(method, WebMethod.class);
ohair@286 454 if (webMethod != null &&
ohair@286 455 !webMethod.exclude()) {
ohair@286 456 usesWebMethod = true;
ohair@286 457 break;
ohair@286 458 }
ohair@286 459 }
ohair@286 460 }*/
ohair@286 461
ohair@286 462 for (Method method : clazz.getMethods()) {
ohair@286 463 if (!clazz.isInterface()) { // if clazz is SEI, then all methods are web methods
mkos@384 464 if (method.getDeclaringClass() == Object.class) continue;
ohair@286 465 if (!getBooleanSystemProperty("com.sun.xml.internal.ws.legacyWebMethod")) { // legacy webMethod computation behaviour to be used
ohair@286 466 if (!isWebMethodBySpec(method, clazz))
ohair@286 467 continue;
ohair@286 468 } else {
mkos@384 469 if (!isWebMethod(method))
ohair@286 470 continue;
ohair@286 471 }
ohair@286 472 }
ohair@286 473 // TODO: binding can be null. We need to figure out how to post-process
ohair@286 474 // RuntimeModel to link to WSDLModel
ohair@286 475 processMethod(method);
ohair@286 476 }
ohair@286 477 //Add additional jaxb classes referenced by {@link XmlSeeAlso}
ohair@286 478 XmlSeeAlso xmlSeeAlso = getAnnotation(clazz, XmlSeeAlso.class);
ohair@286 479 if(xmlSeeAlso != null)
ohair@286 480 model.addAdditionalClasses(xmlSeeAlso.value());
ohair@286 481 }
ohair@286 482
ohair@286 483 /*
ohair@286 484 * Section 3.3 of spec
ohair@286 485 * Otherwise, the class implicitly defines a service endpoint interface (SEI) which
ohair@286 486 * comprises all of the public methods that satisfy one of the following conditions:
ohair@286 487 * 1. They are annotated with the javax.jws.WebMethod annotation with the exclude element set to
ohair@286 488 * false or missing (since false is the default for this annotation element).
ohair@286 489 * 2. They are not annotated with the javax.jws.WebMethod annotation but their declaring class has a
ohair@286 490 * javax.jws.WebService annotation.
ohair@286 491 *
ohair@286 492 * also the method should non-static or non-final
ohair@286 493 */
ohair@286 494 private boolean isWebMethodBySpec(Method method, Class clazz) {
ohair@286 495
ohair@286 496 int modifiers = method.getModifiers();
ohair@286 497 boolean staticFinal = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
ohair@286 498
ohair@286 499 assert Modifier.isPublic(modifiers);
ohair@286 500 assert !clazz.isInterface();
ohair@286 501
ohair@286 502 WebMethod webMethod = getAnnotation(method, WebMethod.class);
ohair@286 503 if (webMethod != null) {
ohair@286 504 if (webMethod.exclude()) {
ohair@286 505 return false; // @WebMethod(exclude="true")
ohair@286 506 }
ohair@286 507 if (staticFinal) {
ohair@286 508 throw new RuntimeModelerException(ModelerMessages.localizableRUNTIME_MODELER_WEBMETHOD_MUST_BE_NONSTATICFINAL(method));
ohair@286 509 }
ohair@286 510 return true; // @WebMethod
ohair@286 511 }
ohair@286 512
ohair@286 513 if (staticFinal) {
ohair@286 514 return false;
ohair@286 515 }
ohair@286 516
ohair@286 517 Class declClass = method.getDeclaringClass();
ohair@286 518 return getAnnotation(declClass, WebService.class) != null;
ohair@286 519 }
ohair@286 520
ohair@286 521 private boolean isWebMethod(Method method) {
ohair@286 522 int modifiers = method.getModifiers();
ohair@286 523 if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers))
ohair@286 524 return false;
ohair@286 525
ohair@286 526 Class clazz = method.getDeclaringClass();
ohair@286 527 boolean declHasWebService = getAnnotation(clazz, WebService.class) != null;
ohair@286 528 WebMethod webMethod = getAnnotation(method, WebMethod.class);
ohair@286 529 if (webMethod != null && !webMethod.exclude() && declHasWebService)
ohair@286 530 return true;
ohair@286 531 return declHasWebService && !classUsesWebMethod.contains(clazz);
ohair@286 532 }
ohair@286 533
ohair@286 534 /**
ohair@286 535 * creates a runtime model <code>SOAPBinding</code> from a <code>javax.jws.soap.SOAPBinding</code> object
ohair@286 536 * @param soapBinding the <code>javax.jws.soap.SOAPBinding</code> to model
ohair@286 537 * @return returns the runtime model SOAPBinding corresponding to <code>soapBinding</code>
ohair@286 538 */
ohair@286 539 protected SOAPBindingImpl createBinding(SOAPBinding soapBinding) {
ohair@286 540 SOAPBindingImpl rtSOAPBinding = new SOAPBindingImpl();
ohair@286 541 Style style = soapBinding!=null ? soapBinding.style() : Style.DOCUMENT;
ohair@286 542 rtSOAPBinding.setStyle(style);
ohair@286 543 assert bindingId != null;
ohair@286 544 model.bindingId = bindingId;
ohair@286 545 SOAPVersion soapVersion = bindingId.getSOAPVersion();
ohair@286 546 rtSOAPBinding.setSOAPVersion(soapVersion);
ohair@286 547 return rtSOAPBinding;
ohair@286 548 }
ohair@286 549
ohair@286 550 /**
ohair@286 551 * gets the namespace <code>String</code> for a given <code>packageName</code>
ohair@286 552 * @param packageName the name of the package used to find a namespace.
ohair@286 553 * can be empty.
ohair@286 554 * @return the namespace for the specified <code>packageName</code>
ohair@286 555 */
ohair@286 556 public static String getNamespace(@NotNull String packageName) {
ohair@286 557 if (packageName.length() == 0)
ohair@286 558 return null;
ohair@286 559
ohair@286 560 StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
ohair@286 561 String[] tokens;
ohair@286 562 if (tokenizer.countTokens() == 0) {
ohair@286 563 tokens = new String[0];
ohair@286 564 } else {
ohair@286 565 tokens = new String[tokenizer.countTokens()];
ohair@286 566 for (int i=tokenizer.countTokens()-1; i >= 0; i--) {
ohair@286 567 tokens[i] = tokenizer.nextToken();
ohair@286 568 }
ohair@286 569 }
ohair@286 570 StringBuilder namespace = new StringBuilder("http://");
ohair@286 571 for (int i=0; i<tokens.length; i++) {
ohair@286 572 if (i!=0)
ohair@286 573 namespace.append('.');
ohair@286 574 namespace.append(tokens[i]);
ohair@286 575 }
ohair@286 576 namespace.append('/');
ohair@286 577 return namespace.toString();
ohair@286 578 }
ohair@286 579
ohair@286 580 /*
ohair@286 581 * Returns true if an exception is service specific exception as per JAX-WS rules.
ohair@286 582 * @param exception
ohair@286 583 * @return
ohair@286 584 */
ohair@286 585 private boolean isServiceException(Class<?> exception) {
ohair@286 586 return EXCEPTION_CLASS.isAssignableFrom(exception) &&
ohair@286 587 !(RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || REMOTE_EXCEPTION_CLASS.isAssignableFrom(exception));
ohair@286 588 }
ohair@286 589
ohair@286 590 /**
ohair@286 591 * creates the runtime model for a method on the <code>portClass</code>
ohair@286 592 * @param method the method to model
ohair@286 593 */
ohair@286 594 private void processMethod(Method method) {
alanb@368 595 // int mods = method.getModifiers();
ohair@286 596 WebMethod webMethod = getAnnotation(method, WebMethod.class);
alanb@368 597 if (webMethod != null && webMethod.exclude()) return;
ohair@286 598 /*
ohair@286 599 validations are already done
ohair@286 600
ohair@286 601 if (!Modifier.isPublic(mods) || Modifier.isStatic(mods)) {
ohair@286 602 if(webMethod != null) {
ohair@286 603 // if the user put @WebMethod on these non-qualifying method,
ohair@286 604 // it's an error
ohair@286 605 if(Modifier.isStatic(mods))
ohair@286 606 throw new RuntimeModelerException(ModelerMessages.localizableRUNTIME_MODELER_WEBMETHOD_MUST_BE_NONSTATIC(method));
ohair@286 607 else
ohair@286 608 throw new RuntimeModelerException(ModelerMessages.localizableRUNTIME_MODELER_WEBMETHOD_MUST_BE_PUBLIC(method));
ohair@286 609 }
ohair@286 610 return;
ohair@286 611 }
ohair@286 612
ohair@286 613 if (webMethod != null && webMethod.exclude())
ohair@286 614 return;
ohair@286 615 */
ohair@286 616
ohair@286 617 String methodName = method.getName();
ohair@286 618 boolean isOneway = (getAnnotation(method, Oneway.class) != null);
ohair@286 619
ohair@286 620 //Check that oneway methods don't thorw any checked exceptions
ohair@286 621 if (isOneway) {
ohair@286 622 for (Class<?> exception : method.getExceptionTypes()) {
ohair@286 623 if(isServiceException(exception)) {
ohair@286 624 throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.checked.exceptions",
ohair@286 625 portClass.getCanonicalName(), methodName, exception.getName());
ohair@286 626 }
ohair@286 627 }
ohair@286 628 }
ohair@286 629
ohair@286 630 JavaMethodImpl javaMethod;
ohair@286 631 //Class implementorClass = portClass;
ohair@286 632 if (method.getDeclaringClass()==portClass) {
ohair@286 633 javaMethod = new JavaMethodImpl(model,method,method,metadataReader);
ohair@286 634 } else {
ohair@286 635 try {
ohair@286 636 Method tmpMethod = portClass.getMethod(method.getName(),
ohair@286 637 method.getParameterTypes());
ohair@286 638 javaMethod = new JavaMethodImpl(model,tmpMethod,method,metadataReader);
ohair@286 639 } catch (NoSuchMethodException e) {
ohair@286 640 throw new RuntimeModelerException("runtime.modeler.method.not.found",
ohair@286 641 method.getName(), portClass.getName());
ohair@286 642 }
ohair@286 643 }
ohair@286 644
ohair@286 645
ohair@286 646
ohair@286 647 //set MEP -oneway, async, req/resp
ohair@286 648 MEP mep = getMEP(method);
ohair@286 649 javaMethod.setMEP(mep);
ohair@286 650
ohair@286 651 String action = null;
ohair@286 652
ohair@286 653
ohair@286 654 String operationName = method.getName();
ohair@286 655 if (webMethod != null ) {
ohair@286 656 action = webMethod.action();
ohair@286 657 operationName = webMethod.operationName().length() > 0 ?
ohair@286 658 webMethod.operationName() :
ohair@286 659 operationName;
ohair@286 660 }
ohair@286 661
ohair@286 662 //override the @WebMethod.action value by the one from the WSDL
ohair@286 663 if(binding != null){
ohair@286 664 WSDLBoundOperation bo = binding.getBinding().get(new QName(targetNamespace, operationName));
ohair@286 665 if(bo != null){
ohair@286 666 WSDLInput wsdlInput = bo.getOperation().getInput();
ohair@286 667 String wsaAction = wsdlInput.getAction();
ohair@286 668 if(wsaAction != null && !wsdlInput.isDefaultAction())
ohair@286 669 action = wsaAction;
ohair@286 670 else
ohair@286 671 action = bo.getSOAPAction();
ohair@286 672 }
ohair@286 673 }
ohair@286 674
ohair@286 675 javaMethod.setOperationQName(new QName(targetNamespace,operationName));
ohair@286 676 SOAPBinding methodBinding = getAnnotation(method, SOAPBinding.class);
ohair@286 677 if(methodBinding != null && methodBinding.style() == SOAPBinding.Style.RPC) {
ohair@286 678 logger.warning(ModelerMessages.RUNTIMEMODELER_INVALID_SOAPBINDING_ON_METHOD(methodBinding, method.getName(), method.getDeclaringClass().getName()));
ohair@286 679 } else if (methodBinding == null && !method.getDeclaringClass().equals(portClass)) {
ohair@286 680 methodBinding = getAnnotation(method.getDeclaringClass(), SOAPBinding.class);
ohair@286 681 if (methodBinding != null && methodBinding.style() == SOAPBinding.Style.RPC && methodBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
ohair@286 682 throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle",
ohair@286 683 methodBinding, method.getDeclaringClass());
ohair@286 684 }
ohair@286 685 }
ohair@286 686
ohair@286 687 if(methodBinding!= null && defaultBinding.getStyle() != methodBinding.style()) {
ohair@286 688 throw new RuntimeModelerException("runtime.modeler.soapbinding.conflict",
ohair@286 689 methodBinding.style(), method.getName(),defaultBinding.getStyle());
ohair@286 690 }
ohair@286 691
ohair@286 692 boolean methodIsWrapped = isWrapped;
ohair@286 693 Style style = defaultBinding.getStyle();
ohair@286 694 if (methodBinding != null) {
ohair@286 695 SOAPBindingImpl mySOAPBinding = createBinding(methodBinding);
ohair@286 696 style = mySOAPBinding.getStyle();
ohair@286 697 if (action != null)
ohair@286 698 mySOAPBinding.setSOAPAction(action);
ohair@286 699 methodIsWrapped = methodBinding.parameterStyle().equals(
ohair@286 700 WRAPPED);
ohair@286 701 javaMethod.setBinding(mySOAPBinding);
ohair@286 702 } else {
ohair@286 703 SOAPBindingImpl sb = new SOAPBindingImpl(defaultBinding);
ohair@286 704 if (action != null) {
ohair@286 705 sb.setSOAPAction(action);
ohair@286 706 } else {
ohair@286 707 String defaults = SOAPVersion.SOAP_11 == sb.getSOAPVersion() ? "" : null;
ohair@286 708 sb.setSOAPAction(defaults);
ohair@286 709 }
ohair@286 710 javaMethod.setBinding(sb);
ohair@286 711 }
ohair@286 712 if (!methodIsWrapped) {
ohair@286 713 processDocBareMethod(javaMethod, operationName, method);
ohair@286 714 } else if (style.equals(Style.DOCUMENT)) {
ohair@286 715 processDocWrappedMethod(javaMethod, methodName, operationName,
ohair@286 716 method);
ohair@286 717 } else {
ohair@286 718 processRpcMethod(javaMethod, methodName, operationName, method);
ohair@286 719 }
ohair@286 720 model.addJavaMethod(javaMethod);
ohair@286 721 }
ohair@286 722
ohair@286 723 private MEP getMEP(Method m){
ohair@286 724 if (getAnnotation(m, Oneway.class)!= null) {
ohair@286 725 return MEP.ONE_WAY;
ohair@286 726 }
ohair@286 727 if(Response.class.isAssignableFrom(m.getReturnType())){
ohair@286 728 return MEP.ASYNC_POLL;
ohair@286 729 }else if(Future.class.isAssignableFrom(m.getReturnType())){
ohair@286 730 return MEP.ASYNC_CALLBACK;
ohair@286 731 }
ohair@286 732 return MEP.REQUEST_RESPONSE;
ohair@286 733 }
ohair@286 734
ohair@286 735 /**
ohair@286 736 * models a document/literal wrapped method
ohair@286 737 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
ohair@286 738 * @param methodName the runtime model <code>JavaMethod</code> instance being created
ohair@286 739 * @param operationName the runtime model <code>JavaMethod</code> instance being created
ohair@286 740 * @param method the <code>method</code> to model
ohair@286 741 */
ohair@286 742 protected void processDocWrappedMethod(JavaMethodImpl javaMethod, String methodName,
ohair@286 743 String operationName, Method method) {
ohair@286 744 boolean methodHasHeaderParams = false;
ohair@286 745 boolean isOneway = getAnnotation(method, Oneway.class)!= null;
ohair@286 746 RequestWrapper reqWrapper = getAnnotation(method,RequestWrapper.class);
ohair@286 747 ResponseWrapper resWrapper = getAnnotation(method,ResponseWrapper.class);
ohair@286 748 String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
alanb@368 749 if (packageName == null || packageName.length() == 0) {
ohair@286 750 beanPackage = JAXWS_PACKAGE_PD;
alanb@368 751 }
ohair@286 752 String requestClassName;
ohair@286 753 if(reqWrapper != null && reqWrapper.className().length()>0){
ohair@286 754 requestClassName = reqWrapper.className();
ohair@286 755 }else{
ohair@286 756 requestClassName = beanPackage + capitalize(method.getName());
ohair@286 757 }
ohair@286 758
ohair@286 759
ohair@286 760 String responseClassName;
ohair@286 761 if(resWrapper != null && resWrapper.className().length()>0){
ohair@286 762 responseClassName = resWrapper.className();
ohair@286 763 }else{
ohair@286 764 responseClassName = beanPackage + capitalize(method.getName()) + RESPONSE;
ohair@286 765 }
ohair@286 766
ohair@286 767 String reqName = operationName;
ohair@286 768 String reqNamespace = targetNamespace;
ohair@286 769 String reqPartName = "parameters";
ohair@286 770 if (reqWrapper != null) {
ohair@286 771 if (reqWrapper.targetNamespace().length() > 0)
ohair@286 772 reqNamespace = reqWrapper.targetNamespace();
ohair@286 773 if (reqWrapper.localName().length() > 0)
ohair@286 774 reqName = reqWrapper.localName();
ohair@286 775 try {
ohair@286 776 if (reqWrapper.partName().length() > 0)
ohair@286 777 reqPartName = reqWrapper.partName();
ohair@286 778 } catch(LinkageError e) {
ohair@286 779 //2.1 API dopes n't have this method
ohair@286 780 //Do nothing, just default to "parameters"
ohair@286 781 }
ohair@286 782 }
ohair@286 783 QName reqElementName = new QName(reqNamespace, reqName);
ohair@286 784 javaMethod.setRequestPayloadName(reqElementName);
ohair@286 785 Class requestClass = getRequestWrapperClass(requestClassName, method, reqElementName);
ohair@286 786
ohair@286 787 Class responseClass = null;
ohair@286 788 String resName = operationName+"Response";
ohair@286 789 String resNamespace = targetNamespace;
ohair@286 790 QName resElementName = null;
ohair@286 791 String resPartName = "parameters";
ohair@286 792 if (!isOneway) {
ohair@286 793 if (resWrapper != null) {
ohair@286 794 if (resWrapper.targetNamespace().length() > 0)
ohair@286 795 resNamespace = resWrapper.targetNamespace();
ohair@286 796 if (resWrapper.localName().length() > 0)
ohair@286 797 resName = resWrapper.localName();
ohair@286 798 try {
ohair@286 799 if (resWrapper.partName().length() > 0)
ohair@286 800 resPartName = resWrapper.partName();
ohair@286 801 } catch (LinkageError e) {
ohair@286 802 //2.1 API does n't have this method
ohair@286 803 //Do nothing, just default to "parameters"
ohair@286 804 }
ohair@286 805 }
ohair@286 806 resElementName = new QName(resNamespace, resName);
ohair@286 807 responseClass = getResponseWrapperClass(responseClassName, method, resElementName);
ohair@286 808 }
ohair@286 809
ohair@286 810 TypeInfo typeRef =
ohair@286 811 new TypeInfo(reqElementName, requestClass);
ohair@286 812 typeRef.setNillable(false);
ohair@286 813 WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef,
ohair@286 814 Mode.IN, 0);
ohair@286 815 requestWrapper.setPartName(reqPartName);
ohair@286 816 requestWrapper.setBinding(ParameterBinding.BODY);
ohair@286 817 javaMethod.addParameter(requestWrapper);
ohair@286 818 WrapperParameter responseWrapper = null;
ohair@286 819 if (!isOneway) {
ohair@286 820 typeRef = new TypeInfo(resElementName, responseClass);
ohair@286 821 typeRef.setNillable(false);
ohair@286 822 responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
ohair@286 823 javaMethod.addParameter(responseWrapper);
ohair@286 824 responseWrapper.setBinding(ParameterBinding.BODY);
ohair@286 825 }
ohair@286 826
ohair@286 827 // return value
ohair@286 828
ohair@286 829
ohair@286 830 WebResult webResult = getAnnotation(method, WebResult.class);
ohair@286 831 XmlElement xmlElem = getAnnotation(method, XmlElement.class);
ohair@286 832 QName resultQName = getReturnQName(method, webResult, xmlElem);
ohair@286 833 Class returnType = method.getReturnType();
ohair@286 834 boolean isResultHeader = false;
ohair@286 835 if (webResult != null) {
ohair@286 836 isResultHeader = webResult.header();
ohair@286 837 methodHasHeaderParams = isResultHeader || methodHasHeaderParams;
ohair@286 838 if (isResultHeader && xmlElem != null) {
ohair@286 839 throw new RuntimeModelerException("@XmlElement cannot be specified on method "+method+" as the return value is bound to header");
ohair@286 840 }
ohair@286 841 if (resultQName.getNamespaceURI().length() == 0 && webResult.header()) {
ohair@286 842 // headers must have a namespace
ohair@286 843 resultQName = new QName(targetNamespace, resultQName.getLocalPart());
ohair@286 844 }
ohair@286 845 }
ohair@286 846
ohair@286 847 if(javaMethod.isAsync()){
ohair@286 848 returnType = getAsyncReturnType(method, returnType);
ohair@286 849 resultQName = new QName(RETURN);
ohair@286 850 }
alanb@368 851 resultQName = qualifyWrappeeIfNeeded(resultQName, resNamespace);
ohair@286 852 if (!isOneway && (returnType != null) && (!returnType.getName().equals("void"))) {
ohair@286 853 Annotation[] rann = getAnnotations(method);
ohair@286 854 if (resultQName.getLocalPart() != null) {
ohair@286 855 TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
ohair@286 856 metadataReader.getProperties(rTypeReference.properties(), method);
alanb@368 857 rTypeReference.setGenericType(method.getGenericReturnType());
ohair@286 858 ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
ohair@286 859 if (isResultHeader) {
ohair@286 860 returnParameter.setBinding(ParameterBinding.HEADER);
ohair@286 861 javaMethod.addParameter(returnParameter);
ohair@286 862 } else {
ohair@286 863 returnParameter.setBinding(ParameterBinding.BODY);
ohair@286 864 responseWrapper.addWrapperChild(returnParameter);
ohair@286 865 }
ohair@286 866 }
ohair@286 867 }
ohair@286 868
ohair@286 869 //get WebParam
ohair@286 870 Class<?>[] parameterTypes = method.getParameterTypes();
ohair@286 871 Type[] genericParameterTypes = method.getGenericParameterTypes();
ohair@286 872 Annotation[][] pannotations = getParamAnnotations(method);
ohair@286 873 int pos = 0;
ohair@286 874 for (Class clazzType : parameterTypes) {
ohair@286 875 String partName=null;
ohair@286 876 String paramName = "arg"+pos;
ohair@286 877 //String paramNamespace = "";
ohair@286 878 boolean isHeader = false;
ohair@286 879
ohair@286 880 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
ohair@286 881 continue;
ohair@286 882 }
ohair@286 883
ohair@286 884 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
ohair@286 885 //set the actual type argument of Holder in the TypeReference
ohair@286 886 if (isHolder) {
ohair@286 887 if(clazzType==Holder.class){
mkos@450 888 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
ohair@286 889 }
ohair@286 890 }
ohair@286 891 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
ohair@286 892 WebParam webParam = null;
ohair@286 893 xmlElem = null;
ohair@286 894 for (Annotation annotation : pannotations[pos]) {
ohair@286 895 if (annotation.annotationType() == WebParam.class)
ohair@286 896 webParam = (WebParam)annotation;
ohair@286 897 else if (annotation.annotationType() == XmlElement.class)
ohair@286 898 xmlElem = (XmlElement)annotation;
ohair@286 899 }
ohair@286 900
ohair@286 901 QName paramQName = getParameterQName(method, webParam, xmlElem, paramName);
ohair@286 902 if (webParam != null) {
ohair@286 903 isHeader = webParam.header();
ohair@286 904 methodHasHeaderParams = isHeader || methodHasHeaderParams;
ohair@286 905 if (isHeader && xmlElem != null) {
ohair@286 906 throw new RuntimeModelerException("@XmlElement cannot be specified on method "+method+" parameter that is bound to header");
ohair@286 907 }
ohair@286 908 if(webParam.partName().length() > 0)
ohair@286 909 partName = webParam.partName();
ohair@286 910 else
ohair@286 911 partName = paramQName.getLocalPart();
ohair@286 912 if (isHeader && paramQName.getNamespaceURI().equals("")) { // headers cannot be in empty namespace
ohair@286 913 paramQName = new QName(targetNamespace, paramQName.getLocalPart());
ohair@286 914 }
ohair@286 915 paramMode = webParam.mode();
ohair@286 916 if (isHolder && paramMode == Mode.IN)
ohair@286 917 paramMode = Mode.INOUT;
ohair@286 918 }
alanb@368 919 paramQName = qualifyWrappeeIfNeeded(paramQName, reqNamespace);
ohair@286 920 typeRef =
ohair@286 921 new TypeInfo(paramQName, clazzType, pannotations[pos]);
ohair@286 922 metadataReader.getProperties(typeRef.properties(), method, pos);
alanb@368 923 typeRef.setGenericType(genericParameterTypes[pos]);
ohair@286 924 ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
ohair@286 925
ohair@286 926 if (isHeader) {
ohair@286 927 param.setBinding(ParameterBinding.HEADER);
ohair@286 928 javaMethod.addParameter(param);
ohair@286 929 param.setPartName(partName);
ohair@286 930 } else {
ohair@286 931 param.setBinding(ParameterBinding.BODY);
ohair@286 932 if (paramMode!=Mode.OUT) {
ohair@286 933 requestWrapper.addWrapperChild(param);
ohair@286 934 }
ohair@286 935 if (paramMode!=Mode.IN) {
ohair@286 936 if (isOneway) {
ohair@286 937 throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters",
ohair@286 938 portClass.getCanonicalName(), methodName);
ohair@286 939 }
ohair@286 940 responseWrapper.addWrapperChild(param);
ohair@286 941 }
ohair@286 942 }
ohair@286 943 }
ohair@286 944
ohair@286 945 //If the method has any parameter or return type that is bound to a header, use "result" as part name to avoid
ohair@286 946 // name collison of same input part name and output part name ("parameters") shown up as param names on the
ohair@286 947 // client mapping.
ohair@286 948 if(methodHasHeaderParams) {
ohair@286 949 resPartName = "result";
ohair@286 950 }
ohair@286 951 if(responseWrapper != null)
ohair@286 952 responseWrapper.setPartName(resPartName);
ohair@286 953 processExceptions(javaMethod, method);
ohair@286 954 }
ohair@286 955
alanb@368 956 private QName qualifyWrappeeIfNeeded(QName resultQName, String ns) {
alanb@368 957 Object o = config.properties().get(DocWrappeeNamespapceQualified);
alanb@368 958 boolean qualified = (o!= null && o instanceof Boolean) ? ((Boolean) o) : false;
alanb@368 959 if (qualified) {
alanb@368 960 if (resultQName.getNamespaceURI() == null || "".equals(resultQName.getNamespaceURI())) {
alanb@368 961 return new QName(ns, resultQName.getLocalPart());
alanb@368 962 }
alanb@368 963 }
alanb@368 964 return resultQName;
alanb@368 965 }
ohair@286 966
ohair@286 967 /**
ohair@286 968 * models a rpc/literal method
ohair@286 969 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
ohair@286 970 * @param methodName the name of the <code>method</code> being modeled.
ohair@286 971 * @param operationName the WSDL operation name for this <code>method</code>
ohair@286 972 * @param method the runtime model <code>JavaMethod</code> instance being created
ohair@286 973 */
ohair@286 974 protected void processRpcMethod(JavaMethodImpl javaMethod, String methodName,
ohair@286 975 String operationName, Method method) {
ohair@286 976 boolean isOneway = getAnnotation(method, Oneway.class) != null;
ohair@286 977
ohair@286 978 // use Map to build parameters in the part order when they are known.
ohair@286 979 // if part is unbound, we just put them at the end, and for that we
ohair@286 980 // use a large index (10000+) to avoid colliding with ordered ones.
ohair@286 981 // this assumes that there's no operation with # of parameters > 10000,
ohair@286 982 // but I think it's a pretty safe assumption - KK.
ohair@286 983 Map<Integer, ParameterImpl> resRpcParams = new TreeMap<Integer, ParameterImpl>();
ohair@286 984 Map<Integer, ParameterImpl> reqRpcParams = new TreeMap<Integer, ParameterImpl>();
ohair@286 985
ohair@286 986 //Lets take the service namespace and overwrite it with the one we get it from wsdl
ohair@286 987 String reqNamespace = targetNamespace;
ohair@286 988 String respNamespace = targetNamespace;
ohair@286 989
ohair@286 990 if(binding != null && Style.RPC.equals(binding.getBinding().getStyle())){
ohair@286 991 QName opQName = new QName(binding.getBinding().getPortTypeName().getNamespaceURI(), operationName);
ohair@286 992 WSDLBoundOperation op = binding.getBinding().get(opQName);
ohair@286 993 if(op != null){
ohair@286 994 //it cant be null, but lets not fail and try to work with service namespce
ohair@286 995 if(op.getRequestNamespace() != null){
ohair@286 996 reqNamespace = op.getRequestNamespace();
ohair@286 997 }
ohair@286 998
ohair@286 999 //it cant be null, but lets not fail and try to work with service namespce
ohair@286 1000 if(op.getResponseNamespace() != null){
ohair@286 1001 respNamespace = op.getResponseNamespace();
ohair@286 1002 }
ohair@286 1003 }
ohair@286 1004 }
ohair@286 1005
ohair@286 1006 QName reqElementName = new QName(reqNamespace, operationName);
ohair@286 1007 javaMethod.setRequestPayloadName(reqElementName);
ohair@286 1008 QName resElementName = null;
ohair@286 1009 if (!isOneway) {
ohair@286 1010 resElementName = new QName(respNamespace, operationName+RESPONSE);
ohair@286 1011 }
ohair@286 1012
ohair@286 1013 Class wrapperType = WrapperComposite.class;
ohair@286 1014 TypeInfo typeRef = new TypeInfo(reqElementName, wrapperType);
ohair@286 1015 WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
ohair@286 1016 requestWrapper.setInBinding(ParameterBinding.BODY);
ohair@286 1017 javaMethod.addParameter(requestWrapper);
ohair@286 1018 WrapperParameter responseWrapper = null;
ohair@286 1019 if (!isOneway) {
ohair@286 1020 typeRef = new TypeInfo(resElementName, wrapperType);
ohair@286 1021 responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
ohair@286 1022 responseWrapper.setOutBinding(ParameterBinding.BODY);
ohair@286 1023 javaMethod.addParameter(responseWrapper);
ohair@286 1024 }
ohair@286 1025
ohair@286 1026 Class returnType = method.getReturnType();
ohair@286 1027 String resultName = RETURN;
ohair@286 1028 String resultTNS = targetNamespace;
ohair@286 1029 String resultPartName = resultName;
ohair@286 1030 boolean isResultHeader = false;
ohair@286 1031 WebResult webResult = getAnnotation(method, WebResult.class);
ohair@286 1032
ohair@286 1033 if (webResult != null) {
ohair@286 1034 isResultHeader = webResult.header();
ohair@286 1035 if (webResult.name().length() > 0)
ohair@286 1036 resultName = webResult.name();
ohair@286 1037 if (webResult.partName().length() > 0) {
ohair@286 1038 resultPartName = webResult.partName();
ohair@286 1039 if (!isResultHeader)
ohair@286 1040 resultName = resultPartName;
ohair@286 1041 } else
ohair@286 1042 resultPartName = resultName;
ohair@286 1043 if (webResult.targetNamespace().length() > 0)
ohair@286 1044 resultTNS = webResult.targetNamespace();
ohair@286 1045 isResultHeader = webResult.header();
ohair@286 1046 }
ohair@286 1047 QName resultQName;
ohair@286 1048 if (isResultHeader)
ohair@286 1049 resultQName = new QName(resultTNS, resultName);
ohair@286 1050 else
ohair@286 1051 resultQName = new QName(resultName);
ohair@286 1052
ohair@286 1053 if(javaMethod.isAsync()){
ohair@286 1054 returnType = getAsyncReturnType(method, returnType);
ohair@286 1055 }
ohair@286 1056
ohair@286 1057 if (!isOneway && returnType!=null && returnType!=void.class) {
ohair@286 1058 Annotation[] rann = getAnnotations(method);
ohair@286 1059 TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
ohair@286 1060 metadataReader.getProperties(rTypeReference.properties(), method);
ohair@286 1061 rTypeReference.setGenericType(method.getGenericReturnType());
ohair@286 1062 ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
ohair@286 1063 returnParameter.setPartName(resultPartName);
ohair@286 1064 if(isResultHeader){
ohair@286 1065 returnParameter.setBinding(ParameterBinding.HEADER);
ohair@286 1066 javaMethod.addParameter(returnParameter);
ohair@286 1067 rTypeReference.setGlobalElement(true);
ohair@286 1068 }else{
ohair@286 1069 ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
ohair@286 1070 returnParameter.setBinding(rb);
ohair@286 1071 if(rb.isBody()){
ohair@286 1072 rTypeReference.setGlobalElement(false);
ohair@286 1073 WSDLPart p = getPart(new QName(targetNamespace,operationName), resultPartName, Mode.OUT);
ohair@286 1074 if(p == null)
ohair@286 1075 resRpcParams.put(resRpcParams.size()+10000, returnParameter);
ohair@286 1076 else
ohair@286 1077 resRpcParams.put(p.getIndex(), returnParameter);
ohair@286 1078 }else{
ohair@286 1079 javaMethod.addParameter(returnParameter);
ohair@286 1080 }
ohair@286 1081 }
ohair@286 1082 }
ohair@286 1083
ohair@286 1084 //get WebParam
ohair@286 1085 Class<?>[] parameterTypes = method.getParameterTypes();
ohair@286 1086 Type[] genericParameterTypes = method.getGenericParameterTypes();
ohair@286 1087 Annotation[][] pannotations = getParamAnnotations(method);
ohair@286 1088 int pos = 0;
ohair@286 1089 for (Class clazzType : parameterTypes) {
ohair@286 1090 String paramName = "";
ohair@286 1091 String paramNamespace = "";
ohair@286 1092 String partName = "";
ohair@286 1093 boolean isHeader = false;
ohair@286 1094
ohair@286 1095 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
ohair@286 1096 continue;
ohair@286 1097 }
ohair@286 1098
ohair@286 1099 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
ohair@286 1100 //set the actual type argument of Holder in the TypeReference
ohair@286 1101 if (isHolder) {
ohair@286 1102 if (clazzType==Holder.class)
mkos@450 1103 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
ohair@286 1104 }
ohair@286 1105 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
ohair@286 1106 for (Annotation annotation : pannotations[pos]) {
ohair@286 1107 if (annotation.annotationType() == javax.jws.WebParam.class) {
ohair@286 1108 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
ohair@286 1109 paramName = webParam.name();
ohair@286 1110 partName = webParam.partName();
ohair@286 1111 isHeader = webParam.header();
ohair@286 1112 WebParam.Mode mode = webParam.mode();
ohair@286 1113 paramNamespace = webParam.targetNamespace();
ohair@286 1114 if (isHolder && mode == Mode.IN)
ohair@286 1115 mode = Mode.INOUT;
ohair@286 1116 paramMode = mode;
ohair@286 1117 break;
ohair@286 1118 }
ohair@286 1119 }
ohair@286 1120
ohair@286 1121 if (paramName.length() == 0) {
ohair@286 1122 paramName = "arg"+pos;
ohair@286 1123 }
ohair@286 1124 if (partName.length() == 0) {
ohair@286 1125 partName = paramName;
ohair@286 1126 } else if (!isHeader) {
ohair@286 1127 paramName = partName;
ohair@286 1128 }
ohair@286 1129 if (partName.length() == 0) {
ohair@286 1130 partName = paramName;
ohair@286 1131 }
ohair@286 1132
ohair@286 1133 QName paramQName;
ohair@286 1134 if (!isHeader) {
ohair@286 1135 //its rpclit body param, set namespace to ""
ohair@286 1136 paramQName = new QName("", paramName);
ohair@286 1137 } else {
ohair@286 1138 if (paramNamespace.length() == 0)
ohair@286 1139 paramNamespace = targetNamespace;
ohair@286 1140 paramQName = new QName(paramNamespace, paramName);
ohair@286 1141 }
ohair@286 1142 typeRef =
ohair@286 1143 new TypeInfo(paramQName, clazzType, pannotations[pos]);
ohair@286 1144 metadataReader.getProperties(typeRef.properties(), method, pos);
ohair@286 1145 typeRef.setGenericType(genericParameterTypes[pos]);
ohair@286 1146 ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
ohair@286 1147 param.setPartName(partName);
ohair@286 1148
ohair@286 1149 if(paramMode == Mode.INOUT){
ohair@286 1150 ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
ohair@286 1151 param.setInBinding(pb);
ohair@286 1152 pb = getBinding(operationName, partName, isHeader, Mode.OUT);
ohair@286 1153 param.setOutBinding(pb);
ohair@286 1154 }else{
ohair@286 1155 if (isHeader) {
ohair@286 1156 typeRef.setGlobalElement(true);
ohair@286 1157 param.setBinding(ParameterBinding.HEADER);
ohair@286 1158 } else {
ohair@286 1159 ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
ohair@286 1160 param.setBinding(pb);
ohair@286 1161 }
ohair@286 1162 }
ohair@286 1163 if(param.getInBinding().isBody()){
ohair@286 1164 typeRef.setGlobalElement(false);
ohair@286 1165 if(!param.isOUT()){
ohair@286 1166 WSDLPart p = getPart(new QName(targetNamespace,operationName), partName, Mode.IN);
ohair@286 1167 if(p == null)
ohair@286 1168 reqRpcParams.put(reqRpcParams.size()+10000, param);
ohair@286 1169 else
ohair@286 1170 reqRpcParams.put(p.getIndex(), param);
ohair@286 1171 }
ohair@286 1172
ohair@286 1173 if(!param.isIN()){
ohair@286 1174 if (isOneway) {
ohair@286 1175 throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters",
ohair@286 1176 portClass.getCanonicalName(), methodName);
ohair@286 1177 }
ohair@286 1178 WSDLPart p = getPart(new QName(targetNamespace,operationName), partName, Mode.OUT);
ohair@286 1179 if(p == null)
ohair@286 1180 resRpcParams.put(resRpcParams.size()+10000, param);
ohair@286 1181 else
ohair@286 1182 resRpcParams.put(p.getIndex(), param);
ohair@286 1183 }
ohair@286 1184 }else{
ohair@286 1185 javaMethod.addParameter(param);
ohair@286 1186 }
ohair@286 1187 }
ohair@286 1188 for (ParameterImpl p : reqRpcParams.values())
ohair@286 1189 requestWrapper.addWrapperChild(p);
ohair@286 1190 for (ParameterImpl p : resRpcParams.values())
ohair@286 1191 responseWrapper.addWrapperChild(p);
ohair@286 1192 processExceptions(javaMethod, method);
ohair@286 1193 }
ohair@286 1194
ohair@286 1195 /**
ohair@286 1196 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
ohair@286 1197 * runtime model object
ohair@286 1198 * @param javaMethod the runtime model object to add the exception model objects to
ohair@286 1199 * @param method the <code>method</code> from which to find the exceptions to model
ohair@286 1200 */
ohair@286 1201 protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
ohair@286 1202 Action actionAnn = getAnnotation(method, Action.class);
ohair@286 1203 FaultAction[] faultActions = {};
ohair@286 1204 if(actionAnn != null)
ohair@286 1205 faultActions = actionAnn.fault();
ohair@286 1206 for (Class<?> exception : method.getExceptionTypes()) {
ohair@286 1207
ohair@286 1208 //Exclude RuntimeException, RemoteException and Error etc
ohair@286 1209 if (!EXCEPTION_CLASS.isAssignableFrom(exception))
ohair@286 1210 continue;
ohair@286 1211 if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || REMOTE_EXCEPTION_CLASS.isAssignableFrom(exception))
ohair@286 1212 continue;
ohair@286 1213
ohair@286 1214 Class exceptionBean;
ohair@286 1215 Annotation[] anns;
ohair@286 1216 WebFault webFault = getAnnotation(exception, WebFault.class);
ohair@286 1217 Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
ohair@286 1218 ExceptionType exceptionType = ExceptionType.WSDLException;
ohair@286 1219 String namespace = targetNamespace;
ohair@286 1220 String name = exception.getSimpleName();
ohair@286 1221 String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
ohair@286 1222 if (packageName.length() == 0)
ohair@286 1223 beanPackage = JAXWS_PACKAGE_PD;
ohair@286 1224 String className = beanPackage+ name + BEAN;
ohair@286 1225 String messageName = exception.getSimpleName();
ohair@286 1226 if (webFault != null) {
ohair@286 1227 if (webFault.faultBean().length()>0)
ohair@286 1228 className = webFault.faultBean();
ohair@286 1229 if (webFault.name().length()>0)
ohair@286 1230 name = webFault.name();
ohair@286 1231 if (webFault.targetNamespace().length()>0)
ohair@286 1232 namespace = webFault.targetNamespace();
ohair@286 1233 if (webFault.messageName().length()>0)
ohair@286 1234 messageName = webFault.messageName();
ohair@286 1235 }
ohair@286 1236 if (faultInfoMethod == null) {
ohair@286 1237 exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
ohair@286 1238 exceptionType = ExceptionType.UserDefined;
ohair@286 1239 anns = getAnnotations(exceptionBean);
ohair@286 1240 } else {
ohair@286 1241 exceptionBean = faultInfoMethod.getReturnType();
ohair@286 1242 anns = getAnnotations(faultInfoMethod);
ohair@286 1243 }
ohair@286 1244 QName faultName = new QName(namespace, name);
ohair@286 1245 TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
ohair@286 1246 CheckedExceptionImpl checkedException =
ohair@286 1247 new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
ohair@286 1248 checkedException.setMessageName(messageName);
ohair@286 1249 for(FaultAction fa: faultActions) {
ohair@286 1250 if(fa.className().equals(exception) && !fa.value().equals("")) {
ohair@286 1251 checkedException.setFaultAction(fa.value());
ohair@286 1252 break;
ohair@286 1253 }
ohair@286 1254 }
ohair@286 1255 javaMethod.addException(checkedException);
ohair@286 1256 }
ohair@286 1257 }
ohair@286 1258
ohair@286 1259 /**
ohair@286 1260 * returns the method that corresponds to "getFaultInfo". Returns null if this is not an
ohair@286 1261 * exception generated from a WSDL
ohair@286 1262 * @param exception the class to search for the "getFaultInfo" method
ohair@286 1263 * @return the method named "getFaultInfo" if this is an exception generated from WSDL or an
ohair@286 1264 * exception that contains the <code>WebFault</code> annotation. Otherwise it returns null
ohair@286 1265 */
ohair@286 1266 protected Method getWSDLExceptionFaultInfo(Class exception) {
ohair@286 1267 // if (!exception.isAnnotationPresent(WebFault.class))
ohair@286 1268 if (getAnnotation(exception, WebFault.class) == null)
ohair@286 1269 return null;
ohair@286 1270 try {
ohair@286 1271 return exception.getMethod("getFaultInfo");
ohair@286 1272 } catch (NoSuchMethodException e) {
ohair@286 1273 return null;
ohair@286 1274 }
ohair@286 1275 }
ohair@286 1276
ohair@286 1277 /**
ohair@286 1278 * models a document/literal bare method
ohair@286 1279 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
ohair@286 1280 * @param operationName the runtime model <code>JavaMethod</code> instance being created
ohair@286 1281 * @param method the runtime model <code>JavaMethod</code> instance being created
ohair@286 1282 */
ohair@286 1283 protected void processDocBareMethod(JavaMethodImpl javaMethod,
ohair@286 1284 String operationName, Method method) {
ohair@286 1285
ohair@286 1286 String resultName = operationName+RESPONSE;
ohair@286 1287 String resultTNS = targetNamespace;
ohair@286 1288 String resultPartName = null;
ohair@286 1289 boolean isResultHeader = false;
ohair@286 1290 WebResult webResult = getAnnotation(method, WebResult.class);
ohair@286 1291 if (webResult != null) {
ohair@286 1292 if (webResult.name().length() > 0)
ohair@286 1293 resultName = webResult.name();
ohair@286 1294 if (webResult.targetNamespace().length() > 0)
ohair@286 1295 resultTNS = webResult.targetNamespace();
ohair@286 1296 resultPartName = webResult.partName();
ohair@286 1297 isResultHeader = webResult.header();
ohair@286 1298 }
ohair@286 1299
ohair@286 1300 Class returnType = method.getReturnType();
ohair@286 1301 Type gReturnType = method.getGenericReturnType();
ohair@286 1302 if(javaMethod.isAsync()){
ohair@286 1303 returnType = getAsyncReturnType(method, returnType);
ohair@286 1304 }
ohair@286 1305
ohair@286 1306 if ((returnType != null) && (!returnType.getName().equals("void"))) {
ohair@286 1307 Annotation[] rann = getAnnotations(method);
ohair@286 1308 if (resultName != null) {
ohair@286 1309 QName responseQName = new QName(resultTNS, resultName);
ohair@286 1310 TypeInfo rTypeReference = new TypeInfo(responseQName, returnType, rann);
ohair@286 1311 rTypeReference.setGenericType(gReturnType);
ohair@286 1312 metadataReader.getProperties(rTypeReference.properties(), method);
ohair@286 1313 ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
ohair@286 1314
ohair@286 1315 if(resultPartName == null || (resultPartName.length() == 0)){
ohair@286 1316 resultPartName = resultName;
ohair@286 1317 }
ohair@286 1318 returnParameter.setPartName(resultPartName);
ohair@286 1319 if(isResultHeader){
ohair@286 1320 returnParameter.setBinding(ParameterBinding.HEADER);
ohair@286 1321 }else{
ohair@286 1322 ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
ohair@286 1323 returnParameter.setBinding(rb);
ohair@286 1324 }
ohair@286 1325 javaMethod.addParameter(returnParameter);
ohair@286 1326 }
ohair@286 1327 }
ohair@286 1328
ohair@286 1329 //get WebParam
ohair@286 1330 Class<?>[] parameterTypes = method.getParameterTypes();
ohair@286 1331 Type[] genericParameterTypes = method.getGenericParameterTypes();
ohair@286 1332 Annotation[][] pannotations = getParamAnnotations(method);
ohair@286 1333 int pos = 0;
ohair@286 1334 for (Class clazzType : parameterTypes) {
ohair@286 1335 String paramName = operationName; //method.getName();
ohair@286 1336 String partName = null;
ohair@286 1337 String requestNamespace = targetNamespace;
ohair@286 1338 boolean isHeader = false;
ohair@286 1339
ohair@286 1340 //async
ohair@286 1341 if(javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)){
ohair@286 1342 continue;
ohair@286 1343 }
ohair@286 1344
ohair@286 1345 boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
ohair@286 1346 //set the actual type argument of Holder in the TypeReference
ohair@286 1347 if (isHolder) {
ohair@286 1348 if (clazzType==Holder.class)
mkos@450 1349 clazzType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)genericParameterTypes[pos]).getActualTypeArguments()[0]);
ohair@286 1350 }
ohair@286 1351
ohair@286 1352 Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
ohair@286 1353 for (Annotation annotation : pannotations[pos]) {
ohair@286 1354 if (annotation.annotationType() == javax.jws.WebParam.class) {
ohair@286 1355 javax.jws.WebParam webParam = (javax.jws.WebParam) annotation;
ohair@286 1356 paramMode = webParam.mode();
ohair@286 1357 if (isHolder && paramMode == Mode.IN)
ohair@286 1358 paramMode = Mode.INOUT;
ohair@286 1359 isHeader = webParam.header();
ohair@286 1360 if(isHeader)
ohair@286 1361 paramName = "arg"+pos;
ohair@286 1362 if(paramMode == Mode.OUT && !isHeader)
ohair@286 1363 paramName = operationName+RESPONSE;
ohair@286 1364 if (webParam.name().length() > 0)
ohair@286 1365 paramName = webParam.name();
ohair@286 1366 partName = webParam.partName();
ohair@286 1367 if (!webParam.targetNamespace().equals("")) {
ohair@286 1368 requestNamespace = webParam.targetNamespace();
ohair@286 1369 }
ohair@286 1370 break;
ohair@286 1371 }
ohair@286 1372 }
ohair@286 1373
ohair@286 1374 QName requestQName = new QName(requestNamespace, paramName);
alanb@368 1375 if (!isHeader && paramMode != Mode.OUT) javaMethod.setRequestPayloadName(requestQName);
ohair@286 1376 //doclit/wrapped
ohair@286 1377 TypeInfo typeRef = //operationName with upper 1 char
ohair@286 1378 new TypeInfo(requestQName, clazzType,
ohair@286 1379 pannotations[pos]);
ohair@286 1380 metadataReader.getProperties(typeRef.properties(), method, pos);
ohair@286 1381 typeRef.setGenericType(genericParameterTypes[pos]);
ohair@286 1382 ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
ohair@286 1383 if(partName == null || (partName.length() == 0)){
ohair@286 1384 partName = paramName;
ohair@286 1385 }
ohair@286 1386 param.setPartName(partName);
ohair@286 1387 if(paramMode == Mode.INOUT){
ohair@286 1388 ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
ohair@286 1389 param.setInBinding(pb);
ohair@286 1390 pb = getBinding(operationName, partName, isHeader, Mode.OUT);
ohair@286 1391 param.setOutBinding(pb);
ohair@286 1392 }else{
ohair@286 1393 if (isHeader){
ohair@286 1394 param.setBinding(ParameterBinding.HEADER);
ohair@286 1395 }else{
ohair@286 1396 ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
ohair@286 1397 param.setBinding(pb);
ohair@286 1398 }
ohair@286 1399 }
ohair@286 1400 javaMethod.addParameter(param);
ohair@286 1401 }
ohair@286 1402 validateDocBare(javaMethod);
ohair@286 1403 processExceptions(javaMethod, method);
ohair@286 1404 }
ohair@286 1405
ohair@286 1406 // Does a conservative check if there is only one BODY part for input
ohair@286 1407 // and output message. We are not considering INOUT parameters at this
ohair@286 1408 // time since binding information is not applied. Also, there isn't
ohair@286 1409 // anyway to represent some cases in SEI. For example, a INOUT parameter
ohair@286 1410 // could be bound to body for input message, header for OUTPUT message
ohair@286 1411 // in wsdl:binding
ohair@286 1412 private void validateDocBare(JavaMethodImpl javaMethod) {
ohair@286 1413 int numInBodyBindings = 0;
ohair@286 1414 for(Parameter param : javaMethod.getRequestParameters()){
ohair@286 1415 if(param.getBinding().equals(ParameterBinding.BODY) && param.isIN()){
ohair@286 1416 numInBodyBindings++;
ohair@286 1417 }
ohair@286 1418 if(numInBodyBindings > 1){
ohair@286 1419 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
ohair@286 1420 }
ohair@286 1421 }
ohair@286 1422
ohair@286 1423 int numOutBodyBindings = 0;
ohair@286 1424 for(Parameter param : javaMethod.getResponseParameters()){
ohair@286 1425 if(param.getBinding().equals(ParameterBinding.BODY) && param.isOUT()){
ohair@286 1426 numOutBodyBindings++;
ohair@286 1427 }
ohair@286 1428 if(numOutBodyBindings > 1){
ohair@286 1429 throw new RuntimeModelerException(ModelerMessages.localizableNOT_A_VALID_BARE_METHOD(portClass.getName(), javaMethod.getMethod().getName()));
ohair@286 1430 }
ohair@286 1431 }
ohair@286 1432 }
ohair@286 1433
ohair@286 1434 private Class getAsyncReturnType(Method method, Class returnType) {
ohair@286 1435 if(Response.class.isAssignableFrom(returnType)){
ohair@286 1436 Type ret = method.getGenericReturnType();
mkos@450 1437 return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)ret).getActualTypeArguments()[0]);
ohair@286 1438 }else{
ohair@286 1439 Type[] types = method.getGenericParameterTypes();
ohair@286 1440 Class[] params = method.getParameterTypes();
ohair@286 1441 int i = 0;
ohair@286 1442 for(Class cls : params){
ohair@286 1443 if(AsyncHandler.class.isAssignableFrom(cls)){
mkos@450 1444 return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)types[i]).getActualTypeArguments()[0]);
ohair@286 1445 }
ohair@286 1446 i++;
ohair@286 1447 }
ohair@286 1448 }
ohair@286 1449 return returnType;
ohair@286 1450 }
ohair@286 1451
ohair@286 1452 /**
ohair@286 1453 * utility to capitalize the first letter in a string
ohair@286 1454 * @param name the string to capitalize
ohair@286 1455 * @return the capitalized string
ohair@286 1456 */
ohair@286 1457 public static String capitalize(String name) {
ohair@286 1458 if (name == null || name.length() == 0) {
ohair@286 1459 return name;
ohair@286 1460 }
ohair@286 1461 char chars[] = name.toCharArray();
ohair@286 1462 chars[0] = Character.toUpperCase(chars[0]);
ohair@286 1463 return new String(chars);
ohair@286 1464 }
ohair@286 1465
ohair@286 1466 /*
ohair@286 1467 * Return service QName
ohair@286 1468 */
ohair@286 1469 /**
ohair@286 1470 * gets the <code>wsdl:serviceName</code> for a given implementation class
ohair@286 1471 * @param implClass the implementation class
ohair@286 1472 * @return the <code>wsdl:serviceName</code> for the <code>implClass</code>
ohair@286 1473 */
ohair@286 1474 public static QName getServiceName(Class<?> implClass) {
ohair@286 1475 return getServiceName(implClass, null);
ohair@286 1476 }
ohair@286 1477
ohair@286 1478 public static QName getServiceName(Class<?> implClass, boolean isStandard) {
ohair@286 1479 return getServiceName(implClass, null, isStandard);
ohair@286 1480 }
ohair@286 1481
ohair@286 1482 public static QName getServiceName(Class<?> implClass, MetadataReader reader) {
ohair@286 1483 return getServiceName(implClass, reader, true);
ohair@286 1484 }
ohair@286 1485
ohair@286 1486 public static QName getServiceName(Class<?> implClass, MetadataReader reader, boolean isStandard) {
ohair@286 1487 if (implClass.isInterface()) {
ohair@286 1488 throw new RuntimeModelerException("runtime.modeler.cannot.get.serviceName.from.interface",
ohair@286 1489 implClass.getCanonicalName());
ohair@286 1490 }
ohair@286 1491
ohair@286 1492 String name = implClass.getSimpleName()+SERVICE;
ohair@286 1493 String packageName = "";
ohair@286 1494 if (implClass.getPackage() != null)
ohair@286 1495 packageName = implClass.getPackage().getName();
ohair@286 1496
ohair@286 1497 WebService webService = getAnnotation(WebService.class, implClass, reader);
ohair@286 1498 if (isStandard && webService == null) {
ohair@286 1499 throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation",
ohair@286 1500 implClass.getCanonicalName());
ohair@286 1501 }
ohair@286 1502 if (webService != null && webService.serviceName().length() > 0) {
ohair@286 1503 name = webService.serviceName();
ohair@286 1504 }
ohair@286 1505 String targetNamespace = getNamespace(packageName);
ohair@286 1506 if (webService != null && webService.targetNamespace().length() > 0) {
ohair@286 1507 targetNamespace = webService.targetNamespace();
ohair@286 1508 } else if (targetNamespace == null) {
ohair@286 1509 throw new RuntimeModelerException("runtime.modeler.no.package",
ohair@286 1510 implClass.getName());
ohair@286 1511 }
ohair@286 1512 return new QName(targetNamespace, name);
ohair@286 1513 }
ohair@286 1514
ohair@286 1515 /**
ohair@286 1516 * gets the <code>wsdl:portName</code> for a given implementation class
ohair@286 1517 * @param implClass the implementation class
ohair@286 1518 * @param targetNamespace Namespace URI for service name
ohair@286 1519 * @return the <code>wsdl:portName</code> for the <code>implClass</code>
ohair@286 1520 */
ohair@286 1521 public static QName getPortName(Class<?> implClass, String targetNamespace) {
alanb@368 1522 return getPortName(implClass, null, targetNamespace);
ohair@286 1523 }
ohair@286 1524
ohair@286 1525 public static QName getPortName(Class<?> implClass, String targetNamespace, boolean isStandard) {
alanb@368 1526 return getPortName(implClass, null, targetNamespace, isStandard);
ohair@286 1527 }
ohair@286 1528
alanb@368 1529 public static QName getPortName(Class<?> implClass, MetadataReader reader, String targetNamespace) {
alanb@368 1530 return getPortName(implClass, reader, targetNamespace, true);
ohair@286 1531 }
ohair@286 1532
alanb@368 1533 public static QName getPortName(Class<?> implClass, MetadataReader reader, String targetNamespace, boolean isStandard) {
ohair@286 1534 WebService webService = getAnnotation(WebService.class, implClass, reader);
ohair@286 1535 if (isStandard && webService == null) {
ohair@286 1536 throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation",
ohair@286 1537 implClass.getCanonicalName());
ohair@286 1538 }
ohair@286 1539 String name;
ohair@286 1540 if (webService != null && webService.portName().length() > 0) {
ohair@286 1541 name = webService.portName();
ohair@286 1542 } else if (webService != null && webService.name().length() > 0) {
ohair@286 1543 name = webService.name()+PORT;
ohair@286 1544 } else {
ohair@286 1545 name = implClass.getSimpleName()+PORT;
ohair@286 1546 }
ohair@286 1547
ohair@286 1548 if (targetNamespace == null) {
ohair@286 1549 if (webService != null && webService.targetNamespace().length() > 0) {
ohair@286 1550 targetNamespace = webService.targetNamespace();
ohair@286 1551 } else {
ohair@286 1552 String packageName = null;
ohair@286 1553 if (implClass.getPackage() != null) {
ohair@286 1554 packageName = implClass.getPackage().getName();
ohair@286 1555 }
alanb@368 1556 if (packageName != null) {
alanb@368 1557 targetNamespace = getNamespace(packageName);
alanb@368 1558 }
ohair@286 1559 if (targetNamespace == null) {
ohair@286 1560 throw new RuntimeModelerException("runtime.modeler.no.package",
ohair@286 1561 implClass.getName());
ohair@286 1562 }
ohair@286 1563 }
ohair@286 1564
ohair@286 1565 }
ohair@286 1566
ohair@286 1567 return new QName(targetNamespace, name);
ohair@286 1568 }
ohair@286 1569
ohair@286 1570 static <A extends Annotation> A getAnnotation(Class<A> t, Class<?> cls, MetadataReader reader) {
ohair@286 1571 return (reader == null)? cls.getAnnotation(t) : reader.getAnnotation(t, cls);
ohair@286 1572 }
ohair@286 1573
ohair@286 1574 /**
ohair@286 1575 * Gives portType QName from implementatorClass or SEI
ohair@286 1576 * @param implOrSeiClass cant be null
ohair@286 1577 * @return <code>wsdl:portType@name</code>, null if it could not find the annotated class.
ohair@286 1578 */
ohair@286 1579 public static QName getPortTypeName(Class<?> implOrSeiClass){
ohair@286 1580 return getPortTypeName(implOrSeiClass, null, null);
ohair@286 1581 }
alanb@368 1582
alanb@368 1583 public static QName getPortTypeName(Class<?> implOrSeiClass, MetadataReader metadataReader){
alanb@368 1584 return getPortTypeName(implOrSeiClass, null, metadataReader);
alanb@368 1585 }
alanb@368 1586
ohair@286 1587 public static QName getPortTypeName(Class<?> implOrSeiClass, String tns, MetadataReader reader){
ohair@286 1588 assert(implOrSeiClass != null);
ohair@286 1589 WebService webService = getAnnotation(WebService.class, implOrSeiClass, reader);
ohair@286 1590 Class<?> clazz = implOrSeiClass;
ohair@286 1591 if (webService == null)
ohair@286 1592 throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation",
ohair@286 1593 implOrSeiClass.getCanonicalName());
ohair@286 1594
ohair@286 1595 if (!implOrSeiClass.isInterface()) {
ohair@286 1596 String epi = webService.endpointInterface();
ohair@286 1597 if (epi.length() > 0) {
ohair@286 1598 try {
ohair@286 1599 clazz = Thread.currentThread().getContextClassLoader().loadClass(epi);
ohair@286 1600 } catch (ClassNotFoundException e) {
ohair@286 1601 throw new RuntimeModelerException("runtime.modeler.class.not.found", epi);
ohair@286 1602 }
alanb@368 1603 WebService ws = getAnnotation(WebService.class, clazz, reader);
alanb@368 1604 if (ws == null) {
ohair@286 1605 throw new RuntimeModelerException("runtime.modeler.endpoint.interface.no.webservice",
ohair@286 1606 webService.endpointInterface());
ohair@286 1607 }
ohair@286 1608 }
ohair@286 1609 }
ohair@286 1610
ohair@286 1611 webService = getAnnotation(WebService.class, clazz, reader);
ohair@286 1612 String name = webService.name();
ohair@286 1613 if(name.length() == 0){
ohair@286 1614 name = clazz.getSimpleName();
ohair@286 1615 }
ohair@286 1616 if (tns == null || "".equals(tns.trim())) tns = webService.targetNamespace();
ohair@286 1617 if (tns.length() == 0)
ohair@286 1618 tns = getNamespace(clazz.getPackage().getName());
ohair@286 1619 if (tns == null) {
ohair@286 1620 throw new RuntimeModelerException("runtime.modeler.no.package", clazz.getName());
ohair@286 1621 }
ohair@286 1622 return new QName(tns, name);
ohair@286 1623 }
ohair@286 1624
ohair@286 1625 private ParameterBinding getBinding(String operation, String part, boolean isHeader, Mode mode){
ohair@286 1626 if(binding == null){
ohair@286 1627 if(isHeader)
ohair@286 1628 return ParameterBinding.HEADER;
ohair@286 1629 else
ohair@286 1630 return ParameterBinding.BODY;
ohair@286 1631 }
ohair@286 1632 QName opName = new QName(binding.getBinding().getPortType().getName().getNamespaceURI(), operation);
ohair@286 1633 return binding.getBinding().getBinding(opName, part, mode);
ohair@286 1634 }
ohair@286 1635
ohair@286 1636 private WSDLPart getPart(QName opName, String partName, Mode mode){
ohair@286 1637 if(binding != null){
ohair@286 1638 WSDLBoundOperation bo = binding.getBinding().get(opName);
ohair@286 1639 if(bo != null)
ohair@286 1640 return bo.getPart(partName, mode);
ohair@286 1641 }
ohair@286 1642 return null;
ohair@286 1643 }
ohair@286 1644
ohair@286 1645 private static Boolean getBooleanSystemProperty(final String prop) {
ohair@286 1646 return AccessController.doPrivileged(
ohair@286 1647 new java.security.PrivilegedAction<Boolean>() {
ohair@286 1648 public Boolean run() {
ohair@286 1649 String value = System.getProperty(prop);
ohair@286 1650 return value != null ? Boolean.valueOf(value) : Boolean.FALSE;
ohair@286 1651 }
ohair@286 1652 }
ohair@286 1653 );
ohair@286 1654 }
ohair@286 1655
ohair@286 1656 private static QName getReturnQName(Method method, WebResult webResult, XmlElement xmlElem) {
ohair@286 1657 String webResultName = null;
ohair@286 1658 if (webResult != null && webResult.name().length() > 0) {
ohair@286 1659 webResultName = webResult.name();
ohair@286 1660 }
ohair@286 1661 String xmlElemName = null;
ohair@286 1662 if (xmlElem != null && !xmlElem.name().equals("##default")) {
ohair@286 1663 xmlElemName = xmlElem.name();
ohair@286 1664 }
ohair@286 1665 if (xmlElemName != null && webResultName != null && !xmlElemName.equals(webResultName)) {
ohair@286 1666 throw new RuntimeModelerException("@XmlElement(name)="+xmlElemName+" and @WebResult(name)="+webResultName+" are different for method " +method);
ohair@286 1667 }
ohair@286 1668 String localPart = RETURN;
ohair@286 1669 if (webResultName != null) {
ohair@286 1670 localPart = webResultName;
ohair@286 1671 } else if (xmlElemName != null) {
ohair@286 1672 localPart = xmlElemName;
ohair@286 1673 }
ohair@286 1674
ohair@286 1675 String webResultNS = null;
ohair@286 1676 if (webResult != null && webResult.targetNamespace().length() > 0) {
ohair@286 1677 webResultNS = webResult.targetNamespace();
ohair@286 1678 }
ohair@286 1679 String xmlElemNS = null;
ohair@286 1680 if (xmlElem != null && !xmlElem.namespace().equals("##default")) {
ohair@286 1681 xmlElemNS = xmlElem.namespace();
ohair@286 1682 }
ohair@286 1683 if (xmlElemNS != null && webResultNS != null && !xmlElemNS.equals(webResultNS)) {
ohair@286 1684 throw new RuntimeModelerException("@XmlElement(namespace)="+xmlElemNS+" and @WebResult(targetNamespace)="+webResultNS+" are different for method " +method);
ohair@286 1685 }
ohair@286 1686 String ns = "";
ohair@286 1687 if (webResultNS != null) {
ohair@286 1688 ns = webResultNS;
ohair@286 1689 } else if (xmlElemNS != null) {
ohair@286 1690 ns = xmlElemNS;
ohair@286 1691 }
ohair@286 1692
ohair@286 1693 return new QName(ns, localPart);
ohair@286 1694 }
ohair@286 1695
ohair@286 1696 private static QName getParameterQName(Method method, WebParam webParam, XmlElement xmlElem, String paramDefault) {
ohair@286 1697 String webParamName = null;
ohair@286 1698 if (webParam != null && webParam.name().length() > 0) {
ohair@286 1699 webParamName = webParam.name();
ohair@286 1700 }
ohair@286 1701 String xmlElemName = null;
ohair@286 1702 if (xmlElem != null && !xmlElem.name().equals("##default")) {
ohair@286 1703 xmlElemName = xmlElem.name();
ohair@286 1704 }
ohair@286 1705 if (xmlElemName != null && webParamName != null && !xmlElemName.equals(webParamName)) {
ohair@286 1706 throw new RuntimeModelerException("@XmlElement(name)="+xmlElemName+" and @WebParam(name)="+webParamName+" are different for method " +method);
ohair@286 1707 }
ohair@286 1708 String localPart = paramDefault;
ohair@286 1709 if (webParamName != null) {
ohair@286 1710 localPart = webParamName;
ohair@286 1711 } else if (xmlElemName != null) {
ohair@286 1712 localPart = xmlElemName;
ohair@286 1713 }
ohair@286 1714
ohair@286 1715 String webParamNS = null;
ohair@286 1716 if (webParam != null && webParam.targetNamespace().length() > 0) {
ohair@286 1717 webParamNS = webParam.targetNamespace();
ohair@286 1718 }
ohair@286 1719 String xmlElemNS = null;
ohair@286 1720 if (xmlElem != null && !xmlElem.namespace().equals("##default")) {
ohair@286 1721 xmlElemNS = xmlElem.namespace();
ohair@286 1722 }
ohair@286 1723 if (xmlElemNS != null && webParamNS != null && !xmlElemNS.equals(webParamNS)) {
ohair@286 1724 throw new RuntimeModelerException("@XmlElement(namespace)="+xmlElemNS+" and @WebParam(targetNamespace)="+webParamNS+" are different for method " +method);
ohair@286 1725 }
ohair@286 1726 String ns = "";
ohair@286 1727 if (webParamNS != null) {
ohair@286 1728 ns = webParamNS;
ohair@286 1729 } else if (xmlElemNS != null) {
ohair@286 1730 ns = xmlElemNS;
ohair@286 1731 }
ohair@286 1732
ohair@286 1733 return new QName(ns, localPart);
ohair@286 1734 }
ohair@286 1735
ohair@286 1736
ohair@286 1737 }

mercurial