|
20 | 20 | package org.elasticsearch.script;
|
21 | 21 |
|
22 | 22 | import java.lang.reflect.Method;
|
23 |
| -import java.util.Collections; |
24 |
| -import java.util.HashMap; |
25 |
| -import java.util.Map; |
26 | 23 |
|
27 | 24 | /**
|
28 | 25 | * The information necessary to compile and run a script.
|
|
32 | 29 | * <p>
|
33 | 30 | * There are two related classes which must be supplied to construct a {@link ScriptContext}.
|
34 | 31 | * <p>
|
35 |
| - * The <i>CompiledType</i> is a factory class for constructing instances of a script. The |
36 |
| - * {@link ScriptService} returns an instance of <i>CompiledType</i> when compiling a script. This class |
| 32 | + * The <i>FactoryType</i> is a factory class for constructing instances of a script. The |
| 33 | + * {@link ScriptService} returns an instance of <i>FactoryType</i> when compiling a script. This class |
37 | 34 | * must be stateless so it is cacheable by the {@link ScriptService}. It must have an abstract method
|
38 | 35 | * named {@code newInstance} which {@link ScriptEngine} implementations will define.
|
39 | 36 | * <p>
|
40 | 37 | * The <i>InstanceType</i> is a class returned by the {@code newInstance} method of the
|
41 |
| - * <i>CompiledType</i>. It is an instance of a script and may be stateful. Instances of |
| 38 | + * <i>FactoryType</i>. It is an instance of a script and may be stateful. Instances of |
42 | 39 | * the <i>InstanceType</i> may be executed multiple times by a caller with different arguments. This
|
43 | 40 | * class must have an abstract method named {@code execute} which {@link ScriptEngine} implementations
|
44 | 41 | * will define.
|
45 | 42 | */
|
46 |
| -public final class ScriptContext<CompiledType> { |
| 43 | +public final class ScriptContext<FactoryType> { |
47 | 44 |
|
48 | 45 | /** A unique identifier for this context. */
|
49 | 46 | public final String name;
|
50 | 47 |
|
51 | 48 | /** A factory class for constructing instances of a script. */
|
52 |
| - public final Class<CompiledType> compiledClazz; |
| 49 | + public final Class<FactoryType> factoryClazz; |
53 | 50 |
|
54 | 51 | /** A class that is an instance of a script. */
|
55 | 52 | public final Class<?> instanceClazz;
|
56 | 53 |
|
57 | 54 | /** Construct a context with the related instance and compiled classes. */
|
58 |
| - public ScriptContext(String name, Class<CompiledType> compiledClazz) { |
| 55 | + public ScriptContext(String name, Class<FactoryType> factoryClazz) { |
59 | 56 | this.name = name;
|
60 |
| - this.compiledClazz = compiledClazz; |
| 57 | + this.factoryClazz = factoryClazz; |
61 | 58 | Method newInstanceMethod = null;
|
62 |
| - for (Method method : compiledClazz.getMethods()) { |
| 59 | + for (Method method : factoryClazz.getMethods()) { |
63 | 60 | if (method.getName().equals("newInstance")) {
|
64 | 61 | if (newInstanceMethod != null) {
|
65 |
| - throw new IllegalArgumentException("Cannot have multiple newInstance methods on CompiledType class [" |
66 |
| - + compiledClazz.getName() + "] for script context [" + name + "]"); |
| 62 | + throw new IllegalArgumentException("Cannot have multiple newInstance methods on FactoryType class [" |
| 63 | + + factoryClazz.getName() + "] for script context [" + name + "]"); |
67 | 64 | }
|
68 | 65 | newInstanceMethod = method;
|
69 | 66 | }
|
70 | 67 | }
|
71 | 68 | if (newInstanceMethod == null) {
|
72 |
| - throw new IllegalArgumentException("Could not find method newInstance on CompiledType class [" |
73 |
| - + compiledClazz.getName() + "] for script context [" + name + "]"); |
| 69 | + throw new IllegalArgumentException("Could not find method newInstance on FactoryType class [" |
| 70 | + + factoryClazz.getName() + "] for script context [" + name + "]"); |
74 | 71 | }
|
75 | 72 | instanceClazz = newInstanceMethod.getReturnType();
|
76 | 73 | }
|
|
0 commit comments