View Javadoc

    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
    23  import javax.wsdl.Binding;
    24  import javax.wsdl.BindingFault;
    25  import javax.wsdl.BindingInput;
    26  import javax.wsdl.BindingOperation;
    27  import javax.wsdl.BindingOutput;
    28  import javax.wsdl.Definition;
    29  import javax.wsdl.Fault;
    30  import javax.wsdl.Import;
    31  import javax.wsdl.Input;
    32  import javax.wsdl.Message;
    33  import javax.wsdl.Operation;
    34  import javax.wsdl.Output;
    35  import javax.wsdl.Part;
    36  import javax.wsdl.Port;
    37  import javax.wsdl.PortType;
    38  import javax.wsdl.Service;
    39  import javax.wsdl.Types;
    40  import javax.wsdl.extensions.soap.SOAPBinding;
    41  import javax.wsdl.extensions.soap.SOAPBody;
    42
    43  public class WSDLVisitor
    44  {
    45      protected final Definition definition;
    46
    47      public WSDLVisitor(Definition definition)
    48      {
    49          this.definition = definition;
    50      }
    51
    52      public void walkTree()
    53      {
    54          begin();
    55          try
    56          {
    57              visit(definition);
    58              Collection imports = definition.getImports().values();
    59              for (Iterator iterator = imports.iterator(); iterator.hasNext();)
    60              {
    61                  Import wsdlImport = (Import) iterator.next();
    62                  visit(wsdlImport);
    63              }
    64              visit(definition.getTypes());
    65
    66              Collection messages = definition.getMessages().values();
    67              for (Iterator iterator = messages.iterator(); iterator.hasNext();)
    68              {
    69                  Message message = (Message) iterator.next();
    70                  visit(message);
    71                  Collection parts = message.getParts().values();
    72                  for (Iterator iterator2 = parts.iterator(); iterator2.hasNext();)
    73                  {
    74                      Part part = (Part) iterator2.next();
    75                      visit(part);
    76                  }
    77              }
    78
    79              Collection services = definition.getServices().values();
    80              for (Iterator iterator = services.iterator(); iterator.hasNext();)
    81              {
    82                  Service service = (Service) iterator.next();
    83                  visit(service);
    84
    85                  Collection ports = service.getPorts().values();
    86                  for (Iterator iterator1 = ports.iterator(); iterator1.hasNext();)
    87                  {
    88                      Port port = (Port) iterator1.next();
    89                      visit(port);
    90
    91                      Binding binding = port.getBinding();
    92                      visit(binding);
    93
    94                      List bindingOperations = binding.getBindingOperations();
    95                      for (int i = 0; i < bindingOperations.size(); i++)
    96                      {
    97                          BindingOperation bindingOperation =
    98                              (BindingOperation) bindingOperations.get(i);
    99                          visit(bindingOperation);
    100                         visit(bindingOperation.getBindingInput());
    101                         visit(bindingOperation.getBindingOutput());
    102
    103                         Collection bindingFaults = bindingOperation.getBindingFaults().values();
    104                         for (Iterator iterator2 = bindingFaults.iterator(); iterator2.hasNext();)
    105                         {
    106                             BindingFault bindingFault = (BindingFault) iterator2.next();
    107                             visit(bindingFault);
    108                         }
    109
    110                     }
    111                     PortType portType = binding.getPortType();
    112                     visit(portType);
    113
    114                     List operations = portType.getOperations();
    115                     for (int i = 0; i < operations.size(); i++)
    116                     {
    117                         Operation operation = (Operation) operations.get(i);
    118                         visit(operation);
    119                         {
    120                             Input input = operation.getInput();
    121                             visit(input);
    122                         }
    123                         {
    124                             Output output = operation.getOutput();
    125                             visit(output);
    126                         }
    127
    128                         Collection faults = operation.getFaults().values();
    129                         for (Iterator iterator2 = faults.iterator(); iterator2.hasNext();)
    130                         {
    131                             Fault fault = (Fault) iterator2.next();
    132                             visit(fault);
    133                         }
    134                     }
    135                 }
    136             }
    137         }
    138         catch (Exception e)
    139         {
    140             e.printStackTrace();
    141         }
    142         finally
    143         {
    144             end();
    145         }
    146     }
    147
    148     protected void begin()
    149     {
    150     }
    151
    152     protected void end()
    153     {
    154     }
    155
    156     protected void visit(Fault fault)
    157     {
    158     }
    159
    160     protected void visit(Definition definition)
    161     {
    162     }
    163
    164     protected void visit(Import wsdlImport)
    165     {
    166     }
    167
    168     protected void visit(Types types)
    169     {
    170     }
    171
    172     protected void visit(BindingFault bindingFault)
    173     {
    174     }
    175
    176     protected void visit(BindingOutput bindingOutput)
    177     {
    178     }
    179
    180     protected void visit(BindingInput bindingInput)
    181     {
    182     }
    183
    184     protected void visit(Output output)
    185     {
    186     }
    187
    188     protected void visit(Part part)
    189     {
    190     }
    191
    192     protected void visit(Message message)
    193     {
    194     }
    195
    196     protected void visit(Input input)
    197     {
    198     }
    199
    200     protected void visit(Operation operation)
    201     {
    202     }
    203
    204     protected void visit(PortType portType)
    205     {
    206     }
    207
    208     protected void visit(BindingOperation bindingOperation)
    209     {
    210     }
    211
    212     protected void visit(Binding binding)
    213     {
    214     }
    215
    216     protected void visit(Port port)
    217     {
    218     }
    219
    220     protected void visit(Service service)
    221     {
    222     }
    223
    224     protected SOAPBody getSOAPBody(List extensibilityElements)
    225     {
    226         SOAPBody body = null;
    227         for (int j = 0; j < extensibilityElements.size(); j++)
    228         {
    229             Object element = extensibilityElements.get(j);
    230             if (element instanceof SOAPBody)
    231             {
    232                 body = (SOAPBody) element;
    233                 break;
    234             }
    235         }
    236         return body;
    237     }
    238
    239     protected SOAPBinding getSOAPBinding(Binding binding)
    240     {
    241         SOAPBinding soapBinding = null;
    242         List extensibilityElements = binding.getExtensibilityElements();
    243         for (int i = 0; i < extensibilityElements.size(); i++)
    244         {
    245             Object element = extensibilityElements.get(i);
    246             if (element instanceof SOAPBinding)
    247             {
    248                 soapBinding = (SOAPBinding) element;
    249             }
    250         }
    251         return soapBinding;
    252     }
    253 }