1 11 package org.eclipse.pde.internal.core.product; 12 13 import org.eclipse.core.runtime.Platform; 14 import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo; 15 import org.eclipse.pde.internal.core.iproduct.IProductModel; 16 import org.w3c.dom.Node ; 17 import org.w3c.dom.NodeList ; 18 19 public class ArgumentsInfo extends ProductObject implements IArgumentsInfo { 20 21 private static final long serialVersionUID = 1L; 22 private String fProgramArgs = ""; private String fProgramArgsLin = ""; private String fProgramArgsMac = ""; private String fProgramArgsSol = ""; private String fProgramArgsWin = ""; 28 private String fVMArgs = ""; private String fVMArgsLin = ""; private String fVMArgsMac = ""; private String fVMArgsSol = ""; private String fVMArgsWin = ""; 34 public ArgumentsInfo(IProductModel model) { 35 super(model); 36 } 37 38 public void setProgramArguments(String args, int platform) { 39 String old; 40 if (args == null) 41 args = ""; switch (platform) { 43 case L_ARGS_ALL: 44 old = fProgramArgs; 45 fProgramArgs = args; 46 if (isEditable()) 47 firePropertyChanged(P_PROG_ARGS, old, fProgramArgs); 48 break; 49 case L_ARGS_LINUX: 50 old = fProgramArgsLin; 51 fProgramArgsLin = args; 52 if (isEditable()) 53 firePropertyChanged(P_PROG_ARGS_LIN, old, fProgramArgsLin); 54 break; 55 case L_ARGS_MACOS: 56 old = fProgramArgsMac; 57 fProgramArgsMac = args; 58 if (isEditable()) 59 firePropertyChanged(P_PROG_ARGS_MAC, old, fProgramArgsMac); 60 break; 61 case L_ARGS_SOLAR: 62 old = fProgramArgsSol; 63 fProgramArgsSol = args; 64 if (isEditable()) 65 firePropertyChanged(P_PROG_ARGS_SOL, old, fProgramArgsSol); 66 break; 67 case L_ARGS_WIN32: 68 old = fProgramArgsWin; 69 fProgramArgsWin = args; 70 if (isEditable()) 71 firePropertyChanged(P_PROG_ARGS_WIN, old, fProgramArgsWin); 72 break; 73 } 74 } 75 76 public String getProgramArguments(int platform) { 77 switch (platform) { 78 case L_ARGS_ALL: 79 return fProgramArgs; 80 case L_ARGS_LINUX: 81 return fProgramArgsLin; 82 case L_ARGS_MACOS: 83 return fProgramArgsMac; 84 case L_ARGS_SOLAR: 85 return fProgramArgsSol; 86 case L_ARGS_WIN32: 87 return fProgramArgsWin; 88 } 89 return ""; } 91 92 public String getCompleteProgramArguments(String os) { 93 if (Platform.OS_WIN32.equals(os)) { 94 return getCompleteArgs(getProgramArguments(L_ARGS_WIN32), fProgramArgs); 95 } else if (Platform.OS_LINUX.equals(os)) { 96 return getCompleteArgs(getProgramArguments(L_ARGS_LINUX), fProgramArgs); 97 } else if (Platform.OS_MACOSX.equals(os)) { 98 return getCompleteArgs(getProgramArguments(L_ARGS_MACOS), fProgramArgs); 99 } else if (Platform.OS_SOLARIS.equals(os)) { 100 return getCompleteArgs(getProgramArguments(L_ARGS_SOLAR), fProgramArgs); 101 } else { 102 return getProgramArguments(L_ARGS_ALL); 103 } 104 } 105 106 public void setVMArguments(String args, int platform) { 107 String old; 108 if (args == null) 109 args = ""; switch (platform) { 111 case L_ARGS_ALL: 112 old = fVMArgs; 113 fVMArgs = args; 114 if (isEditable()) 115 firePropertyChanged(P_VM_ARGS, old, fVMArgs); 116 break; 117 case L_ARGS_LINUX: 118 old = fVMArgsLin; 119 fVMArgsLin = args; 120 if (isEditable()) 121 firePropertyChanged(P_VM_ARGS_LIN, old, fVMArgsLin); 122 break; 123 case L_ARGS_MACOS: 124 old = fVMArgsMac; 125 fVMArgsMac = args; 126 if (isEditable()) 127 firePropertyChanged(P_VM_ARGS_MAC, old, fVMArgsMac); 128 break; 129 case L_ARGS_SOLAR: 130 old = fVMArgsSol; 131 fVMArgsSol = args; 132 if (isEditable()) 133 firePropertyChanged(P_VM_ARGS_SOL, old, fVMArgsSol); 134 break; 135 case L_ARGS_WIN32: 136 old = fVMArgsWin; 137 fVMArgsWin = args; 138 if (isEditable()) 139 firePropertyChanged(P_VM_ARGS_WIN, old, fVMArgsWin); 140 break; 141 } 142 } 143 144 public String getVMArguments(int platform) { 145 switch (platform) { 146 case L_ARGS_ALL: 147 return fVMArgs; 148 case L_ARGS_LINUX: 149 return fVMArgsLin; 150 case L_ARGS_MACOS: 151 return fVMArgsMac; 152 case L_ARGS_SOLAR: 153 return fVMArgsSol; 154 case L_ARGS_WIN32: 155 return fVMArgsWin; 156 } 157 return ""; } 159 160 public String getCompleteVMArguments(String os) { 161 if (Platform.OS_WIN32.equals(os)) { 162 return getCompleteArgs(getVMArguments(L_ARGS_WIN32), fVMArgs); 163 } else if (Platform.OS_LINUX.equals(os)) { 164 return getCompleteArgs(getVMArguments(L_ARGS_LINUX), fVMArgs); 165 } else if (Platform.OS_MACOSX.equals(os)) { 166 return getCompleteArgs(getVMArguments(L_ARGS_MACOS), fVMArgs); 167 } else if (Platform.OS_SOLARIS.equals(os)) { 168 return getCompleteArgs(getVMArguments(L_ARGS_SOLAR), fVMArgs); 169 } else { 170 return getVMArguments(L_ARGS_ALL); 171 } 172 } 173 174 private String getCompleteArgs(String platformArgs, String univArgs) { 175 String args = platformArgs; 176 if (univArgs.length() > 0) 177 args = univArgs + " " + args; return args.trim(); 179 } 180 181 public void parse(Node node) { 182 NodeList list = node.getChildNodes(); 183 for (int i = 0; i < list.getLength(); i++) { 184 Node child = list.item(i); 185 if (child.getNodeType() == Node.ELEMENT_NODE) { 186 if (child.getNodeName().equals(P_PROG_ARGS)) { 187 fProgramArgs = getText(child); 188 } else if (child.getNodeName().equals(P_PROG_ARGS_LIN)) { 189 fProgramArgsLin = getText(child); 190 } else if (child.getNodeName().equals(P_PROG_ARGS_MAC)) { 191 fProgramArgsMac = getText(child); 192 } else if (child.getNodeName().equals(P_PROG_ARGS_SOL)) { 193 fProgramArgsSol = getText(child); 194 } else if (child.getNodeName().equals(P_PROG_ARGS_WIN)) { 195 fProgramArgsWin = getText(child); 196 } else if (child.getNodeName().equals(P_VM_ARGS)) { 197 fVMArgs = getText(child); 198 } else if (child.getNodeName().equals(P_VM_ARGS_LIN)) { 199 fVMArgsLin = getText(child); 200 } else if (child.getNodeName().equals(P_VM_ARGS_MAC)) { 201 fVMArgsMac = getText(child); 202 } else if (child.getNodeName().equals(P_VM_ARGS_SOL)) { 203 fVMArgsSol = getText(child); 204 } else if (child.getNodeName().equals(P_VM_ARGS_WIN)) { 205 fVMArgsWin = getText(child); 206 } 207 } 208 } 209 } 210 211 private String getText(Node node) { 212 node.normalize(); 213 Node text = node.getFirstChild(); 214 if (text != null && text.getNodeType() == Node.TEXT_NODE) { 215 return text.getNodeValue(); 216 } 217 return ""; } 219 220 public void write(String indent,java.io.PrintWriter writer) { 221 writer.println(indent + "<launcherArgs>"); if (fProgramArgs.length() > 0) { 223 writer.println(indent + " " + "<" + P_PROG_ARGS + ">" + getWritableString(fProgramArgs) + "</" + P_PROG_ARGS + ">"); } 225 if (fProgramArgsLin.length() > 0) { 226 writer.println(indent + " " + "<" + P_PROG_ARGS_LIN + ">" + getWritableString(fProgramArgsLin) + "</" + P_PROG_ARGS_LIN + ">"); } 228 if (fProgramArgsMac.length() > 0) { 229 writer.println(indent + " " + "<" + P_PROG_ARGS_MAC + ">" + getWritableString(fProgramArgsMac) + "</" + P_PROG_ARGS_MAC + ">"); } 231 if (fProgramArgsSol.length() > 0) { 232 writer.println(indent + " " + "<" + P_PROG_ARGS_SOL + ">" + getWritableString(fProgramArgsSol) + "</" + P_PROG_ARGS_SOL + ">"); } 234 if (fProgramArgsWin.length() > 0) { 235 writer.println(indent + " " + "<" + P_PROG_ARGS_WIN + ">" + getWritableString(fProgramArgsWin) + "</" + P_PROG_ARGS_WIN + ">"); } 237 if (fVMArgs.length() > 0) { 238 writer.println(indent + " " + "<" + P_VM_ARGS + ">" + getWritableString(fVMArgs) + "</" + P_VM_ARGS + ">"); } 240 if (fVMArgsLin.length() > 0) { 241 writer.println(indent + " " + "<" + P_VM_ARGS_LIN + ">" + getWritableString(fVMArgsLin) + "</" + P_VM_ARGS_LIN + ">"); } 243 if (fVMArgsMac.length() > 0) { 244 writer.println(indent + " " + "<" + P_VM_ARGS_MAC + ">" + getWritableString(fVMArgsMac) + "</" + P_VM_ARGS_MAC + ">"); } 246 if (fVMArgsSol.length() > 0) { 247 writer.println(indent + " " + "<" + P_VM_ARGS_SOL + ">" + getWritableString(fVMArgsSol) + "</" + P_VM_ARGS_SOL + ">"); } 249 if (fVMArgsWin.length() > 0) { 250 writer.println(indent + " " + "<" + P_VM_ARGS_WIN + ">" + getWritableString(fVMArgsWin) + "</" + P_VM_ARGS_WIN + ">"); } 252 writer.println(indent + "</launcherArgs>"); } 254 255 } 256 | Popular Tags |