KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > wsdl2 > validators > WSIBPValidator


1 package org.objectweb.celtix.tools.processors.wsdl2.validators;
2
3 import java.lang.reflect.Method JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.jws.soap.SOAPBinding;
9 import javax.wsdl.Binding;
10 import javax.wsdl.BindingOperation;
11 import javax.wsdl.Definition;
12 import javax.wsdl.Message;
13 import javax.wsdl.Operation;
14 import javax.wsdl.Part;
15 import javax.wsdl.PortType;
16 import javax.wsdl.extensions.soap.SOAPBody;
17 import javax.wsdl.extensions.soap.SOAPHeader;
18
19 import org.objectweb.celtix.helpers.WSDLHelper;
20 import org.objectweb.celtix.tools.common.ToolException;
21
22 public class WSIBPValidator extends AbstractValidator {
23     private List JavaDoc<String JavaDoc> operationMap = new ArrayList JavaDoc<String JavaDoc>();
24     private WSDLHelper wsdlHelper = new WSDLHelper();
25     
26     public WSIBPValidator(Definition def) {
27         super(def);
28     }
29
30     public boolean isValid() {
31         for (Method JavaDoc m : getClass().getMethods()) {
32             Boolean JavaDoc res = Boolean.TRUE;
33
34             if (m.getName().startsWith("check")) {
35                 try {
36                     res = (Boolean JavaDoc)m.invoke(this, new Object JavaDoc[] {});
37                 } catch (Exception JavaDoc e) {
38                     e.printStackTrace();
39                     throw new ToolException(e);
40                 }
41                 if (!res.booleanValue()) {
42                     return false;
43                 }
44             }
45         }
46         return true;
47
48     }
49
50     public boolean checkR2201() {
51         for (PortType portType : wsdlHelper.getPortTypes(def)) {
52             Iterator JavaDoc ite = portType.getOperations().iterator();
53             while (ite.hasNext()) {
54                 Operation operation = (Operation)ite.next();
55                 if (isOverloading(operation.getName())) {
56                     continue;
57                 }
58                 BindingOperation bop = wsdlHelper.getBindingOperation(def, operation.getName());
59                 Binding binding = wsdlHelper.getBinding(bop, def);
60                 String JavaDoc bindingStyle = binding != null ? wsdlHelper.getBindingStyle(binding) : "";
61
62                 String JavaDoc style = "".equals(wsdlHelper.getSOAPOperationStyle(bop))
63                     ? bindingStyle : wsdlHelper.getSOAPOperationStyle(bop);
64
65                 if ("DOCUMENT".equalsIgnoreCase(style)) {
66                     List JavaDoc<Part> partsList = wsdlHelper.getInMessageParts(operation);
67                     int inmessagePartsCount = partsList.size();
68                     SOAPBody soapBody = wsdlHelper.getBindingInputSOAPBody(bop);
69                     if (soapBody != null) {
70                         List JavaDoc parts = soapBody.getParts();
71                         int boundPartSize = parts == null ? inmessagePartsCount : parts.size();
72                         SOAPHeader soapHeader = wsdlHelper.getBindingInputSOAPHeader(bop);
73                         boundPartSize = soapHeader != null
74                                         && soapHeader.getMessage().equals(
75                                                                           operation.getInput().getMessage()
76                                                                               .getQName())
77                             ? boundPartSize - 1 : boundPartSize;
78
79                         if (parts != null) {
80                             Iterator JavaDoc partsIte = parts.iterator();
81                             while (partsIte.hasNext()) {
82                                 String JavaDoc partName = (String JavaDoc)partsIte.next();
83                                 boolean isDefined = false;
84                                 for (Part part : partsList) {
85                                     if (partName.equalsIgnoreCase(part.getName())) {
86                                         isDefined = true;
87                                         break;
88                                     }
89                                 }
90                                 if (!isDefined) {
91                                     addErrorMessage("opartion: " + operation.getName() + " soapBody parts : "
92                                                     + partName + " not found in the message, wrong WSDL");
93                                     return false;
94                                 }
95
96                             }
97                         }
98
99                         if (boundPartSize > 1) {
100                             addErrorMessage("operation:" + operation.getName()
101                                             + " more than one part bound to body");
102                             return false;
103                         }
104                     }
105
106                     int outmessagePartsCount = wsdlHelper.getOutMessageParts(operation).size();
107                     soapBody = wsdlHelper.getBindingOutputSOAPBody(bop);
108                     if (soapBody != null) {
109                         List JavaDoc parts = soapBody.getParts();
110                         int boundPartSize = parts == null ? outmessagePartsCount : parts.size();
111                         SOAPHeader soapHeader = wsdlHelper.getBindingOutputSOAPHeader(bop);
112                         boundPartSize = soapHeader != null
113                                         && soapHeader.getMessage().equals(
114                                                                           operation.getOutput().getMessage()
115                                                                               .getQName())
116                             ? boundPartSize - 1 : boundPartSize;
117                         if (parts != null) {
118                             Iterator JavaDoc partsIte = parts.iterator();
119                             while (partsIte.hasNext()) {
120                                 String JavaDoc partName = (String JavaDoc)partsIte.next();
121                                 boolean isDefined = false;
122                                 for (Part part : wsdlHelper.getOutMessageParts(operation)) {
123                                     if (partName.equalsIgnoreCase(part.getName())) {
124                                         isDefined = true;
125                                         break;
126                                     }
127                                 }
128                                 if (!isDefined) {
129                                     addErrorMessage("opartion: " + operation.getName() + " soapBody parts : "
130                                                     + partName + " not found in the message, wrong WSDL");
131                                     return false;
132                                 }
133
134                             }
135                         }
136
137                         if (boundPartSize > 1) {
138                             addErrorMessage("operation:" + operation.getName()
139                                             + " more than one part bound to body");
140                             return false;
141                         }
142                     }
143                 }
144
145             }
146         }
147         return true;
148
149     }
150
151     public boolean checkR2203And2204() {
152
153         for (Iterator JavaDoc ite = def.getBindings().values().iterator(); ite.hasNext();) {
154             Binding binding = (Binding)ite.next();
155
156             String JavaDoc style = wsdlHelper.getCanonicalBindingStyle(binding);
157
158             //
159

160             for (Iterator JavaDoc ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext();) {
161                 Operation operation = (Operation)ite2.next();
162                 if (operation.getInput() != null && operation.getInput().getMessage() != null) {
163                     Message inMess = operation.getInput().getMessage();
164
165                     for (Iterator JavaDoc ite3 = inMess.getParts().values().iterator(); ite3.hasNext();) {
166                         Part p = (Part)ite3.next();
167                         if (style.equalsIgnoreCase(SOAPBinding.Style.RPC.name()) && p.getTypeName() == null) {
168                             addErrorMessage("An rpc-literal binding in a DESCRIPTION MUST refer, "
169                                             + "in its soapbind:body element(s), only to "
170                                             + "wsdl:part element(s) that have been defined "
171                                             + "using the type attribute.");
172                             return false;
173                         }
174
175                         if (style.equalsIgnoreCase(SOAPBinding.Style.DOCUMENT.name())
176                             && p.getElementName() == null) {
177                             addErrorMessage("A document-literal binding in a DESCRIPTION MUST refer, "
178                                             + "in each of its soapbind:body element(s),"
179                                             + "only to wsdl:part element(s)"
180                                             + " that have been defined using the element attribute.");
181                             return false;
182                         }
183
184                     }
185                 }
186                 if (operation.getOutput() != null && operation.getOutput().getMessage() != null) {
187                     Message outMess = operation.getOutput().getMessage();
188                     for (Iterator JavaDoc ite3 = outMess.getParts().values().iterator(); ite3.hasNext();) {
189                         Part p = (Part)ite3.next();
190                         if (style.equalsIgnoreCase(SOAPBinding.Style.RPC.name()) && p.getTypeName() == null) {
191                             addErrorMessage("An rpc-literal binding in a DESCRIPTION MUST refer, "
192                                             + "in its soapbind:body element(s), only to "
193                                             + "wsdl:part element(s) that have been defined "
194                                             + "using the type attribute.");
195                             return false;
196                         }
197
198                         if (style.equalsIgnoreCase(SOAPBinding.Style.DOCUMENT.name())
199                             && p.getElementName() == null) {
200                             addErrorMessage("A document-literal binding in a DESCRIPTION MUST refer, "
201                                             + "in each of its soapbind:body element(s),"
202                                             + "only to wsdl:part element(s)"
203                                             + " that have been defined using the element attribute.");
204                             return false;
205                         }
206
207                     }
208                 }
209             }
210
211         }
212         return true;
213     }
214
215     public boolean checkR2705() {
216         Iterator JavaDoc ite = def.getBindings().values().iterator();
217         while (ite.hasNext()) {
218             Object JavaDoc obj = ite.next();
219             Binding binding = (Binding)obj;
220             if (wsdlHelper.isMixedStyle(binding)) {
221                 addErrorMessage("Mixted style ,Wrong WSDL");
222                 return false;
223             }
224         }
225         return true;
226     }
227
228     private boolean isOverloading(String JavaDoc operationName) {
229         if (operationMap.contains(operationName)) {
230             return true;
231         } else {
232             operationMap.add(operationName);
233         }
234         return false;
235     }
236
237 }
238
Popular Tags