24
24
import java .util .Objects ;
25
25
26
26
/**
27
- * Whitelist contains data structures designed to be used to generate a white-list of Java classes,
27
+ * Whitelist contains data structures designed to be used to generate a whitelist of Java classes,
28
28
* constructors, methods, and fields that can be used within a Painless script at both compile-time
29
29
* and run-time.
30
30
*
31
- * A white-list consists of several pieces with {@link Struct}s as the top level. Each {@link Struct}
32
- * will contain zero-to-many {@link Constructor}s, {@link Method}s, and {@link Field}s which are what
33
- * will be available with a Painless script. See each individual white-list object for more detail.
31
+ * A whitelist consists of several pieces with {@link WhitelistClass}s as the top level. Each
32
+ * {@link WhitelistClass} will contain zero-to-many {@link WhitelistConstructor}s, {@link WhitelistMethod}s, and
33
+ * {@link WhitelistField}s which are what will be available with a Painless script. See each individual
34
+ * whitelist object for more detail.
34
35
*/
35
36
public final class Whitelist {
36
37
@@ -54,166 +55,14 @@ public final class Whitelist {
54
55
public static final List <Whitelist > BASE_WHITELISTS =
55
56
Collections .singletonList (WhitelistLoader .loadFromResourceFiles (Whitelist .class , BASE_WHITELIST_FILES ));
56
57
57
- /**
58
- * Struct represents the equivalent of a Java class in Painless complete with super classes,
59
- * constructors, methods, and fields. In Painless a class is known as a struct primarily to avoid
60
- * naming conflicts internally. There must be a one-to-one mapping of struct names to Java classes.
61
- * Though, since multiple white-lists may be combined into a single white-list for a specific
62
- * {@link org.elasticsearch.script.ScriptContext}, as long as multiple structs representing the same
63
- * Java class have the same Painless type name and have legal constructor/method overloading they
64
- * can be merged together.
65
- *
66
- * Structs in Painless allow for arity overloading for constructors and methods. Arity overloading
67
- * means that multiple constructors are allowed for a single struct as long as they have a different
68
- * number of parameter types, and multiples methods with the same name are allowed for a single struct
69
- * as long as they have the same return type and a different number of parameter types.
70
- *
71
- * Structs will automatically extend other white-listed structs if the Java class they represent is a
72
- * subclass of other structs including Java interfaces.
73
- */
74
- public static final class Struct {
75
-
76
- /** Information about where this struct was white-listed from. Can be used for error messages. */
77
- public final String origin ;
78
-
79
- /** The Java class name this struct represents. */
80
- public final String javaClassName ;
81
-
82
- /**
83
- * Allow the Java class name to only be specified as the fully-qualified name.
84
- */
85
- public final boolean onlyFQNJavaClassName ;
86
-
87
- /** The {@link List} of white-listed ({@link Constructor}s) available to this struct. */
88
- public final List <Constructor > whitelistConstructors ;
89
-
90
- /** The {@link List} of white-listed ({@link Method}s) available to this struct. */
91
- public final List <Method > whitelistMethods ;
92
-
93
- /** The {@link List} of white-listed ({@link Field}s) available to this struct. */
94
- public final List <Field > whitelistFields ;
95
-
96
- /** Standard constructor. All values must be not {@code null}. */
97
- public Struct (String origin , String javaClassName , boolean onlyFQNJavaClassName ,
98
- List <Constructor > whitelistConstructors , List <Method > whitelistMethods , List <Field > whitelistFields ) {
99
- this .origin = Objects .requireNonNull (origin );
100
- this .javaClassName = Objects .requireNonNull (javaClassName );
101
- this .onlyFQNJavaClassName = onlyFQNJavaClassName ;
102
-
103
- this .whitelistConstructors = Collections .unmodifiableList (Objects .requireNonNull (whitelistConstructors ));
104
- this .whitelistMethods = Collections .unmodifiableList (Objects .requireNonNull (whitelistMethods ));
105
- this .whitelistFields = Collections .unmodifiableList (Objects .requireNonNull (whitelistFields ));
106
- }
107
- }
108
-
109
- /**
110
- * Constructor represents the equivalent of a Java constructor available as a white-listed struct
111
- * constructor within Painless. Constructors for Painless structs may be accessed exactly as
112
- * constructors for Java classes are using the 'new' keyword. Painless structs may have multiple
113
- * constructors as long as they comply with arity overloading described for {@link Struct}.
114
- */
115
- public static final class Constructor {
116
-
117
- /** Information about where this constructor was white-listed from. Can be used for error messages. */
118
- public final String origin ;
119
-
120
- /**
121
- * A {@link List} of {@link String}s that are the Painless type names for the parameters of the
122
- * constructor which can be used to look up the Java constructor through reflection.
123
- */
124
- public final List <String > painlessParameterTypeNames ;
125
-
126
- /** Standard constructor. All values must be not {@code null}. */
127
- public Constructor (String origin , List <String > painlessParameterTypeNames ) {
128
- this .origin = Objects .requireNonNull (origin );
129
- this .painlessParameterTypeNames = Collections .unmodifiableList (Objects .requireNonNull (painlessParameterTypeNames ));
130
- }
131
- }
132
-
133
- /**
134
- * Method represents the equivalent of a Java method available as a white-listed struct method
135
- * within Painless. Methods for Painless structs may be accessed exactly as methods for Java classes
136
- * are using the '.' operator on an existing struct variable/field. Painless structs may have multiple
137
- * methods with the same name as long as they comply with arity overloading described for {@link Method}.
138
- *
139
- * Structs may also have additional methods that are not part of the Java class the struct represents -
140
- * these are known as augmented methods. An augmented method can be added to a struct as a part of any
141
- * Java class as long as the method is static and the first parameter of the method is the Java class
142
- * represented by the struct. Note that the augmented method's parent Java class does not need to be
143
- * white-listed.
144
- */
145
- public static class Method {
146
-
147
- /** Information about where this method was white-listed from. Can be used for error messages. */
148
- public final String origin ;
149
-
150
- /**
151
- * The Java class name for the owner of an augmented method. If the method is not augmented
152
- * this should be {@code null}.
153
- */
154
- public final String javaAugmentedClassName ;
155
-
156
- /** The Java method name used to look up the Java method through reflection. */
157
- public final String javaMethodName ;
158
-
159
- /**
160
- * The Painless type name for the return type of the method which can be used to look up the Java
161
- * method through reflection.
162
- */
163
- public final String painlessReturnTypeName ;
164
-
165
- /**
166
- * A {@link List} of {@link String}s that are the Painless type names for the parameters of the
167
- * method which can be used to look up the Java method through reflection.
168
- */
169
- public final List <String > painlessParameterTypeNames ;
170
-
171
- /**
172
- * Standard constructor. All values must be not {@code null} with the exception of jAugmentedClass;
173
- * jAugmentedClass will be {@code null} unless the method is augmented as described in the class documentation.
174
- */
175
- public Method (String origin , String javaAugmentedClassName , String javaMethodName ,
176
- String painlessReturnTypeName , List <String > painlessParameterTypeNames ) {
177
- this .origin = Objects .requireNonNull (origin );
178
- this .javaAugmentedClassName = javaAugmentedClassName ;
179
- this .javaMethodName = javaMethodName ;
180
- this .painlessReturnTypeName = Objects .requireNonNull (painlessReturnTypeName );
181
- this .painlessParameterTypeNames = Collections .unmodifiableList (Objects .requireNonNull (painlessParameterTypeNames ));
182
- }
183
- }
184
-
185
- /**
186
- * Field represents the equivalent of a Java field available as a white-listed struct field
187
- * within Painless. Fields for Painless structs may be accessed exactly as fields for Java classes
188
- * are using the '.' operator on an existing struct variable/field.
189
- */
190
- public static class Field {
191
-
192
- /** Information about where this method was white-listed from. Can be used for error messages. */
193
- public final String origin ;
194
-
195
- /** The Java field name used to look up the Java field through reflection. */
196
- public final String javaFieldName ;
197
-
198
- /** The Painless type name for the field which can be used to look up the Java field through reflection. */
199
- public final String painlessFieldTypeName ;
200
-
201
- /** Standard constructor. All values must be not {@code null}. */
202
- public Field (String origin , String javaFieldName , String painlessFieldTypeName ) {
203
- this .origin = Objects .requireNonNull (origin );
204
- this .javaFieldName = Objects .requireNonNull (javaFieldName );
205
- this .painlessFieldTypeName = Objects .requireNonNull (painlessFieldTypeName );
206
- }
207
- }
208
-
209
- /** The {@link ClassLoader} used to look up the white-listed Java classes, constructors, methods, and fields. */
58
+ /** The {@link ClassLoader} used to look up the whitelisted Java classes, constructors, methods, and fields. */
210
59
public final ClassLoader javaClassLoader ;
211
60
212
- /** The {@link List} of all the white-listed Painless structs . */
213
- public final List <Struct > whitelistStructs ;
61
+ /** The {@link List} of all the whitelisted Painless classes . */
62
+ public final List <WhitelistClass > whitelistStructs ;
214
63
215
64
/** Standard constructor. All values must be not {@code null}. */
216
- public Whitelist (ClassLoader javaClassLoader , List <Struct > whitelistStructs ) {
65
+ public Whitelist (ClassLoader javaClassLoader , List <WhitelistClass > whitelistStructs ) {
217
66
this .javaClassLoader = Objects .requireNonNull (javaClassLoader );
218
67
this .whitelistStructs = Collections .unmodifiableList (Objects .requireNonNull (whitelistStructs ));
219
68
}
0 commit comments