Skip to main content
summaryrefslogtreecommitdiffstats
blob: 50de6c311a3f355b295e70c38d4713b79829f835 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Import;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Part;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.extensions.soap.SOAPBody;

import org.eclipse.wst.wsi.internal.core.WSIConstants;

/**
 * The utility class to automate WSDL processing.
 * 
 * @author Kulik
 */
public final class WSDLUtil
{

  /**
   * The method extracts list of parts for the given soapbind:body,
   * binding operation, message, and style.
   * 
   * @param op an operation.
   * @param m  a message.
   * @param body a SOAP body.
   * @param style an operation style.
   * @return list of parts for the given soapbind:body,
   *         binding operation, message, and style.
   */
  static public List getParts(
    Operation op,
    Message m,
    SOAPBody body,
    String style)
  {
    //		if null, get parts from message 
    if (body.getParts() == null)
      // if rpc style is used, try to use partOrder attribute from operation
      if (WSIConstants.ATTRVAL_SOAP_BIND_STYLE_RPC.equals(style))
        return m.getOrderedParts(op.getParameterOrdering());
      else
        return m.getOrderedParts(null);
    else
      // converse parts name to parts objects
      return m.getOrderedParts(body.getParts());
  }

  /**
   * The method iterates all imports from the given definition and expands all
   * imported messages, service, portTypes, and bindings to the definition.
   * 
   * @param def a WSDL definition.
   */
  static public void expandDefinition(Definition def)
  {
    if (def != null && def.getImports() != null)
    {
      Iterator it = def.getImports().values().iterator();
      while (it.hasNext())
      {
        List v = (List) it.next();
        if (v != null)
        {
          Iterator it2 = v.iterator();
          while (it2.hasNext())
            expandDefinition(def, (Import) it2.next(), new ArrayList());
        }
      }
    }
  }

  /**
   * The internal method to expand definition.
   * @param target WSDL definition.
   * @param im internal method.
   */
  static private void expandDefinition(Definition target, Import im, List processedDefinitions)
  {
    if (im != null)
    {
      Definition d = im.getDefinition();
      if ((d != null) && (!processedDefinitions.contains(d)))
      {
    	processedDefinitions.add(d);

        if (d.getMessages() != null)
        {
          Iterator it = d.getMessages().values().iterator();
          while (it.hasNext())
            target.addMessage((Message) it.next());
        }
        if (d.getPortTypes() != null)
        {
          Iterator it = d.getPortTypes().values().iterator();
          while (it.hasNext())
            target.addPortType((PortType) it.next());
        }
        if (d.getBindings() != null)
        {
          Iterator it = d.getBindings().values().iterator();
          while (it.hasNext())
            target.addBinding((Binding) it.next());
        }
        if (d.getServices() != null)
        {
          Iterator it = d.getServices().values().iterator();
          while (it.hasNext())
            target.addService((Service) it.next());
        }

        Iterator it = d.getImports().values().iterator();
        while (it.hasNext())
        {
          List v = (List) it.next();
          if (v != null)
          {
            Iterator it2 = v.iterator();
            while (it2.hasNext())
              expandDefinition(target, (Import) it2.next(), processedDefinitions);
          }
        }
      }
    }
  }

  /**
   * The method extracts part from the message.
   * 
   * @param message a SOAP message.
   * @param part a part name.
   * @return part from the specified message.
   */
  static public Part getPart(Message message, String part)
  {
    Part mesPart = null;
    if (part == null)
      mesPart = (Part) message.getOrderedParts(null).get(0);
    else
      mesPart = message.getPart(part);
    return mesPart;
  }
}

Back to the top