home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 June
/
PCWorld_2007-06_cd.bin
/
multimedia
/
ppsee
/
PPSeeSetup.exe
/
lib
/
bsh-commands-2.0b4.jar
/
bsh
/
commands
/
run.bsh
< prev
next >
Wrap
Text File
|
2005-05-23
|
2KB
|
62 lines
/**
Run a command in its own in its own private global namespace, with its
own class manager and interpeter context. (kind of like unix "chroot" for
a namespace).
The root bsh system object is extended (with the extend() command) and
made visible here, so that general system info (e.g. current working
directory) is effectively inherited. Because the root bsh object is
extended it is effectively read only / copy on write...
e.g. you can change directories in the child context, do imports, change
the classpath, etc. and it will not affect the calling context.
<p>
run() is like source() except that it runs the command in a new,
subordinate and prune()'d namespace. So it's like "running" a command
instead of "sourcing" it. run() teturns the object context in which the
command was run.
<p>
Returns the object context so that you can gather results.
<p>
Parameter runArgument an argument passed to the child context under the
name runArgument. e.g. you might pass in the calling This context
from which to draw variables, etc.
<p>
@return Returns the object context so that you can gather results.
@param runArgument an argument passed to the child context under the
name runArgument. e.g. you might pass in the calling This context
from which to draw variables, etc.
*/
bsh.help.run= "usage: Thread run( filename )";
run( String filename, Object runArgument )
{
// Our local namespace is going to be the new root (global)
// make local copies of the system stuff.
//
// Extend the root system object
// this is problematic... probably need more here...
this.bsh=extend(global.bsh);
this.bsh.help=extend(bsh.help);
// save the classpath before pruning
this.cp = this.caller.namespace.getClassManager()
.getClassPath().getUserClassPathComponents();
// Cut us off... make us the root (global) namespace for this command
// Prune() will also create a new class manager for us.
this.namespace.prune();
// Inherit user classpath
this.namespace.getClassManager().setClassPath( cp );
this.interpreter.source( filename, this.namespace );
return this;
}
run( String filename ) {
run( filename, null );
}