View Javadoc

1   package delight.nashornsandbox;
2   
3   import java.util.concurrent.ExecutorService;
4   
5   @SuppressWarnings("all")
6   public interface NashornSandbox {
7     /**
8      * <p>Add a new class to the list of allowed classes.
9      * <p>WARNING: Adding a new class, AFTER a script has been evaluated, will destroy the engine and recreate it. The script context will thus be lost.
10     */
11    public abstract NashornSandbox allow(final Class<?> clazz);
12    
13    /**
14     * <p>Remove a class from the list of allowed classes.
15     */
16    public abstract void disallow(final Class<?> clazz);
17    
18    /**
19     * <p>Check if a class is in the list of allowed classes.
20     */
21    public abstract boolean isAllowed(final Class<?> clazz);
22    
23    /**
24     * <p>Remove all classes from the list of allowed classes.
25     */
26    public abstract void disallowAllClasses();
27    
28    /**
29     * Will add a global variable available to all scripts executed with this sandbox.
30     */
31    public abstract NashornSandbox inject(final String variableName, final Object object);
32    
33    /**
34     * Sets the maximum CPU time in milliseconds allowed for script execution.
35     */
36    public abstract NashornSandbox setMaxCPUTime(final long limit);
37    
38    /**
39     * Specifies the executor service which is used to run scripts when a CPU time limit is specified.
40     */
41    public abstract NashornSandbox setExecutor(final ExecutorService executor);
42    
43    public abstract ExecutorService getExecutor();
44    
45    /**
46     * Evaluates the string.
47     */
48    public abstract Object eval(final String js);
49    
50    /**
51     * Obtains the value of the specified JavaScript variable.
52     */
53    public abstract Object get(final String variableName);
54    
55    /**
56     * Allow Nashorn print and echo functions.
57     */
58    public abstract void allowPrintFunctions(final boolean v);
59    
60    /**
61     * Allow Nashorn readLine and readFully functions.
62     */
63    public abstract void allowReadFunctions(final boolean v);
64    
65    /**
66     * Allow Nashorn load and loadWithNewGlobal functions.
67     */
68    public abstract void allowLoadFunctions(final boolean v);
69    
70    /**
71     * Allow Nashorn quit and exit functions.
72     */
73    public abstract void allowExitFunctions(final boolean v);
74    
75    /**
76     * Allow Nashorn globals object $ARG, $ENV, $EXEC, $OPTIONS, $OUT, $ERR and $EXIT.
77     */
78    public abstract void allowGlobalsObjects(final boolean v);
79  }