Skip to main content
summaryrefslogtreecommitdiffstats
blob: 246fea5afd554351a33d3e35bc02f97a5d665ec4 (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
/*******************************************************************************
 * Copyright (c) 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.wsil.actions;

import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.wst.ws.internal.explorer.platform.actions.Action;
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.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.uddi.actions.OpenRegistryAction;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.RegistryElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.RegistryNode;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.UDDIMainNode;
import org.eclipse.wst.ws.internal.explorer.platform.util.Validator;
import org.eclipse.wst.ws.internal.explorer.platform.wsil.perspective.ListUDDIBusinessTool;
import org.eclipse.wst.ws.internal.explorer.platform.wsil.perspective.ListUDDIServicesTool;

public abstract class AddToUDDIPerspectiveAction extends MultipleLinkAction
{
  public AddToUDDIPerspectiveAction(Controller controller)
  {
    super(controller);
  }

  public static String getActionLink(int nodeID, int toolID, int viewID, int viewToolID)
  {
    StringBuffer actionLink = new StringBuffer("wsil/actions/WsilAddToUDDIPerspectiveActionJSP.jsp?");
    actionLink.append(ActionInputs.NODEID);
    actionLink.append('=');
    actionLink.append(nodeID);
    actionLink.append('&');
    actionLink.append(ActionInputs.TOOLID);
    actionLink.append('=');
    actionLink.append(toolID);
    actionLink.append('&');
    actionLink.append(ActionInputs.VIEWID);
    actionLink.append('=');
    actionLink.append(viewID);
    actionLink.append('&');
    actionLink.append(ActionInputs.VIEWTOOLID);
    actionLink.append('=');
    actionLink.append(viewToolID);
    return actionLink.toString();
  }

  public static String getBaseActionLink()
  {
    return "wsil/actions/WsilAddToUDDIPerspectiveActionJSP.jsp";
  }

  public static Action newAction(HttpServletRequest request, Controller controller)
  {
    String nodeID = request.getParameter(ActionInputs.NODEID);
    NodeManager nodeManager = controller.getWSILPerspective().getNodeManager();
    Tool selectedTool = nodeManager.getNode(Integer.parseInt(nodeID)).getToolManager().getSelectedTool();
    if (selectedTool instanceof ListUDDIServicesTool)
      return new AddServiceToUDDIPerspectiveAction(controller);
    else if (selectedTool instanceof ListUDDIBusinessTool)
      return new AddBusinessToUDDIPerspectiveAction(controller);
    else
      return new NullAction();
  }

  protected boolean createRegistryInUDDIPerspective(String inquiryAPI, String publishAPI, String registryName)
  {
    Vector registryNodes = getRegistryNodesByInquiryURL(inquiryAPI);
    if (registryNodes != null)
    {
      // Always attempt to use an existing registry.
      Node registryNode = (Node) registryNodes.elementAt(0);
      NodeManager nodeManager = registryNode.getNodeManager();
      nodeManager.setSelectedNodeId(registryNode.getNodeId());
      return true;
    }
    // open the registry if it is not already opened in the UDDI perspective
    OpenRegistryAction openRegAction = new OpenRegistryAction(controller_);
    // populate the property table
    Hashtable propertyTable = openRegAction.getPropertyTable();
    if (Validator.validateString(registryName))
      propertyTable.put(UDDIActionInputs.REGISTRY_NAME, registryName);
    else
      return false;
    if (Validator.validateURL(inquiryAPI))
      propertyTable.put(UDDIActionInputs.INQUIRY_URL, inquiryAPI);
    else
      return false;
    // run the action
    if (!openRegAction.run())
      return false;
    return true;
  }

  protected Vector getRegistryNodesByInquiryURL(String inquiryURL)
  {
    Vector registryNodes = null;
    NodeManager navigatorManager = controller_.getUDDIPerspective().getNavigatorManager();
    UDDIMainNode uddiMainNode = (UDDIMainNode) (navigatorManager.getRootNode());
    Vector childNodes = uddiMainNode.getChildNodes();
    for (int i = 0; i < childNodes.size(); i++)
    {
      Node childNode = (Node) childNodes.elementAt(i);
      if (childNode instanceof RegistryNode)
      {
        RegistryElement regElement = (RegistryElement) childNode.getTreeElement();
        if (regElement.getInquiryURL().equals(inquiryURL))
        {
          if (registryNodes == null)
            registryNodes = new Vector();
          registryNodes.addElement(childNode);
        }
      }
    }
    return registryNodes;
  }
}

Back to the top