1 /*** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.codehaus.xfire.wsdl11; 18 19 import java.util.Collection; 20 import java.util.Iterator; 21 import java.util.List; 22 import javax.wsdl.*; 23 import javax.wsdl.extensions.soap.SOAPBody; 24 import javax.wsdl.extensions.soap.SOAPBinding; 25 26 public class WSDLVisitor 27 { 28 protected final Definition definition; 29 30 public WSDLVisitor(Definition definition) 31 { 32 this.definition = definition; 33 } 34 35 public void walkTree() 36 { 37 begin(); 38 try 39 { 40 visit(definition); 41 Collection imports = definition.getImports().values(); 42 for (Iterator iterator = imports.iterator(); iterator.hasNext();) 43 { 44 Import wsdlImport = (Import) iterator.next(); 45 visit(wsdlImport); 46 } 47 visit(definition.getTypes()); 48 49 Collection messages = definition.getMessages().values(); 50 for (Iterator iterator = messages.iterator(); iterator.hasNext();) 51 { 52 Message message = (Message) iterator.next(); 53 visit(message); 54 Collection parts = message.getParts().values(); 55 for (Iterator iterator2 = parts.iterator(); iterator2.hasNext();) 56 { 57 Part part = (Part) iterator2.next(); 58 visit(part); 59 } 60 } 61 62 Collection services = definition.getServices().values(); 63 for (Iterator iterator = services.iterator(); iterator.hasNext();) 64 { 65 Service service = (Service) iterator.next(); 66 visit(service); 67 68 Collection ports = service.getPorts().values(); 69 for (Iterator iterator1 = ports.iterator(); iterator1.hasNext();) 70 { 71 Port port = (Port) iterator1.next(); 72 visit(port); 73 74 Binding binding = port.getBinding(); 75 visit(binding); 76 77 List bindingOperations = binding.getBindingOperations(); 78 for (int i = 0; i < bindingOperations.size(); i++) 79 { 80 BindingOperation bindingOperation = 81 (BindingOperation) bindingOperations.get(i); 82 visit(bindingOperation); 83 visit(bindingOperation.getBindingInput()); 84 visit(bindingOperation.getBindingOutput()); 85 86 Collection bindingFaults = bindingOperation.getBindingFaults().values(); 87 for (Iterator iterator2 = bindingFaults.iterator(); iterator2.hasNext();) 88 { 89 BindingFault bindingFault = (BindingFault) iterator2.next(); 90 visit(bindingFault); 91 } 92 93 } 94 PortType portType = binding.getPortType(); 95 visit(portType); 96 97 List operations = portType.getOperations(); 98 for (int i = 0; i < operations.size(); i++) 99 { 100 Operation operation = (Operation) operations.get(i); 101 visit(operation); 102 { 103 Input input = operation.getInput(); 104 visit(input); 105 } 106 { 107 Output output = operation.getOutput(); 108 visit(output); 109 } 110 111 Collection faults = operation.getFaults().values(); 112 for (Iterator iterator2 = faults.iterator(); iterator2.hasNext();) 113 { 114 Fault fault = (Fault) iterator2.next(); 115 visit(fault); 116 } 117 } 118 } 119 } 120 } 121 catch (Exception e) 122 { 123 e.printStackTrace(); 124 } 125 finally 126 { 127 end(); 128 } 129 } 130 131 protected void begin() 132 { 133 } 134 135 protected void end() 136 { 137 } 138 139 protected void visit(Fault fault) 140 { 141 } 142 143 protected void visit(Definition definition) 144 { 145 } 146 147 protected void visit(Import wsdlImport) 148 { 149 } 150 151 protected void visit(Types types) 152 { 153 } 154 155 protected void visit(BindingFault bindingFault) 156 { 157 } 158 159 protected void visit(BindingOutput bindingOutput) 160 { 161 } 162 163 protected void visit(BindingInput bindingInput) 164 { 165 } 166 167 protected void visit(Output output) 168 { 169 } 170 171 protected void visit(Part part) 172 { 173 } 174 175 protected void visit(Message message) 176 { 177 } 178 179 protected void visit(Input input) 180 { 181 } 182 183 protected void visit(Operation operation) 184 { 185 } 186 187 protected void visit(PortType portType) 188 { 189 } 190 191 protected void visit(BindingOperation bindingOperation) 192 { 193 } 194 195 protected void visit(Binding binding) 196 { 197 } 198 199 protected void visit(Port port) 200 { 201 } 202 203 protected void visit(Service service) 204 { 205 } 206 207 protected SOAPBody getSOAPBody(List extensibilityElements) 208 { 209 SOAPBody body = null; 210 for (int j = 0; j < extensibilityElements.size(); j++) 211 { 212 Object element = extensibilityElements.get(j); 213 if (element instanceof SOAPBody) 214 { 215 body = (SOAPBody) element; 216 break; 217 } 218 } 219 return body; 220 } 221 222 protected SOAPBinding getSOAPBinding(Binding binding) 223 { 224 SOAPBinding soapBinding = null; 225 List extensibilityElements = binding.getExtensibilityElements(); 226 for (int i = 0; i < extensibilityElements.size(); i++) 227 { 228 Object element = extensibilityElements.get(i); 229 if (element instanceof SOAPBinding) 230 { 231 soapBinding = (SOAPBinding) element; 232 } 233 } 234 return soapBinding; 235 } 236 }