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: e2453e58f4d8b91ee7bac382e0bf096d31d689b5 (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
/*******************************************************************************
 * 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
 * -------- -------- -----------------------------------------------------------
 * 20060222   125574 zina@ca.ibm.com - Zina Mostafia
 * 20060222   225574 gilberta@ca.ibm.com - Gilbert Andrews
 *******************************************************************************/
/*
 * Created on May 8, 2004
 */
package org.eclipse.jst.ws.internal.common;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jst.j2ee.webservice.wsclient.ServiceRef;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.internal.impl.ServiceImpl;
import org.eclipse.wst.wsdl.util.WSDLResourceImpl;


/**
 * @author gilberta
 */
public class J2EEActionAdapterFactory {
	
 	
  public static String getWSDLURI(ServiceImpl serviceImpl)
  {
  	Definition definition = serviceImpl.getEnclosingDefinition();
  	String location = definition.getLocation();
  	
  	return location;
  }
   
  //has to be under the webcontent
  public static final String EJB_MODULE = "ejbModule";
  public static final String APPCLIENT_MODULE = "appClientModule";
  public static final String WEB_MODULE = "WebContent";

  public static String getWSDLURI(ServiceRef serviceImpl)
  {
  	 String moduleRoot = null;
	 IProject project = ProjectUtilities.getProject(serviceImpl);
	 if(J2EEUtils.isWebComponent(project))
	 {
	   moduleRoot = WEB_MODULE;
	 }
     else if (J2EEUtils.isEJBComponent(project))
	 {
	   moduleRoot = EJB_MODULE;
	 }
	 else if (J2EEUtils.isAppClientComponent(project))
	 {
	   moduleRoot = APPCLIENT_MODULE;
	 }
	 IPath path = project.getLocation().addTrailingSeparator();
	 path = path.append(moduleRoot).addTrailingSeparator();
	 path = path.append(serviceImpl.getWsdlFile());
	 File file = new File(path.toString());
	 try{
	   URL url = file.toURL();
	   return url.toString();
	 }catch(MalformedURLException e){return null;}
	 
  
	  
	
 }
  
  public static String getWSDLURI(WSDLResourceImpl wsdlRI)
  {
  	Definition definition = wsdlRI.getDefinition();
  	String location = definition.getLocation();
  	
  	return location;
  }
  
  public static String getWSILPath(WSDLResourceImpl wsdlRI)
  {
  	return convertToRelative(getWSDLURI(wsdlRI));
  }
  
  public static String getWSILPath(ServiceRef serviceImpl)
  {
  	return convertToRelative(getWSDLURI(serviceImpl));
  }
  
  public static String getWSILPath(ServiceImpl serviceImpl)
  {
  	return convertToRelative(getWSDLURI(serviceImpl));
  }
  
  public static String FILE="file:/";
  public static String FILEL="file:"; 
  public static String convertToRelative(String uri)
  {
  	//remove file:
  	String root = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
    root = FILE + root;
  	String rootL = FILEL + root;
    if(uri.startsWith(root) || uri.startsWith(rootL)){
      return uri.substring(root.length());  	
    }
    return uri;
  }



}

Back to the top