Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: d1dac0f1ac1828405d7427567edf4ea75aeb164a (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
/*******************************************************************************
 * Copyright (c) 2004, 2008 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
 * -------- -------- -----------------------------------------------------------
 * 20070116   159618 makandre@ca.ibm.com - Andrew Mak, Project and EAR not defaulted properly when wizard launched from JSR-109 Web services branch in J2EE Project Explorer
 * 20070327   172339 kathy@ca.ibm.com - Kathy Chan
 * 20070125   171071 makandre@ca.ibm.com - Andrew Mak, Create public utility method for copying WSDL files
 * 20070410   181827 kathy@ca.ibm.com - Kathy Chan
 * 20080220   219537 makandre@ca.ibm.com - Andrew Mak
 * 20080501   229728 makandre@ca.ibm.com - Andrew Mak, uppercase .WSDL cannot be found by the Web Service Client wizard
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.widgets;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.j2ee.webservice.wsclient.ServiceRef;
import org.eclipse.jst.ws.internal.common.J2EEActionAdapterFactory;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.ws.internal.ui.utils.AdapterUtils;
import org.eclipse.wst.ws.internal.util.UniversalPathTransformer;
import org.eclipse.wst.wsdl.internal.impl.ServiceImpl;
import org.eclipse.wst.wsdl.util.WSDLResourceImpl;

public class WSDLSelectionWidgetDefaultingCommand extends AbstractDataModelOperation
{
  private IStructuredSelection selection_;
  private String uri_;
  
  public String getWebServiceURI()
  {
	if (uri_ != null)
		return uri_;
	  
    uri_ = "";
    
  	if (selection_ != null && !selection_.isEmpty())
  	{
  	  Object firstSel = selection_.getFirstElement();
  	  if (firstSel instanceof IFile)
  	  {
  	    IFile ifile = (IFile)firstSel;
  	    String ext = ifile.getFileExtension();
  	    if (ext != null && (ext.equalsIgnoreCase("wsdl") || ext.equalsIgnoreCase("wsil") || ext.equalsIgnoreCase("html")))
  	    {
  	      uri_ = ifile.getFullPath().toString();
  	    }
  	  } else if (firstSel instanceof ServiceImpl)
      {
        ServiceImpl serviceImpl = (ServiceImpl)firstSel;
        uri_ = J2EEActionAdapterFactory.getWSDLURI(serviceImpl);
      } else if (firstSel instanceof ServiceRef)
      {
  	    ServiceRef serviceRef = (ServiceRef)firstSel;
        uri_ = J2EEActionAdapterFactory.getWSDLURI(serviceRef);
      } else if (firstSel instanceof WSDLResourceImpl)
  	  {
  	    WSDLResourceImpl wsdlRI = (WSDLResourceImpl)firstSel;
  	    uri_ = J2EEActionAdapterFactory.getWSDLURI(wsdlRI);
  	  } else if (firstSel instanceof String)
  	  {
  	    uri_ = (String)firstSel;
  	  } else {
  		String adaptedUri = AdapterUtils.getAdaptedWSDL(firstSel);
  		if (adaptedUri != null) {
  			uri_ = adaptedUri;
  		}
  	  }
  	  
  	  uri_ = UniversalPathTransformer.toPath(uri_);
  	}
    return uri_;
  }
 
  public void setInitialSelection( IStructuredSelection selection )
  {
    selection_ = selection;   
    uri_ = null;
  }
  
  public boolean getGenWSIL()
  {
    return false;
  }
  
  public String getWsilURI()
  {
  	String wsURI = getWebServiceURI();
  	if (wsURI != null && wsURI.length() > 0 && wsURI.toLowerCase().endsWith("wsdl"))
  	{
      StringBuffer sb = new StringBuffer(wsURI.substring(0, wsURI.length()-4));
      sb.append("wsil");
      return sb.toString();
  	}
    return "";
  }
  
  public IProject getProject()
  {
  	IProject p = getProjectFromInitialSelection(selection_);
  	return p;
  }
  
  public String getComponentName()
  {
    String cname = getComponentNameFromInitialSelection(selection_);
    return cname;
  }
  
  private boolean hasProtocol(String url) {	  
    return url.indexOf(":") != -1;	  
  }
  
  private IProject getProjectFromInitialSelection(IStructuredSelection selection)
  {
    if (selection != null && selection.size() == 1)
    {
      Object obj = selection.getFirstElement();
      if (obj != null) 
      {
        try
        { 
          IResource resource = ResourceUtils.getResourceFromSelection(obj);
          if (resource==null) {
            String uri = getWebServiceURI();
            if (hasProtocol(uri)) return null;
            return ResourceUtils.getProjectOf(new Path(uri));
          }
          else
            return ResourceUtils.getProjectOf(resource.getFullPath());
        } catch(CoreException e)
        {
          return null;
        }        
      }
    }
    return null;
  }
  
  private String getComponentNameFromInitialSelection(IStructuredSelection selection)
  {
    if (selection != null && selection.size() == 1)
    {
      Object obj = selection.getFirstElement();
      if (obj != null) 
      {
        try
        { 
          IResource resource = ResourceUtils.getResourceFromSelection(obj);
          IVirtualComponent comp;
          if (resource==null) {
            String uri = getWebServiceURI();
            if (hasProtocol(uri)) return null;              
            comp = ResourceUtils.getComponentOf(new Path(uri)) ;
          }
          else 
            comp = ResourceUtils.getComponentOf(resource);
          if (comp!=null)
          {
            return comp.getName();
          }
        } catch(CoreException e)
        {
          return null;
        }        
      }
    }
    return null;
  }

  public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
  {
	  return Status.OK_STATUS;
  }    
     
}

Back to the top