Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9e5c73cb91b4c6662429f58159579433eed0c3ae (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
/*******************************************************************************
 * Copyright (c) 2004, 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * 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
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.widgets.object;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jst.j2ee.webservice.wsdd.ServiceImplBean;
import org.eclipse.jst.j2ee.webservice.wsdd.ServletLink;
import org.eclipse.jst.j2ee.webservice.wsdd.internal.impl.PortComponentImpl;
import org.eclipse.wst.command.internal.env.core.data.Transformer;

public class JavaBeanSelectionTransformer implements Transformer
{
  public Object transform(Object value)
  {
    if (value instanceof IStructuredSelection)
    {
      Object sel = ((IStructuredSelection)value).getFirstElement();
      if (sel instanceof IFile)
      {
        return new StructuredSelection(computeFullyQualifiedJavaName((IFile)sel));
      }
      else if (sel instanceof ICompilationUnit)
      {
        IResource res = ((ICompilationUnit)sel).getResource();
        if (res instanceof IFile)
          return new StructuredSelection(computeFullyQualifiedJavaName((IFile)res));
      }
      else if (sel instanceof ServiceImplBean)
      {
        return new StructuredSelection(getBeanName((ServiceImplBean) sel));
      }
      else if(sel instanceof ServletLink)
      {
        return new StructuredSelection(getBeanName((ServletLink) sel));
      }
    }
    return value;
  }

  private String computeFullyQualifiedJavaName(IFile resource)
  {
    IPath path = resource.getFullPath();
    String basename = path.lastSegment();
    String beanClass = "";
    if (basename != null && basename.length() > 0)
    {
      String beanPackage = org.eclipse.jst.ws.internal.common.ResourceUtils.getJavaResourcePackageName(path);
      beanClass = (beanPackage == null || beanPackage.length() == 0 ? basename : (beanPackage + "." + basename));
      if (beanClass.toLowerCase().endsWith(".java") || beanClass.toLowerCase().endsWith(".class"))
        beanClass = beanClass.substring(0, beanClass.lastIndexOf('.'));
    }
    return beanClass;
  }
  
  private String getBeanName(ServiceImplBean bean) {
    EObject eObject = bean.eContainer();
    if (eObject instanceof PortComponentImpl) {
      PortComponentImpl pci = (PortComponentImpl) eObject;
      return pci.getServiceEndpointInterface();	      	
    }
    return "";
  }
  
  private String getBeanName(ServletLink link) {    
    EObject eObject = link.eContainer();
    if (eObject instanceof ServiceImplBean)
      return getBeanName((ServiceImplBean) eObject);
    return "";
  }
}

Back to the top