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

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 384
8f2986ff0235
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/model/RuntimeModeler.java	Thu Apr 04 19:05:24 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/RuntimeModeler.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -26,6 +26,7 @@
    1.11  package com.sun.xml.internal.ws.model;
    1.12  
    1.13  import com.sun.istack.internal.NotNull;
    1.14 +import com.sun.istack.internal.localization.Localizable;
    1.15  import com.sun.xml.internal.ws.api.BindingID;
    1.16  import com.sun.xml.internal.ws.api.SOAPVersion;
    1.17  import com.sun.xml.internal.ws.api.WSBinding;
    1.18 @@ -47,8 +48,8 @@
    1.19  import com.sun.xml.internal.ws.spi.db.BindingHelper;
    1.20  import com.sun.xml.internal.ws.spi.db.TypeInfo;
    1.21  import com.sun.xml.internal.ws.spi.db.WrapperComposite;
    1.22 -import com.sun.xml.internal.ws.util.localization.Localizable;
    1.23 -import com.sun.xml.internal.org.jvnet.ws.databinding.DatabindingMode;
    1.24 +
    1.25 +import static com.sun.xml.internal.ws.binding.WebServiceFeatureList.getSoapVersion;
    1.26  
    1.27  import javax.jws.*;
    1.28  import javax.jws.WebParam.Mode;
    1.29 @@ -117,6 +118,9 @@
    1.30      public static final Class<RemoteException> REMOTE_EXCEPTION_CLASS = RemoteException.class;
    1.31      public static final Class<RuntimeException> RUNTIME_EXCEPTION_CLASS = RuntimeException.class;
    1.32      public static final Class<Exception> EXCEPTION_CLASS = Exception.class;
    1.33 +    public static final String DecapitalizeExceptionBeanProperties = "com.sun.xml.internal.ws.api.model.DecapitalizeExceptionBeanProperties";
    1.34 +    public static final String SuppressDocLitWrapperGeneration = "com.sun.xml.internal.ws.api.model.SuppressDocLitWrapperGeneration";
    1.35 +    public static final String DocWrappeeNamespapceQualified = "com.sun.xml.internal.ws.api.model.DocWrappeeNamespapceQualified";
    1.36  
    1.37    /*public RuntimeModeler(@NotNull Class portClass, @NotNull QName serviceName, @NotNull BindingID bindingId, @NotNull WebServiceFeature... features) {
    1.38          this(portClass, serviceName, null, bindingId, features);
    1.39 @@ -151,6 +155,7 @@
    1.40          this.config = config;
    1.41          this.wsBinding = config.getWSBinding();
    1.42          metadataReader = config.getMetadataReader();
    1.43 +        targetNamespace = config.getMappingInfo().getTargetNamespace();
    1.44          if (metadataReader == null) metadataReader = new ReflectAnnotationReader();
    1.45          if (wsBinding != null) {
    1.46              this.bindingId = wsBinding.getBindingId();
    1.47 @@ -159,21 +164,31 @@
    1.48                  this.features = WebServiceFeatureList.toList(wsBinding.getFeatures());
    1.49          } else {
    1.50              this.bindingId = config.getMappingInfo().getBindingID();
    1.51 +            this.features = WebServiceFeatureList.toList(config.getFeatures());
    1.52              if (binding != null) bindingId = binding.getBinding().getBindingId();
    1.53              if (bindingId == null) bindingId = getDefaultBindingID();
    1.54 -            this.features = WebServiceFeatureList.toList(config.getFeatures());
    1.55              if (!features.contains(MTOMFeature.class)) {
    1.56                  MTOM mtomAn = getAnnotation(portClass, MTOM.class);
    1.57                  if (mtomAn != null) features.add(WebServiceFeatureList.getFeature(mtomAn));
    1.58              }
    1.59 +            if (!features.contains(com.oracle.webservices.internal.api.EnvelopeStyleFeature.class)) {
    1.60 +                com.oracle.webservices.internal.api.EnvelopeStyle es = getAnnotation(portClass, com.oracle.webservices.internal.api.EnvelopeStyle.class);
    1.61 +                if (es != null) features.add(WebServiceFeatureList.getFeature(es));
    1.62 +            }
    1.63              this.wsBinding = bindingId.createBinding(features);
    1.64          }
    1.65      }
    1.66  
    1.67      private BindingID getDefaultBindingID() {
    1.68          BindingType bt = getAnnotation(portClass, BindingType.class);
    1.69 -        String id = (bt != null) ? bt.value() :  javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
    1.70 -                return BindingID.parse(id);
    1.71 +        if (bt != null) return BindingID.parse(bt.value());
    1.72 +        SOAPVersion ver = getSoapVersion(features);
    1.73 +        boolean mtomEnabled = features.isEnabled(MTOMFeature.class);
    1.74 +        if (SOAPVersion.SOAP_12.equals(ver)) {
    1.75 +            return (mtomEnabled) ? BindingID.SOAP12_HTTP_MTOM : BindingID.SOAP12_HTTP;
    1.76 +        } else {
    1.77 +            return (mtomEnabled) ? BindingID.SOAP11_HTTP_MTOM : BindingID.SOAP11_HTTP;
    1.78 +        }
    1.79          }
    1.80  
    1.81          /**
    1.82 @@ -295,12 +310,12 @@
    1.83  //                serviceName, portName);
    1.84  //        }
    1.85  
    1.86 -        if (portName == null) portName = getPortName(portClass, serviceName.getNamespaceURI(), metadataReader);
    1.87 +        if (portName == null) portName = getPortName(portClass, metadataReader, serviceName.getNamespaceURI());
    1.88          model.setPortName(portName);
    1.89  
    1.90          // Check if databinding is overridden in annotation.
    1.91 -        DatabindingMode dbm = getAnnotation(portClass, DatabindingMode.class);
    1.92 -        if (dbm != null) model.databindingInfo.setDatabindingMode(dbm.value());
    1.93 +        com.oracle.webservices.internal.api.databinding.DatabindingMode dbm2 = getAnnotation(portClass, com.oracle.webservices.internal.api.databinding.DatabindingMode.class);
    1.94 +        if (dbm2 != null) model.databindingInfo.setDatabindingMode(dbm2.value());
    1.95  
    1.96          processClass(seiClass);
    1.97          if (model.getJavaMethods().size() == 0)
    1.98 @@ -345,11 +360,17 @@
    1.99          }
   1.100      }
   1.101  
   1.102 +    private boolean noWrapperGen() {
   1.103 +        Object o = config.properties().get(SuppressDocLitWrapperGeneration);
   1.104 +        return (o!= null && o instanceof Boolean) ? ((Boolean) o) : false;
   1.105 +    }
   1.106 +
   1.107      private Class getRequestWrapperClass(String className, Method method, QName reqElemName) {
   1.108          ClassLoader loader =  (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
   1.109          try {
   1.110              return loader.loadClass(className);
   1.111          } catch (ClassNotFoundException e) {
   1.112 +            if (noWrapperGen()) return WrapperComposite.class;
   1.113              logger.fine("Dynamically creating request wrapper Class " + className);
   1.114              return WrapperBeanGenerator.createRequestWrapperBean(className, method, reqElemName, loader);
   1.115          }
   1.116 @@ -360,6 +381,7 @@
   1.117          try {
   1.118              return loader.loadClass(className);
   1.119          } catch (ClassNotFoundException e) {
   1.120 +            if (noWrapperGen()) return WrapperComposite.class;
   1.121              logger.fine("Dynamically creating response wrapper bean Class " + className);
   1.122              return WrapperBeanGenerator.createResponseWrapperBean(className, method, resElemName, loader);
   1.123          }
   1.124 @@ -367,12 +389,15 @@
   1.125  
   1.126  
   1.127      private Class getExceptionBeanClass(String className, Class exception, String name, String namespace) {
   1.128 +        boolean decapitalizeExceptionBeanProperties = true;
   1.129 +        Object o = config.properties().get(DecapitalizeExceptionBeanProperties);
   1.130 +        if (o!= null && o instanceof Boolean) decapitalizeExceptionBeanProperties = (Boolean) o;
   1.131          ClassLoader loader =  (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader;
   1.132          try {
   1.133              return loader.loadClass(className);
   1.134          } catch (ClassNotFoundException e) {
   1.135              logger.fine("Dynamically creating exception bean Class " + className);
   1.136 -            return WrapperBeanGenerator.createExceptionBean(className, exception, targetNamespace, name, namespace, loader);
   1.137 +            return WrapperBeanGenerator.createExceptionBean(className, exception, targetNamespace, name, namespace, loader, decapitalizeExceptionBeanProperties);
   1.138          }
   1.139      }
   1.140  
   1.141 @@ -417,6 +442,7 @@
   1.142          targetNamespace = portTypeName.getNamespaceURI();
   1.143          model.setPortTypeName(portTypeName);
   1.144          model.setTargetNamespace(targetNamespace);
   1.145 +        model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix();
   1.146          model.setWSDLLocation(webService.wsdlLocation());
   1.147  
   1.148          SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class);
   1.149 @@ -580,8 +606,9 @@
   1.150       * @param method the method to model
   1.151       */
   1.152      private void processMethod(Method method) {
   1.153 -        int mods = method.getModifiers();
   1.154 +//        int mods = method.getModifiers();
   1.155          WebMethod webMethod = getAnnotation(method, WebMethod.class);
   1.156 +        if (webMethod != null && webMethod.exclude()) return;
   1.157  /*
   1.158          validations are already done
   1.159  
   1.160 @@ -733,8 +760,9 @@
   1.161          RequestWrapper reqWrapper = getAnnotation(method,RequestWrapper.class);
   1.162          ResponseWrapper resWrapper = getAnnotation(method,ResponseWrapper.class);
   1.163          String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
   1.164 -        if (packageName == null || (packageName != null && packageName.length() == 0))
   1.165 +        if (packageName == null || packageName.length() == 0) {
   1.166              beanPackage = JAXWS_PACKAGE_PD;
   1.167 +        }
   1.168          String requestClassName;
   1.169          if(reqWrapper != null && reqWrapper.className().length()>0){
   1.170              requestClassName = reqWrapper.className();
   1.171 @@ -834,12 +862,13 @@
   1.172              returnType = getAsyncReturnType(method, returnType);
   1.173              resultQName = new QName(RETURN);
   1.174          }
   1.175 -
   1.176 +        resultQName = qualifyWrappeeIfNeeded(resultQName, resNamespace);
   1.177          if (!isOneway && (returnType != null) && (!returnType.getName().equals("void"))) {
   1.178              Annotation[] rann = getAnnotations(method);
   1.179              if (resultQName.getLocalPart() != null) {
   1.180                  TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
   1.181                  metadataReader.getProperties(rTypeReference.properties(), method);
   1.182 +                rTypeReference.setGenericType(method.getGenericReturnType());
   1.183                  ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
   1.184                  if (isResultHeader) {
   1.185                      returnParameter.setBinding(ParameterBinding.HEADER);
   1.186 @@ -901,9 +930,11 @@
   1.187                  if (isHolder && paramMode == Mode.IN)
   1.188                      paramMode = Mode.INOUT;
   1.189              }
   1.190 +            paramQName = qualifyWrappeeIfNeeded(paramQName, reqNamespace);
   1.191              typeRef =
   1.192                  new TypeInfo(paramQName, clazzType, pannotations[pos]);
   1.193              metadataReader.getProperties(typeRef.properties(), method, pos);
   1.194 +            typeRef.setGenericType(genericParameterTypes[pos]);
   1.195              ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
   1.196  
   1.197              if (isHeader) {
   1.198 @@ -936,6 +967,16 @@
   1.199          processExceptions(javaMethod, method);
   1.200      }
   1.201  
   1.202 +    private QName qualifyWrappeeIfNeeded(QName resultQName, String ns) {
   1.203 +        Object o = config.properties().get(DocWrappeeNamespapceQualified);
   1.204 +        boolean qualified = (o!= null && o instanceof Boolean) ? ((Boolean) o) : false;
   1.205 +        if (qualified) {
   1.206 +            if (resultQName.getNamespaceURI() == null || "".equals(resultQName.getNamespaceURI())) {
   1.207 +                return new QName(ns, resultQName.getLocalPart());
   1.208 +            }
   1.209 +        }
   1.210 +        return resultQName;
   1.211 +    }
   1.212  
   1.213      /**
   1.214       * models a rpc/literal method
   1.215 @@ -1345,7 +1386,7 @@
   1.216              }
   1.217  
   1.218              QName requestQName = new QName(requestNamespace, paramName);
   1.219 -            if (!isHeader) javaMethod.setRequestPayloadName(requestQName);
   1.220 +            if (!isHeader && paramMode != Mode.OUT) javaMethod.setRequestPayloadName(requestQName);
   1.221              //doclit/wrapped
   1.222              TypeInfo typeRef = //operationName with upper 1 char
   1.223                  new TypeInfo(requestQName, clazzType,
   1.224 @@ -1492,18 +1533,18 @@
   1.225       * @return the <code>wsdl:portName</code> for the <code>implClass</code>
   1.226       */
   1.227      public static QName getPortName(Class<?> implClass, String targetNamespace) {
   1.228 -        return getPortName(implClass, targetNamespace, null);
   1.229 +        return getPortName(implClass, null, targetNamespace);
   1.230      }
   1.231  
   1.232      public static QName getPortName(Class<?> implClass, String targetNamespace, boolean isStandard) {
   1.233 -        return getPortName(implClass, targetNamespace, null, isStandard);
   1.234 +        return getPortName(implClass, null, targetNamespace, isStandard);
   1.235      }
   1.236  
   1.237 -    public static QName getPortName(Class<?> implClass, String targetNamespace, MetadataReader reader) {
   1.238 -        return getPortName(implClass, targetNamespace, reader, true);
   1.239 +    public static QName getPortName(Class<?> implClass, MetadataReader reader, String targetNamespace) {
   1.240 +        return getPortName(implClass, reader, targetNamespace, true);
   1.241      }
   1.242  
   1.243 -    public static QName getPortName(Class<?> implClass, String targetNamespace, MetadataReader reader, boolean isStandard) {
   1.244 +    public static QName getPortName(Class<?> implClass, MetadataReader reader, String targetNamespace, boolean isStandard) {
   1.245          WebService webService = getAnnotation(WebService.class, implClass, reader);
   1.246          if (isStandard && webService == null) {
   1.247              throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation",
   1.248 @@ -1526,7 +1567,9 @@
   1.249                  if (implClass.getPackage() != null) {
   1.250                      packageName = implClass.getPackage().getName();
   1.251                  }
   1.252 -                targetNamespace = getNamespace(packageName);
   1.253 +                if (packageName != null) {
   1.254 +                    targetNamespace = getNamespace(packageName);
   1.255 +                }
   1.256                  if (targetNamespace == null) {
   1.257                      throw new RuntimeModelerException("runtime.modeler.no.package",
   1.258                          implClass.getName());
   1.259 @@ -1550,6 +1593,11 @@
   1.260      public static QName getPortTypeName(Class<?> implOrSeiClass){
   1.261          return getPortTypeName(implOrSeiClass, null, null);
   1.262      }
   1.263 +
   1.264 +    public static QName getPortTypeName(Class<?> implOrSeiClass, MetadataReader metadataReader){
   1.265 +        return getPortTypeName(implOrSeiClass, null, metadataReader);
   1.266 +    }
   1.267 +
   1.268      public static QName getPortTypeName(Class<?> implOrSeiClass, String tns, MetadataReader reader){
   1.269          assert(implOrSeiClass != null);
   1.270          WebService webService = getAnnotation(WebService.class, implOrSeiClass, reader);
   1.271 @@ -1566,7 +1614,8 @@
   1.272                  } catch (ClassNotFoundException e) {
   1.273                      throw new RuntimeModelerException("runtime.modeler.class.not.found", epi);
   1.274                  }
   1.275 -                if (!clazz.isAnnotationPresent(javax.jws.WebService.class)) {
   1.276 +                WebService ws = getAnnotation(WebService.class, clazz, reader);
   1.277 +                if (ws == null) {
   1.278                      throw new RuntimeModelerException("runtime.modeler.endpoint.interface.no.webservice",
   1.279                                          webService.endpointInterface());
   1.280                  }
   1.281 @@ -1578,7 +1627,6 @@
   1.282          if(name.length() == 0){
   1.283              name = clazz.getSimpleName();
   1.284          }
   1.285 -        tns = webService.targetNamespace();
   1.286          if (tns == null || "".equals(tns.trim())) tns = webService.targetNamespace();
   1.287          if (tns.length() == 0)
   1.288              tns = getNamespace(clazz.getPackage().getName());

mercurial