Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9288c7d5e0d72cb466885c662364f03801c796f9 (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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*******************************************************************************
 * Copyright (c) 2004, 2006 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
 * -------- -------- -----------------------------------------------------------
 * 20060912   141796 gilberta@ca.ibm.com - Gilbert Andrews
 *******************************************************************************/
package org.eclipse.wst.ws.internal.explorer.platform.uddi.actions;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Vector;
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.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.perspective.ToolManager;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIModelConstants;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.CategoryModel;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.RegistryElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.UDDIMainElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.UDDIMainNode;
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.datatype.tmodel.TModel;
import org.uddi4j.response.TModelDetail;
import org.uddi4j.response.TModelInfo;
import org.uddi4j.response.TModelInfos;
import org.uddi4j.response.TModelList;
import org.uddi4j.transport.TransportException;
import org.uddi4j.util.CategoryBag;
import org.uddi4j.util.KeyedReference;

public class OpenRegistryAction extends UDDIPropertiesFormAction
{
  public OpenRegistryAction(Controller controller)
  {
    super(controller);
    // Select UDDI Main.
  }

  protected final boolean processParsedResults(MultipartFormDataParser parser) throws MultipartFormDataException
  {
    String registryName = parser.getParameter(UDDIActionInputs.REGISTRY_NAME);
    String inquiryURL = parser.getParameter(UDDIActionInputs.INQUIRY_URL);
    String publishURL = parser.getParameter(UDDIActionInputs.PUBLISH_URL);
    String username = parser.getParameter(UDDIActionInputs.UDDI_USERNAME);
    String password = parser.getParameter(UDDIActionInputs.UDDI_PASSWORD);
    String checkUserDefinedCategoriesChecked = parser.getParameter(UDDIActionInputs.CHECK_USER_DEFINED_CATEGORIES);
    String categoriesDirectory = parser.getParameter(UDDIActionInputs.CATEGORIES_DIRECTORY);

    // Validate the data.
    boolean inputsValid = true;
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    FormTool formTool = getSelectedFormTool();
    if (registryName != null)
      propertyTable_.put(UDDIActionInputs.REGISTRY_NAME,registryName);

    if (!Validator.validateString(registryName))
    {
      inputsValid = false;
      formTool.flagError(UDDIActionInputs.REGISTRY_NAME);
      messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_REGISTRY_NAME"));
    }

    if (inquiryURL != null)
      propertyTable_.put(UDDIActionInputs.INQUIRY_URL,inquiryURL);
    if (!Validator.validateURL(inquiryURL))
    {
      inputsValid = false;
      formTool.flagError(UDDIActionInputs.INQUIRY_URL);
      messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_INQUIRY_URL"));
    }

    if (publishURL != null)
      propertyTable_.put(UDDIActionInputs.PUBLISH_URL, publishURL);
    
    if (username != null)
      propertyTable_.put(UDDIActionInputs.UDDI_USERNAME, username);

    if (password != null)
      propertyTable_.put(UDDIActionInputs.UDDI_PASSWORD, password);

    if (checkUserDefinedCategoriesChecked != null)
      propertyTable_.put(UDDIActionInputs.CHECK_USER_DEFINED_CATEGORIES,checkUserDefinedCategoriesChecked);
    else
      removeProperty(UDDIActionInputs.CHECK_USER_DEFINED_CATEGORIES);
      
    if (categoriesDirectory != null)
      propertyTable_.put(UDDIActionInputs.CATEGORIES_DIRECTORY,categoriesDirectory);
    else
      removeProperty(UDDIActionInputs.CATEGORIES_DIRECTORY);

    formTool.updatePropertyTable(propertyTable_);
    return inputsValid;
  }

  public final void gatherWSUserDefinedCategories(UDDIProxy proxy,Hashtable categoryModels)
  {
    try
    {
      CategoryBag categoryBag = new CategoryBag();
      categoryBag.add(new KeyedReference("","categorization",TModel.TYPES_TMODEL_KEY));
      TModelList tModelList = proxy.find_tModel("%",categoryBag,null,null,100);
      TModelInfos tModelInfos = tModelList.getTModelInfos();
      Vector tModelKeyVector = new Vector();
      for (int i=0;i<tModelInfos.size();i++)
      {
        TModelInfo tModelInfo = tModelInfos.get(i);
        tModelKeyVector.addElement(tModelInfo.getTModelKey());
      }
      TModelDetail tModelDetail = proxy.get_tModelDetail(tModelKeyVector);
      Vector tModelVector = tModelDetail.getTModelVector();
      for (int i=0;i<tModelVector.size();i++)
      {
        TModel tModel = (TModel)tModelVector.elementAt(i);
        boolean checked = false;
        String displayName = null;
        String categoryKey = null;
        categoryBag = tModel.getCategoryBag();
        for (int j=0;j<categoryBag.size();j++)
        {
          KeyedReference kr = categoryBag.get(j);
          String krTModelKey = kr.getTModelKey();
          if (krTModelKey.equalsIgnoreCase(TModel.GENERAL_KEYWORDS_TMODEL_KEY))
          {
            String krKeyName = kr.getKeyName();
            if (krKeyName.equals("urn:x-ibm:uddi:customTaxonomy:key"))
              categoryKey = kr.getKeyValue();
            else if (krKeyName.equals("urn:x-ibm:uddi:customTaxonomy:displayName"))
              displayName = kr.getKeyValue();
          }
          else if (krTModelKey.equalsIgnoreCase(TModel.TYPES_TMODEL_KEY))
            checked = kr.getKeyValue().equals("checked");            
        }
        if (categoryKey != null)
        {
          if (displayName == null)
            displayName = tModel.getNameString();
          CategoryModel categoryModel = new CategoryModel();
          categoryModel.setCategoryKey(categoryKey);
          categoryModel.enableChecked(checked);
          categoryModel.setDisplayName(displayName);
          String tModelKey = tModel.getTModelKey();
          categoryModel.setTModelKey(tModelKey);
          categoryModels.put(tModelKey,categoryModel);
        }
      }
    }
    catch (UDDIException e)
    {
    }
    catch (TransportException e)
    {
    }
  }
  
  public final boolean run()
  {
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    try
    {
      String registryName = (String)propertyTable_.get(UDDIActionInputs.REGISTRY_NAME);
      String inquiryURL = (String)propertyTable_.get(UDDIActionInputs.INQUIRY_URL);
      String publishURL = (String)propertyTable_.get(UDDIActionInputs.PUBLISH_URL);
      String registrationURL = (String)propertyTable_.get(UDDIActionInputs.REGISTRATION_URL);
      String username = (String)propertyTable_.get(UDDIActionInputs.UDDI_USERNAME);
      String password = (String)propertyTable_.get(UDDIActionInputs.UDDI_PASSWORD);
      boolean checkForUserDefinedCategoriesChecked = (propertyTable_.get(UDDIActionInputs.CHECK_USER_DEFINED_CATEGORIES) != null);
      String categoriesDirectory = (String)propertyTable_.get(UDDIActionInputs.CATEGORIES_DIRECTORY);

      String recognizedPublishURL = uddiPerspective.getKnownRegistryPublishURL(inquiryURL);
      String recognizedRegistrationURL = uddiPerspective.getKnownRegistryRegistrationURL(inquiryURL);
      
      if (publishURL == null)
        publishURL = recognizedPublishURL;
      if (registrationURL == null)
        registrationURL = recognizedRegistrationURL;
        
      UDDIMainNode uddiMainNode = (UDDIMainNode)(controller_.getUDDIPerspective().getNavigatorManager().getRootNode());
      UDDIMainElement uddiMainElement = (UDDIMainElement)uddiMainNode.getTreeElement();
      Properties props = new Properties();
      props.put(ActionInputs.TRANSPORT_CLASS_NAME, ActionInputs.TRASPORT_CLASS);
      UDDIProxy proxy = new UDDIProxy(props);
      proxy.setInquiryURL(new URL(inquiryURL));
      RegistryElement registryElement = new RegistryElement(proxy,inquiryURL,registryName,uddiMainElement.getModel());
      // Set registry element's publish URL and registration URL provided by external callers (e.g. favorites).
      if (publishURL != null)
        registryElement.setCachedPublishURL(publishURL);
      if (registrationURL != null)
        registryElement.setRegistrationURL(registrationURL);
      if (username != null)
      	registryElement.setUserId(username);
      if (password != null)
      	registryElement.setCred(password);
      registryElement.setCheckForUserDefinedCategories(checkForUserDefinedCategoriesChecked);
      if (checkForUserDefinedCategoriesChecked)
      {
        Hashtable categoryModels = new Hashtable();
        gatherWSUserDefinedCategories(proxy,categoryModels);
        if (categoryModels.size() > 0)
          registryElement.setUserDefinedCategories(categoryModels);
      }
      registryElement.setCategoriesDirectory(categoriesDirectory);
      uddiMainElement.connect(registryElement,UDDIModelConstants.REL_REGISTRIES,ModelConstants.REL_OWNER);
      NodeManager nodeManager = uddiMainNode.getNodeManager();
      int newRegistryNodeId = uddiMainNode.getChildNode(registryElement).getNodeId();
      // Select the new registry node and add the select action to the history.
      nodeManager.setSelectedNodeId(newRegistryNodeId);
      Node registryNode = nodeManager.getSelectedNode();
      ToolManager toolManager = registryNode.getCurrentToolManager();
      addToHistory(ActionInputs.PERSPECTIVE_UDDI,toolManager.getSelectedTool().getSelectToolActionHref(true));
      messageQueue.addMessage(uddiPerspective.getMessage("MSG_INFO_REGISTRY_OPENED",new String[]{registryName,inquiryURL}));
      return true;
    }
    catch (MalformedURLException e)
    {
      messageQueue.addMessage(controller_.getMessage("MSG_ERROR_UNEXPECTED"));
      messageQueue.addMessage("MalformedURLException");
      messageQueue.addMessage(e.getMessage());
      FormTool formTool = getSelectedFormTool();
      formTool.flagError(UDDIActionInputs.INQUIRY_URL);
    }
    /*
    catch (FormInputException e)
    {
      messageQueue.addMessage(e.getMessage());
    }
    */
    return false;
  }
}

Back to the top