Class RequireBuilder
- java.lang.Object
-
- org.mozilla.javascript.commonjs.module.RequireBuilder
-
- All Implemented Interfaces:
java.io.Serializable
public class RequireBuilder extends java.lang.Object implements java.io.Serializable
A builder forRequire
instances. Useful when you're creating many instances ofRequire
that are identical except for their top-level scope and currentContext
. Also useful if you prefer configuring it using named setters instead of passing many parameters in a constructor. Every setter returns "this", so you can easily chain their invocations for additional convenience.- Version:
- $Id: RequireBuilder.java,v 1.4 2011/04/07 20:26:11 hannes%helma.at Exp $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private ModuleScriptProvider
moduleScriptProvider
private Script
postExec
private Script
preExec
private boolean
sandboxed
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description RequireBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Require
createRequire(Context cx, Scriptable globalScope)
Creates a new require() function.RequireBuilder
setModuleScriptProvider(ModuleScriptProvider moduleScriptProvider)
Sets theModuleScriptProvider
for theRequire
instances that this builder builds.RequireBuilder
setPostExec(Script postExec)
Sets the script that should execute in every module's scope after the module's own script has executed.RequireBuilder
setPreExec(Script preExec)
Sets the script that should execute in every module's scope before the module's own script has executed.RequireBuilder
setSandboxed(boolean sandboxed)
Sets whether the created require() instances will be sandboxed.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
sandboxed
private boolean sandboxed
-
moduleScriptProvider
private ModuleScriptProvider moduleScriptProvider
-
preExec
private Script preExec
-
postExec
private Script postExec
-
-
Method Detail
-
setModuleScriptProvider
public RequireBuilder setModuleScriptProvider(ModuleScriptProvider moduleScriptProvider)
Sets theModuleScriptProvider
for theRequire
instances that this builder builds.- Parameters:
moduleScriptProvider
- the module script provider for theRequire
instances that this builder builds.- Returns:
- this, so you can chain ("fluidize") setter invocations
-
setPostExec
public RequireBuilder setPostExec(Script postExec)
Sets the script that should execute in every module's scope after the module's own script has executed.- Parameters:
postExec
- the post-exec script.- Returns:
- this, so you can chain ("fluidize") setter invocations
-
setPreExec
public RequireBuilder setPreExec(Script preExec)
Sets the script that should execute in every module's scope before the module's own script has executed.- Parameters:
preExec
- the pre-exec script.- Returns:
- this, so you can chain ("fluidize") setter invocations
-
setSandboxed
public RequireBuilder setSandboxed(boolean sandboxed)
Sets whether the created require() instances will be sandboxed. SeeRequire(Context, Scriptable, ModuleScriptProvider, Script, Script, boolean)
for explanation.- Parameters:
sandboxed
- true if the created require() instances will be sandboxed.- Returns:
- this, so you can chain ("fluidize") setter invocations
-
createRequire
public Require createRequire(Context cx, Scriptable globalScope)
Creates a new require() function. You are still responsible for invoking eitherRequire.install(Scriptable)
orRequire.requireMain(Context, String)
to effectively make it available to its JavaScript program.- Parameters:
cx
- the current contextglobalScope
- the global scope containing the JS standard natives.- Returns:
- a new Require instance.
-
-