79311cd118ce01d0335cc252eb06db63e19c8fb7
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / launcher / ExecutionArguments.java
1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
2
3 import org.eclipse.core.resources.IFile;
4 import org.eclipse.core.runtime.CoreException;
5 import org.eclipse.core.runtime.QualifiedName;
6
7 public class ExecutionArguments {
8         protected static final QualifiedName EXECUTION_ARGUMENTS_PROPERTY = new QualifiedName(
9                         "net.sourceforge.phpdt", "executionArguments");
10
11         protected static final String ARGUMENT_SEPARATOR = "**<ArgBreak>**";
12
13         protected String interpreterArguments, phpFileArguments;
14
15         public static ExecutionArguments getExecutionArguments(IFile phpScriptFile) {
16                 try {
17                         String executionArgumentsPersistableFormat = phpScriptFile
18                                         .getPersistentProperty(EXECUTION_ARGUMENTS_PROPERTY);
19                         ExecutionArguments executionArguments = new ExecutionArguments();
20
21                         if (executionArgumentsPersistableFormat != null) {
22                                 int argBreakIndex = executionArgumentsPersistableFormat
23                                                 .indexOf(ARGUMENT_SEPARATOR);
24                                 executionArguments
25                                                 .setInterpreterArguments(executionArgumentsPersistableFormat
26                                                                 .substring(0, argBreakIndex));
27                                 executionArguments
28                                                 .setPHPFileArguments(executionArgumentsPersistableFormat
29                                                                 .substring(argBreakIndex
30                                                                                 + ARGUMENT_SEPARATOR.length()));
31                         }
32
33                         return executionArguments;
34                 } catch (CoreException e) {
35                 }
36
37                 return null;
38         }
39
40         public static void setExecutionArguments(IFile phpScriptFile,
41                         ExecutionArguments arguments) {
42                 try {
43                         phpScriptFile.setPersistentProperty(EXECUTION_ARGUMENTS_PROPERTY,
44                                         arguments.toPersistableFormat());
45                 } catch (CoreException e) {
46                 }
47         }
48
49         public void setInterpreterArguments(String theArguments) {
50                 interpreterArguments = theArguments;
51         }
52
53         public void setPHPFileArguments(String theArguments) {
54                 phpFileArguments = theArguments;
55         }
56
57         public String toPersistableFormat() {
58                 return interpreterArguments + ARGUMENT_SEPARATOR + phpFileArguments;
59         }
60 }