PageRenderTime 36ms CodeModel.GetById 33ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/bsh/commands/run.bsh

#
Unknown | 61 lines | 51 code | 10 blank | 0 comment | 0 complexity | 02057685cef6ea8713b94358f411731e MD5 | raw file
 1/**
 2	Run a command in its own in its own private global namespace, with its
 3	own class manager and interpeter context.  (kind of like unix "chroot" for 
 4	a namespace).
 5	The root bsh system object is extended (with the extend() command) and 
 6	made visible here, so that general system info (e.g. current working
 7	directory) is effectively inherited.  Because the root bsh object is 
 8	extended it is effectively read only / copy on write...  
 9	e.g. you can change directories in the child context, do imports, change
10	the classpath, etc. and it will not affect the calling context.
11	<p>
12
13	run() is like source() except that it runs the command in a new, 
14	subordinate and prune()'d namespace.  So it's like "running" a command 
15	instead of "sourcing" it.  run() teturns the object context in which the 
16	command was run.
17	<p>
18
19	Returns the object context so that you can gather results.
20	<p>
21	Parameter runArgument an argument passed to the child context under the
22		name runArgument.  e.g. you might pass in the calling This context
23		from which to draw variables, etc.
24	<p>
25
26	@return Returns the object context so that you can gather results.
27	@param runArgument an argument passed to the child context under the
28		name runArgument.  e.g. you might pass in the calling This context
29		from which to draw variables, etc.
30*/
31
32bsh.help.run= "usage: Thread run( filename )";
33
34run( String filename, Object runArgument ) 
35{
36	// Our local namespace is going to be the new root (global)
37	// make local copies of the system stuff.
38	//
39	// Extend the root system object
40	// this is problematic...  probably need more here...
41	this.bsh=extend(global.bsh); 
42	this.bsh.help=extend(bsh.help);
43
44	// save the classpath before pruning
45	this.cp = this.caller.namespace.getClassManager()
46		.getClassPath().getUserClassPathComponents();
47
48	// Cut us off... make us the root (global) namespace for this command
49	// Prune() will also create a new class manager for us.
50	this.namespace.prune();
51
52	// Inherit user classpath 
53	this.namespace.getClassManager().setClassPath( cp );
54
55	this.interpreter.source( filename, this.namespace );
56	return this;
57}
58
59run( String filename ) {
60	run( filename, null );
61}