Skip to main content
summaryrefslogtreecommitdiffstats
blob: 764f15b5a876162e26494571b2a4f5ca2a7de605 (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 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 Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.ws.internal.explorer.platform.wsdl.actions;

import java.util.Vector;
import javax.wsdl.WSDLException;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ModelConstants;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.TreeElement;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.FormTool;
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.util.MultipartFormDataException;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataParser;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.WSDLModelConstants;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.datamodel.WSDLElement;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.perspective.WSDLPerspective;

public class OpenWSDLAction extends WSDLPropertiesFormAction {

  public OpenWSDLAction(Controller controller) {
    super(controller);
  }

  protected boolean processParsedResults(MultipartFormDataParser parser) throws MultipartFormDataException {
    String wsdlUrl = parser.getParameter(ActionInputs.QUERY_INPUT_WSDL_URL);
    FormTool formTool = getSelectedFormTool();
    propertyTable_.put(ActionInputs.QUERY_INPUT_WSDL_URL, wsdlUrl);
    formTool.updatePropertyTable(propertyTable_);
    return true;
  }

  public boolean run() {
    String wsdlUrl = (String)propertyTable_.get(ActionInputs.QUERY_INPUT_WSDL_URL);
    WSDLPerspective wsdlPerspective = controller_.getWSDLPerspective();
    MessageQueue messageQueue = wsdlPerspective.getMessageQueue();
    NodeManager nodeManager = wsdlPerspective.getNodeManager();
    Node rootNode = nodeManager.getRootNode();
    TreeElement rootElement = rootNode.getTreeElement();

    // create a WSDLElement representing the WSDL
    WSDLElement wsdlElement = new WSDLElement(wsdlUrl, rootElement.getModel(), wsdlUrl);
    try
    {
      // open WSDL
      Vector errorMessages = wsdlElement.loadWSDL();
      if (errorMessages.size() > 0)
      {
        messageQueue.addMessage(wsdlPerspective.getMessage("MSG_ERROR_XSD_VALIDATION"));
        for (int i=0;i<errorMessages.size();i++)
          messageQueue.addMessage((String)errorMessages.elementAt(i));
      }            
    }
    catch (WSDLException e)
    {
      messageQueue.addMessage(wsdlPerspective.getMessage("MSG_ERROR_OPEN_WSDL",wsdlUrl));          
      handleUnexpectedException(wsdlPerspective,messageQueue,"WSDLException",e);
      return false;
    }
    rootElement.connect(wsdlElement,WSDLModelConstants.REL_WSDL, ModelConstants.REL_OWNER);

    // build the datamodel for this WSDLElement
    wsdlElement.buildModel();

    // If there is more than 1 service node, select the WSDL node. If there is more than 1 binding node, select the service node.
    // If there is just the one service and binding node, select the binding node.
    // select the new WSDL node
    Node wsdlNode = rootNode.getChildNode(wsdlElement);
    Vector serviceNodes = wsdlNode.getChildNodes();
    int newSelectedNodeId = wsdlNode.getNodeId();
    if (serviceNodes.size() == 1)
    {
      Node serviceNode = (Node)serviceNodes.elementAt(0);
      Vector bindingNodes = serviceNode.getChildNodes();
      if (bindingNodes.size() == 1)
      {
        Node bindingNode = (Node)bindingNodes.elementAt(0);
        newSelectedNodeId = bindingNode.getNodeId();
      }
      else
        newSelectedNodeId = serviceNode.getNodeId();
    }
    nodeManager.setSelectedNodeId(newSelectedNodeId);
    nodeManager.makeNodeVisible(nodeManager.getNode(newSelectedNodeId));
    addToHistory(ActionInputs.PERSPECTIVE_WSDL,SelectWSDLPropertiesToolAction.getActionLink(newSelectedNodeId, 0, ActionInputs.VIEWID_DEFAULT, ActionInputs.VIEWTOOLID_DEFAULT, true));
    messageQueue.addMessage(wsdlPerspective.getMessage("MSG_INFO_OPEN_WSDL_SUCCESSFUL", wsdlUrl));
    return true;
  }
}

Back to the top