1 19 20 package org.netbeans.modules.xml.wsdlextui.template; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.List ; 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 49 public class SoapBindingValidator { 50 51 private List <ValidationInfo> mVList = new ArrayList <ValidationInfo>(); 52 53 54 public SoapBindingValidator() { 55 } 56 57 65 public List <ValidationInfo> validate(Binding binding) { 66 SOAPBinding.Style style = null; 67 68 List <ExtensibilityElement> ee = binding.getExtensibilityElements(); 69 Iterator <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 <BindingOperation> bOps = binding.getBindingOperations(); 82 Iterator <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 <BindingFault> bFaults = bindingOperation.getBindingFaults(); 105 if (bFaults != null && !bFaults.isEmpty()) { 106 Iterator <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 <ExtensibilityElement> eeList = bIn.getExtensibilityElements(); 117 Iterator <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 <ExtensibilityElement> eeList = bOut.getExtensibilityElements(); 148 Iterator <ExtensibilityElement> it = eeList.iterator(); 149 while(it.hasNext()) { 150 ExtensibilityElement ee = it.next(); 151 if(ee instanceof SOAPBody) { 152 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 <ExtensibilityElement> eeList = bFault.getExtensibilityElements(); 186 Iterator <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 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 <Part> parts = message.getParts(); 223 Iterator <Part> it = parts.iterator(); 224 if(it.hasNext()) { 225 Part part = it.next(); 226 String typeValue = part.getAttribute(new StringAttribute("type")); 227 228 if(typeValue != null && !typeValue.trim().equals("")) { 229 String 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 <Part> parts = message.getParts(); 245 Iterator <Part> it = parts.iterator(); 246 if(it.hasNext()) { 247 Part part = it.next(); 248 String elementValue = part.getAttribute(new StringAttribute("element")); 249 250 if(elementValue != null && !elementValue.trim().equals("")) { 251 String 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 |