3333
3434import java .io .File ;
3535import java .io .FileNotFoundException ;
36- import java .io .IOException ;
3736import java .io .Reader ;
37+ import java .io .StringReader ;
38+ import java .util .ArrayList ;
3839import java .util .Collection ;
3940import java .util .List ;
4041import java .util .Map ;
@@ -83,13 +84,19 @@ public interface ScriptService extends SingletonService<ScriptLanguage>,
8384 * This method does the same thing as {@link #getInstances()}.
8485 * </p>
8586 */
86- List <ScriptLanguage > getLanguages ();
87+ default List <ScriptLanguage > getLanguages () {
88+ return new ArrayList <>(getIndex ());
89+ }
8790
8891 /** Gets the scripting language that handles the given file extension. */
89- ScriptLanguage getLanguageByExtension (String extension );
92+ default ScriptLanguage getLanguageByExtension (final String extension ) {
93+ return getIndex ().getByExtension (extension );
94+ }
9095
9196 /** Gets the scripting language with the given name. */
92- ScriptLanguage getLanguageByName (String name );
97+ default ScriptLanguage getLanguageByName (final String name ) {
98+ return getIndex ().getByName (name );
99+ }
93100
94101 // -- Scripts --
95102
@@ -180,8 +187,11 @@ Future<ScriptModule> run(File file, boolean process,
180187 * @return {@link Future} of the module instance being executed. Calling
181188 * {@link Future#get()} will block until execution is complete.
182189 */
183- Future <ScriptModule > run (String path , String script , boolean process ,
184- Object ... inputs ) throws IOException , ScriptException ;
190+ default Future <ScriptModule > run (final String path , final String script ,
191+ final boolean process , final Object ... inputs )
192+ {
193+ return run (path , new StringReader (script ), process , inputs );
194+ }
185195
186196 /**
187197 * Executes the given script.
@@ -201,8 +211,11 @@ Future<ScriptModule> run(String path, String script, boolean process,
201211 * @return {@link Future} of the module instance being executed. Calling
202212 * {@link Future#get()} will block until execution is complete.
203213 */
204- Future <ScriptModule > run (String path , String script , boolean process ,
205- Map <String , Object > inputMap ) throws IOException , ScriptException ;
214+ default Future <ScriptModule > run (final String path , final String script ,
215+ final boolean process , final Map <String , Object > inputMap )
216+ {
217+ return run (path , new StringReader (script ), process , inputMap );
218+ }
206219
207220 /**
208221 * Executes the given script.
@@ -224,8 +237,11 @@ Future<ScriptModule> run(String path, String script, boolean process,
224237 * @return {@link Future} of the module instance being executed. Calling
225238 * {@link Future#get()} will block until execution is complete.
226239 */
227- Future <ScriptModule > run (String path , Reader reader , boolean process ,
228- Object ... inputs ) throws IOException , ScriptException ;
240+ default Future <ScriptModule > run (final String path , final Reader reader ,
241+ final boolean process , final Object ... inputs )
242+ {
243+ return run (new ScriptInfo (getContext (), path , reader ), process , inputs );
244+ }
229245
230246 /**
231247 * Executes the given script.
@@ -245,8 +261,11 @@ Future<ScriptModule> run(String path, Reader reader, boolean process,
245261 * @return {@link Future} of the module instance being executed. Calling
246262 * {@link Future#get()} will block until execution is complete.
247263 */
248- Future <ScriptModule > run (String path , Reader reader , boolean process ,
249- Map <String , Object > inputMap ) throws IOException , ScriptException ;
264+ default Future <ScriptModule > run (final String path , final Reader reader ,
265+ final boolean process , final Map <String , Object > inputMap )
266+ {
267+ return run (new ScriptInfo (getContext (), path , reader ), process , inputMap );
268+ }
250269
251270 /**
252271 * Executes the given script.
@@ -286,18 +305,30 @@ Future<ScriptModule> run(ScriptInfo info, boolean process,
286305 Map <String , Object > inputMap );
287306
288307 /** TODO */
289- boolean canHandleFile (File file );
308+ default boolean canHandleFile (final File file ) {
309+ return getIndex ().canHandleFile (file );
310+ }
290311
291312 /** TODO */
292- boolean canHandleFile (String fileName );
313+ default boolean canHandleFile (final String fileName ) {
314+ return getIndex ().canHandleFile (fileName );
315+ }
293316
294317 /** TODO */
295- void addAlias (Class <?> type );
318+ default void addAlias (final Class <?> type ) {
319+ addAlias (type .getSimpleName (), type );
320+ }
296321
297322 /** TODO */
298323 void addAlias (String alias , Class <?> type );
299324
300325 /** TODO */
301326 Class <?> lookupClass (String typeName ) throws ScriptException ;
302327
328+ // -- PTService methods --
329+
330+ @ Override
331+ default Class <ScriptLanguage > getPluginType () {
332+ return ScriptLanguage .class ;
333+ }
303334}
0 commit comments