Author: dennyxu
Date: 2008-06-19 22:51:06 -0400 (Thu, 19 Jun 2008)
New Revision: 8856
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java
Log:
JBIDE-2387: code refactor
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java 2008-06-20
02:51:06 UTC (rev 8856)
@@ -0,0 +1,139 @@
+package org.jboss.tools.ws.creation.core.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+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.osgi.util.NLS;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.core.utils.StatusUtils;
+import org.jboss.tools.ws.creation.core.JBossWSCreationCore;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+
+abstract class AbstractGenerateCodeCommand extends AbstractDataModelOperation{
+
+ protected ServiceModel model;
+ private String cmdFileName_linux;
+ private String cmdFileName_win;
+
+ public AbstractGenerateCodeCommand(ServiceModel model){
+ this.model = model;
+ cmdFileName_linux = getCommandLineFileName_linux();
+ cmdFileName_win = getCommandLineFileName_win();
+ }
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ IStatus status = Status.OK_STATUS;
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(model
+ .getWebProjectName());
+
+ try {
+ String runtimeLocation = JBossWSCreationUtils.getJbossWSRuntimeLocation(project);
+ String commandLocation = runtimeLocation + Path.SEPARATOR + "bin";
+ IPath path = new Path(commandLocation);
+ String command = "sh " + cmdFileName_linux;
+ if(System.getProperty("os.name").toLowerCase().indexOf("win")
>= 0){
+ command = "cmd.exe /c " + cmdFileName_win;
+ path = path.append(cmdFileName_win);
+ }else{
+ path = path.append(cmdFileName_linux);
+ }
+
+ if(!path.toFile().getAbsoluteFile().exists()){
+ return StatusUtils.errorStatus(
+ NLS.bind(JBossWSCreationCoreMessages.Error_Message_Command_File_Not_Found,
+ new String[] {path.toOSString()}));
+ }
+
+ String args = getCommandlineArgs();
+ command += " -k " + args + " " + model.getWsdlURI();
+ Runtime rt = Runtime.getRuntime();
+ Process proc = rt.exec(command, null, new File(commandLocation));
+ InputStreamReader ir = new InputStreamReader(proc.getErrorStream());
+ LineNumberReader input = new LineNumberReader(ir);
+ String str = input.readLine();
+ StringBuffer result = new StringBuffer();
+ while(str != null){
+ result.append(str).append("\t\r");
+ str = input.readLine();
+
+ }
+ int exitValue = proc.waitFor();
+ if(exitValue != 0){
+ return StatusUtils.errorStatus(result.toString());
+ }
+
+ // log the result of the command execution
+ String resultOutput = convertInputStreamToString(proc.getInputStream());
+ if(resultOutput != null && resultOutput.indexOf("[ERROR]")
>= 0){
+ JBossWSCreationCore.getDefault().logError(resultOutput);
+ IStatus errorStatus = StatusUtils.errorStatus(resultOutput);
+ status = StatusUtils
+ .errorStatus(
+ JBossWSCreationCoreMessages.Error_Message_Failed_To_Generate_Code,
+ new CoreException(errorStatus));
+ }else{
+ JBossWSCreationCore.getDefault().logInfo(resultOutput);
+ }
+ } catch (IOException e) {
+ JBossWSCreationCore.getDefault().logError(e);
+
+ } catch (InterruptedException e) {
+ // ignore
+ } catch (CoreException e) {
+ JBossWSCreationCore.getDefault().logError(e);
+ //unable to get runtime location
+ return e.getStatus();
+ }
+
+ refreshProject(model.getWebProjectName(), monitor);
+
+
+ return status;
+ }
+
+ private String convertInputStreamToString(InputStream input) throws IOException{
+ InputStreamReader ir = new InputStreamReader(input);
+ LineNumberReader reader = new LineNumberReader(ir);
+ String str = reader.readLine();
+ StringBuffer result = new StringBuffer();
+ while(str != null){
+ result.append(str).append("\t\r");
+ str = reader.readLine();
+
+ }
+ return result.toString();
+ }
+ private void refreshProject(String project, IProgressMonitor monitor){
+ try {
+ JBossWSCreationUtils.getProjectByName(project).refreshLocal(2, monitor);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ JBossWSCreationCore.getDefault().logError(e);
+ }
+ }
+
+ abstract protected String getCommandlineArgs();
+
+ abstract protected String getCommandLineFileName_linux();
+ abstract protected String getCommandLineFileName_win();
+
+
+}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2008-06-19
23:45:51 UTC (rev 8855)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2008-06-20
02:51:06 UTC (rev 8856)
@@ -1,135 +1,34 @@
package org.jboss.tools.ws.creation.core.commands;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
import java.util.List;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-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.osgi.util.NLS;
-import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
-import org.jboss.tools.ws.core.utils.StatusUtils;
-import org.jboss.tools.ws.creation.core.JBossWSCreationCore;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
-import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
-public class WSDL2JavaCommand extends AbstractDataModelOperation{
+public class WSDL2JavaCommand extends AbstractGenerateCodeCommand{
- private ServiceModel model;
private static String WSCONSUEM_FILE_NAME_LINUX = "wsconsume.sh";
private static String WSCONSUEM_FILE_NAME_WIN = "wsconsume.bat";
public WSDL2JavaCommand(ServiceModel model){
- this.model = model;
+ super(model);
}
+
@Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- IStatus status = Status.OK_STATUS;
-
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(model
- .getWebProjectName());
-
- try {
- String runtimeLocation = JBossWSCreationUtils.getJbossWSRuntimeLocation(project);
- String commandLocation = runtimeLocation + Path.SEPARATOR + "bin";
- IPath path = new Path(commandLocation);
- String command = "sh " + WSCONSUEM_FILE_NAME_LINUX;
- if(System.getProperty("os.name").toLowerCase().indexOf("win")
>= 0){
- command = "cmd.exe /c " + WSCONSUEM_FILE_NAME_WIN;
- path = path.append(WSCONSUEM_FILE_NAME_WIN);
- }else{
- path = path.append(WSCONSUEM_FILE_NAME_LINUX);
- }
-
- if(!path.toFile().getAbsoluteFile().exists()){
- return StatusUtils.errorStatus(
- NLS.bind(JBossWSCreationCoreMessages.Error_Message_Command_File_Not_Found,
- new String[] {path.toOSString()}));
- }
-
- String args = getCommandlineArgs();
- command += " -k " + args + " " + model.getWsdlURI();
- Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(command, null, new File(commandLocation));
- InputStreamReader ir = new InputStreamReader(proc.getErrorStream());
- LineNumberReader input = new LineNumberReader(ir);
- String str = input.readLine();
- StringBuffer result = new StringBuffer();
- while(str != null){
- result.append(str).append("\t\r");
- str = input.readLine();
-
- }
- int exitValue = proc.waitFor();
- if(exitValue != 0){
- return StatusUtils.errorStatus(result.toString());
- }
-
- // log the result of the command execution
- String resultOutput = convertInputStreamToString(proc.getInputStream());
- if(resultOutput != null && resultOutput.indexOf("[ERROR]")
>= 0){
- JBossWSCreationCore.getDefault().logError(resultOutput);
- IStatus errorStatus = StatusUtils.errorStatus(resultOutput);
- status = StatusUtils
- .errorStatus(
- JBossWSCreationCoreMessages.Error_Message_Failed_To_Generate_Code,
- new CoreException(errorStatus));
- }else{
- JBossWSCreationCore.getDefault().logInfo(resultOutput);
- }
- } catch (IOException e) {
- JBossWSCreationCore.getDefault().logError(e);
-
- } catch (InterruptedException e) {
- // ignore
- } catch (CoreException e) {
- JBossWSCreationCore.getDefault().logError(e);
- //unable to get runtime location
- return e.getStatus();
- }
-
- refreshProject(model.getWebProjectName(), monitor);
-
-
- return status;
+ protected String getCommandLineFileName_linux() {
+ return WSCONSUEM_FILE_NAME_LINUX;
}
-
- private String convertInputStreamToString(InputStream input) throws IOException{
- InputStreamReader ir = new InputStreamReader(input);
- LineNumberReader reader = new LineNumberReader(ir);
- String str = reader.readLine();
- StringBuffer result = new StringBuffer();
- while(str != null){
- result.append(str).append("\t\r");
- str = reader.readLine();
-
- }
- return result.toString();
+
+ @Override
+ protected String getCommandLineFileName_win() {
+ return WSCONSUEM_FILE_NAME_WIN;
}
- private void refreshProject(String project, IProgressMonitor monitor){
- try {
- JBossWSCreationUtils.getProjectByName(project).refreshLocal(2, monitor);
- } catch (CoreException e) {
- e.printStackTrace();
- JBossWSCreationCore.getDefault().logError(e);
- }
- }
-
- private String getCommandlineArgs(){
+
+ @Override
+ protected String getCommandlineArgs() {
String commandLine;
String project = model.getWebProjectName();
String projectRoot = JBossWSCreationUtils.getProjectRoot(project).toOSString();
@@ -160,7 +59,6 @@
return commandLine;
-
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java 2008-06-19
23:45:51 UTC (rev 8855)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java 2008-06-20
02:51:06 UTC (rev 8856)
@@ -11,95 +11,35 @@
package org.jboss.tools.ws.creation.core.commands;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.ResourcesPlugin;
-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.wst.common.frameworks.datamodel.AbstractDataModelOperation;
-import org.jboss.tools.ws.core.utils.StatusUtils;
-import org.jboss.tools.ws.creation.core.JBossWSCreationCore;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
/**
* @author Grid Qian
*/
-public class WSProviderInvokeCommand extends AbstractDataModelOperation {
+public class WSProviderInvokeCommand extends AbstractGenerateCodeCommand {
- private ServiceModel model;
-
+ private static String WSPROVIDER_FILE_NAME_LINUX = "wsprovide.sh";
+ private static String WSPROVIDER_FILE_NAME_WIN = "wsprovide.bat";
+
public WSProviderInvokeCommand(ServiceModel model) {
- this.model = model;
+ super(model);
}
- @Override
- public IStatus execute(IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- String runtimeLocation;
- try {
- runtimeLocation =
JBossWSCreationUtils.getJbossWSRuntimeLocation(ResourcesPlugin.getWorkspace().getRoot().getProject(model
- .getWebProjectName()));
- } catch (CoreException e1) {
- JBossWSCreationCore.getDefault().logError(e1);
- //unable to get runtime location
- return e1.getStatus();
- }
- String commandLocation = runtimeLocation + Path.SEPARATOR + "bin";
- String command = "sh wsprovide.sh ";
- if (System.getProperty("os.name").toLowerCase().indexOf("win")
>= 0) {
- command = "cmd.exe /C wsprovide.bat";
- }
- String args = getCommandlineArgs();
- command += " -k " + args;
-
- try {
- Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(command, null, new File(commandLocation));
- InputStreamReader ir = new InputStreamReader(proc.getErrorStream());
- LineNumberReader input = new LineNumberReader(ir);
- String str = input.readLine();
- StringBuffer result = new StringBuffer();
- while (str != null) {
- result.append(str).append("\t\r");
- str = input.readLine();
-
- }
- int exitValue = proc.waitFor();
- if (exitValue != 0) {
- return StatusUtils.errorStatus(result.toString());
- }
-
- } catch (IOException e) {
- JBossWSCreationCore.getDefault().logError(e);
- } catch (InterruptedException e) {
- JBossWSCreationCore.getDefault().logError(e);
- }
-
- refreshProject(model.getWebProjectName(), monitor);
-
- return Status.OK_STATUS;
+ @Override
+ protected String getCommandLineFileName_linux() {
+ return WSPROVIDER_FILE_NAME_LINUX;
}
- private void refreshProject(String project, IProgressMonitor monitor) {
- try {
- JBossWSCreationUtils.getProjectByName(project).refreshLocal(2,
- monitor);
- } catch (CoreException e) {
- JBossWSCreationCore.getDefault().logError(e);
- }
+ @Override
+ protected String getCommandLineFileName_win() {
+ return WSPROVIDER_FILE_NAME_WIN;
}
- private String getCommandlineArgs() {
+ @Override
+ protected String getCommandlineArgs() {
String commandLine;
String project = model.getWebProjectName();
String projectRoot = JBossWSCreationUtils.getProjectRoot(project)
Show replies by date