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.apache.geronimo.webservices; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import java.util.Collection; 23 import java.util.Iterator; 24 import java.util.List; 25 import java.util.Map; 26 import javax.wsdl.*; 27 import javax.wsdl.extensions.soap.SOAPBody; 28 import javax.wsdl.extensions.soap.SOAPBinding; 29 30 public class WSDLVisitor { 31 32 private static final Log log = LogFactory.getLog(WSDLVisitor.class); 33 34 protected final Definition definition; 35 36 public WSDLVisitor(Definition definition) { 37 this.definition = definition; 38 } 39 40 public void walkTree() { 41 begin(); 42 try { 43 visit(definition); 44 for (Iterator iterator = definition.getImports().entrySet().iterator(); iterator.hasNext();) { 45 Map.Entry entry = (Map.Entry) iterator.next(); 46 String namespaceURI = (String) entry.getKey(); 47 List importsForNamespace = (List) entry.getValue(); 48 for (Iterator iterator1 = importsForNamespace.iterator(); iterator1.hasNext();) { 49 Import anImport = (Import) iterator1.next(); 50 visit(anImport); 51 } 52 } 53 visit(definition.getTypes()); 54 Collection messages = definition.getMessages().values(); 55 for (Iterator iterator = messages.iterator(); iterator.hasNext();) { 56 Message message = (Message) iterator.next(); 57 visit(message); 58 Collection parts = message.getParts().values(); 59 for (Iterator iterator2 = parts.iterator(); iterator2.hasNext();) { 60 Part part = (Part) iterator2.next(); 61 visit(part); 62 } 63 } 64 Collection services = definition.getServices().values(); 65 for (Iterator iterator = services.iterator(); iterator.hasNext();) { 66 Service service = (Service) iterator.next(); 67 visit(service); 68 Collection ports = service.getPorts().values(); 69 for (Iterator iterator1 = ports.iterator(); iterator1.hasNext();) { 70 Port port = (Port) iterator1.next(); 71 visit(port); 72 Binding binding = port.getBinding(); 73 visit(binding); 74 List bindingOperations = binding.getBindingOperations(); 75 for (int i = 0; i < bindingOperations.size(); i++) { 76 BindingOperation bindingOperation = (BindingOperation) bindingOperations.get(i); 77 visit(bindingOperation); 78 visit(bindingOperation.getBindingInput()); 79 visit(bindingOperation.getBindingOutput()); 80 Collection bindingFaults = bindingOperation.getBindingFaults().values(); 81 for (Iterator iterator2 = bindingFaults.iterator(); iterator2.hasNext();) { 82 BindingFault bindingFault = (BindingFault) iterator2.next(); 83 visit(bindingFault); 84 } 85 86 } 87 PortType portType = binding.getPortType(); 88 visit(portType); 89 List operations = portType.getOperations(); 90 for (int i = 0; i < operations.size(); i++) { 91 Operation operation = (Operation) operations.get(i); 92 visit(operation); 93 { 94 Input input = operation.getInput(); 95 visit(input); 96 } 97 { 98 Output output = operation.getOutput(); 99 visit(output); 100 } 101 Collection faults = operation.getFaults().values(); 102 for (Iterator iterator2 = faults.iterator(); iterator2.hasNext();) { 103 Fault fault = (Fault) iterator2.next(); 104 visit(fault); 105 } 106 107 } 108 } 109 } 110 } catch(Exception e){ 111 log.error(e.getMessage(), e); 112 } finally { 113 end(); 114 } 115 } 116 117 protected void begin() { 118 } 119 120 protected void end() { 121 } 122 123 protected void visit(Fault fault) { 124 } 125 126 protected void visit(Definition definition) { 127 } 128 129 protected void visit(Import wsdlImport) { 130 } 131 132 protected void visit(Types types) { 133 } 134 135 protected void visit(BindingFault bindingFault) { 136 } 137 138 protected void visit(BindingOutput bindingOutput) { 139 } 140 141 protected void visit(BindingInput bindingInput) { 142 } 143 144 protected void visit(Output output) { 145 } 146 147 protected void visit(Part part) { 148 } 149 150 protected void visit(Message message) { 151 } 152 153 protected void visit(Input input) { 154 } 155 156 protected void visit(Operation operation) { 157 } 158 159 protected void visit(PortType portType) { 160 } 161 162 protected void visit(BindingOperation bindingOperation) { 163 } 164 165 protected void visit(Binding binding) { 166 } 167 168 protected void visit(Port port) { 169 } 170 171 protected void visit(Service service) { 172 } 173 174 protected SOAPBody getSOAPBody(List extensibilityElements) { 175 SOAPBody body = null; 176 for (int j = 0; j < extensibilityElements.size(); j++) { 177 Object element = extensibilityElements.get(j); 178 if (element instanceof SOAPBody) { 179 body = (SOAPBody) element; 180 break; 181 } 182 } 183 return body; 184 } 185 186 protected SOAPBinding getSOAPBinding(Binding binding) { 187 SOAPBinding soapBinding = null; 188 List extensibilityElements = binding.getExtensibilityElements(); 189 for (int i = 0; i < extensibilityElements.size(); i++) { 190 Object element = extensibilityElements.get(i); 191 if (element instanceof SOAPBinding) { 192 soapBinding = (SOAPBinding) element; 193 } 194 } 195 return soapBinding; 196 } 197 }