// ctx -b bindname1 bindname2 bindname3
// Will read 3 objects from shell-in and bind them under the specified names
public void process(String exename, String[] params) throws Exception {
log.debug("entered");
if (helpRequested()) {
PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
out.print("Usage:\n");
out.print(" BIND some objects in the context under their respective names:\n");
out.print(" <OBJ_GEN> | ctx [-ex] -b name1, name2, name3\n\n");
out.print(" UNBIND some objects from the context:\n");
out.print(" ctx [-ex] -u name1, name2, name3\n\n");
out.print(" GET some objects from the context:\n");
out.print(" ctx [-ex] -g name1, name2, name3 | <OBJ_CONSUMER>\n\n");
out.print(" LIST children of an existing object to some other existing object:\n");
out.print(" ctx [-ex] -l\n\n");
out.print(" --help : this help\n");
out.close();
log.debug("done");
return;
}
int action = -1;
PrintWriter2 err = new PrintWriter2(new BufferWriter(getStdOut())), pout = err;
LinkedList names = new LinkedList();
Context ctx = shell.getContext();
if (params.length == 0) {
if (canThrowEx()) {
throw new Exception("Need to specify some parameters.");
} else {
printUsage();
log.debug("done");
return;
}
}
for (int i = 0; i < params.length; i++) {
String tmp = params[i];
if (tmp.equals("-b")) {
action = BIND;
// zdaj bere� dokler je:
for (int j = i + 1; j < params.length; j++, i++) {
names.add(params[j]);
}
if (names.size() == 0) {
if (canThrowEx()) {
throw new Exception("No bind name specified.");
} else {
err.println("No bind name specified.");
printUsage();
log.debug("done");
return;
}
}
} else if (tmp.equals("-u")) {
action = UNBIND;
// zdaj bere� dokler je:
for (int j = i + 1; j < params.length; j++, i++) {
names.add(params[j]);
}
if (names.size() == 0) {
if (canThrowEx()) {
throw new Exception("No unbind name specified.");
} else {
err.println("No unbind name specified.");
printUsage();
log.debug("done");
return;
}
}
} else if (tmp.equals("-g")) {
action = GET;
for (int j = i + 1; j < params.length; j++, i++) {
names.add(params[j]);
}
if (names.size() == 0) {
if (canThrowEx()) {
throw new Exception("No get name specified.");
} else {
err.println("No get name specified.");
printUsage();
log.debug("done");
return;
}
}
} else if (tmp.equals("-l")) {
action = LIST;
} else {
printUsage();
log.debug("done");
return;
}
}
switch (action) {
case BIND:
{
BufferObjectReader objin = new BufferObjectReader(getStdIn());
// read from input names.length() objects
// bind each one as you go
Iterator it = names.iterator();
while (it.hasNext()) {
String name = String.valueOf(it.next());
Object obj = null;
if (!objin.isFinished()) obj = objin.readObject();
if (obj == null) {
if (canThrowEx()) {
throw new Exception("Could not read object from std-in for name: " + name);
} else {
err.println("Could not read object from std-in for name: " + name);
printUsage();
log.debug("done");
return;
}
}