private ScriptEngine newScriptEngine(File file) throws ScriptException {
  String filename=file.getName();
  int index=filename.lastIndexOf('.');
  if ((index < 0) || (index >= filename.length() - 1)) {
    throw new ScriptException("file has no extension");
  }
  String extension=filename.substring(index + 1);
  ScriptEngineManager manager=new ScriptEngineManager();
  ScriptEngine engine=manager.getEngineByExtension(extension);
  if (engine == null) {
    throw new ScriptException("no scripting engine for extension ." + extension);
  }
  return engine;
}

private ScriptEngine newScriptEngine ( File file ) throws ScriptException { String filename = file . getName ( ) ; int index = filename . lastIndexOf ( '.' ) ; if ( ( index < 0 ) || ( index >= filename . length ( ) - 1 ) ) { throw new ScriptException ( "file has no extension" ) ; } String extension = filename . substring ( index + 1 ) ; ScriptEngineManager manager = new ScriptEngineManager ( ) ; ScriptEngine engine = manager . getEngineByExtension ( extension ) ; if ( engine == null ) { throw new ScriptException ( "no scripting engine for extension ." + extension ) ; } return engine ; }
returns a new scripting engine for the scripting language identified by the file name extension .
