src/share/jaxws_classes/com/sun/tools/internal/ws/processor/generator/SeiGenerator.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -34,14 +34,12 @@
 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType;
 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
 import com.sun.tools.internal.ws.wscompile.Options;
 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
-import com.sun.tools.internal.ws.wscompile.AbortException;
 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
 import com.sun.tools.internal.ws.wsdl.document.PortType;
-import com.sun.tools.internal.ws.wsdl.document.Kinds;
 import com.sun.tools.internal.ws.resources.GeneratorMessages;
 
 import javax.jws.WebMethod;
 import javax.jws.WebParam;
 import javax.jws.WebService;

@@ -53,11 +51,10 @@
 import java.util.List;
 
 import org.xml.sax.Locator;
 
 public class SeiGenerator extends GeneratorBase {
-    private String serviceNS;
     private TJavaGeneratorExtension extension;
     private List<TJavaGeneratorExtension> extensionHandlers;
 
     public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions){
         SeiGenerator seiGenerator = new SeiGenerator();

@@ -74,14 +71,15 @@
         // 2.2 Spec requires generation of @Action when wsam:Action is explicitly stated in wsdl
         if (options.target.isLaterThan(Options.Target.V2_2)) {
            register(new W3CAddressingJavaGeneratorExtension());
         }
 
-        for (TJavaGeneratorExtension j : extensions)
+        for (TJavaGeneratorExtension j : extensions) {
             register(j);
+        }
 
-        this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[0]));
+        this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[extensionHandlers.size()]));
     }
 
     private void write(Port port) {
         JavaInterface intf = port.getJavaInterface();
         String className = Names.customJavaTypeClassName(intf);

@@ -90,30 +88,32 @@
             log("Class " + className + " exists. Not overriding.");
             return;
         }
 
 
-        JDefinedClass cls = null;
+        JDefinedClass cls;
         try {
             cls = getClass(className, ClassType.INTERFACE);
         } catch (JClassAlreadyExistsException e) {
             QName portTypeName =
                 (QName) port.getProperty(
                         ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
             Locator loc = null;
             if(portTypeName != null){
                 PortType pt = port.portTypes.get(portTypeName);
-                if(pt!=null)
+                if (pt!=null) {
                     loc = pt.getLocator();
             }
+            }
             receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
             return;
         }
         // If the class has methods it has already been defined
         // so skip it.
-        if (!cls.methods().isEmpty())
+        if (!cls.methods().isEmpty()) {
             return;
+        }
 
         //write class comment - JAXWS warning
         JDocComment comment = cls.javadoc();
 
         String ptDoc = intf.getJavaDoc();

@@ -136,12 +136,13 @@
 
         //@SOAPBinding
         writeSOAPBinding(port, cls);
 
         //@XmlSeeAlso
-        if(options.target.isLaterThan(Options.Target.V2_1))
+        if (options.target.isLaterThan(Options.Target.V2_1)) {
             writeXmlSeeAlso(cls);
+        }
 
         for (Operation operation: port.getOperations()) {
             JavaMethod method = operation.getJavaMethod();
 
             //@WebMethod

@@ -157,12 +158,13 @@
                 retType.annotate(m);
                 methodDoc = m.javadoc();
                 JCommentPart ret = methodDoc.addReturn();
                 ret.add("returns "+retType.getName());
             }
-            if(methodJavaDoc != null)
+            if (methodJavaDoc != null) {
                 methodDoc.add(methodJavaDoc);
+            }
 
             writeWebMethod(operation, m);
             JClass holder = cm.ref(Holder.class);
             for (JavaParameter parameter: method.getParametersList()) {
                 JVar var;

@@ -194,12 +196,13 @@
     private void writeXmlSeeAlso(JDefinedClass cls) {
         if (model.getJAXBModel().getS2JJAXBModel() != null) {
             List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories();
 
             //if there are no object facotires, dont generate @XmlSeeAlso
-            if(objectFactories.size() == 0)
+            if (objectFactories.isEmpty()) {
                 return;
+            }
 
             JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class));
             JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value");
             for (JClass of : objectFactories) {
                 paramArray = paramArray.param(of);

@@ -259,25 +262,28 @@
 
                         if(!resultName.equals("return")){
                             wr = m.annotate(javax.jws.WebResult.class);
                             wr.param("name", resultName);
                         }
-                        if((nsURI != null) && (!nsURI.equals(serviceNS) || (isDocStyle && operation.isWrapped()))){
-                            if(wr == null)
+                        if (nsURI != null || (isDocStyle && operation.isWrapped())) {
+                            if(wr == null) {
                                 wr = m.annotate(javax.jws.WebResult.class);
+                            }
                             wr.param("targetNamespace", nsURI);
                         }
                         //doclit wrapped could have additional headers
                         if(!(isDocStyle && operation.isWrapped()) ||
                                 (parameter.getBlock().getLocation() == Block.HEADER)){
-                            if(wr == null)
+                            if (wr == null) {
                                 wr = m.annotate(javax.jws.WebResult.class);
+                            }
                             wr.param("partName", parameter.getName());
                         }
                         if(parameter.getBlock().getLocation() == Block.HEADER){
-                            if(wr == null)
+                            if (wr == null) {
                                 wr = m.annotate(javax.jws.WebResult.class);
+                            }
                             wr.param("header",true);
                         }
                     }
                 }
 

@@ -316,38 +322,47 @@
                (message.getHeaderBlockCount() > 0 &&
                block.equals(message.getHeaderBlocks().next()));
     }
 
     private boolean isHeaderParam(Parameter param, Message message) {
-        if (message.getHeaderBlockCount() == 0)
+        if (message.getHeaderBlockCount() == 0) {
             return false;
+        }
 
-        for (Block headerBlock : message.getHeaderBlocksMap().values())
-            if (param.getBlock().equals(headerBlock))
+        for (Block headerBlock : message.getHeaderBlocksMap().values()) {
+            if (param.getBlock().equals(headerBlock)) {
                 return true;
+            }
+        }
 
         return false;
     }
 
     private boolean isAttachmentParam(Parameter param, Message message){
-        if (message.getAttachmentBlockCount() == 0)
+        if (message.getAttachmentBlockCount() == 0) {
             return false;
+        }
 
-        for (Block attBlock : message.getAttachmentBlocksMap().values())
-            if (param.getBlock().equals(attBlock))
+        for (Block attBlock : message.getAttachmentBlocksMap().values()) {
+            if (param.getBlock().equals(attBlock)) {
                 return true;
+            }
+        }
 
         return false;
     }
 
     private boolean isUnboundParam(Parameter param, Message message){
-        if (message.getUnboundBlocksCount() == 0)
+        if (message.getUnboundBlocksCount() == 0) {
             return false;
+        }
 
-        for (Block unboundBlock : message.getUnboundBlocksMap().values())
-            if (param.getBlock().equals(unboundBlock))
+        for (Block unboundBlock : message.getUnboundBlocksMap().values()) {
+            if (param.getBlock().equals(unboundBlock)) {
                 return true;
+            }
+        }
 
         return false;
     }
 
     private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) {

@@ -359,14 +374,15 @@
             (res != null && isHeaderParam(param, res));
 
         String name;
         boolean isWrapped = operation.isWrapped();
 
-        if((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped))
+        if ((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) {
             name = param.getBlock().getName().getLocalPart();
-        else
+        } else {
             name = param.getName();
+        }
 
         paramAnno.param("name", name);
 
         String ns= null;
 

@@ -377,12 +393,13 @@
             }
         }else if(header){
             ns = param.getBlock().getName().getNamespaceURI();
         }
 
