KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdlextui > template > SoapBindingValidator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdlextui.template;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.netbeans.modules.xml.wsdl.model.Binding;
28 import org.netbeans.modules.xml.wsdl.model.BindingFault;
29 import org.netbeans.modules.xml.wsdl.model.BindingInput;
30 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
31 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
32 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
33 import org.netbeans.modules.xml.wsdl.model.Fault;
34 import org.netbeans.modules.xml.wsdl.model.Input;
35 import org.netbeans.modules.xml.wsdl.model.Message;
36 import org.netbeans.modules.xml.wsdl.model.Output;
37 import org.netbeans.modules.xml.wsdl.model.Part;
38 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding;
39 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
40 import org.netbeans.modules.xml.wsdl.ui.spi.ValidationInfo;
41 import org.netbeans.modules.xml.xam.Reference;
42 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
43 import org.openide.util.NbBundle;
44
45 /**
46  *
47  * @author radval
48  */

49 public class SoapBindingValidator {
50     
51     private List JavaDoc<ValidationInfo> mVList = new ArrayList JavaDoc<ValidationInfo>();
52     
53     /** Creates a new instance of SoapBindingValidator */
54     public SoapBindingValidator() {
55     }
56     
57     /**
58      * validate Binding and its child elements based on
59      * the information available in corresponding PortType. This will be called
60      * when binding user goes from portType configuration wizard to binding
61      * configuration or when user changes subtype of binding in binding configuration.
62      * Note this binding is not yet added to definition.
63      * @param binding Binding for portType
64      */

65     public List JavaDoc<ValidationInfo> validate(Binding binding) {
66         SOAPBinding.Style style = null;
67         
68         List JavaDoc<ExtensibilityElement> ee = binding.getExtensibilityElements();
69         Iterator JavaDoc<ExtensibilityElement> it = ee.iterator();
70         while(it.hasNext()) {
71             ExtensibilityElement e = it.next();
72             if(e instanceof SOAPBinding) {
73                 SOAPBinding sBinding = (SOAPBinding) e;
74                 style = sBinding.getStyle();
75                 break;
76             }
77         }
78         
79         if(style != null) {
80             
81             Collection JavaDoc<BindingOperation> bOps = binding.getBindingOperations();
82             Iterator JavaDoc<BindingOperation> itBops = bOps.iterator();
83             while(itBops.hasNext()) {
84                 BindingOperation op = itBops.next();
85                 processBindingOperation(style, op);
86             }
87         }
88         
89         return this.mVList;
90         
91     }
92     
93     private void processBindingOperation(SOAPBinding.Style style, BindingOperation bindingOperation) {
94         BindingInput bIn = bindingOperation.getBindingInput();
95         if (bIn != null) {
96             processBindingOperationInput(style, bIn);
97         }
98         
99         BindingOutput bOut = bindingOperation.getBindingOutput();
100         if (bOut != null) {
101             processBindingOperationOutput(style, bOut);
102         }
103         
104         Collection JavaDoc<BindingFault> bFaults = bindingOperation.getBindingFaults();
105         if (bFaults != null && !bFaults.isEmpty()) {
106             Iterator JavaDoc<BindingFault> it = bFaults.iterator();
107             while(it.hasNext()) {
108                 BindingFault bFault = it.next();
109                 processBindingOperationFault(style, bFault);
110             }
111         }
112     }
113     
114     
115     private void processBindingOperationInput(SOAPBinding.Style style, BindingInput bIn) {
116             List JavaDoc<ExtensibilityElement> eeList = bIn.getExtensibilityElements();
117             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
118             while(it.hasNext()) {
119                 ExtensibilityElement ee = it.next();
120                 if(ee instanceof SOAPBody) {
121                     SOAPBody sBody = (SOAPBody) ee;
122                     SOAPBody.Use use = sBody.getUse();
123                     if(use != null) {
124                         Reference<Input> inputRef = bIn.getInput();
125                         if(inputRef != null && inputRef.get() != null) {
126                             Input input = inputRef.get();
127                             NamedComponentReference<Message> messageRef = input.getMessage();
128                             if(use.equals(SOAPBody.Use.LITERAL)) {
129                                 if(style.equals(SOAPBinding.Style.DOCUMENT)) {
130                                     processSoapBodyForDocumentLiteral(messageRef);
131                                 } else if (style.equals(SOAPBinding.Style.RPC)) {
132                                     processSoapBodyForRPCLiteral(messageRef);
133                                 }
134                             }
135
136                         }
137                         
138                     }
139                     
140                 }
141             }
142         
143     }
144     
145     private void processBindingOperationOutput(SOAPBinding.Style style, BindingOutput bOut ) {
146         if(style.equals(SOAPBinding.Style.DOCUMENT)) {
147             List JavaDoc<ExtensibilityElement> eeList = bOut.getExtensibilityElements();
148             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
149             while(it.hasNext()) {
150                 ExtensibilityElement ee = it.next();
151                 if(ee instanceof SOAPBody) {
152 // SOAPBody sBody = (SOAPBody) ee;
153
// Reference<Output> outputRef = bOut.getOutput();
154
// if(outputRef != null && outputRef.get() != null) {
155
// Output output = outputRef.get();
156
// NamedComponentReference<Message> messageRef = output.getMessage();
157
// processSoapBodyForDocumentLiteral(messageRef);
158
//
159
// }
160
SOAPBody sBody = (SOAPBody) ee;
161                     SOAPBody.Use use = sBody.getUse();
162                     if(use != null) {
163                         Reference<Output> outputRef = bOut.getOutput();
164                         if(outputRef != null && outputRef.get() != null) {
165                             Output output = outputRef.get();
166                             NamedComponentReference<Message> messageRef = output.getMessage();
167                             if(use.equals(SOAPBody.Use.LITERAL)) {
168                                 if(style.equals(SOAPBinding.Style.DOCUMENT)) {
169                                     processSoapBodyForDocumentLiteral(messageRef);
170                                 } else if (style.equals(SOAPBinding.Style.RPC)) {
171                                     processSoapBodyForRPCLiteral(messageRef);
172                                 }
173                             }
174
175                         }
176                         
177                     }
178                 }
179             }
180         }
181     }
182     
183     private void processBindingOperationFault(SOAPBinding.Style style, BindingFault bFault) {
184         if(style.equals(SOAPBinding.Style.DOCUMENT)) {
185             List JavaDoc<ExtensibilityElement> eeList = bFault.getExtensibilityElements();
186             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
187             while(it.hasNext()) {
188                 ExtensibilityElement ee = it.next();
189                 if(ee instanceof SOAPBody) {
190                     SOAPBody sBody = (SOAPBody) ee;
191                     SOAPBody.Use use = sBody.getUse();
192                     if(use != null) {
193                         Reference<Fault> faultRef = bFault.getFault();
194                         if(faultRef != null && faultRef.get() != null) {
195                             Fault fault = faultRef.get();
196                             NamedComponentReference<Message> messageRef = fault.getMessage();
197                             if(use.equals(SOAPBody.Use.LITERAL)) {
198                                 if(style.equals(SOAPBinding.Style.DOCUMENT)) {
199                                     processSoapBodyForDocumentLiteral(messageRef);
200                                 } else if (style.equals(SOAPBinding.Style.RPC)) {
201                                     processSoapBodyForRPCLiteral(messageRef);
202                                 }
203                             }
204
205                         }
206                         
207                     }
208                 }
209             }
210         }
211     }
212     
213     private void processSoapBodyForDocumentLiteral(NamedComponentReference<Message> messageRef) {
214         if(messageRef != null && messageRef.get() != null) {
215             Message message = messageRef.get();
216             if(message.getParts().size() > 1) {
217                 String JavaDoc desc = NbBundle.getMessage(SoapBindingValidator.class, "LBL_doc_literal_R2210");
218                 ValidationInfo vInfo =
219                         new ValidationInfo(ValidationInfo.ValidationType.ERROR, desc);
220                 this.mVList.add(vInfo);
221             } else {
222                 Collection JavaDoc<Part> parts = message.getParts();
223                 Iterator JavaDoc<Part> it = parts.iterator();
224                 if(it.hasNext()) {
225                     Part part = it.next();
226                     String JavaDoc typeValue = part.getAttribute(new StringAttribute("type"));
227                     
228                     if(typeValue != null && !typeValue.trim().equals("")) {
229                     //Not to add schema model dependency
230
//if(part.getType() != null && part.getType().get() != null) {
231
String JavaDoc desc = NbBundle.getMessage(SoapBindingValidator.class, "LBL_doc_literal_R2204");
232                         ValidationInfo vInfo =
233                             new ValidationInfo(ValidationInfo.ValidationType.ERROR, desc);
234                         this.mVList.add(vInfo);
235                     }
236                 }
237             }
238         }
239     }
240     
241     private void processSoapBodyForRPCLiteral(NamedComponentReference<Message> messageRef) {
242         if(messageRef != null && messageRef.get() != null) {
243             Message message = messageRef.get();
244                 Collection JavaDoc<Part> parts = message.getParts();
245                 Iterator JavaDoc<Part> it = parts.iterator();
246                 if(it.hasNext()) {
247                     Part part = it.next();
248                     String JavaDoc elementValue = part.getAttribute(new StringAttribute("element"));
249                     
250                     if(elementValue != null && !elementValue.trim().equals("")) {
251                     //Not to add schema model dependency
252
//if(part.getElement() != null && part.Element().get() != null) {
253
String JavaDoc desc = NbBundle.getMessage(SoapBindingValidator.class, "LBL_rpc_literal_R2203");
254                         ValidationInfo vInfo =
255                             new ValidationInfo(ValidationInfo.ValidationType.ERROR, desc);
256                         this.mVList.add(vInfo);
257                     }
258                 }
259             
260         }
261     }
262 }
263
Popular Tags