1 package org.objectweb.celtix.helpers; 2 3 import java.io.File ; 4 import java.lang.annotation.Annotation ; 5 import java.lang.reflect.Method ; 6 import java.util.*; 7 import javax.jws.WebParam; 8 import javax.wsdl.Binding; 9 import javax.wsdl.BindingInput; 10 import javax.wsdl.BindingOperation; 11 import javax.wsdl.BindingOutput; 12 import javax.wsdl.Definition; 13 import javax.wsdl.Input; 14 import javax.wsdl.Message; 15 import javax.wsdl.Operation; 16 import javax.wsdl.Output; 17 import javax.wsdl.Part; 18 import javax.wsdl.PortType; 19 import javax.wsdl.extensions.soap.SOAPBinding; 20 import javax.wsdl.extensions.soap.SOAPBody; 21 import javax.wsdl.extensions.soap.SOAPHeader; 22 import javax.wsdl.extensions.soap.SOAPOperation; 23 import javax.wsdl.factory.WSDLFactory; 24 import javax.wsdl.xml.WSDLReader; 25 import javax.xml.ws.RequestWrapper; 26 27 public class WSDLHelper { 28 29 public BindingOperation getBindingOperation(Definition def, String operationName) { 30 if (operationName == null) { 31 return null; 32 } 33 Iterator ite = def.getBindings().values().iterator(); 34 while (ite.hasNext()) { 35 Binding binding = (Binding)ite.next(); 36 Iterator ite1 = binding.getBindingOperations().iterator(); 37 while (ite1.hasNext()) { 38 BindingOperation bop = (BindingOperation)ite1.next(); 39 if (bop.getName().equals(operationName)) { 40 return bop; 41 } 42 } 43 } 44 return null; 45 } 46 47 public BindingOperation getBindingOperation(Binding binding, String operationName) { 48 if (operationName == null) { 49 return null; 50 } 51 List bindingOperations = binding.getBindingOperations(); 52 for (Iterator iter = bindingOperations.iterator(); iter.hasNext();) { 53 BindingOperation bindingOperation = (BindingOperation)iter.next(); 54 if (operationName.equals(bindingOperation.getName())) { 55 return bindingOperation; 56 } 57 } 58 return null; 59 } 60 61 public Map getParts(Operation operation, boolean out) { 62 Message message = null; 63 if (out) { 64 Output output = operation.getOutput(); 65 message = output.getMessage(); 66 } else { 67 Input input = operation.getInput(); 68 message = input.getMessage(); 69 } 70 return message.getParts() == null ? new HashMap() : message.getParts(); 71 } 72 73 public javax.jws.soap.SOAPBinding getBindingAnnotationFromClass(List<Class <?>> classList) { 74 javax.jws.soap.SOAPBinding sb = null; 75 for (Class <?> c : classList) { 76 sb = c.getAnnotation(javax.jws.soap.SOAPBinding.class); 77 if (null != sb) { 78 break; 79 } 80 } 81 return sb; 82 } 83 84 public javax.jws.soap.SOAPBinding getBindingAnnotationFromMethod(Method m) { 85 javax.jws.soap.SOAPBinding sb = null; 86 if (null != m) { 87 sb = m.getAnnotation(javax.jws.soap.SOAPBinding.class); 88 } 89 return sb; 90 } 91 92 public WebParam getWebParamAnnotation(Annotation [] pa) { 93 WebParam wp = null; 94 95 if (null != pa) { 96 for (Annotation annotation : pa) { 97 if (WebParam.class.equals(annotation.annotationType())) { 98 wp = (WebParam)annotation; 99 break; 100 } 101 } 102 } 103 return wp; 104 } 105 106 public RequestWrapper getRequestWrapperAnnotation(Method m) { 107 RequestWrapper rw = null; 108 109 if (null != m) { 110 rw = m.getAnnotation(RequestWrapper.class); 111 } 112 return rw; 113 } 114 115 public List<PortType> getPortTypes(Definition def) { 116 List<PortType> portTypes = new ArrayList<PortType>(); 117 Iterator ite = def.getPortTypes().values().iterator(); 118 while (ite.hasNext()) { 119 PortType portType = (PortType)ite.next(); 120 portTypes.add(portType); 121 } 122 return portTypes; 123 } 124 125 public List<Part> getInMessageParts(Operation operation) { 126 Input input = operation.getInput(); 127 List<Part> partsList = new ArrayList<Part>(); 128 if (input != null) { 129 Iterator ite = input.getMessage().getParts().values().iterator(); 130 while (ite.hasNext()) { 131 partsList.add((Part)ite.next()); 132 } 133 } 134 return partsList; 135 } 136 137 public List<Part> getOutMessageParts(Operation operation) { 138 Output output = operation.getOutput(); 139 List<Part> partsList = new ArrayList<Part>(); 140 if (output != null) { 141 Iterator ite = output.getMessage().getParts().values().iterator(); 142 while (ite.hasNext()) { 143 partsList.add((Part)ite.next()); 144 } 145 } 146 return partsList; 147 } 148 149 public String getBindingStyle(Binding binding) { 150 Iterator ite = binding.getExtensibilityElements().iterator(); 151 while (ite.hasNext()) { 152 Object obj = ite.next(); 153 if (obj instanceof SOAPBinding) { 154 return ((SOAPBinding)obj).getStyle(); 155 } 156 } 157 return ""; 158 } 159 160 public Binding getBinding(BindingOperation bop, Definition def) { 161 Iterator ite = def.getBindings().values().iterator(); 162 while (ite.hasNext()) { 163 Binding binding = (Binding)ite.next(); 164 for (Iterator ite2 = binding.getBindingOperations().iterator(); ite2.hasNext();) { 165 BindingOperation bindingOperation = (BindingOperation)ite2.next(); 166 if (bindingOperation.getName().equals(bop)) { 167 return binding; 168 } 169 } 170 } 171 return null; 172 } 173 174 public String getSOAPOperationStyle(BindingOperation bop) { 175 String style = ""; 176 Iterator ite = bop.getExtensibilityElements().iterator(); 177 while (ite.hasNext()) { 178 Object obj = ite.next(); 179 if (obj instanceof SOAPOperation) { 180 SOAPOperation soapOperation = (SOAPOperation)obj; 181 style = soapOperation.getStyle(); 182 break; 183 } 184 } 185 return style; 186 187 } 188 189 public SOAPBody getBindingInputSOAPBody(BindingOperation bop) { 190 BindingInput bindingInput = bop.getBindingInput(); 191 if (bindingInput != null) { 192 Iterator ite = bindingInput.getExtensibilityElements().iterator(); 193 while (ite.hasNext()) { 194 Object obj = ite.next(); 195 if (obj instanceof SOAPBody) { 196 return (SOAPBody)obj; 197 } 198 } 199 } 200 201 return null; 202 } 203 204 public SOAPHeader getBindingInputSOAPHeader(BindingOperation bop) { 205 BindingInput bindingInput = bop.getBindingInput(); 206 if (bindingInput != null) { 207 Iterator ite = bindingInput.getExtensibilityElements().iterator(); 208 while (ite.hasNext()) { 209 Object obj = ite.next(); 210 if (obj instanceof SOAPHeader) { 211 return (SOAPHeader)obj; 212 } 213 } 214 } 215 216 return null; 217 } 218 219 public SOAPHeader getBindingOutputSOAPHeader(BindingOperation bop) { 220 BindingOutput bindingOutput = bop.getBindingOutput(); 221 if (bindingOutput != null) { 222 Iterator ite = bindingOutput.getExtensibilityElements().iterator(); 223 while (ite.hasNext()) { 224 Object obj = ite.next(); 225 if (obj instanceof SOAPHeader) { 226 return (SOAPHeader)obj; 227 } 228 } 229 } 230 231 return null; 232 } 233 234 public SOAPBody getBindingOutputSOAPBody(BindingOperation bop) { 235 BindingOutput bindingOutput = bop.getBindingOutput(); 236 if (bindingOutput != null) { 237 Iterator ite = bindingOutput.getExtensibilityElements().iterator(); 238 while (ite.hasNext()) { 239 Object obj = ite.next(); 240 if (obj instanceof SOAPBody) { 241 return (SOAPBody)obj; 242 } 243 } 244 } 245 246 return null; 247 } 248 249 public Definition getDefinition(File wsdlFile) throws Exception { 250 WSDLFactory wsdlFactory = WSDLFactory.newInstance(); 251 WSDLReader reader = wsdlFactory.newWSDLReader(); 252 reader.setFeature("javax.wsdl.verbose", false); 253 return reader.readWSDL(wsdlFile.toURL().toString()); 254 } 255 256 public boolean isMixedStyle(Binding binding) { 257 Iterator ite = binding.getExtensibilityElements().iterator(); 258 String bindingStyle = ""; 259 String previousOpStyle = ""; 260 String style = ""; 261 while (ite.hasNext()) { 262 Object obj = ite.next(); 263 if (obj instanceof SOAPBinding) { 264 SOAPBinding soapBinding = (SOAPBinding)obj; 265 bindingStyle = soapBinding.getStyle(); 266 if (bindingStyle == null) { 267 bindingStyle = ""; 268 } 269 } 270 } 271 Iterator ite2 = binding.getBindingOperations().iterator(); 272 while (ite2.hasNext()) { 273 BindingOperation bop = (BindingOperation)ite2.next(); 274 Iterator ite3 = bop.getExtensibilityElements().iterator(); 275 while (ite3.hasNext()) { 276 Object obj = ite3.next(); 277 278 if (obj instanceof SOAPOperation) { 279 SOAPOperation soapOperation = (SOAPOperation)obj; 280 style = soapOperation.getStyle(); 281 if (style == null) { 282 style = ""; 283 } 284 285 if ("".equals(bindingStyle) && "".equals(previousOpStyle) || "".equals(bindingStyle) 286 && previousOpStyle.equalsIgnoreCase(style)) { 287 previousOpStyle = style; 288 289 } else if (!"".equals(bindingStyle) && "".equals(previousOpStyle) 290 && bindingStyle.equalsIgnoreCase(style) 291 || bindingStyle.equalsIgnoreCase(previousOpStyle) 292 && bindingStyle.equalsIgnoreCase(style)) { 293 previousOpStyle = style; 294 } else if (!"".equals(bindingStyle) && "".equals(style) && "".equals(previousOpStyle)) { 295 continue; 296 } else { 297 return true; 298 } 299 300 } 301 302 } 303 } 304 305 return false; 306 307 } 308 309 public String getCanonicalBindingStyle(Binding binding) { 310 String bindingStyle = getBindingStyle(binding); 311 if (bindingStyle != null && !("".equals(bindingStyle))) { 312 return bindingStyle; 313 } 314 for (Iterator ite2 = binding.getBindingOperations().iterator(); ite2.hasNext();) { 315 BindingOperation bindingOp = (BindingOperation)ite2.next(); 316 String bopStyle = getSOAPOperationStyle(bindingOp); 317 if (!"".equals(bopStyle)) { 318 return bopStyle; 319 } 320 } 321 return ""; 322 323 } 324 } 325 | Popular Tags |