001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.webservices;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020:
021: import java.util.Collection;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025: import javax.wsdl.*;
026: import javax.wsdl.extensions.soap.SOAPBody;
027: import javax.wsdl.extensions.soap.SOAPBinding;
028:
029: public class WSDLVisitor {
030:
031: private static final Log log = LogFactory.getLog(WSDLVisitor.class);
032:
033: protected final Definition definition;
034:
035: public WSDLVisitor(Definition definition) {
036: this .definition = definition;
037: }
038:
039: public void walkTree() {
040: begin();
041: try {
042: visit(definition);
043: for (Iterator iterator = definition.getImports().entrySet()
044: .iterator(); iterator.hasNext();) {
045: Map.Entry entry = (Map.Entry) iterator.next();
046: String namespaceURI = (String) entry.getKey();
047: List importsForNamespace = (List) entry.getValue();
048: for (Iterator iterator1 = importsForNamespace
049: .iterator(); iterator1.hasNext();) {
050: Import anImport = (Import) iterator1.next();
051: visit(anImport);
052: }
053: }
054: visit(definition.getTypes());
055: Collection messages = definition.getMessages().values();
056: for (Iterator iterator = messages.iterator(); iterator
057: .hasNext();) {
058: Message message = (Message) iterator.next();
059: visit(message);
060: Collection parts = message.getParts().values();
061: for (Iterator iterator2 = parts.iterator(); iterator2
062: .hasNext();) {
063: Part part = (Part) iterator2.next();
064: visit(part);
065: }
066: }
067: Collection services = definition.getServices().values();
068: for (Iterator iterator = services.iterator(); iterator
069: .hasNext();) {
070: Service service = (Service) iterator.next();
071: visit(service);
072: Collection ports = service.getPorts().values();
073: for (Iterator iterator1 = ports.iterator(); iterator1
074: .hasNext();) {
075: Port port = (Port) iterator1.next();
076: visit(port);
077: Binding binding = port.getBinding();
078: visit(binding);
079: List bindingOperations = binding
080: .getBindingOperations();
081: for (int i = 0; i < bindingOperations.size(); i++) {
082: BindingOperation bindingOperation = (BindingOperation) bindingOperations
083: .get(i);
084: visit(bindingOperation);
085: visit(bindingOperation.getBindingInput());
086: visit(bindingOperation.getBindingOutput());
087: Collection bindingFaults = bindingOperation
088: .getBindingFaults().values();
089: for (Iterator iterator2 = bindingFaults
090: .iterator(); iterator2.hasNext();) {
091: BindingFault bindingFault = (BindingFault) iterator2
092: .next();
093: visit(bindingFault);
094: }
095:
096: }
097: PortType portType = binding.getPortType();
098: visit(portType);
099: List operations = portType.getOperations();
100: for (int i = 0; i < operations.size(); i++) {
101: Operation operation = (Operation) operations
102: .get(i);
103: visit(operation);
104: {
105: Input input = operation.getInput();
106: visit(input);
107: }
108: {
109: Output output = operation.getOutput();
110: visit(output);
111: }
112: Collection faults = operation.getFaults()
113: .values();
114: for (Iterator iterator2 = faults.iterator(); iterator2
115: .hasNext();) {
116: Fault fault = (Fault) iterator2.next();
117: visit(fault);
118: }
119:
120: }
121: }
122: }
123: } catch (Exception e) {
124: log.error(e.getMessage(), e);
125: } finally {
126: end();
127: }
128: }
129:
130: protected void begin() {
131: }
132:
133: protected void end() {
134: }
135:
136: protected void visit(Fault fault) {
137: }
138:
139: protected void visit(Definition definition) {
140: }
141:
142: protected void visit(Import wsdlImport) {
143: }
144:
145: protected void visit(Types types) {
146: }
147:
148: protected void visit(BindingFault bindingFault) {
149: }
150:
151: protected void visit(BindingOutput bindingOutput) {
152: }
153:
154: protected void visit(BindingInput bindingInput) {
155: }
156:
157: protected void visit(Output output) {
158: }
159:
160: protected void visit(Part part) {
161: }
162:
163: protected void visit(Message message) {
164: }
165:
166: protected void visit(Input input) {
167: }
168:
169: protected void visit(Operation operation) {
170: }
171:
172: protected void visit(PortType portType) {
173: }
174:
175: protected void visit(BindingOperation bindingOperation) {
176: }
177:
178: protected void visit(Binding binding) {
179: }
180:
181: protected void visit(Port port) {
182: }
183:
184: protected void visit(Service service) {
185: }
186:
187: protected SOAPBody getSOAPBody(List extensibilityElements) {
188: SOAPBody body = null;
189: for (int j = 0; j < extensibilityElements.size(); j++) {
190: Object element = extensibilityElements.get(j);
191: if (element instanceof SOAPBody) {
192: body = (SOAPBody) element;
193: break;
194: }
195: }
196: return body;
197: }
198:
199: protected SOAPBinding getSOAPBinding(Binding binding) {
200: SOAPBinding soapBinding = null;
201: List extensibilityElements = binding.getExtensibilityElements();
202: for (int i = 0; i < extensibilityElements.size(); i++) {
203: Object element = extensibilityElements.get(i);
204: if (element instanceof SOAPBinding) {
205: soapBinding = (SOAPBinding) element;
206: }
207: }
208: return soapBinding;
209: }
210: }
|