KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > services > KelpExecutor


1 package org.enhydra.kelp.forte.services;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import org.enhydra.kelp.forte.node.ForteProject;
8 import org.enhydra.kelp.common.deployer.RunParameters;
9 import org.enhydra.tool.ToolBoxInfo;
10
11 import org.openide.execution.*;
12 import org.openide.util.HelpCtx;
13 import org.openide.util.NbBundle;
14
15 /** Runs an external process to "execute" a type of file.
16  *
17  * @author root
18  */

19 public class KelpExecutor extends ProcessExecutor {
20
21     private static final NbProcessDescriptor DEFAULT = new NbProcessDescriptor (
22                 // PROCESS NAME:
23
// This need not be the Java launcher, of course:
24
"{" + Format.TAG_JAVAHOME + "}{" + Format.TAG_SEPARATOR + "}bin{" + Format.TAG_SEPARATOR + "}java",
25                // You can modify the default format however you like, and insert or remove tags like so:
26
"{" + MyFormat.TAG_MYOPTIONVAL + "} " //+
27
);
28
29     // The default value for an unconfigured executor.
30
private String JavaDoc valueOfMyOption = "";
31
32     public KelpExecutor () {
33         // Override the default executor choice made in ProcessExecutor:
34
setExternalExecutor (DEFAULT);
35     }
36
37     public String JavaDoc getRunOption () {
38         if (valueOfMyOption.equals(""))
39         {
40             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
41             ForteProject proj = new ForteProject();
42
43             String JavaDoc easRoot = ToolBoxInfo.getEnhydraRoot();
44             char sep = File.separatorChar;
45             char psep = File.pathSeparatorChar;
46             RunParameters rp = new RunParameters(proj);
47
48             buf.append("-cp \"");
49             buf.append(proj.getSourcePath());
50             buf.append(psep);
51             buf.append(easRoot);
52             buf.append(sep);
53             buf.append("lib");
54             buf.append(sep);
55             buf.append("build");
56             buf.append(sep);
57             buf.append("toolbox.jar");
58
59             // dr 24.06.2002
60
buf.append(psep);
61             buf.append(easRoot);
62             buf.append(sep);
63             buf.append("lib");
64             buf.append(sep);
65             buf.append("enhydra.jar");
66             
67             //SV
68
buf.append(psep);
69             buf.append(easRoot);
70             buf.append(sep);
71             buf.append("lib");
72             buf.append(sep);
73             buf.append("servlet.jar");
74
75             // dr 24.06.2002
76
buf.append(psep);
77             buf.append(easRoot);
78             buf.append(sep);
79             buf.append("lib");
80             buf.append(sep);
81             buf.append("tomcat.jar");
82
83             // dr 23.03.2003
84
buf.append(psep);
85             buf.append(easRoot);
86             buf.append(sep);
87             buf.append("lib");
88             buf.append(sep);
89             buf.append("util.jar");
90
91             // Dusan 26.01.2003.
92
buf.append(psep);
93             buf.append(easRoot);
94             buf.append(sep);
95             buf.append("lib");
96             buf.append(sep);
97             buf.append("log4j.jar");
98
99             // Dusan 11.02.2003.
100
buf.append(psep);
101             buf.append(easRoot);
102             buf.append(sep);
103             buf.append("dods");
104             buf.append(sep);
105             buf.append("lib");
106             buf.append(sep);
107             buf.append("dbmanager.jar");
108             
109             buf.append(psep);
110             buf.append(easRoot);
111             buf.append(sep);
112             buf.append("dods");
113             buf.append(sep);
114             buf.append("lib");
115             buf.append(sep);
116             buf.append("dbmanager-api.jar");
117             
118             buf.append(psep);
119             buf.append(easRoot);
120             buf.append(sep);
121             buf.append("dods");
122             buf.append(sep);
123             buf.append("lib");
124             buf.append(sep);
125             buf.append("dsconnection.jar");
126             
127             buf.append(psep);
128             buf.append(easRoot);
129             buf.append(sep);
130             buf.append("dods");
131             buf.append(sep);
132             buf.append("lib");
133             buf.append(sep);
134             buf.append("stdcaches.jar");
135             
136             buf.append(psep);
137             buf.append(easRoot);
138             buf.append(sep);
139             buf.append("dods");
140             buf.append(sep);
141             buf.append("lib");
142             buf.append(sep);
143             buf.append("stdconnection.jar");
144             
145             buf.append(psep);
146             buf.append(easRoot);
147             buf.append(sep);
148             buf.append("dods");
149             buf.append(sep);
150             buf.append("lib");
151             buf.append(sep);
152             buf.append("stdtransaction.jar");
153
154             String JavaDoc s = System.getProperty("java.home");
155             s = s.substring(0, s.lastIndexOf("jre")-1);
156             buf.append(psep);
157             buf.append(s);
158             buf.append(sep);
159             buf.append("lib");
160             buf.append(sep);
161             buf.append("tools.jar");
162
163             buf.append('\"');
164             buf.append(' ');
165             buf.append(rp.getTCcpArg());
166             buf.append(' ');
167             buf.append(rp.getPolicyArg());
168             buf.append(' ');
169             buf.append(rp.getBootArg());
170             buf.append(" StartServer ");
171             buf.append(rp.getAppParameters());
172             setRunOption(buf.toString());
173         }
174         return valueOfMyOption;
175     }
176
177     public synchronized void setRunOption (String JavaDoc nue) {
178         String JavaDoc old = valueOfMyOption;
179         valueOfMyOption = nue;
180         firePropertyChange ("valueOfMyOption", old, nue);
181     }
182
183     protected Process JavaDoc createProcess (ExecInfo info) throws IOException JavaDoc {
184         return getExternalExecutor ().exec (new MyFormat (info,
185                                             getClassPath (),
186                                             getBootClassPath (),
187                                             getRepositoryPath (),
188                                             getLibraryPath (),
189                                             getRunOption ()));
190     }
191
192     /*
193     public HelpCtx getHelpCtx () {
194         return new HelpCtx (KelpExecutor.class);
195     }
196     */

197
198     static class MyFormat extends Format {
199
200         // Define whatever other substitutable tags you want:
201
static final String JavaDoc TAG_MYOPTIONVAL = "myOptionVal"; // this will appear as -myoption {myOptionVal}
202

203         MyFormat (ExecInfo info, NbClassPath classPath, NbClassPath bootClassPath,
204                   NbClassPath repositoryPath, NbClassPath libraryPath,
205                   // Get the values to substitute from somewhere:
206
String JavaDoc valueOfMyOption) {
207             // This fills in all the tags defined in Format, like TAG_LIBRARY, etc.:
208
super (info, classPath, bootClassPath, repositoryPath, libraryPath);
209             // Add definitions for your own tags here:
210
Map JavaDoc map = getMap ();
211             map.put (TAG_MYOPTIONVAL, valueOfMyOption);
212         }
213
214     }
215
216 }
217
Popular Tags