Skip to main content
summaryrefslogtreecommitdiffstats
blob: e7bb5be75e6407531c98928e3d3443ab16deecf6 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
 * Copyright (c) 2004, 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 Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.ws.internal.explorer.platform.uddi.actions;

import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.ListElement;
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.FormToolPropertiesInterface;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Node;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.ToolManager;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.ViewTool;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.MultipleFormToolPropertiesInterface;
import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.datatype.service.BusinessService;
import org.uddi4j.datatype.tmodel.TModel;

public class SelectSubQueryItemAction extends SelectPropertiesToolAction
{
  private boolean requiresTreeViewRefresh_;
  private boolean requiresViewSelection_;
  private boolean newUUIDQueryCreated_;
  private String itemName_;
  public SelectSubQueryItemAction(Controller controller)
  {
    super(controller);
    requiresTreeViewRefresh_ = false;
    requiresViewSelection_ = false;
    newUUIDQueryCreated_ = false;
    itemName_ = null;
  }

  // /uddi/actions/SelectSubQueryItemAction.jsp?nodeId=...&toolId=...<&viewId=...>&subQueryKey=...&subQueryListKey=...&subQueryListItemId=...&queryItem=...<&isHistory=1>
  public static final String getActionLink(int nodeId,int toolId,int viewId,String subQueryKey,String subQueryListKey,int subQueryListItemId,int queryItem,boolean forHistory)
  {
    StringBuffer actionLink = new StringBuffer("uddi/actions/SelectSubQueryItemActionJSP.jsp?");
    actionLink.append(ActionInputs.NODEID).append('=').append(nodeId);
    actionLink.append('&').append(ActionInputs.TOOLID).append('=').append(toolId);
    if (viewId != ActionInputs.VIEWID_DEFAULT)
      actionLink.append('&').append(ActionInputs.VIEWID).append('=').append(viewId);
    actionLink.append('&').append(UDDIActionInputs.SUBQUERY_KEY).append('=').append(subQueryKey);
    actionLink.append('&').append(UDDIActionInputs.SUBQUERY_LIST_KEY).append('=').append(subQueryListKey);
    actionLink.append('&').append(UDDIActionInputs.SUBQUERY_LIST_ITEMID).append('=').append(subQueryListItemId);
    actionLink.append('&').append(UDDIActionInputs.QUERY_ITEM).append('=').append(queryItem);

    if (forHistory)
      actionLink.append('&').append(ActionInputs.ISHISTORY).append("=1");
    return actionLink.toString();
  }

  public boolean processLinkParameters(HttpServletRequest request)
  {
    boolean result = super.processLinkParameters(request);
    String subQueryKey = request.getParameter(UDDIActionInputs.SUBQUERY_KEY);
    String subQueryListKey = request.getParameter(UDDIActionInputs.SUBQUERY_LIST_KEY);
    String subQueryListItemId = request.getParameter(UDDIActionInputs.SUBQUERY_LIST_ITEMID);
    String queryItemString = request.getParameter(UDDIActionInputs.QUERY_ITEM);

    if (subQueryKey != null)
      propertyTable_.put(UDDIActionInputs.SUBQUERY_KEY,subQueryKey);

    if (subQueryListKey != null)
      propertyTable_.put(UDDIActionInputs.SUBQUERY_LIST_KEY,subQueryListKey);

    if (subQueryListItemId != null)
      propertyTable_.put(UDDIActionInputs.SUBQUERY_LIST_ITEMID,subQueryListItemId);

    if (queryItemString != null)
      propertyTable_.put(UDDIActionInputs.QUERY_ITEM,queryItemString);
    return result;
  }

