Skip to main content
summaryrefslogtreecommitdiffstats
blob: ab1f0dbfacf290e943a9853360eaab4733f4561a (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.ws.internal.explorer.platform.wsdl.actions;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.MessageQueue;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Node;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.NodeManager;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Tool;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataException;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataParser;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.WSDLActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.datamodel.WSDLBindingElement;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.perspective.InvokeWSDLOperationTool;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.perspective.WSDLBindingNode;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.perspective.WSDLPerspective;

public class UpdateWSDLBindingAction extends WSDLPropertiesFormAction
{
  public UpdateWSDLBindingAction(Controller controller)
  {
    super(controller);
  }

  protected boolean processParsedResults(MultipartFormDataParser parser) throws MultipartFormDataException
  {
    String[] nodeIds = parser.getParameterValues(ActionInputs.NODEID);
    if (nodeIds == null)
      nodeIds = new String[0];
    propertyTable_.put(ActionInputs.NODEID, nodeIds);
    String[] endpoints = parser.getParameterValues(WSDLActionInputs.END_POINT);
    if (endpoints == null)
      endpoints = new String[0];
    propertyTable_.put(WSDLActionInputs.END_POINT, endpoints);
    return true;
  }

  public boolean run()
  {
    String[] nodeIds = getPropertyAsStringArray(ActionInputs.NODEID);
    String[] endpoints = getPropertyAsStringArray(WSDLActionInputs.END_POINT);
    WSDLPerspective wsdlPerspective = controller_.getWSDLPerspective();
    NodeManager nodeManager = wsdlPerspective.getNodeManager();
    for (int i = 0; i < nodeIds.length; i++)
    {
      try
      {
        Node bindingNode = nodeManager.getNode(Integer.parseInt(nodeIds[i]));
        if (bindingNode instanceof WSDLBindingNode)
        {
          WSDLBindingElement bindingElement = (WSDLBindingElement)bindingNode.getTreeElement();
          String[] endpointsCopy = endpoints;
          bindingElement.setEndPoints(endpointsCopy);
          if (endpointsCopy.length <= 0)
            endpointsCopy = bindingElement.getEndPoints();
          if (endpointsCopy.length > 0)
          {
            Vector operationNodes = bindingNode.getChildNodes();
            for (Iterator it = operationNodes.iterator(); it.hasNext();)
            {
              Node operationNode = (Node)it.next();
              List tools = operationNode.getCurrentToolManager().getTools();
              for (Iterator toolsIterator = tools.iterator(); toolsIterator.hasNext();)
              {
                Tool tool = (Tool)toolsIterator.next();
                if (tool instanceof InvokeWSDLOperationTool)
                  ((InvokeWSDLOperationTool)tool).setEndPoint(endpointsCopy[0]);
              }
            }
          }
        }
      }
      catch (NumberFormatException nfe)
      {
      }
    }
    MessageQueue messageQueue = wsdlPerspective.getMessageQueue();
    messageQueue.addMessage(wsdlPerspective.getMessage("MSG_INFO_UPDATE_WSDL_BINDING_SUCCESSFUL"));
    return true;
  }
}

Back to the top