KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > product > ArgumentsInfo


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18
19 public class ArgumentsInfo extends ProductObject implements IArgumentsInfo {
20
21     private static final long serialVersionUID = 1L;
22     private String JavaDoc fProgramArgs = ""; //$NON-NLS-1$
23
private String JavaDoc fProgramArgsLin = ""; //$NON-NLS-1$
24
private String JavaDoc fProgramArgsMac = ""; //$NON-NLS-1$
25
private String JavaDoc fProgramArgsSol = ""; //$NON-NLS-1$
26
private String JavaDoc fProgramArgsWin = ""; //$NON-NLS-1$
27

28     private String JavaDoc fVMArgs = ""; //$NON-NLS-1$
29
private String JavaDoc fVMArgsLin = ""; //$NON-NLS-1$
30
private String JavaDoc fVMArgsMac = ""; //$NON-NLS-1$
31
private String JavaDoc fVMArgsSol = ""; //$NON-NLS-1$
32
private String JavaDoc fVMArgsWin = ""; //$NON-NLS-1$
33

34     public ArgumentsInfo(IProductModel model) {
35         super(model);
36     }
37
38     public void setProgramArguments(String JavaDoc args, int platform) {
39         String JavaDoc old;
40         if (args == null)
41             args = ""; //$NON-NLS-1$
42
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 JavaDoc 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 ""; //$NON-NLS-1$
90
}
91     
92     public String JavaDoc getCompleteProgramArguments(String JavaDoc 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 JavaDoc args, int platform) {
107         String JavaDoc old;
108         if (args == null)
109             args = ""; //$NON-NLS-1$
110
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 JavaDoc 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 ""; //$NON-NLS-1$
158
}
159
160     public String JavaDoc getCompleteVMArguments(String JavaDoc 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 JavaDoc getCompleteArgs(String JavaDoc platformArgs, String JavaDoc univArgs) {
175         String JavaDoc args = platformArgs;
176         if (univArgs.length() > 0)
177             args = univArgs + " " + args; //$NON-NLS-1$
178
return args.trim();
179     }
180     
181     public void parse(Node JavaDoc node) {
182         NodeList JavaDoc list = node.getChildNodes();
183         for (int i = 0; i < list.getLength(); i++) {
184             Node JavaDoc 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 JavaDoc getText(Node JavaDoc node) {
212         node.normalize();
213         Node JavaDoc text = node.getFirstChild();
214         if (text != null && text.getNodeType() == Node.TEXT_NODE) {
215             return text.getNodeValue();
216         }
217         return ""; //$NON-NLS-1$
218
}
219     
220     public void write(String JavaDoc indent,java.io.PrintWriter JavaDoc writer) {
221         writer.println(indent + "<launcherArgs>"); //$NON-NLS-1$
222
if (fProgramArgs.length() > 0) {
223             writer.println(indent + " " + "<" + P_PROG_ARGS + ">" + getWritableString(fProgramArgs) + "</" + P_PROG_ARGS + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
224
}
225         if (fProgramArgsLin.length() > 0) {
226             writer.println(indent + " " + "<" + P_PROG_ARGS_LIN + ">" + getWritableString(fProgramArgsLin) + "</" + P_PROG_ARGS_LIN + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
227
}
228         if (fProgramArgsMac.length() > 0) {
229             writer.println(indent + " " + "<" + P_PROG_ARGS_MAC + ">" + getWritableString(fProgramArgsMac) + "</" + P_PROG_ARGS_MAC + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
230
}
231         if (fProgramArgsSol.length() > 0) {
232             writer.println(indent + " " + "<" + P_PROG_ARGS_SOL + ">" + getWritableString(fProgramArgsSol) + "</" + P_PROG_ARGS_SOL + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
233
}
234         if (fProgramArgsWin.length() > 0) {
235             writer.println(indent + " " + "<" + P_PROG_ARGS_WIN + ">" + getWritableString(fProgramArgsWin) + "</" + P_PROG_ARGS_WIN + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
236
}
237         if (fVMArgs.length() > 0) {
238             writer.println(indent + " " + "<" + P_VM_ARGS + ">" + getWritableString(fVMArgs) + "</" + P_VM_ARGS + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
239
}
240         if (fVMArgsLin.length() > 0) {
241             writer.println(indent + " " + "<" + P_VM_ARGS_LIN + ">" + getWritableString(fVMArgsLin) + "</" + P_VM_ARGS_LIN + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
242
}
243         if (fVMArgsMac.length() > 0) {
244             writer.println(indent + " " + "<" + P_VM_ARGS_MAC + ">" + getWritableString(fVMArgsMac) + "</" + P_VM_ARGS_MAC + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
245
}
246         if (fVMArgsSol.length() > 0) {
247             writer.println(indent + " " + "<" + P_VM_ARGS_SOL + ">" + getWritableString(fVMArgsSol) + "</" + P_VM_ARGS_SOL + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
248
}
249         if (fVMArgsWin.length() > 0) {
250             writer.println(indent + " " + "<" + P_VM_ARGS_WIN + ">" + getWritableString(fVMArgsWin) + "</" + P_VM_ARGS_WIN + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
251
}
252         writer.println(indent + "</launcherArgs>"); //$NON-NLS-1$
253
}
254     
255 }
256
Popular Tags