  private final boolean findByUUID()
  {
    Node currentNode = nodeManager_.getSelectedNode();
    FormTool formTool = (FormTool)(currentNode.getCurrentToolManager().getSelectedTool());
    FormToolPropertiesInterface formToolPI = ((MultipleFormToolPropertiesInterface)formTool).getFormToolProperties((String)propertyTable_.get(UDDIActionInputs.SUBQUERY_KEY));
    Vector list = (Vector)formToolPI.getProperty((String)propertyTable_.get(UDDIActionInputs.SUBQUERY_LIST_KEY));
    ListElement listElement = (ListElement)list.elementAt(Integer.parseInt((String)propertyTable_.get(UDDIActionInputs.SUBQUERY_LIST_ITEMID)));
    int queryItem = Integer.parseInt((String)propertyTable_.get(UDDIActionInputs.QUERY_ITEM));
    FindAction findAction = null;
    String uuidKey = null;
    String uuidKeyValue = null;
    switch (queryItem)
    {
      case UDDIActionInputs.QUERY_ITEM_BUSINESSES:
        findAction = new RegFindBusinessUUIDAction(controller_);
        uuidKey = UDDIActionInputs.QUERY_INPUT_UUID_BUSINESS_KEY;
        BusinessEntity sp = (BusinessEntity)listElement.getObject();
        uuidKeyValue = sp.getBusinessKey();
        itemName_ = sp.getDefaultNameString();
        break;
      case UDDIActionInputs.QUERY_ITEM_SERVICES:
        findAction = new RegFindServiceUUIDAction(controller_);
        uuidKey = UDDIActionInputs.QUERY_INPUT_UUID_SERVICE_KEY;
        BusinessService bs = (BusinessService)listElement.getObject();
        uuidKeyValue = bs.getServiceKey();
        itemName_ = bs.getDefaultNameString();
        break;
      case UDDIActionInputs.QUERY_ITEM_SERVICE_INTERFACES:
      default:
        findAction = new RegFindServiceInterfaceUUIDAction(controller_);
        uuidKey = UDDIActionInputs.QUERY_INPUT_UUID_SERVICE_INTERFACE_KEY;
        TModel tModel = (TModel)listElement.getObject();
        uuidKeyValue = tModel.getTModelKey();
        itemName_ = tModel.getNameString();
    }
    Hashtable propertyTable = findAction.getPropertyTable();
    propertyTable.put(UDDIActionInputs.QUERY_NAME,uuidKeyValue);
    propertyTable.put(uuidKey,uuidKeyValue);
    boolean result = findAction.run();
    if (result)
    {
      Node itemNode = nodeManager_.getSelectedNode();
      int nodeId = itemNode.getNodeId();
      int toolId = itemNode.getToolManager().getSelectedToolId();
      int viewId = ActionInputs.VIEWID_DEFAULT;
      int viewToolId = ActionInputs.VIEWTOOLID_DEFAULT;
      propertyTable_.put(ActionInputs.NODEID,String.valueOf(nodeId));
      propertyTable_.put(ActionInputs.TOOLID,String.valueOf(toolId));
      propertyTable_.put(ActionInputs.VIEWID,String.valueOf(viewId));
      propertyTable_.put(ActionInputs.VIEWTOOLID,String.valueOf(viewToolId));
      super.run();
      requiresTreeViewRefresh_ = true;
      requiresViewSelection_ = true;
      newUUIDQueryCreated_ = true;
      listElement.setTargetViewToolInfo(nodeId,toolId,viewId);
      return true;
    }
    else
    {
      // The item is no longer in the registry.
      return false;
    }
  }

  public final String getItemName()
  {
    return itemName_;
  }
  
  public boolean run()
  {
    // Given the nodeId, toolId and viewId, check if the node or view is stale.
    int nodeId = Integer.parseInt((String)propertyTable_.get(ActionInputs.NODEID));
    int toolId = Integer.parseInt((String)propertyTable_.get(ActionInputs.TOOLID));
    int viewId = ActionInputs.VIEWID_DEFAULT;
    try
    {
      viewId = Integer.parseInt((String)propertyTable_.get(ActionInputs.VIEWID));
    }
    catch (NumberFormatException e)
    {
    }
    int viewToolId = 0;
    if (!isStaleNode(nodeId))
    {
      // Enusre the node is visible.
      requiresTreeViewRefresh_ = makeNodeVisible(nodeManager_.getNode(nodeId));

      Node node = nodeManager_.getNode(nodeId);
      if (viewId != ActionInputs.VIEWID_DEFAULT)
      {
        ViewTool viewTool = (ViewTool)(node.getToolManager().getTool(toolId));
        ToolManager elementToolManager = viewTool.getToolManager(viewId);
        if (elementToolManager != null)
          viewToolId = elementToolManager.getSelectedToolId();
        else
        {
          // Stale view
          return findByUUID();
        }
      }
      propertyTable_.put(ActionInputs.VIEWTOOLID,String.valueOf(viewToolId));
      return super.run();
    }
    else
    {
      // Stale node
      return findByUUID();
    }
  }

  protected String getActionLinkForHistory()
  {
    int nodeId = selectedNode_.getNodeId();
    int toolId = selectedTool_.getToolId();
    int viewId = selectedNode_.getViewId();
    int viewToolId = selectedNode_.getViewToolId();
    return SelectPropertiesToolAction.getActionLink(nodeId,toolId,viewId,viewToolId,true);
  }

  public boolean requiresTreeViewRefresh()
  {
    return super.requiresTreeViewRefresh()|requiresTreeViewRefresh_;
  }

  public boolean requiresViewSelection()
  {
    return super.requiresViewSelection()|requiresViewSelection_;
  }

  public boolean requiresStatusUpdate()
  {
    return newUUIDQueryCreated_;
  }

  public final String getStatusContentVar()
  {
    return "statusContent";
  }

  public final String getStatusContentPage()
  {
    return "uddi/status_content.jsp";
  }
}

Back to the top