Author: Grid.Qian
Date: 2010-01-29 01:56:35 -0500 (Fri, 29 Jan 2010)
New Revision: 20010
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
Log:
JBIDE-5715: create a wizard for generating a sample web service class in a dynamic
project
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java 2010-01-29
06:54:07 UTC (rev 20009)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ClientSampleCreationCommand.java 2010-01-29
06:56:35 UTC (rev 20010)
@@ -19,6 +19,7 @@
import org.eclipse.core.runtime.IPath;
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.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
@@ -51,7 +52,6 @@
.getProperty("line.separator"); //$NON-NLS-1$
private static final String PACAKAGE = ".*"; //$NON-NLS-1$
private static final String PACAKAGESPLIT = "\\."; //$NON-NLS-1$
- private static final String SRC = "src"; //$NON-NLS-1$
private ServiceModel model;
private int serviceNum = 1;
@@ -195,15 +195,18 @@
sb.append(" System.out.println(\"Server said: \" + ");
//$NON-NLS-1$
sb.append("port").append(portNum).append("."); //$NON-NLS-1$
//$NON-NLS-2$
sb.append(method.getName()).append("("); //$NON-NLS-1$
-
+
boolean noNull = true;
for (int j = 0; j < method.parameters().size(); j++) {
- noNull = createWebServiceOperationParameters(method.parameters(),sb, j) &&
noNull;
+ noNull = createWebServiceOperationParameters(method
+ .parameters(), sb, j)
+ && noNull;
}
sb.append("));"); //$NON-NLS-1$
sb.append(LINE_SEPARATOR);
- if(!noNull){
- sb.append(" //Please input the parameters instead of 'null' for
the upper method!"); //$NON-NLS-1$
+ if (!noNull) {
+ sb
+ .append(" //Please input the parameters instead of 'null' for
the upper method!"); //$NON-NLS-1$
sb.append(LINE_SEPARATOR);
sb.append(LINE_SEPARATOR);
}
@@ -222,7 +225,8 @@
@SuppressWarnings("unchecked")
private boolean createWebServiceOperationParameters(List list,
StringBuffer sb, int j) {
- SingleVariableDeclaration para = (SingleVariableDeclaration)list.get(j);
+ SingleVariableDeclaration para = (SingleVariableDeclaration) list
+ .get(j);
if ("String".equals(para.getType().toString())) { //$NON-NLS-1$
sb.append("args[").append(argsNum).append("]"); //$NON-NLS-1$
//$NON-NLS-2$
@@ -232,12 +236,12 @@
argsNum += 1;
return true;
}
-
- if(list.get(j) instanceof Object){
+
+ if (list.get(j) instanceof Object) {
sb.append("null"); //$NON-NLS-1$
if (j != list.size() - 1) {
sb.append(","); //$NON-NLS-1$
- }
+ }
return false;
}
return true;
@@ -320,11 +324,17 @@
*
* @param project
* @return
+ * @throws JavaModelException
*/
- private IPath addPackagetoPath(IJavaProject project) {
+ private IPath addPackagetoPath(IJavaProject project)
+ throws JavaModelException {
String packagename = model.getCustomPackage();
String[] names = packagename.split(PACAKAGESPLIT);
- IPath path = project.getPath().append(SRC);
+ IPath path = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(project.getProject()));
+ path = project.getPath().append(
+ path.makeRelativeTo(project.getProject().getLocation()));
+
if (names != null && names.length > 0) {
for (String name : names) {
path = path.append(name);
@@ -347,8 +357,11 @@
String className, boolean isInterface, String interfaceName,
IJavaProject javaProject) {
try {
- IPath srcPath = javaProject.getProject().getFolder(SRC)
- .getFullPath();
+ IPath srcPath = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(javaProject.getProject()));
+ srcPath = javaProject.getPath().append(
+ srcPath.makeRelativeTo(javaProject.getProject()
+ .getLocation()));
IPackageFragmentRoot root = javaProject
.findPackageFragmentRoot(srcPath);
if (packageName == null) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java 2010-01-29
06:54:07 UTC (rev 20009)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java 2010-01-29
06:56:35 UTC (rev 20010)
@@ -5,6 +5,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
@@ -21,7 +22,6 @@
public class ServiceSampleCreationCommand extends AbstractDataModelOperation {
private ServiceModel model;
- private static final String SRC = "src"; //$NON-NLS-1$
public static final String LINE_SEPARATOR = System
.getProperty("line.separator"); //$NON-NLS-1$
@@ -51,7 +51,11 @@
private ICompilationUnit createJavaClass(String packageName,
String className, IJavaProject project) {
try {
- IPath srcPath = project.getProject().getFolder(SRC).getFullPath();
+ IPath srcPath = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(project.getProject()));
+ srcPath = project.getPath().append(
+ srcPath.makeRelativeTo(project.getProject()
+ .getLocation()));
IPackageFragmentRoot root = project
.findPackageFragmentRoot(srcPath);
if (packageName == null) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2010-01-29
06:54:07 UTC (rev 20009)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/JBossWSCreationUtils.java 2010-01-29
06:56:35 UTC (rev 20010)
@@ -43,7 +43,9 @@
import org.eclipse.jdt.core.IParent;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jst.ws.internal.common.J2EEUtils;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -71,6 +73,7 @@
"return", "short", "static", "strictfp",
"super", "switch", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
"synchronized", "this", "throw", "throws",
"transient", "true", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
"try", "void", "volatile", "while" };
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ static final String WEBINF = "WEB-INF"; //$NON-NLS-1$
public static boolean isJavaKeyword(String keyword) {
if (hasUpperCase(keyword)) {
@@ -111,11 +114,10 @@
public static String pathToWebProjectContainer(String project) {
IPath projectRoot = getProjectRoot(project);
- IPath currentDynamicWebProjectDir = J2EEUtils
- .getWebContentPath(getProjectByName(project));
- IPath currentDynamicWebProjectDirWithoutProjectRoot = J2EEUtils
- .getWebContentPath(getProjectByName(project))
- .removeFirstSegments(1).makeAbsolute();
+ IPath currentDynamicWebProjectDir = getWebContentRootPath(getProjectByName(project));
+ IPath currentDynamicWebProjectDirWithoutProjectRoot = getWebContentRootPath(
+ getProjectByName(project)).removeFirstSegments(1)
+ .makeAbsolute();
if (projectRoot.toOSString().contains(getWorkspace().toOSString())) {
return getWorkspace().append(currentDynamicWebProjectDir)
.toOSString();
@@ -128,10 +130,10 @@
public static String pathToWebProjectContainerWEBINF(String project) {
IPath projectRoot = getProjectRoot(project);
- IPath webContainerWEBINFDir = J2EEUtils
- .getWebInfPath(getProjectByName(project));
- IPath webContainerWEBINFDirWithoutProjectRoot = J2EEUtils
- .getWebInfPath(getProjectByName(project))
+ IPath webContainerWEBINFDir = getWebContentRootPath(
+ getProjectByName(project)).append(WEBINF);
+ IPath webContainerWEBINFDirWithoutProjectRoot = getWebContentRootPath(
+ getProjectByName(project)).append(WEBINF)
.removeFirstSegments(1).makeAbsolute();
if (projectRoot.toOSString().contains(getWorkspace().toOSString())) {
return getWorkspace().append(webContainerWEBINFDir).toOSString();
@@ -360,47 +362,55 @@
return ""; //$NON-NLS-1$
}
-
- public static boolean supportSOAP12(String projectName){
+
+ public static boolean supportSOAP12(String projectName) {
try {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if(project == null){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ if (project == null) {
return false;
}
-
+
IFacetedProject facetedPrj = ProjectFacetsManager.create(project);
- IProjectFacet jbossWSFacet =
ProjectFacetsManager.getProjectFacet(JBossWSFacetInstallDataModelProvider.JBOSS_WS_FACET_ID);
- IProjectFacetVersion fpVersion = facetedPrj.getProjectFacetVersion(jbossWSFacet);
- if(fpVersion != null &&
fpVersion.getVersionString().compareTo("3.0") >= 0){ //$NON-NLS-1$
+ IProjectFacet jbossWSFacet = ProjectFacetsManager
+ .getProjectFacet(JBossWSFacetInstallDataModelProvider.JBOSS_WS_FACET_ID);
+ IProjectFacetVersion fpVersion = facetedPrj
+ .getProjectFacetVersion(jbossWSFacet);
+ if (fpVersion != null
+ && fpVersion.getVersionString().compareTo("3.0") >= 0) {
//$NON-NLS-1$
return true;
}
-
-// if the project doesn't get JBossWS facet installed, check its primary target
runtime
-// if the jboss runtime version is 5.0 or higher, return true
- org.eclipse.wst.common.project.facet.core.runtime.IRuntime targetRuntime =
facetedPrj.getPrimaryRuntime();
- if(targetRuntime != null){
+
+ // if the project doesn't get JBossWS facet installed, check its
+ // primary target runtime
+ // if the jboss runtime version is 5.0 or higher, return true
+ org.eclipse.wst.common.project.facet.core.runtime.IRuntime targetRuntime = facetedPrj
+ .getPrimaryRuntime();
+ if (targetRuntime != null) {
IRuntime runtime = getRuntime(targetRuntime);
IRuntimeType rt = runtime.getRuntimeType();
- if(rt.getName().toUpperCase().indexOf("JBOSS") >= 0){ //$NON-NLS-1$
+ if (rt.getName().toUpperCase().indexOf("JBOSS") >= 0) { //$NON-NLS-1$
String runtimeVersion = rt.getVersion();
- if(runtimeVersion != null && runtimeVersion.compareTo("5.0") >=
0){ //$NON-NLS-1$
+ if (runtimeVersion != null
+ && runtimeVersion.compareTo("5.0") >= 0) { //$NON-NLS-1$
return true;
}
}
-
+
}
} catch (CoreException e) {
-// ignore
-// e.printStackTrace();
+ // ignore
+ // e.printStackTrace();
}
-
- //check the version of default jbossws runtime configured at the Web Service preference
page
+
+ // check the version of default jbossws runtime configured at the Web
+ // Service preference page
JBossWSRuntime jbws = JBossWSRuntimeManager.getInstance()
- .getDefaultRuntime();
- if(jbws != null && "3.0".compareTo(jbws.getVersion()) <= 0){
//$NON-NLS-1$
+ .getDefaultRuntime();
+ if (jbws != null && "3.0".compareTo(jbws.getVersion()) <= 0) {
//$NON-NLS-1$
return true;
}
-
+
return false;
}
@@ -424,7 +434,8 @@
return null;
}
- public static String getJavaProjectSrcLocation(IProject project) throws
JavaModelException {
+ public static String getJavaProjectSrcLocation(IProject project)
+ throws JavaModelException {
IResource[] rs = getJavaSourceRoots(project);
String src = ""; //$NON-NLS-1$
if (rs == null || rs.length == 0)
@@ -438,7 +449,8 @@
return src;
}
- public static IResource[] getJavaSourceRoots(IProject project) throws JavaModelException
{
+ public static IResource[] getJavaSourceRoots(IProject project)
+ throws JavaModelException {
IJavaProject javaProject = JavaCore.create(project);
if (javaProject == null)
return null;
@@ -456,4 +468,19 @@
return resources.toArray(new IResource[resources.size()]);
}
+ public static IPath getWebContentRootPath(IProject project) {
+ if (project == null)
+ return null;
+
+ if (!ModuleCoreNature.isFlexibleProject(project))
+ return null;
+
+ IPath path = null;
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ if (component != null && component.exists()) {
+ path = component.getRootFolder().getWorkspaceRelativePath();
+ }
+ return path;
+ }
+
}