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.openejb.server.webservices;
017:
018: import org.apache.openejb.util.LogCategory;
019: import org.apache.openejb.util.Logger;
020:
021: import javax.wsdl.Binding;
022: import javax.wsdl.BindingFault;
023: import javax.wsdl.BindingInput;
024: import javax.wsdl.BindingOperation;
025: import javax.wsdl.BindingOutput;
026: import javax.wsdl.Definition;
027: import javax.wsdl.Fault;
028: import javax.wsdl.Import;
029: import javax.wsdl.Input;
030: import javax.wsdl.Message;
031: import javax.wsdl.Operation;
032: import javax.wsdl.Output;
033: import javax.wsdl.Part;
034: import javax.wsdl.Port;
035: import javax.wsdl.PortType;
036: import javax.wsdl.Service;
037: import javax.wsdl.Types;
038: import javax.wsdl.extensions.soap.SOAPBinding;
039: import javax.wsdl.extensions.soap.SOAPBody;
040: import java.util.Collection;
041: import java.util.Iterator;
042: import java.util.List;
043: import java.util.Map;
044:
045: public class WsdlVisitor {
046: private static final Logger logger = Logger.getInstance(
047: LogCategory.OPENEJB_WS, WsdlVisitor.class);
048:
049: protected final Definition definition;
050:
051: public WsdlVisitor(Definition definition) {
052: this .definition = definition;
053: }
054:
055: public void walkTree() {
056: begin();
057: try {
058: visit(definition);
059: for (Iterator iterator = definition.getImports().entrySet()
060: .iterator(); iterator.hasNext();) {
061: Map.Entry entry = (Map.Entry) iterator.next();
062: String namespaceURI = (String) entry.getKey();
063: List importsForNamespace = (List) entry.getValue();
064: for (Iterator iterator1 = importsForNamespace
065: .iterator(); iterator1.hasNext();) {
066: Import anImport = (Import) iterator1.next();
067: visit(anImport);
068: }
069: }
070: visit(definition.getTypes());
071: Collection messages = definition.getMessages().values();
072: for (Iterator iterator = messages.iterator(); iterator
073: .hasNext();) {
074: Message message = (Message) iterator.next();
075: visit(message);
076: Collection parts = message.getParts().values();
077: for (Iterator iterator2 = parts.iterator(); iterator2
078: .hasNext();) {
079: Part part = (Part) iterator2.next();
080: visit(part);
081: }
082: }
083: Collection services = definition.getServices().values();
084: for (Iterator iterator = services.iterator(); iterator
085: .hasNext();) {
086: Service service = (Service) iterator.next();
087: visit(service);
088: Collection ports = service.getPorts().values();
089: for (Iterator iterator1 = ports.iterator(); iterator1
090: .hasNext();) {
091: Port port = (Port) iterator1.next();
092: visit(port);
093: Binding binding = port.getBinding();
094: visit(binding);
095: List bindingOperations = binding
096: .getBindingOperations();
097: for (int i = 0; i < bindingOperations.size(); i++) {
098: BindingOperation bindingOperation = (BindingOperation) bindingOperations
099: .get(i);
100: visit(bindingOperation);
101: visit(bindingOperation.getBindingInput());
102: visit(bindingOperation.getBindingOutput());
103: Collection bindingFaults = bindingOperation
104: .getBindingFaults().values();
105: for (Iterator iterator2 = bindingFaults
106: .iterator(); iterator2.hasNext();) {
107: BindingFault bindingFault = (BindingFault) iterator2
108: .next();
109: visit(bindingFault);
110: }
111:
112: }
113: PortType portType = binding.getPortType();
114: visit(portType);
115: List operations = portType.getOperations();
116: for (int i = 0; i < operations.size(); i++) {
117: Operation operation = (Operation) operations
118: .get(i);
119: visit(operation);
120: {
121: Input input = operation.getInput();
122: visit(input);
123: }
124: {
125: Output output = operation.getOutput();
126: visit(output);
127: }
128: Collection faults = operation.getFaults()
129: .values();
130: for (Iterator iterator2 = faults.iterator(); iterator2
131: .hasNext();) {
132: Fault fault = (Fault) iterator2.next();
133: visit(fault);
134: }
135:
136: }
137: }
138: }
139: } catch (Exception e) {
140: logger.error(e.getMessage(), e);
141: } finally {
142: end();
143: }
144: }
145:
146: protected void begin() {
147: }
148:
149: protected void end() {
150: }
151:
152: protected void visit(Fault fault) {
153: }
154:
155: protected void visit(Definition definition) {
156: }
157:
158: protected void visit(Import wsdlImport) {
159: }
160:
161: protected void visit(Types types) {
162: }
163:
164: protected void visit(BindingFault bindingFault) {
165: }
166:
167: protected void visit(BindingOutput bindingOutput) {
168: }
169:
170: protected void visit(BindingInput bindingInput) {
171: }
172:
173: protected void visit(Output output) {
174: }
175:
176: protected void visit(Part part) {
177: }
178:
179: protected void visit(Message message) {
180: }
181:
182: protected void visit(Input input) {
183: }
184:
185: protected void visit(Operation operation) {
186: }
187:
188: protected void visit(PortType portType) {
189: }
190:
191: protected void visit(BindingOperation bindingOperation) {
192: }
193:
194: protected void visit(Binding binding) {
195: }
196:
197: protected void visit(Port port) {
198: }
199:
200: protected void visit(Service service) {
201: }
202:
203: protected SOAPBody getSOAPBody(List extensibilityElements) {
204: SOAPBody body = null;
205: for (int j = 0; j < extensibilityElements.size(); j++) {
206: Object element = extensibilityElements.get(j);
207: if (element instanceof SOAPBody) {
208: body = (SOAPBody) element;
209: break;
210: }
211: }
212: return body;
213: }
214:
215: protected SOAPBinding getSOAPBinding(Binding binding) {
216: SOAPBinding soapBinding = null;
217: List extensibilityElements = binding.getExtensibilityElements();
218: for (int i = 0; i < extensibilityElements.size(); i++) {
219: Object element = extensibilityElements.get(i);
220: if (element instanceof SOAPBinding) {
221: soapBinding = (SOAPBinding) element;
222: }
223: }
224: return soapBinding;
225: }
226: }
|