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: 2d28a715fcbc724698b4aeb54642c64de1aeb80f (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) 2000, 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.jst.ws.internal.consumption.ui.wizard;

import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.jst.ws.internal.consumption.ui.wsrt.WebServiceImpl;
import org.eclipse.jst.ws.internal.consumption.ui.wsrt.WebServiceRuntimeExtensionUtils;
import org.eclipse.wst.ws.internal.wsrt.WebServiceScenario;


public class TypeSelectionFilter
{
  // Copyright
  public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";

  public String[] getWebServiceTypeByInitialSelection(IStructuredSelection initialSelection, ArrayList webServiceTypeList)
  {
        
    ArrayList supportedTypes = new ArrayList();
    if (initialSelection != null && initialSelection.size() == 1)
    {
      
      // Check for null initial selection
      Object initialObject = initialSelection.getFirstElement();
      if (initialObject == null)
      {
        return null;
      }
      // Match up resource type metadata with initial selection
      Iterator iter = webServiceTypeList.iterator();
      while (iter.hasNext())
      {
        String wst = (String)iter.next();
        String scenario = wst.substring(0,wst.indexOf("/"));
        String implId = wst.substring(wst.indexOf("/")+1);        
        //IWebServiceType wst = (IWebServiceType)iter.next();
        //String typeId = (String)wst.getId();
        if (scenario.equals(String.valueOf(WebServiceScenario.BOTTOMUP)) && !supportedTypes.contains(wst))
        {

          
          WebServiceImpl wsimpl = WebServiceRuntimeExtensionUtils.getWebServiceImplById(implId);
          String[] resourceTypes = wsimpl.getResourceTypeMetadata();
          for (int i=0; i<resourceTypes.length; i++)
          {
            if (resourceTypes[i]!=null)
            {              
              if ((initialObject.getClass().getName()).endsWith(resourceTypes[i]))
              {
                String name = null;
                IResource resource = null;

                try
                {                  
                  resource = ResourceUtils.getResourceFromSelection(initialObject);
                }
                catch( CoreException exc )
                {
                  resource = null;
                }

                if (resource instanceof IContainer)
                {
                  name = initialObject.getClass().getName();
                }
                else if( resource != null )
                {
                  name = resource.getFullPath().toString();
                }
                else
                {
                  name = initialObject.getClass().getName();
                }
                String[] extensions = wsimpl.getExtensionMetadata();
                if (acceptsName(name, extensions))
                {
                  supportedTypes.add(wst);
                }
              }
              
            }
          }
        }
      }
      
      //If no wsImpls have accepted this selection, check if this is WSDL. If it is,
      //add the top-down Java service type to the list.
      if (supportedTypes.isEmpty())
      {
        String[] resourceTypes = {"File", "IResource", "String", "ServiceImpl", "ServiceRefImpl", "WSDLResourceImpl"};
        for (int i=0; i<resourceTypes.length; i++)
        {
          if (resourceTypes[i]!=null)
          {              
            if ((initialObject.getClass().getName()).endsWith(resourceTypes[i]))
            {
              String name = null;
              IResource resource = null;

              try
              {                  
                resource = ResourceUtils.getResourceFromSelection(initialObject);
              }
              catch( CoreException exc )
              {
                resource = null;
              }

              if (resource instanceof IContainer)
              {
                name = initialObject.getClass().getName();
              }
              else if( resource != null )
              {
                name = resource.getFullPath().toString();
              }
              else
              {
                name = initialObject.getClass().getName();
              }
              String[] extensions = {".wsdl", ".wsil", ".html", ".ServiceImpl", ".ServiceRefImpl", ".WSDLResourceImpl"};
              if (acceptsName(name, extensions))
              {
                StringBuffer entrybuff = new StringBuffer();
                entrybuff.append(String.valueOf(WebServiceScenario.TOPDOWN));
                entrybuff.append("/");
                entrybuff.append("org.eclipse.jst.ws.wsImpl.java");
                String entry = entrybuff.toString();                
                supportedTypes.add(entry);
              }
            }
            
          }
        }      
      }
      
    }    
  

    
    if (supportedTypes.isEmpty())
    {
      //It's not a registered implementation and its not WSDL so return null;
      return null;
    }
    else
    {
      return (String[])supportedTypes.toArray(new String[0]);
    }
  }
  //
  // Checks if the given name is acceptable based upon its extension
  //
  private boolean acceptsName ( String name, String[] extensions)
  {
    //Return true if "all" extensions are supported.

    if (extensions[0]!=null)
    {
      if (extensions[0].equals("all"))
      {
        return true;
      }
    }

    for (int i=0; i<extensions.length; i++)
    {
      if (extensions[i]!=null)
      {
        if (name.endsWith(extensions[i]))
          return true;
      }
    }
    return false;
  }


}

Back to the top