KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > wsdl2 > internal > SEIAnnotationProcessor


1 package org.objectweb.celtix.tools.processors.wsdl2.internal;
2
3 import java.util.*;
4 import javax.jws.soap.SOAPBinding;
5 import javax.wsdl.Definition;
6
7 import org.objectweb.celtix.tools.common.ProcessorEnvironment;
8 import org.objectweb.celtix.tools.common.model.JavaAnnotation;
9 import org.objectweb.celtix.tools.common.model.JavaInterface;
10 import org.objectweb.celtix.tools.common.model.JavaMethod;
11 import org.objectweb.celtix.tools.common.model.JavaModel;
12 import org.objectweb.celtix.tools.utils.SOAPBindingUtil;
13
14 public class SEIAnnotationProcessor extends AbstractProcessor {
15
16     public SEIAnnotationProcessor(ProcessorEnvironment penv) {
17         super(penv);
18     }
19     
20     public void process(JavaModel javaModel, Definition def) {
21         Map<String JavaDoc, JavaInterface> interfaces = javaModel.getInterfaces();
22         for (Iterator iter = interfaces.keySet().iterator(); iter.hasNext();) {
23             String JavaDoc interfaceName = (String JavaDoc)iter.next();
24             JavaInterface intf = interfaces.get(interfaceName);
25             
26             JavaAnnotation serviceAnnotation = new JavaAnnotation("WebService");
27             serviceAnnotation.addArgument("targetNamespace", intf.getNamespace());
28             serviceAnnotation.addArgument("wsdlLocation", intf.getLocation());
29             serviceAnnotation.addArgument("name", intf.getWebServiceName());
30
31             intf.addAnnotation(serviceAnnotation.toString());
32             
33             if (def.getBindings().size() == 0) {
34                 return;
35             }
36             if (processBinding(intf)) {
37                 JavaAnnotation bindingAnnotation = new JavaAnnotation("SOAPBinding");
38                 String JavaDoc style = SOAPBindingUtil.getBindingAnnotation(intf.getSOAPStyle().toString());
39                 bindingAnnotation.addArgument("style", style, "");
40                 String JavaDoc use = SOAPBindingUtil.getBindingAnnotation(intf.getSOAPUse().toString());
41                 bindingAnnotation.addArgument("use", use, "");
42                 if (intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT) {
43                     String JavaDoc parameterStyle = SOAPBindingUtil.getBindingAnnotation(intf.
44                                                                                  getSOAPParameterStyle().
45                                                                                  toString());
46                     bindingAnnotation.addArgument("parameterStyle", parameterStyle, "");
47                 }
48                 intf.addAnnotation(bindingAnnotation.toString());
49             }
50         }
51     }
52
53     private boolean processBinding(JavaInterface intf) {
54         SOAPBinding.Style soapStyle = intf.getSOAPStyle();
55         SOAPBinding.Use soapUse = intf.getSOAPUse();
56         boolean isWrapped = true;
57         int count = 0;
58         for (JavaMethod method : intf.getMethods()) {
59             if (!method.isWrapperStyle()) {
60                 isWrapped = false;
61                 count++;
62             }
63             if (soapStyle == null
64                 && method.getSoapStyle() != null) {
65                 soapStyle = method.getSoapStyle();
66             }
67             if (soapUse == null
68                 && method.getSoapUse() != null) {
69                 soapUse = method.getSoapUse();
70             }
71         }
72
73         if (soapStyle == SOAPBinding.Style.DOCUMENT) {
74             intf.setSOAPStyle(SOAPBinding.Style.DOCUMENT);
75             if (isWrapped) {
76                 intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.WRAPPED);
77             } else {
78                 intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.BARE);
79             }
80         } else if (soapStyle == null) {
81             intf.setSOAPStyle(SOAPBinding.Style.DOCUMENT);
82             if (isWrapped) {
83                 intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.WRAPPED);
84             } else {
85                 intf.setSOAPParameterStyle(SOAPBinding.ParameterStyle.BARE);
86             }
87             
88         } else {
89             intf.setSOAPStyle(SOAPBinding.Style.RPC);
90         }
91         
92         if (soapUse == SOAPBinding.Use.LITERAL) {
93             intf.setSOAPUse(SOAPBinding.Use.LITERAL);
94         } else if (soapUse == null) {
95             intf.setSOAPUse(SOAPBinding.Use.LITERAL);
96         } else {
97             intf.setSOAPUse(SOAPBinding.Use.ENCODED);
98         }
99
100         if (intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT
101             && count != 0
102             && count != intf.getMethods().size()) {
103             return false;
104         }
105
106         if (intf.getSOAPStyle() == SOAPBinding.Style.DOCUMENT
107             && intf.getSOAPUse() == SOAPBinding.Use.LITERAL
108             && intf.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.WRAPPED) {
109             return false;
110         }
111         return true;
112     }
113 }
114
Popular Tags