-        if((ns != null) && (!ns.equals(serviceNS) || (isDocStyle && isWrapped)))
+        if (ns != null || (isDocStyle && isWrapped)) {
             paramAnno.param("targetNamespace", ns);
+        }
 
         if (header) {
             paramAnno.param("header", true);
         }
 

@@ -392,13 +409,14 @@
                 isUnboundParam(param,res) || param.isOUT())){
             paramAnno.param("mode", javax.jws.WebParam.Mode.OUT);
         }
 
         //doclit wrapped could have additional headers
-        if(!(isDocStyle && isWrapped) || header)
+        if (!(isDocStyle && isWrapped) || header) {
             paramAnno.param("partName", javaParameter.getParameter().getName());
     }
+    }
 
     private boolean isDocStyle = true;
     private boolean sameParamStyle = true;
     private void writeSOAPBinding(Port port, JDefinedClass cls) {
         JAnnotationUse soapBindingAnn = null;

@@ -416,38 +434,40 @@
                     isWrapper = operation.isWrapped();
                     first = false;
                     continue;
                 }
                 sameParamStyle = (isWrapper == operation.isWrapped());
-                if(!sameParamStyle)
+                if (!sameParamStyle) {
                     break;
             }
-            if(sameParamStyle)
+            }
+            if (sameParamStyle) {
                 port.setWrapped(isWrapper);
         }
+        }
         if(sameParamStyle && !port.isWrapped()){
-            if(soapBindingAnn == null)
+            if (soapBindingAnn == null) {
                 soapBindingAnn = cls.annotate(SOAPBinding.class);
+            }
             soapBindingAnn.param("parameterStyle", SOAPBinding.ParameterStyle.BARE);
         }
     }
 
     private void writeWebServiceAnnotation(Port port, JAnnotationUse wsa) {
         QName name = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
         wsa.param("name", name.getLocalPart());
         wsa.param("targetNamespace", name.getNamespaceURI());
     }
 
-
-
-
+    @Override
     public void visit(Model model) throws Exception {
         for(Service s:model.getServices()){
             s.accept(this);
         }
     }
 
+    @Override
     public void visit(Service service) throws Exception {
         String jd = model.getJavaDoc();
         if(jd != null){
             JPackage pkg = cm._package(options.defaultPackage);
             pkg.javadoc().add(jd);