Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9dc37d37df6ac1a09dfae51d25abe20d215718c0 (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
/*******************************************************************************
 * Copyright (c) 2001, 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 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
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20070419 182864   gilberta@ca.ibm.com - Gilbert Andrews
 *******************************************************************************/

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

import java.net.MalformedURLException;
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.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.BusinessElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.RegistryElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.ServiceElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.ServiceInterfaceElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.RegistryNode;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.UDDIPerspective;
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.util.Validator;
import org.uddi4j.UDDIException;
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.DispositionReport;
import org.uddi4j.transport.TransportException;

public class UnpublishAction extends UDDIPropertiesFormAction
{
  protected RegistryNode registryNode_;
  protected boolean isLoggedIn_;

  public UnpublishAction(Controller controller)
  {
    super(controller);
    registryNode_ = getRegistryNode();
  }

  protected final boolean processParsedResults(MultipartFormDataParser parser) throws MultipartFormDataException
  {
    RegistryElement regElement = (RegistryElement)registryNode_.getTreeElement();
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    FormTool formTool = getSelectedFormTool();

    // if not yet logged in, validate the parameters needed to log in
    if (!regElement.isLoggedIn())
    {
      String publishURL = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL);
      String userId = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID);
      String password = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD);

      boolean inputsValid = true;
      if (publishURL != null)
        propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL, publishURL);
        
      if (!Validator.validateURL(publishURL))
      {
        formTool.flagError(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL);
        inputsValid = false;
        messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_PUBLISH_URL"));
      }

      if (userId != null)
        propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID,userId);
        
      if (!Validator.validateString(userId))
      {
        formTool.flagError(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID);
        inputsValid = false;
        messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_USERID"));
      }

      propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD, password);
      
      formTool.updatePropertyTable(propertyTable_);

      return inputsValid;
    }

    return true;
  }

  public boolean run()
  {

	RegistryElement registryElement = (RegistryElement)registryNode_.getTreeElement();
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    NodeManager navigatorManager = uddiPerspective.getNavigatorManager();
    Node selectedNode = navigatorManager.getSelectedNode();
    TreeElement selectedElement = selectedNode.getTreeElement();

    try
    {
      if (!registryElement.isLoggedIn())
      {
        // if not yet logged in, log in first
        String publishURL = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_PUBLISH_URL);
        String userId = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_USERID);
        String password = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_PASSWORD);
        
        registryElement.performLogin(publishURL,userId,password);
      }

      String selectedElementKey = selectedElement.getKey();
      String unpublishTypeMessageKey = null;
      UDDIProxy proxy = registryElement.getProxy();
      String authInfo = registryElement.getAuthInfoString();
      DispositionReport dr = null;
      if (selectedElement instanceof BusinessElement)
      {
        unpublishTypeMessageKey = "MSG_INFO_BUSINESS_UNPUBLISHED";
        dr = proxy.delete_business(authInfo,selectedElementKey);
      }
      else if (selectedElement instanceof ServiceElement)
      {
        unpublishTypeMessageKey = "MSG_INFO_SERVICE_UNPUBLISHED";
        dr = proxy.delete_service(authInfo,selectedElementKey);
      }
      else if (selectedElement instanceof ServiceInterfaceElement)
      {
        unpublishTypeMessageKey = "MSG_INFO_SERVICE_INTERFACE_UNPUBLISHED";
        dr = proxy.delete_tModel(authInfo,selectedElementKey);
      }
      if (!dr.success())
        throw new Exception(dr.toString());
      else
      {
        selectedElement.disconnectAll();
        messageQueue.addMessage(uddiPerspective.getMessage(unpublishTypeMessageKey,selectedElement.getName()));
        return true;
      }
    }
    catch (TransportException e)
    {
      handleUnexpectedException(uddiPerspective,messageQueue,"TransportException",e);
      return false;
    }
    catch (UDDIException e)
    {
    	if(UDDIExceptionHandler.requiresReset(e))
    		registryElement.setDefaults();
    	messageQueue.addMessage(uddiPerspective.getController().getMessage("MSG_ERROR_UNEXPECTED"));
    	messageQueue.addMessage("UDDIException");
    	messageQueue.addMessage(e.toString());
    	return false;
    }
    catch (MalformedURLException e)
    {
      handleUnexpectedException(uddiPerspective,messageQueue,"MalformedURLException",e);
      return false;
    }
    catch (Exception e)
    {
      handleUnexpectedException(uddiPerspective, messageQueue, "Exception", e);
      return false;
    }
  }
}

Back to the top